Esempio n. 1
0
        public static DbModel.Location.Data.LocationCardPosition ToDbModel(
            this Location.TModel.Location.Data.TagPosition item1)
        {
            if (item1 == null)
            {
                return(null);
            }
            var item2 = new DbModel.Location.Data.LocationCardPosition();

            item2.Id            = item1.Tag;
            item2.X             = item1.X;
            item2.Y             = item1.Y;
            item2.Z             = item1.Z;
            item2.DateTime      = TimeConvert.TimeStampToDateTime(item1.Time);
            item2.DateTimeStamp = item1.Time;
            item2.Power         = item1.Power;
            item2.Number        = item1.Number;
            item2.Flag          = item1.Flag;
            item2.Archors       = item1.Archors;
            item2.AreaId        = item1.AreaId;
            item2.AreaState     = item1.AreaState;
            item2.PowerState    = item1.PowerState;
            item2.MoveState     = item1.MoveState;
            return(item2);
        }
Esempio n. 2
0
        public void SetTime()
        {
            DateTime now = DateTime.Now;

            DateTimeStamp = TimeConvert.DateTimeToTimeStamp(now);
            DateTime now2 = TimeConvert.TimeStampToDateTime(DateTimeStamp);
        }
Esempio n. 3
0
        /// <summary>Handles a message.</summary>
        public void HandleMessage(IMessage message)
        {
            string msg  = Encoding.UTF8.GetString(message.Body);
            events recv = JsonConvert.DeserializeObject <events>(msg);

            if (recv == null || recv.deviceId == null)
            {
                return;
            }

            DevInfo di = bll.DevInfos.DbSet.Where(p => p.Abutment_Id == recv.deviceId).FirstOrDefault();

            if (di == null)
            {
                return;
            }

            DevAlarm da    = bll.DevAlarms.DbSet.Where(p => p.Abutment_Id == recv.id).FirstOrDefault();
            int      nFlag = 0;

            if (da == null)
            {
                da    = new DevAlarm();
                nFlag = 1;
            }

            da.Abutment_Id    = recv.id;
            da.Title          = recv.title;
            da.Msg            = recv.msg;
            da.Level          = (Abutment_DevAlarmLevel)recv.level;
            da.Code           = recv.code;
            da.Src            = (Abutment_DevAlarmSrc)recv.src;
            da.DevInfoId      = di.Id;
            da.Device_desc    = recv.deviceDesc;
            da.AlarmTime      = TimeConvert.TimeStampToDateTime(recv.t / 1000);
            da.AlarmTimeStamp = recv.t;

            if (nFlag == 1)
            {
                bll.DevAlarms.Add(da);
            }
            else
            {
                bll.DevAlarms.Edit(da);
            }

            OnDevAlarmReceived(da);
            return;
        }
