Esempio n. 1
0
        public void Execute(IJobExecutionContext context)
        {
            string jobname     = "handleusermessagesetting";
            int    maxpkid     = 0;
            var    checkresult = HandleExpiredMessageBoxJob.CheckIsOpenWithDescription(jobname);

            if (!checkresult.Item1)
            {
                Logger.Info("开关已关 return");
            }

            var navigations = SelectAllMessageNavigationTypesAsync();

            int.TryParse(checkresult.Item2, out maxpkid);
            int count = 0;

            while (true)
            {
                count++;
                Logger.Info($"开始刷新第{count}批次");
                checkresult = HandleExpiredMessageBoxJob.CheckIsOpenWithDescription(jobname);
                if (!checkresult.Item1)
                {
                    Logger.Info("开关已关 return");
                }
                int.TryParse(checkresult.Item2, out maxpkid);
                var results = SelectUserMessageSetting(maxpkid);
                if (results != null && results.Any())
                {
                    Parallel.ForEach(results, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 3
                    }, setting =>
                    {
                        try
                        {
                            string topname = navigations.FirstOrDefault(x => x.PkId == setting.MessageNavigationType)?.PushAlias;
                            if (!string.IsNullOrEmpty(topname))
                            {
                                using (var client = new Tuhu.Service.Push.MessageBoxPushClient())
                                {
                                    var result = client.SubscribeUserMessageSwitchInfo(setting);
                                    result.ThrowIfException(true);
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            Logger.Warn("HandleUserMessageSettingJob ex=>" + ex);
                        }
                    });
                    HandleExpiredMessageBoxJob.UpdateRunTimeSwitchDescription(jobname,
                                                                              results.Max(x => x.PkId).ToString());
                    Logger.Info($"结束刷新第{count}批次");
                }
                else
                {
                    break;
                }
            }
            Logger.Info($"刷新结束");
        }
        public void Execute(IJobExecutionContext context)
        {
            string jobname     = "SubscribeAllUserTokens";
            var    checkresult = HandleExpiredMessageBoxJob.CheckIsOpenWithDescription(jobname);

            if (!checkresult.Item1)
            {
                Logger.Info("开关已关 return");
            }
            int count = 0;

            while (true)
            {
                count++;
                Logger.Info($"开始刷新第{count}批次");
                checkresult = HandleExpiredMessageBoxJob.CheckIsOpenWithDescription(jobname);
                if (!checkresult.Item1)
                {
                    Logger.Info("开关已关 return");
                }
                int maxpkid = 0;
                int.TryParse(checkresult.Item2, out maxpkid);
                var results    = SelectDeviceInfos(maxpkid);
                var topicnames = SelectAllTopicNames();
                if (results != null && results.Any())
                {
                    var tokens = ParseTargets(results, 900);
                    Parallel.ForEach(tokens, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 4,
                        TaskScheduler          = TaskScheduler.Default
                    }, t =>
                    {
                        try
                        {
                            var iostokens = t.Where(x =>
                                                    string.Equals(x.Platform, "ios", StringComparison.OrdinalIgnoreCase));
                            var androidtokens = t.Where(x =>
                                                        string.Equals(x.Platform, "android", StringComparison.OrdinalIgnoreCase));

                            foreach (var topicname in topicnames)
                            {
                                if (iostokens.Any())
                                {
                                    using (var client = new Tuhu.Service.Push.TemplatePushClient())
                                    {
                                        var result = client.SubscribeByRegids(iostokens.Select(x => x.Token), topicname, DeviceType.iOS);
                                        Logger.Info($"第{count}批次 ios结果{result.Result}");
                                    }
                                }
                                if (androidtokens.Any())
                                {
                                    using (var client = new Tuhu.Service.Push.TemplatePushClient())
                                    {
                                        var result = client.SubscribeByRegids(androidtokens.Select(x => x.Token), topicname, DeviceType.Android);
                                        Logger.Info($"第{count}批次 android结果{result.Result}");
                                    }
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            Logger.Warn("HandleUserMessageSettingJob ex=>" + ex);
                        }
                    });
                    HandleExpiredMessageBoxJob.UpdateRunTimeSwitchDescription(jobname, results.Max(x => x.PKID).ToString());
                    Logger.Info($"结束刷新第{count}批次");
                }
                else
                {
                    break;
                }
            }
            Logger.Info($"刷新结束");
        }