コード例 #1
0
        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 List <SensorAcqResult>();

            rslt1.Add(new SensorAcqResult()
            {
                Data = new SensorData(new double[] { 65, 45, 87 }, new double[] { 12, 23, 56 }, new double[] { 65, 45, 87 })
            });
            rslt1[0].ErrorCode = 1;
            DacTaskResultConsumerService.OnDacTaskResultProduced(rslt1);
            //Thread.Sleep(8000);
            Console.WriteLine("source: {0}", rslt1[0].ErrorCode);
            Assert.AreNotEqual(7, rslt1[0].ErrorCode);


            //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
ファイル: EtController.cs プロジェクト: icprog/FS-SMISCloud
        public EtController(Service.Service service)
        {
            this.dataStatusJudge = new DataStatusJudge(service);

            if (GlobalConfig.ConnectionString == null)
            {
                throw new Exception("GlobalConfig.ConnectionString is null");
            }

            if (GlobalConfig.DataSourcePath == null)
            {
                throw new Exception("GlobalConfig.DataSourcePath is null");
            }

            if (GlobalConfig.ErrorFilePath == null)
            {
                throw new Exception("GlobalConfig.ErrorFilePath is null");
            }
            if (!Directory.Exists(GlobalConfig.ErrorFilePath))
            {
                Directory.CreateDirectory(GlobalConfig.ErrorFilePath);
            }

            if (GlobalConfig.ParsedFilePath == null)
            {
                throw new Exception("GlobalConfig.ParsedFilePath is null");
            }
            if (!Directory.Exists(GlobalConfig.ParsedFilePath))
            {
                Directory.CreateDirectory(GlobalConfig.ParsedFilePath);
            }

            DacTaskResultConsumerService.Init();
            Log.Info("ET init success, scaning file to consume");
        }
コード例 #3
0
 public void Init()
 {
     DacTaskResultConsumerService.RegisterConsumer("test", typeof(DataAnalyzer));
     DacTaskResultConsumerService.RegisterConsumer("C1", typeof(C1));
     DacTaskResultConsumerService.RegisterConsumer("C2", typeof(C2));
     DacTaskResultConsumerService.RegisterConsumer("C3", typeof(C3));
     DacTaskResultConsumerService.RegisterConsumer("CE", typeof(Ce));
     DacTaskResultConsumerService.Queues.Clear();
 }
コード例 #4
0
        public void TestInit()
        {
            DacTaskResultConsumerService.Init();

            Assert.AreEqual(
                DacTaskResultConsumerService.GetConsumer("DataAnalyzer").GetType().ToString(),
                "FS.SMIS_Cloud.DAC.DataAnalyzer.DataAnalyzer");

            Assert.AreEqual(
                DacTaskResultConsumerService.GetConsumer("DataAnalyzer").GetType(),
                DacTaskResultConsumerService.Queues[0][5].GetType());
        }
コード例 #5
0
ファイル: EtController.cs プロジェクト: icprog/FS-SMISCloud
        public void DoFileParseWork()
        {
            var files = new DirectoryInfo(GlobalConfig.DataSourcePath).GetFiles();

            if (files.Length == 0)
            {
                return;
            }
            Log.InfoFormat("{0} files is found to parse, start..", files.Length);
            var sw = new Stopwatch();

            sw.Start();
            int count = 0;

            foreach (FileInfo file in files)
            {
                try
                {
                    lock (FileLock)
                    {
                        if (ProcessiongFiles.Exists(f => f == file.FullName))
                        {
                            return;
                        }

                        ProcessiongFiles.Add(file.FullName);
                    }

                    var data     = new List <SensorAcqResult>();
                    var hasError = false;
                    lock (LockObj)
                    {
                        if (IsExiting)
                        {
                            return;
                        }
                    }
                    Log.InfoFormat("parsing file: {0}", file.FullName);
                    // 扫描数据
                    using (var fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        using (var sr = new StreamReader(fs))
                        {
                            var line = 1;
                            while (sr.Peek() > -1)
                            {
                                string s      = sr.ReadLine();
                                var    parser = new JsonParser();
                                try
                                {
                                    var rslt = parser.Parse(s);
                                    if (this.dataStatusJudge.JudgeDataStatusIsOk(rslt))
                                    {
                                        var sensorId = rslt.Sensor.SensorID;
                                        rslt.Sensor = DbAccessor.DbConfigAccessor.GetSensorInfo(sensorId);
                                        data.Add(rslt);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Log.Error(
                                        string.Format("file: {0},line: {1},json parse error", file.Name, line),
                                        e);
                                    hasError = true;
                                }
                                line++;
                            }
                        }
                        var filePath = file.FullName;
                        var fileName = file.Name;
                        lock (LockObj)
                        {
                            if (IsExiting)
                            {
                                return;
                            }
                            Log.InfoFormat("parsing file: {0} end, send to consumers", file.FullName);
                            var consumeTask = new Task(
                                () =>
                            {
                                var task = DacTaskResultConsumerService.OnDacTaskResultProduced(data);
                                task.ContinueWith(
                                    t =>
                                {
                                    hasError = hasError || t.Exception != null;
                                    ArchiveDataFile(hasError, fileName, filePath);
                                    Log.InfoFormat("consume file: {0} end", filePath);
                                    lock (FileLock)
                                    {
                                        ProcessiongFiles.Remove(filePath);
                                    }
                                }).Wait();
                            });
                            tasks.Add(consumeTask);
                            consumeTask.Start();
                            consumeTask.ContinueWith(
                                t =>
                            {
                                lock (LockObj)
                                {
                                    tasks.Remove(t);
                                }
                            });
                        }
                        count++;
                    }
                }
                catch (IOException e)
                {
                    Log.Warn(string.Format("file:{0} is being opened", file.Name), e);
                }
                catch (Exception e)
                {
                    Log.Error(string.Format("unknow exception when open file:{0}", file.Name), e);
                }
            }

            sw.Stop();
            Log.InfoFormat(
                "{0} files has parsed in {1} seconds, error: {2}",
                count,
                sw.Elapsed.TotalSeconds,
                files.Length - count);
        }
コード例 #6
0
 public void TestGetConsumer()
 {
     Assert.AreEqual(
         "FS.SMIS_Cloud.DAC.DataAnalyzer.DataAnalyzer",
         DacTaskResultConsumerService.GetConsumer("test").GetType().ToString());
 }
コード例 #7
0
 public void TestRegisterConsumer()
 {
     Assert.IsNotNull(DacTaskResultConsumerService.GetConsumer("test"));
 }