首页 新闻 搜索 专区 学院

定时推送不成功

0
悬赏园豆:5 [已解决问题] 解决于 2014-01-15 13:07

添加了一条定时推送的信息,里面有个过期时间的字段,我做的功能的意思就是:根据过期时间字段,来定时推送信息到客户端,

这是global里面的信息,

我不知道是不是少写了东西还是怎么,就是没有推送,我也不知道怎么调试,哪位大侠给支点招

问题补充:

我找到问题的所在了,应该是数据获取不到,所以,才不会推送,这是我获取数据的代码,不知道哪里出问题了,就是获取不到数据

protected List<Domain.Entity.PushContents> GetAutoPushContentTrueState(
            Infrastructure.Data.Uow.EfRepository<Domain.Entity.AutoPush> autoPushRepository,
            Infrastructure.Data.Uow.EfRepository<Domain.Entity.AutoPushDetail> autoPushdetailRepository,
            Infrastructure.Data.Uow.EfRepository<Domain.Entity.AutoPushTimer> autoPushTimerRepository,
            Infrastructure.Data.Uow.EfRepository<Domain.Entity.PushContents> contentRepository)
        {
            var now = System.DateTime.Now;
            var hour = now.Hour;
            var minute = now.Minute;
            var data = (from auto in autoPushRepository.GetList()
                        join detail in autoPushdetailRepository.GetList() on auto.Id equals detail.AutoPushId
                        join timer in autoPushTimerRepository.GetList() on detail.TimerId equals timer.Id
                        join content in contentRepository.GetList() on auto.ContentId equals content.Id
                        where auto.State == true
                        && (
                            (
                            auto.ExpiredDateTime >= now &&
                            (
                            //9.30-12.30 9.40(在),9.12(不在)
                                (hour == timer.BeginHour && minute >= timer.BeninMinute) ||
                            //9.30-12.30 10.20(在),11.20(在)
                                (hour > timer.BeginHour && hour < timer.EndHour) ||
                            //9.30-12.30 12.30(在),12.40(不在)
                                (hour == timer.EndHour && minute <= timer.EndMinute))
                            ) || (
                            //精确到分就行了,
                            //auto.IntervalTime <= 0 && timer.BeginHour == hour && timer.BeninMinute == minute
                            auto.IntervalTime <= 0 &&
                            //
                            auto.ExpiredDateTime.Year == now.Year &&
                            //
                            auto.ExpiredDateTime.Month == now.Month &&
                            //
                            auto.ExpiredDateTime.Day == now.Day &&
                            //
                            auto.ExpiredDateTime.Hour == now.Hour &&
                            //
                            auto.ExpiredDateTime.Minute == now.Minute
                            )
                        )
                        select content).Distinct();

            return data.ToList();
        }
View Code

运行出来的那条sql语句是这样的

{SELECT 
[Distinct1].[Id] AS [Id], 
[Distinct1].[Content] AS [Content], 
[Distinct1].[ExpiredDateTime] AS [ExpiredDateTime], 
[Distinct1].[AddTime] AS [AddTime], 
[Distinct1].[IpAddress] AS [IpAddress], 
[Distinct1].[State] AS [State], 
[Distinct1].[SortNum] AS [SortNum]
FROM ( SELECT DISTINCT 
    [Extent4].[Id] AS [Id], 
    [Extent4].[Content] AS [Content], 
    [Extent4].[ExpiredDateTime] AS [ExpiredDateTime], 
    [Extent4].[AddTime] AS [AddTime], 
    [Extent4].[IpAddress] AS [IpAddress], 
    [Extent4].[State] AS [State], 
    [Extent4].[SortNum] AS [SortNum]
    FROM   (SELECT [Extent1].[ContentId] AS [ContentId], [Extent1].[IntervalTime] AS [IntervalTime], [Extent1].[ExpiredDateTime] AS [ExpiredDateTime], [Extent3].[BeginHour] AS [BeginHour], [Extent3].[EndHour] AS [EndHour], [Extent3].[BeninMinute] AS [BeninMinute], [Extent3].[EndMinute] AS [EndMinute]
        FROM   [dbo].[AutoPush] AS [Extent1]
        INNER JOIN [dbo].[AutoPushDetail] AS [Extent2] ON [Extent1].[Id] = [Extent2].[AutoPushId]
        INNER JOIN [dbo].[AutoPushTimer] AS [Extent3] ON [Extent2].[TimerId] = [Extent3].[Id]
        WHERE 1 = [Extent1].[State] ) AS [Filter1]
    INNER JOIN [dbo].[PushContents] AS [Extent4] ON [Filter1].[ContentId] = [Extent4].[Id]
    WHERE (([Filter1].[ExpiredDateTime] >= @p__linq__0) AND (((@p__linq__1 = [Filter1].[BeginHour]) AND (@p__linq__2 >= [Filter1].[BeninMinute])) OR ((@p__linq__3 > [Filter1].[BeginHour]) AND (@p__linq__4 < [Filter1].[EndHour])) OR ((@p__linq__5 = [Filter1].[EndHour]) AND (@p__linq__6 <= [Filter1].[EndMinute])))) OR (([Filter1].[IntervalTime] <= 0) AND ((DATEPART (year, [Filter1].[ExpiredDateTime])) = (DATEPART (year, @p__linq__7))) AND ((DATEPART (month, [Filter1].[ExpiredDateTime])) = (DATEPART (month, @p__linq__8))) AND ((DATEPART (day, [Filter1].[ExpiredDateTime])) = (DATEPART (day, @p__linq__9))) AND ((DATEPART (hour, [Filter1].[ExpiredDateTime])) = (DATEPART (hour, @p__linq__10))) AND ((DATEPART (minute, [Filter1].[ExpiredDateTime])) = (DATEPART (minute, @p__linq__11))))
)  AS [Distinct1]}
View Code

