/// <summary>
        /// 更新或新建Tracker的基本信息
        /// </summary>
        private void UpdateTrackerInfo(TX300 tx300, AsyncUserDataBuffer data, TrackerBLL bll)
        {
            var sim     = GetSimFromData(tx300);
            var tracker = bll.Find(f => f.SimCard.Equals(sim));

            if (null == tracker)
            {
                // 新增一个tracker
                tracker              = bll.GetObject();
                tracker.SimCard      = sim;
                tracker.LastActionAt = data.ReceiveTime;
                tracker.Socket       = data.SocketHandle;
                tracker.State        = 1;
                bll.Add(tracker);
            }
            else
            {
                bll.Update(f => f.id == tracker.id, act =>
                {
                    act.LastActionAt = data.ReceiveTime;
                    act.Socket       = data.SocketHandle;
                    if (tx300.CommandID == 0x7020 || tx300.CommandID == 0x7030 || tx300.CommandID == 0x7040)
                    {
                        act.CSQ = tx300.MsgContent[0];
                    }
                });
            }
        }
Example #2
0
        /// <summary>
        /// 添加或查询相同device id的tracker
        /// </summary>
        /// <param name="device"></param>
        /// <returns>返回具有相同device id的tracker或新建一个tracker</returns>
        private TB_Tracker addTracker(string device, TrackerBLL bll)
        {
            if (string.IsNullOrEmpty(device))
            {
                return(null);
            }

            var tracker = bll.Find(f => f.DeviceId.Equals(device) && f.Deleted == false);

            if (null == tracker)
            {
                if (string.IsNullOrEmpty(TrackerNumberPrefix))
                {
                    TrackerNumberPrefix = ConfigurationManager.AppSettings["TRACKER_NUMBER_PREFIX"];
                }
                // 生成一个新的tracker并与当前账户绑定
                tracker = bll.FindList <TB_Tracker>(f => f.SimCard.StartsWith(TrackerNumberPrefix) && f.Deleted == false, "SimCard", true).FirstOrDefault();
                string number;
                if (null == tracker)
                {
                    number = TrackerNumberPrefix + "0000";
                }
                else
                {
                    var old = int.Parse(tracker.SimCard) + 1;
                    number = old.ToString();
                }
                tracker          = bll.GetObject();
                tracker.SimCard  = number;
                tracker.DeviceId = device;
                tracker          = bll.Add(tracker);
                // 保存tracker绑定历史记录
                SaveHistory(new TB_AccountHistory()
                {
                    Account  = null,
                    ActionId = new ActionBLL().Find(f => f.Name.Equals("AddNewTracker")).id,
                    ObjectA  = string.Format("tracker: {0}, device: {1}", tracker.SimCard, tracker.DeviceId)
                });
                return(tracker);
            }
            return(tracker);
        }