Esempio n. 1
0
        //测试数据方法
        public Task Execute2(IJobExecutionContext context)
        {
            Console.WriteLine("PopSend任务调度");
            LogWrite.WriteLogInfo("PopSend任务调度");
            #region 测试

            var stockSignalSingles          = MongoService.GetAllStockSignalSingle();
            var model1                      = stockSignalSingles.FindLast(m => m.code == "000001");
            var model2                      = stockSignalSingles.FindLast(m => m.code == "600000");
            var model3                      = stockSignalSingles.FindLast(m => m.code == "000063");
            var model4                      = stockSignalSingles.FindLast(m => m.code == "603999");
            var model5                      = stockSignalSingles.FindLast(m => m.code == "603998");
            List <stock_signal_single> list = new List <stock_signal_single>
            {
                model1, model2, model3, model4, model5
            };
            foreach (var online in InitService.GetOnlineCache())
            {
                var memoryCacheManager = new MemoryCacheManager();
                var cacheUserId        = memoryCacheManager.Get <string>(online);
                Console.WriteLine($"signal:{online}-userId:{cacheUserId}");
                var cacheCodeList = memoryCacheManager.Get <List <string> >(cacheUserId);
                foreach (var s in cacheCodeList)
                {
                    Console.WriteLine($"user:{cacheUserId}-codeList{s}");
                }

                var cacheCodeList1 = memoryCacheManager.Get <List <string> >($"push{online}");
                Console.WriteLine($"signal:push{online}-codeList{cacheCodeList1.Count}");
                var codeList = InitService.GetOnlineCodeList(online);
                //signalNowList和codeList取交集
                var nowCodeList = list.Select(m => m.code).ToList();
                //得到了交集
                if (codeList == null || codeList.Count <= 0 || nowCodeList.Count <= 0)
                {
                    continue;
                }
                var intersect = codeList.Intersect(nowCodeList).ToList();
                if (intersect.Count <= 0)
                {
                    continue;
                }
                //构建推送架构
                List <HashPop> hashPops = MongoService.CreatePopList(list, intersect);
                if (hashPops == null || hashPops.Count <= 0)
                {
                    continue;
                }
                Console.WriteLine($"信号推送:用户{online},信号{hashPops.Count}");
                //                LogWrite.WriteLogInfo("---------信号推送start-------------");
                //                LogWrite.WriteLogInfo($"用户:{online}");
                //                foreach (var pop in hashPops)
                //                {
                //                    LogWrite.WriteLogInfo($"信号代码:{pop.Code}");
                //                }
                //                LogWrite.WriteLogInfo("---------信号推送end-------------");
                GlobalHost.ConnectionManager.GetHubContext <SignalHub>().Clients
                .User(online)
                .alert_signal(hashPops);
            }

            #endregion
            return(Task.FromResult(0));
        }