Esempio n. 4
0
        public bool Parse(string info)
        {
            try
            {
                string[] parts  = info.Split(',');
                int      length = parts.Length;
                if (length <= 1)
                {
                    return(false);            //心跳包回拨
                }
                Code     = parts[0];
                X        = float.Parse(parts[1]); //平面位置
                Z        = float.Parse(parts[2]); //平面位置
                Y        = float.Parse(parts[3]); //高度位置,为了和Unity坐标信息一致,Y为高度轴
                Time     = long.Parse(parts[4]);
                DateTime = TimeConvert.TimeStampToDateTime(Time / 1000);

                if (length > 5)
                {
                    Power = int.Parse(parts[5]);
                }
                if (length > 6)
                {
                    Number = int.Parse(parts[6]);
                }
                if (length > 7)
                {
                    Flag = parts[7];
                }
                if (length > 8)
                {
                    Archors = parts[8].Split('@').ToList();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
        }
Esempio n. 5
0
        public bool Parse(string info)
        {
            try
            {
                string[] parts  = info.Split(',');
                int      length = parts.Length;
                if (length <= 1)
                {
                    return(false);            //心跳包回拨
                }
                Tag      = parts[0];
                X        = double.Parse(parts[1]);
                Y        = double.Parse(parts[2]);
                Z        = double.Parse(parts[3]);
                Time     = long.Parse(parts[4]);
                DateTime = TimeConvert.TimeStampToDateTime(Time / 1000);

                if (length > 4)
                {
                    Power = int.Parse(parts[5]);
                }
                if (length > 5)
                {
                    Number = int.Parse(parts[6]);
                }
                if (length > 6)
                {
                    Flag = parts[7];
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
        }
        /// <summary>
        /// 获取门禁卡操作历史
        /// </summary>
        /// <param name="id"></param>
        /// <param name="begin_date"></param>
        /// <param name="end_date"></param>
        /// <returns></returns>
        public BaseTran <cards_actions> GetSingleCardActionHistory(int id, string begin_date, string end_date)
        {
            BaseTran <cards_actions> recv = new BaseTran <cards_actions>();

            try
            {
                string path = "api/cards/" + Convert.ToString(id) + "/actions";
                string url  = BaseUri + path;
                if (begin_date != null)
                {
                    url += "?begin_date=" + begin_date;
                }
                else
                {
                    url += "?begin_date";
                }

                if (end_date != null)
                {
                    url += "&end_date=" + end_date;
                }
                else
                {
                    url += "&end_date";
                }

                recv = GetEntityList <cards_actions>(url);

                if (recv.data == null)
                {
                    recv.data = new List <cards_actions>();
                }

                EntranceGuardCard egc = bll.EntranceGuardCards.DbSet.FirstOrDefault(p => p.Abutment_Id == id);

                if (egc != null)
                {
                    foreach (cards_actions item in recv.data)
                    {
                        DevEntranceGuardCardAction degca = bll.DevEntranceGuardCardActions.DbSet.FirstOrDefault(p => p.Abutment_Id == item.id);
                        DevInfo devinfo = bll.DevInfos.DbSet.FirstOrDefault(p => p.Abutment_Id == item.device_id);
                        if (devinfo == null)
                        {
                            continue;
                        }

                        int nFlag = 0;
                        if (degca == null)
                        {
                            degca             = new DevEntranceGuardCardAction();
                            degca.OperateTime = null;
                            nFlag             = 1;
                        }

                        degca.Abutment_Id         = item.id;
                        degca.DevInfoId           = devinfo.Id;
                        degca.EntranceGuardCardId = egc.Id;
                        degca.code             = item.code;
                        degca.description      = item.description;
                        degca.OperateTimeStamp = item.t;
                        degca.nInOutState      = 0;

                        if (item.t != null)
                        {
                            long t = (long)item.t;
                            degca.OperateTime = TimeConvert.TimeStampToDateTime(t);
                        }

                        if (nFlag == 1)
                        {
                            bll.DevEntranceGuardCardActions.Add(degca);
                        }
                        else
                        {
                            bll.DevEntranceGuardCardActions.Edit(degca);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string messgae = ex.Message;
            }

            return(recv);
        }
        /// <summary>
        /// 获取告警事件列表
        /// </summary>
        /// <param name="src"></param>
        /// <param name="level"></param>
        /// <param name="begin_t"></param>
        /// <param name="end_t"></param>
        /// <returns></returns>
        public BaseTran <events> GeteventsList(int?src, int?level, long?begin_t, long?end_t)
        {
            BaseTran <events> recv = new BaseTran <events>();

            try
            {
                string path = "api/events";
                string url  = BaseUri + path;
                if (src != null)
                {
                    url += "?src=" + Convert.ToString(src);
                }
                else
                {
                    url += "?src";
                }

                if (level != null)
                {
                    url += "&level=" + Convert.ToString(level);
                }
                else
                {
                    url += "&level";
                }

                if (begin_t != null && end_t != null)
                {
                    url += "&begin_t=" + Convert.ToString(begin_t) + "&end_t=" + Convert.ToString(end_t);
                }
                else
                {
                    url += "&begin_t" + "&end_t";
                }

                recv = GetEntityList <events>(url);

                if (recv.data == null)
                {
                    recv.data = new List <events>();
                }

                foreach (events item in recv.data)
                {
                    if (item.device_id == null)
                    {
                        continue;
                    }

                    DevInfo di = bll.DevInfos.DbSet.Where(p => p.Abutment_Id == item.device_id).FirstOrDefault();
                    if (di == null)
                    {
                        continue;
                    }

                    DevAlarm da    = bll.DevAlarms.DbSet.Where(p => p.Abutment_Id == item.id).FirstOrDefault();
                    int      nFlag = 0;
                    if (da == null)
                    {
                        da    = new DevAlarm();
                        nFlag = 1;
                    }

                    da.Abutment_Id    = item.id;
                    da.Title          = item.title;
                    da.Msg            = item.msg;
                    da.Level          = (Abutment_DevAlarmLevel)item.level;
                    da.Code           = item.code;
                    da.Src            = (Abutment_DevAlarmSrc)item.src;
                    da.DevInfoId      = di.Id;
                    da.Device_desc    = item.device_desc;
                    da.AlarmTime      = TimeConvert.TimeStampToDateTime(item.t);
                    da.AlarmTimeStamp = item.t;

                    if (nFlag == 1)
                    {
                        bll.DevAlarms.Add(da);
                    }
                    else
                    {
                        bll.DevAlarms.Edit(da);
                    }
                }
            }
            catch (Exception ex)
            {
                string messgae = ex.Message;
            }

            return(recv);
        }
Esempio n. 8
0
        private void DealPatrolPointItem(Bll bll, List <InspectionTrack> All, List <InspectionTrackHistory> HAdd, List <PatrolPoint> PAll, List <PatrolPoint> PDelete, List <PatrolPointHistory> PHAdd, WebApiLib.Clients.BaseDataClient client)
        {
            try
            {
                List <PatrolPointItem>        ppiList  = bll.PatrolPointItems.ToList();
                List <PatrolPointItemHistory> ppiHList = bll.PatrolPointItemHistorys.ToList();
                if (ppiList == null)
                {
                    ppiList = new List <PatrolPointItem>();
                }

                if (ppiHList == null)
                {
                    ppiHList = new List <PatrolPointItemHistory>();
                }

                List <PatrolPointItem>        PIAll    = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIAdd    = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIEdit   = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIDelete = new List <PatrolPointItem>();
                List <PatrolPointItemHistory> PIHAdd   = new List <PatrolPointItemHistory>();


                foreach (PatrolPoint item in PAll)
                {
                    int             Id       = item.Id;
                    string          deviceId = item.DeviceId;
                    int             ParentId = item.ParentId;
                    InspectionTrack it       = All.Find(p => p.Id == ParentId);
                    if (it == null)
                    {
                        continue;
                    }

                    int patrolId = (int)it.Abutment_Id;
                    CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId);
                    if (recv == null || recv.checks.Count() <= 0)
                    {
                        continue;
                    }

                    foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks)
                    {
                        PatrolPointItem now = ppiList.Find(p => p.CheckId == item2.checkId && p.ParentId == Id);

                        if (now == null)
                        {
                            now             = new PatrolPointItem();
                            now.ParentId    = Id;
                            now.KksCode     = item2.kksCode;
                            now.CheckItem   = item2.checkItem;
                            now.StaffCode   = item2.staffCode;
                            now.CheckTime   = null;
                            now.dtCheckTime = null;
                            if (item2.checkTime != null)
                            {
                                now.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime);
                            }
                            now.CheckId     = item2.checkId;
                            now.CheckResult = item2.checkResult;
                            PIAdd.Add(now);
                        }
                        else
                        {
                            if (item2.checkTime != null)
                            {
                                now.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime);
                            }

                            now.CheckResult = item2.checkResult;
                            PIEdit.Add(now);
                        }
                    }
                }

                foreach (PatrolPoint item in PDelete)
                {
                    int Id = item.Id;
                    List <PatrolPointItem> lstDelete = ppiList.FindAll(p => p.ParentId == Id).ToList();
                    if (lstDelete != null && lstDelete.Count() > 0)
                    {
                        PIDelete.AddRange(lstDelete);
                    }
                }

                foreach (PatrolPointHistory item in PHAdd)
                {
                    int    Id                  = item.Id;
                    string deviceId            = item.DeviceId;
                    int    ParentId            = item.ParentId;
                    InspectionTrackHistory ith = HAdd.Find(p => p.Id == ParentId);
                    if (ith == null)
                    {
                        continue;
                    }

                    int patrolId = (int)ith.Abutment_Id;
                    CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId);
                    if (recv == null || recv.checks.Count() <= 0)
                    {
                        continue;
                    }

                    foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks)
                    {
                        PatrolPointItemHistory history = bll.PatrolPointItemHistorys.Find(p => p.CheckId == item2.checkId && p.ParentId == Id);

                        if (history == null)
                        {
                            history             = new PatrolPointItemHistory();
                            history.ParentId    = Id;
                            history.KksCode     = item2.kksCode;
                            history.CheckItem   = item2.checkItem;
                            history.StaffCode   = item2.staffCode;
                            history.CheckTime   = null;
                            history.dtCheckTime = null;
                            if (item2.checkTime != null)
                            {
                                history.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                history.dtCheckTime = TimeConvert.TimeStampToDateTime((long)history.CheckTime);
                            }
                            history.CheckId     = item2.checkId;
                            history.CheckResult = item2.checkResult;
                            PIHAdd.Add(history);
                        }
                    }
                }

                bll.PatrolPointItems.AddRange(PIAdd);
                bll.PatrolPointItems.EditRange(PIEdit);
                bll.PatrolPointItems.RemoveList(PIDelete);
                bll.PatrolPointItemHistorys.AddRange(PIHAdd);
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return;
        }
Esempio n. 9
0
        private bool DealInspectionTrack(BaseDataClient client, DateTime dtBegin, DateTime dtEnd, bool bFlag)
        {
            List <InspectionTrack>        All    = new List <InspectionTrack>();
            List <InspectionTrack>        Add    = new List <InspectionTrack>();
            List <InspectionTrack>        Edit   = new List <InspectionTrack>();
            List <InspectionTrack>        Delete = new List <InspectionTrack>();
            List <InspectionTrackHistory> HAdd   = new List <InspectionTrackHistory>();

            long lBegin = TimeConvert.DateTimeToTimeStamp(dtBegin) / 1000;
            long lEnd   = TimeConvert.DateTimeToTimeStamp(dtEnd) / 1000;
            var  recv   = client.Getinspectionlist(lBegin, lEnd, true);

            if (recv == null)
            {
                return(false);
            }

            Bll bll = new Bll(false, false, true, false);//第三参数要设置为true
            List <InspectionTrack> itList = bll.InspectionTracks.ToList();

            if (itList == null)
            {
                itList = new List <InspectionTrack>();
            }

            List <InspectionTrackHistory> itHList = bll.InspectionTrackHistorys.ToList();

            if (itHList == null)
            {
                itHList = new List <InspectionTrackHistory>(0);
            }

            foreach (patrols item in recv)
            {
                InspectionTrack        now     = itList.Find(p => p.Abutment_Id == item.id);
                InspectionTrackHistory history = itHList.Find(p => p.Abutment_Id == item.id);

                if (item.state == "新建" || item.state == "已下达" || item.state == "执行中")
                {
                    if (now == null)
                    {
                        now = new InspectionTrack();

                        now.Abutment_Id  = item.id;
                        now.Code         = item.code;
                        now.Name         = item.name;
                        now.CreateTime   = (item.createTime + nEightHourSecond) * 1000;
                        now.dtCreateTime = TimeConvert.TimeStampToDateTime(now.CreateTime);
                        now.State        = item.state;
                        now.StartTime    = (item.startTime + nEightHourSecond) * 1000;
                        now.dtStartTime  = TimeConvert.TimeStampToDateTime(now.StartTime);
                        now.EndTime      = (item.endTime + nEightHourSecond) * 1000;
                        now.dtEndTime    = TimeConvert.TimeStampToDateTime(now.EndTime);
                        Add.Add(now);
                    }
                    else
                    {
                        now.State = item.state;
                        Edit.Add(now);
                    }
                }
                else
                {
                    if (now != null)
                    {
                        Delete.Add(now);
                    }

                    if (history == null)
                    {
                        history = new InspectionTrackHistory();

                        history.Abutment_Id  = item.id;
                        history.Code         = item.code;
                        history.Name         = item.name;
                        history.CreateTime   = (item.createTime + nEightHourSecond) * 1000;
                        history.dtCreateTime = TimeConvert.TimeStampToDateTime(history.CreateTime);
                        history.State        = item.state;
                        history.StartTime    = (item.startTime + nEightHourSecond) * 1000;
                        history.dtStartTime  = TimeConvert.TimeStampToDateTime(history.StartTime);
                        history.EndTime      = (item.endTime + nEightHourSecond) * 1000;
                        history.dtEndTime    = TimeConvert.TimeStampToDateTime(history.EndTime);

                        HAdd.Add(history);
                    }
                }
            }

            bll.InspectionTracks.AddRange(Add);
            bll.InspectionTracks.EditRange(Edit);
            bll.InspectionTracks.RemoveList(Delete);
            bll.InspectionTrackHistorys.AddRange(HAdd);

            All.AddRange(Add);
            All.AddRange(Edit);
            DealPatrolPoint(bll, All, Delete, HAdd, client);

            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// 解析位置信息
        /// </summary>
        /// <param name="info"></param>
        /// <param name="offsetX">偏移量X 和定位引擎约定好具体偏移数值</param>
        /// <param name="offsetY">偏移量Y 和定位引擎约定好具体偏移数值</param>
        /// <returns></returns>
        public bool Parse(string info, float offsetX, float offsetY)
        {
            try
            {
                _info = info;
                string[] parts  = info.Split(new[] { ',' });
                int      length = parts.Length;
                if (length <= 1)
                {
                    return(false);            //心跳包回拨
                }
                Code = parts[0];
                if (Code.StartsWith("1"))
                {
                    LogEvent.Info("Code.StartsWith(1):" + info);
                }
                if (parts[1] == "-1.#IND0")
                {
                    parts[1] = "-1.0";
                }
                if (parts[2] == "-1.#IND0")
                {
                    parts[2] = "-1.0";
                }
                float x = parts[1].ToFloat();
                float y = parts[2].ToFloat();
                if (x < offsetX)
                {
                    X = x + offsetX; //平面位置
                    Z = y + offsetY; //平面位置
                }
                else //模拟数据是可以没有偏移量的 看模拟程序的版本
                {
                    X = x;
                    Z = y;
                }

                Y             = parts[3].ToFloat();//高度位置,为了和Unity坐标信息一致,Y为高度轴
                DateTimeStamp = parts[4].ToLong();
                DateTime      = TimeConvert.TimeStampToDateTime(DateTimeStamp);
                //TimeSpan time1 = DateTime.Now - DateTime;
                //long DateTimeStamp2 = TimeConvert.DateTimeToTimeStamp(DateTime);
                if (length > 5)
                {
                    Power = parts[5].ToInt();
                }
                if (length > 6)
                {
                    Number = parts[6].ToInt();
                }
                if (length > 7)
                {
                    Flag = parts[7];
                }
                if (length > 8)
                {
                    ArchorsText = parts[8];
                    Archors     = ArchorsText.Split(new [] { '@' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    if (Archors.Count > 1)
                    {
                        Console.Write("Archors.Count > 1");
                    }
                    IsSimulate = ArchorsText == "@0000" || string.IsNullOrEmpty(ArchorsText);
                }

                if (Power >= 400)
                {
                    PowerState = 0;
                }
                else
                {
                    PowerState = 1;
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogEvent.Info(ex.ToString());
                return(false);
            }
        }