コード例 #1
0
ファイル: ConsumerTester.cs プロジェクト: icprog/FS-SMISCloud
        public void TestAsyncQueueInvoke()
        {
            var syncQueue = new DACTaskResultConsumerQueue(ConsumeType.Async);

            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C1"));
            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C2"));
            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C3"));

            DACTaskResultConsumerService.AddComsumerQueue(syncQueue);

            var rslt1 = new DACTaskResult();

            rslt1.ErrorMsg = "队列1";
            DACTaskResultConsumerService.OnDacTaskResultProduced(rslt1);
            //Thread.Sleep(8000);
            Console.WriteLine("source: {0}", rslt1.ErrorMsg);
            Assert.AreNotEqual("C---1C---2C---3", rslt1.ErrorMsg);


            var rslt2 = new DACTaskResult();

            rslt2.ErrorMsg = "队列2";
            DACTaskResultConsumerService.OnDacTaskResultProduced(rslt2);
            //Thread.Sleep(8000);
            Console.WriteLine("source: {0}", rslt2.ErrorMsg);
            Assert.AreNotEqual("C---1C---2C---3", rslt2.ErrorMsg);
            Thread.Sleep(5000);
        }
コード例 #2
0
ファイル: ConsumerTester.cs プロジェクト: icprog/FS-SMISCloud
        public void TestSyncQueueInvoke()
        {
            var syncQueue = new DACTaskResultConsumerQueue(ConsumeType.Sync);

            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C1"));
            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C2"));
            syncQueue.Enqueue(DACTaskResultConsumerService.GetConsumer("C3"));

            DACTaskResultConsumerService.AddComsumerQueue(syncQueue);

            var rslt1 = new DACTaskResult();

            rslt1.AddSensorResult(new SensorAcqResult()
            {
                Data = new Gps3dData(65, 45, 87, 12, 23, 56)
            });
            rslt1.ErrorMsg = "队列1";
            DACTaskResultConsumerService.OnDacTaskResultProduced(rslt1);
            //Thread.Sleep(8000);
            Console.WriteLine("source: {0}", rslt1.ErrorMsg);
            Assert.AreNotEqual("C---1C---2C---3", rslt1.ErrorMsg);


            //var rslt2 = new DACTaskResult();
            //rslt2.ErrorMsg = "队列2";
            //DACTaskResultConsumerService.OnDacTaskResultProduced(rslt2);
            ////Thread.Sleep(8000);
            //Console.WriteLine("source: {0}", rslt2.ErrorMsg);
            //Assert.AreNotEqual("C---1C---2C---3", rslt2.ErrorMsg);
            Thread.Sleep(5000);
        }
コード例 #3
0
        public EtService(string svrConfig, string busPath)
            : base(MyName, svrConfig, busPath)
        {
            string cs            = ConfigurationManager.AppSettings["SecureCloud"];
            int    dacServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["Port"], 10);

            Log.InfoFormat("DBConnecting: {0}", cs);
            try
            {
                DbAccessorHelper.Init(new MsDbAccessor(cs)); // 配置
                DACTaskResultConsumerService.Init();         // 消费
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("系统初始化失败:{0}", ex.Message);
                return;
            }

            etDataStatus = new EtDataStatusConsumer(this);
            // 自定义消费者
            if (DACTaskResultConsumerService.Queues.Count == 0)
            {
                var queue = new DACTaskResultConsumerQueue(ConsumeType.Async);
                queue.Enqueue(etDataStatus);
                DACTaskResultConsumerService.AddComsumerQueue(queue);
            }
            else
            {
                DACTaskResultConsumerService.InsertComsumer(0, 2, etDataStatus);
                //DACTaskResultConsumerService.Queues[0].Insert(etDataStatus, 1);
            }

            _warningHelper = new WarningHelper();
            _dacServer     = new GprsDtuServer(dacServerPort);
            _fileServer    = new FileDtuServer();
            Dtm            = new DACTaskManager(_dacServer, DbAccessorHelper.DbAccessor.QueryDtuNodes(), null); // DbAccessorHelper.DbAccessor.GetUnfinishedTasks()
            Dtm.SetFileServer(_fileServer);
            // Push/Pull mode.
            Pull(null, OnMessageReceived);
            Response(ResponseHandler);
            Subscribe("cm", "/cm/datachanged/dtu/sensor/", OnSubscribed);
            ConsoleCtrlManager.Instance.RegCmd("reload", LoadHandler); // 注册重新加载传感器信息
            ConsoleCtrlManager.Instance.Exit += Instance_Exit;
            _warningHelper.UpdateAllDtuStatus();
        }