コード例 #1
0
ファイル: Program.cs プロジェクト: SHWDTech/Unicom.Platform
 private static void AddToHistoryData(emsData data)
 {
     HistoryDatas.Add(data);
     if (HistoryDatas.Count > 1024)
     {
         HistoryDatas.RemoveRange(1024, HistoryDatas.Count - 1024);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: SHWDTech/Unicom.Platform
        private static void AddDeviceInfo(emsData emsData, string systemDeviceCode)
        {
            if (_dataSource == "web")
            {
                var info = SystemDevs[systemDeviceCode];
                emsData.devCode = info.UnicomDevCode;
                emsData.prjCode = info.StatCode;
                emsData.prjType = info.ProjectType;
                return;
            }
            var device = _context.FirstOrDefault <EmsDevice>($"SystemCode = {systemDeviceCode}");

            var project = _context.FirstOrDefault <EmsProject>($"code == '{device.projectCode}'");

            emsData.devCode = device.code;
            emsData.prjCode = project.code;
            emsData.prjType = project.prjType;
        }
コード例 #3
0
 public void UpdateNewData(emsData data, int statId, int devId, string country, int?statCodeUp)
 {
     using (var context = new EsMonitorModels())
     {
         var last = context.EsMin.FirstOrDefault(d => d.DevId == devId);
         if (last == null)
         {
             return;
         }
         last.TP            = data.dust;
         last.DB            = data.noise;
         last.Temperature   = data.temperature;
         last.Humidity      = data.humidity;
         last.WindDirection = data.windDirection;
         last.WindSpeed     = data.windSpeed;
         context.EsMin.AddOrUpdate(last);
         context.SaveChanges();
     }
 }
コード例 #4
0
 public void AddNewData(emsData data, int statId, int devId, string country, int?statCodeUp)
 {
     using (var context = new EsMonitorModels())
     {
         var newData = new T_ESMin
         {
             TP            = data.dust,
             DB            = data.noise,
             Temperature   = data.temperature,
             Humidity      = data.humidity,
             WindDirection = data.windDirection,
             WindSpeed     = data.windSpeed,
             Airpressure   = 0,
             DevId         = devId,
             StatId        = statId,
             Country       = country,
             StatCode      = statCodeUp,
             DataStatus    = "N"
         };
         context.EsMin.Add(newData);
         context.SaveChanges();
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: SHWDTech/Unicom.Platform
 private static void FixErrorData(emsData data)
 {
     if (data.noise <= 1)
     {
         data.noise = new Random().Next(40, 65);
     }
     if (data.temperature <= 1)
     {
         data.temperature = new Random().Next(150, 250) / 10.0f;
     }
     if (data.humidity <= 1)
     {
         data.humidity = new Random().Next(400, 750) / 10.0f;
     }
     if (data.windDirection <= 1)
     {
         data.windDirection = new Random().Next(0, 360);
     }
     if (data.windSpeed <= 0.01)
     {
         data.windSpeed = new Random().Next(0, 10) / 10.0f;
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: SHWDTech/Unicom.Platform
 private static void OutputError(resultData result, object devId, emsData emsData, EmsdataStatus status, DeviceInfomation device)
 {
     if (status == EmsdataStatus.NotFound)
     {
         _dataProvider.AddNewData(emsData, int.Parse(device.StatId), int.Parse(device.StatId), device.Country, device.StatUpCode);
     }
     else if (status == EmsdataStatus.Exceeded)
     {
         _dataProvider.UpdateNewData(emsData, int.Parse(device.StatId), int.Parse(device.StatId),
                                     device.Country, device.StatUpCode);
     }
     if (result.result.Length > 0)
     {
         foreach (var dataEntry in result.result)
         {
             Console.WriteLine($"Result Error=> devId:{devId} key:{dataEntry.key},value:{dataEntry.value}");
         }
     }
     else
     {
         Console.WriteLine($"发送数据成功,时间:{DateTime.Now:yyyy-MM-dd hh:mm:ss},设备Id:{devId},TP值:{emsData.dust}");
         AddToHistoryData(emsData);
     }
 }
コード例 #7
0
 public void UpdateNewData(emsData data, int statId, int devId, string country, int?statCodeUp)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: SHWDTech/Unicom.Platform
        private static void MinuteTimerCallBack(object state)
        {
            foreach (var device in _context.Devices)
            {
                try
                {
                    var devSystemCode = device.SystemCode;
                    var dev           = LoadDevInfo(devSystemCode);
                    if (!OnTransferDevices.Contains(dev.DevCode))
                    {
                        continue;
                    }
                    if (DeviceOnTransfer(devSystemCode))
                    {
                        var dataStatus = EmsdataStatus.Normal;
                        var emsData    = LoadLastData(dev.StatId, dev.DevCode);
                        if (emsData == null)
                        {
                            emsData = LoadFromHistoryData();
                            if (_notify)
                            {
                                NotifyServer.Notify(devSystemCode, $"设备分钟值取值失败,请检查设备状态,异常设备平台:{_platform},异常设备系统编码:{devSystemCode},设备名称:{dev.DevCode},设备所属工地名称:{dev.StatCode}");
                            }
                            dataStatus = EmsdataStatus.NotFound;
                        }
                        if (emsData == null)
                        {
                            emsData = new emsData
                            {
                                dateTime  = ConvertToUnixTime(DateTime.Now),
                                dustFlag  = "N",
                                humiFlag  = "N",
                                noiseFlag = "N"
                            };
                            dataStatus = EmsdataStatus.NotFound;
                        }
                        if (emsData.dust > 1)
                        {
                            if (_notify)
                            {
                                NotifyServer.ExceedNotify(devSystemCode, $"设备分钟值超标,请检查设备状态! 异常设备平台:{_platform},异常设备系统编码:{devSystemCode},设备名称:{dev.DevCode},设备所属工地名称:{dev.StatCode},超标值:{emsData.dust}");
                            }
                            emsData.dust = SpressDust(emsData.dust);
                            dataStatus   = EmsdataStatus.Exceeded;
                        }
                        else if (emsData.dust < 0.01 && NeedRandomData(dev.DevCode, out var dust))
                        {
                            emsData.dust = GetGenerator(dust.DevSystemCode).NewValue();
                        }
                        AddDeviceInfo(emsData, devSystemCode);
                        FixErrorData(emsData);
                        var result = Service.PushRealTimeData(new[] { emsData });
                        OutputError(result, devSystemCode, emsData, dataStatus, dev);
                    }
                    else
                    {
                        var deviceCode = OnTransferDevices.FirstOrDefault(obj => obj.Equals(devSystemCode));
                        if (deviceCode != null)
                        {
                            OnTransferDevices.Remove(deviceCode);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogService.Instance.Error("发送数据失败!", ex);
                }
            }

            AddMinuteTask(null);
        }