我觉得应该是处理过期时间与现在时间的比较上面出问题了,但是,我不知道应该怎么写,上面的代码都贴出来了,希望大家帮我看看,在这里我致以真诚的谢意。。。

魔女小溪的主页 魔女小溪 | 初学一级 | 园豆:38
提问于:2014-01-14 15:16
< >
分享
最佳答案
0

首先确定 TimerPush 已经被调用,然后检查 TimerPush 中的实现推送的代码是否调用成功。

收获园豆:5
Launcher | 高人七级 |园豆:45045 | 2014-01-14 15:36

就是不知道怎么调试,因为是定时的嘛,我是菜鸟,(*^__^*) 嘻嘻……

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 15:39

@魔女小溪: 你把推送的代码贴出来。

Launcher | 园豆:45045 (高人七级) | 2014-01-14 15:40

@魔女小溪: 关键代码应该是这句:opt.PushMessage(pOpts);

因此,它具体是怎么实现推送的我不知道,你看看它的 SDK 文档是怎么描述的。

Launcher | 园豆:45045 (高人七级) | 2014-01-14 15:50

@Launcher: 我就是不知道怎么去调试,所以,看不到到底执行到哪步了,哎。。。你有什么办法调试这个定时的推送吗?

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 15:51

@魔女小溪: 很简单,你写个控制台程序,把代码放到控制台程序中调试。

Launcher | 园豆:45045 (高人七级) | 2014-01-14 15:52

@Launcher: 我手动推送都行,就是定时推送不行,感觉上没有执行似的,所以,就想调试一下,但是,不知道怎么调试这定时的推送

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 15:52

@魔女小溪: //创建推送的信息
                    BaiduPushExtension opt=new BaiduPushExtension("POST", sk);
                    String messages = "";
                    String method = "push_msg";
                    TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
                    uint device_type = 3;
                    uint unixTime = (uint)ts.TotalSeconds;
                    uint message_type=1;
                    string messageksy = "xxxxxx";
                  
                    BaiduPushNotification notification = new BaiduPushNotification();
                    notification.title ="";
                    notification.description=content.Content;
                    messages = notification.getJsonString();

                     PushOptions pOpts =
                        new PushOptions(method, ak, device_type, messages, messageksy, unixTime);
                    pOpts.message_type = message_type;
                    string response = opt.PushMessage(pOpts);
                 
                    sysLog.ShortMessage = "Notification Queued!";
                    sysLog.FullMessage = "Notification Queued! " + response;

 

把这段代码放到一个页面的 load 中去执行。

Launcher | 园豆:45045 (高人七级) | 2014-01-14 15:54

@Launcher: 你是说,怀疑推送这块出问题了,而不是定时那块出错?但是,我手动推送用的都是这些呀?呜呜,怎么调试?

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:01

@魔女小溪: 调试-附加到进程,找到在 IIS 运行的进程。

Launcher | 园豆:45045 (高人七级) | 2014-01-14 16:04

@Launcher: 恩呢

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:07

@Launcher:什么时候点击调试,是不是快要到定时的时间点,才点击调试,还有就是点击调试以后,在点击那个附加到进程,还是?

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:24

@魔女小溪: 不用点击调试,直接附加,附加后它就进入调试状态了

Launcher | 园豆:45045 (高人七级) | 2014-01-14 16:35

@Launcher: 我有点弄不懂了,是要点击调试下面的附加进程这个按钮,然后呢?

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:42

@魔女小溪: “调试”-〉“附加到进程”

Launcher | 园豆:45045 (高人七级) | 2014-01-14 16:43

@Launcher: 然后呢?

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:45

@Launcher: 呵呵,知道了,然后就是找到运行的程序的IIs托管,附加进去就可以调试了

魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 16:55
其他回答(2)
0

timer.start写了没?

undefined | 园豆:698 (小虾三级) | 2014-01-14 15:31

这不是System.Trimer,是System.threading下面的Trimer

支持(0) 反对(0) 魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 15:33
0

Web里用Timer看似不太靠谱。。。用Thread试一试吧。记得try

路过秋天 | 园豆:4746 (老鸟四级) | 2014-01-14 15:32

确实不靠谱, 没准会回收. 但是lz说一次都没成功过, 还是五分钟这么少的时间, 十有八九是没start

支持(0) 反对(0) undefined | 园豆:698 (小虾三级) | 2014-01-14 15:33

用的就是System.threading下面的Trimer

支持(0) 反对(0) 魔女小溪 | 园豆:38 (初学一级) | 2014-01-14 15:34

我想了一下, Thread也不靠谱. 应用程序池一回收, 啥都没有了. 必须找个普通的进程跑啊

支持(0) 反对(0) undefined | 园豆:698 (小虾三级) | 2014-01-14 15:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册