public void ProcVehicleInfo(object sender, StanMsgHandlerArgs handler)
        {
            var bytes = handler.Message.Data;

            //var workItem = new BackgroundWorkItem
            //    (app, bytes);
            //app.BackgroundWork_ProcessVhPositionUpdate.triggerBackgroundWork("ProcVehicleInfo", workItem);

            sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(bytes);

            app.ObjCacheManager.PutVehicle(vh_info);
        }
        public void PutVehicle(sc.ProtocolFormat.OHTMessage.VEHICLE_INFO new_vh)
        {
            if (new_vh == null)
            {
                return;
            }
            AVEHICLE vh = Vehicles.Where(v => v.VEHICLE_ID == new_vh.VEHICLEID.Trim()).SingleOrDefault();

            vh.set(new_vh);
            vh.NotifyVhPositionChange();
            vh.NotifyVhStatusChange();
            VehicleUpdateComplete?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 3
0
        public void doWork(string workKey, BackgroundWorkItem item)
        {
            try
            {
                byte[]             bytes = item.Param[1] as byte[];
                WindownApplication app   = item.Param[0] as WindownApplication;

                sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(bytes);
                app.ObjCacheManager.PutVehicle(vh_info);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
        }
        public void loadVhHistoricalInfo()
        {
            string[] file_rows_data = File.ReadAllLines(@"C:\LogFiles\OHxC\VehicleHistoricalInfo.log", System.Text.Encoding.Default);


            BlockingCollection <Vo.VehicleHistoricalInfo> listTemp = new BlockingCollection <Vo.VehicleHistoricalInfo>();

            Parallel.For(0, file_rows_data.Count(), rowCount =>
            {
                Vo.VehicleHistoricalInfo Historyinfo = new Vo.VehicleHistoricalInfo();
                MatchCollection matches = Regex.Matches(file_rows_data[rowCount], pattern);
                string sTime            = matches.Count > 0 ? matches[0].Value.Replace("[", "").Replace("]", "") : string.Empty;
                string sVh_ID           = matches.Count > 1 ? matches[1].Value.Replace("[", "").Replace("]", "") : string.Empty;
                string sRaw_data        = matches.Count > 2 ? matches[2].Value.Replace("[", "").Replace("]", "") : string.Empty;
                DateTime parseDateTime  = default(DateTime);
                if (!DateTime.TryParseExact
                        (sTime, sc.App.SCAppConstants.DateTimeFormat_23, CultureInfo.InvariantCulture, DateTimeStyles.None, out parseDateTime))
                {
                    logger.Warn($"{nameof(sTime)} parse fail. value{sTime}");
                }
                byte[] vh_info_bytes = Common.WinFromUtility.unCompressString(sRaw_data);
                sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(vh_info_bytes);
                Historyinfo.Time   = parseDateTime;
                Historyinfo.ID     = sVh_ID;
                Historyinfo.VhInfo = vh_info;
                listTemp.Add(Historyinfo);
                // 每處理幾筆就停止5ms
                if (rowCount != 0 && rowCount % 20000 == 0)
                {
                    System.Threading.SpinWait.SpinUntil(() => false, 5);
                }
            });
            vh_historical_infos = listTemp.OrderBy(info => info.Time).ToList();
            StartPlayTime       = vh_historical_infos.First().Time;
            var groupResult = from vh_historical_info in vh_historical_infos
                              group vh_historical_info by vh_historical_info.Time;

            Vh_Historical_Info_GroupByTime = groupResult.OrderBy(infos => infos.Key).ToDictionary
                                                 (infos => infos.Key, infos => infos.ToList());
            currentPlayIndex = 0;

            //foreach (var info in vh_historical_infos)
            //{
            //    Console.WriteLine(info.VhInfo.ToString());
            //}
        }
        public static void set(this sc.AVEHICLE vh, sc.ProtocolFormat.OHTMessage.VEHICLE_INFO new_vh)
        {
            int vh_type    = (int)new_vh.VEHICLETYPE;
            int cmd_type   = (int)new_vh.CmdType;
            int cmd_status = (int)new_vh.VhCMDStatus;

            vh.isTcpIpConnect = new_vh.IsTcpIpConnect;
            vh.VEHICLE_TYPE   = (sc.E_VH_TYPE)vh_type;
            vh.CUR_ADR_ID     = new_vh.CURADRID;
            vh.CUR_SEC_ID     = new_vh.CURSECID;
            //vh.SEC_ENTRY_TIME = new_vh.SEC_ENTRY_TIME;
            vh.ACC_SEC_DIST = new_vh.ACCSECDIST;
            vh.MODE_STATUS  = new_vh.MODESTATUS;
            vh.ACT_STATUS   = new_vh.ACTSTATUS;
            vh.MCS_CMD      = new_vh.MCSCMD;
            if (!SCUtility.isMatche(vh.OHTC_CMD, new_vh.OHTCCMD))
            {
                vh.OHTC_CMD = new_vh.OHTCCMD;
                vh.NotifyVhExcuteCMDStatusChange();
            }
            vh.PauseStatus       = new_vh.PauseStatus;
            vh.BLOCK_PAUSE       = new_vh.BLOCKPAUSE;
            vh.CMD_PAUSE         = new_vh.CMDPAUSE;
            vh.OBS_PAUSE         = new_vh.OBSPAUSE;
            vh.HID_PAUSE         = new_vh.HIDPAUSE;
            vh.SAFETY_DOOR_PAUSE = new_vh.SAFETYDOORPAUSE;
            vh.EARTHQUAKE_PAUSE  = new_vh.EARTHQUAKEPAUSE;
            vh.ERROR             = new_vh.ERROR;
            vh.OBS_DIST          = new_vh.OBSDIST;
            vh.HAS_CST           = new_vh.HASCST;
            vh.CST_ID            = new_vh.CSTID;
            //vh.UPD_TIME = new_vh.UPDTIME;
            vh.VEHICLE_ACC_DIST = new_vh.VEHICLEACCDIST;
            vh.MANT_ACC_DIST    = new_vh.MANTACCDIST;
            //vh.MANT_DATE = new_vh.MANTDATE;
            vh.GRIP_COUNT      = new_vh.GRIPCOUNT;
            vh.GRIP_MANT_COUNT = new_vh.GRIPMANTCOUNT;
            //   vh.GRIP_MANT_DATE = new_vh.GRIPMANTDATE;
            //vh.NODE_ADR = new_vh.NODE_ADR;
            vh.IS_PARKING = new_vh.ISPARKING;
            //   vh.PARK_TIME = new_vh.PARKTIME;
            vh.PARK_ADR_ID = new_vh.PARKADRID;
            vh.IS_CYCLING  = new_vh.ISCYCLING;
            //  vh.CYCLERUN_TIME = new_vh.CYCLERUNTIME;
            vh.CYCLERUN_ID = new_vh.CYCLERUNID;

            vh.PredictPath  = new_vh.PredictPath.ToArray();
            vh.CyclingPath  = new_vh.CyclingPath.ToArray();
            vh.startAdr     = new_vh.StartAdr;
            vh.FromAdr      = new_vh.FromAdr;
            vh.ToAdr        = new_vh.ToAdr;
            vh.CMD_Priority = new_vh.CMDPRIOTITY;
            vh.CMD_CST_ID   = new_vh.CMDCSTID;
            vh.Speed        = new_vh.Speed;

            vh.ObsVehicleID        = new_vh.ObsVehicleID;
            vh.Alarms              = new_vh.Alarms.ToList();
            vh.CmdType             = (sc.E_CMD_TYPE)cmd_type;
            vh.vh_CMD_Status       = (sc.E_CMD_STATUS)cmd_status;
            vh.VhRecentTranEvent   = new_vh.VhRecentTranEvent;
            vh.WillPassSectionID   = new_vh.WillPassSectionID.ToList();
            vh.procProgress_Percen = new_vh.ProcProgressPercen;
            vh.State    = new_vh.State;
            vh.UPD_TIME = (new DateTime(1970, 1, 1, 0, 0, 0)).AddHours(8).AddSeconds(new_vh.UPDTIME.Seconds);
        }
 public void ProcVehicleInfo(sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_obj)
 {
     app.ObjCacheManager.PutVehicle(vh_obj);
 }
        public void loadVhHistoricalInfo(DateTime start_time, DateTime end_time)
        {
            var node = new Uri($"http://{Common.ElasticSearchManager.ELASTIC_URL}:9200");
            // var node = new Uri("http://192.168.9.211:9200");
            var settings = new ConnectionSettings(node).DefaultIndex("default");

            settings.DisableDirectStreaming();
            var client = new ElasticClient(settings);
            //SearchRequest sr = new SearchRequest("ohtc-test-objecthistoricalinfo*");
            SearchRequest  sr = new SearchRequest("mfoht100-ohtc1-objecthistoricalinfo*");
            DateRangeQuery dq = new DateRangeQuery
            {
                Field       = "@timestamp",
                GreaterThan = start_time,
                LessThan    = end_time,
            };
            //TermsQuery tsq = new TermsQuery
            //{
            //};
            int startIndex     = 0;
            int eachSearchSize = 9999;
            List <ObjectHistricalInfo> object_infos = new List <ObjectHistricalInfo>();

            do
            {
                sr.From = startIndex;
                sr.Size = eachSearchSize;
                dq      = new DateRangeQuery
                {
                    Field       = "@timestamp",
                    GreaterThan = start_time,
                    LessThan    = end_time,
                };
                sr.Query  = dq;
                sr.Source = new SourceFilter()
                {
                    Includes = new string[] { "@timestamp", "OBJECT_ID", "RAWDATA" },
                };

                var result = client.Search <ObjectHistricalInfo>(sr);
                if (result.Documents.Count == 0)
                {
                    break;
                }
                var result_info = result.Documents.OrderBy(info => info.timestamp);
                object_infos.AddRange(result_info.ToList());
                // if (object_infos.Count >= result.Total) break;
                //startIndex += eachSearchSize;
                if (result.Documents.Count < eachSearchSize)
                {
                    break;
                }

                start_time = result_info.Last().timestamp.AddMilliseconds(1);
            }while (true);
            if (object_infos.Count == 0)
            {
                return;
            }
            BlockingCollection <Vo.VehicleHistoricalInfo> listTemp = new BlockingCollection <Vo.VehicleHistoricalInfo>();

            Parallel.For(0, object_infos.Count(), rowCount =>
            {
                Vo.VehicleHistoricalInfo Historyinfo = new Vo.VehicleHistoricalInfo();
                DateTime Time    = object_infos[rowCount].timestamp;
                string sVh_ID    = object_infos[rowCount].OBJECT_ID;
                string sRaw_data = object_infos[rowCount].RAWDATA;

                byte[] vh_info_bytes = Common.WinFromUtility.unCompressString(sRaw_data);
                sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(vh_info_bytes);
                Historyinfo.Time   = Time.ToLocalTime();
                Historyinfo.ID     = sVh_ID;
                Historyinfo.VhInfo = vh_info;
                listTemp.Add(Historyinfo);
                // 每處理幾筆就停止5ms
                if (rowCount != 0 && rowCount % 20000 == 0)
                {
                    System.Threading.SpinWait.SpinUntil(() => false, 5);
                }
            });
            vh_historical_infos = listTemp.OrderBy(info => info.Time).ToList();
            StartPlayTime       = vh_historical_infos.First().Time;
            var groupResult = from vh_historical_info in vh_historical_infos
                              group vh_historical_info by vh_historical_info.Time;

            Vh_Historical_Info_GroupByTime = groupResult.OrderBy(infos => infos.Key).ToDictionary
                                                 (infos => infos.Key, infos => infos.ToList());
            startIndex = 0;


            LoadComplete?.Invoke(this, Vh_Historical_Info_GroupByTime);
            //foreach (var info in vh_historical_infos)
            //{
            //    Console.WriteLine(info.VhInfo.ToString());
            //}
        }