Ejemplo n.º 1
0
 public void ResetDevice(Model.Entity.Device device)
 {
     device.UserId           = 0;
     device.ContactVersionNO = 0;
     device.SetVersionNO     = 0;
     device.State            = 2;
     device.OperatorType     = 0;
     device.SmsNumber        = null;
     device.SmsBalanceKey    = null;
     device.SmsFlowKey       = null;
     device.Photo            = null;
     device.BabyName         = null;
     device.PhoneCornet      = null;
     device.Gender           = false;
     device.Birthday         = null;
     device.Grade            = 0;
     device.SchoolAddress    = null;
     device.SchoolLat        = null;
     device.SchoolLng        = null;
     device.HomeAddress      = null;
     device.HomeLat          = null;
     device.HomeLng          = null;
     device.ActiveDate       = null;
     device.IsGuard          = false;
     device.Password         = null;
     device.UpdateTime       = DateTime.Now;
     if (device.CloudPlatform == 0)
     {
         device.PhoneNumber = null;
     }
 }
Ejemplo n.º 2
0
        public void CleanRelation(int deviceId)
        {
            if (_dictionaryByDeviceId.ContainsKey(deviceId))
            {
                if (_dictionaryByDeviceId.ContainsKey(deviceId))
                {
                    Model.Entity.Device device = Get(deviceId);
                    _dictionaryByDeviceId[deviceId].IsGuard = false;
                    lock (device)
                    {
                        DeviceContact.GetInstance().CleanByDeviceId(deviceId);  //删除联系人
                        GeoFence.GetInstence().CleanByDeviceId(deviceId);       //删除电子围栏
                        SchoolGuardian.GetInstance().CleanByDeviceId(deviceId); //删除上学守护
                        DeviceSet.GetInstance().Del(deviceId);                  //删除配置信息

                        //删除绑定号用户
                        User.GetInstance().DelByBindNumber(device.BindNumber);
                        User.GetInstance().DelReal(device.UserId);
                        UserDevice.GetInstance().DelDevice(deviceId); //删除关联信息

                        //清理消息
                        Notification.GetInstance().CleanByDeviceId(deviceId);
                        DeviceException.GetInstance().CleanByDeviceId(deviceId);
                        DeviceSMS.GetInstance().CleanByDeviceId(deviceId);
                        DeviceVoice.GetInstance().CleanByDeviceId(deviceId);
                        DevicePhoto.GetInstance().CleanByDeviceId(deviceId);
                        DeviceState.GetInstance().CleanByDeviceId(deviceId);
                        DeviceFriend.GetInstance().DelDevice(deviceId);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private bool SyncE23AgentNumbers(Model.Entity.DeviceContact contact, Model.Entity.Device device, int opt)
        {
            if (opt == 2)
            {
                return(true);
            }

            try
            {
                var url     = "http://ask.968824.com/api/callback.aspx?calla={0}&callb={1}&zjh1={2}&zjh2={3}&tcid=27951224&dlname=1009";
                var client  = new RestClient(string.Format(url, device.PhoneNumber, contact.PhoneNumber, contact.AgentNumber, contact.CallOutNumber));
                var request = new RestRequest(Method.GET);
                request.Timeout          = 5000;
                request.ReadWriteTimeout = 5000;
                var    response = client.Execute <JObject>(request);
                string code     = null;
                string tips     = null;
                try
                {
                    var json = response.Data;
                    if (json == null)
                    {
                        json = JObject.Parse(response.Content);
                    }

                    code = Utils.GetJObjVal(json["code"]);
                    tips = Utils.GetJObjVal(json["tips"]);
                }
#pragma warning disable CS0168 // 声明了变量“e”,但从未使用过
                catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”,但从未使用过
                {
                    Logger.Error("同步E23中间号接口输入json无效:" + response.Content);
                }

                if ("0".Equals(code) || (response.Content != null && response.Content.Contains("\"0\"")))
                {
                    return(true);
                }

                Logger.Error("同步E23中间号失败:" + tips + " Contact:" + contact + " Device:" + device);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error("同步E23中间号失败,异常:" + " Contact:" + contact + " Device:" + device, e);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int deviceId)
        {
            Models.User         user   = BLL.Authorize.GetUser();
            Model.Entity.Device device = BLL.Client.Get(user.Server).ManageGetDevice(user.LoginId, deviceId);
            if (user.Dealer.DealerType < 3)
            {
                ViewBag.EditEnable = 0;
            }
            else
            {
                ViewBag.EditEnable = 1;
            }

            ViewBag.User = user;
            return(View(device));
        }
Ejemplo n.º 5
0
        private void ProcessSync(object obj)
        {
            Thread.Sleep(100);
            object[] paras = (object[])obj;
            Model.Entity.DeviceContact contact = (Model.Entity.DeviceContact)paras[0];
            int opt = (int)paras[1];

            Model.Entity.Device device = Device.GetInstance().Get(contact.DeviceID);
//            Logger.Info("开始同步通讯录绑定关系,DeviceID:" + device.DeviceID + " Platform:" + device.CloudPlatform);
            if (device == null || string.IsNullOrEmpty(device.PhoneNumber) || string.IsNullOrEmpty(contact.AgentNumber) || string.IsNullOrEmpty(contact.CallOutNumber))
            {
                Logger.Error("设备异常,不用同步!DeviceContactId:" + contact.DeviceContactId);
                return;
            }

            bool res = false;

            switch (device.CloudPlatform)
            {
            case 2:
            {
                res = SyncAgentNumber(contact, device, device.PhoneNumber, contact.PhoneNumber, contact.AgentNumber, contact.CallOutNumber, opt);
                Logger.Error("同步通讯录绑定关系(手表打手机):" + contact.DeviceContactId + (res ? "成功!" : "失败!"));
                if (res)
                {
                    res = SyncAgentNumber(contact, device, contact.PhoneNumber, device.PhoneNumber, contact.CallOutNumber, contact.AgentNumber, opt);
                    Logger.Error("同步通讯录绑定关系(手机打手表):" + contact.DeviceContactId + (res ? "成功!" : "失败!"));
                }

                break;
            }

            case 1:
            case 3:
            case 4:
            {
                res = SyncE23AgentNumbers(contact, device, opt);
                break;
            }
            }

            if (res && opt != 2)
            {
                contact.Sync = 1;
                Save(contact, true);
            }
        }
Ejemplo n.º 6
0
        private bool SyncAgentNumber(Model.Entity.DeviceContact contact, Model.Entity.Device device, string callerNum, string calledNum, string callInMidNum, string callOutMidNum, int opt)
        {
            try
            {
                SetBindNum sbn = new SetBindNum();
                sbn.header.SERVICENAME = "setBindNum";
                sbn.header.OPERATE     = opt;
                CloudPlatformInfo cpi   = AgentNumber.GetInstance().GetCloudPlatformInfo(2);
                string            time  = DateTime.Now.ToString("yyyyMMddHHmmss");
                string            token = MD5Helper.MD5Encrypt(cpi.Key + time, null);
                sbn.header.TOKEN = token.ToLower();
                sbn.header.VCCID = int.Parse(cpi.VccId);

                sbn.body.TYPE         = 1;
                sbn.body.STREAMNUMBER = Guid.NewGuid().ToString();
                sbn.body.MESSAGEID    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                sbn.body.WAYBILLNUM   = "";
                sbn.body.CALLERNUM    = callerNum;
                sbn.body.MIDDLEINNUM  = callInMidNum;
                sbn.body.MIDDLEOUTNUM = callOutMidNum;
                sbn.body.CALLEDNUM    = calledNum;
                sbn.body.MAXDURATION  = 3600;
                sbn.body.ISRECORD     = 0;
                sbn.body.STATE        = 0;
                sbn.body.VALIDTIME    = "";

                var client = new RestClient(cpi.UrlNumberAnalysis);
                client.AddHandler("application/json", new CommAnalysisResponseDeserializer());
                var request = new RestRequest(Method.POST);
                request.AddJsonBody(sbn);
                request.Timeout          = 5000;
                request.ReadWriteTimeout = 5000;
                JsonSerializer jsonSerializer = new JsonSerializer {
                    ContentType = "application/json"
                };
                request.JsonSerializer = jsonSerializer;
                Logger.Error("开始同步通讯录绑定关系,内容为:" + jsonSerializer.Serialize(sbn));
                var response = client.Execute <CommAnalysisResponse>(request);
                return(ProcessResponse(contact, opt, response));
            }
            catch (Exception e)
            {
                Logger.Error("同步通讯录绑定关系出错:", e);
                return(false);
            }
        }
Ejemplo n.º 7
0
        public void PreModAgentNumber(Model.Entity.DeviceContact contact, int opt)
        {
            var enabled = AppConfig.GetValue(Constants.CLOUDPLATFORM_ENABLED);

            if (!"1".Equals(enabled))
            {
                return;
            }

            Model.Entity.Device device = Device.GetInstance().Get(contact.DeviceID);
            if (device == null || string.IsNullOrEmpty(device.PhoneNumber) || device.CloudPlatform == 0)
            {
                Logger.Debug("设备数据异常,不用同步!");
                return;
            }

//            Logger.Error("获取中间号列表");
            List <Model.Entity.AgentNumber> list = AgentNumber.GetInstance().Get(device.CloudPlatform);

            if (list == null || list.Count == 0)
            {
                Logger.Error("中间号为空,请先添加中间号");
                return;
            }

            if (string.IsNullOrEmpty(contact.AgentNumber) || string.IsNullOrEmpty(contact.CallOutNumber))
            {
//            Logger.Info("计算中间号:"+contact.PhoneNumber);
                List <Model.Entity.DeviceContact> dcList = GetByDeviceId(contact.DeviceID);
                dcList.Remove(contact);
                List <string> agNumList = dcList.ConvertAll(x => x.AgentNumber).ToList();
                List <Model.Entity.AgentNumber> availableANs = list.Where(x => !agNumList.Contains(x.Number)).ToList();
                if (availableANs.Count == 0)
                {
                    Logger.Error("没有可用的中间号,请先添加足够的中间号!");
                    return;
                }

                contact.AgentNumber   = availableANs[0].Number;
                contact.CallOutNumber = availableANs[0].CallOutNumber;
            }

            object[] obj = { contact, opt };
            new Thread(ProcessSync).Start(obj);
        }
Ejemplo n.º 8
0
        public void ChangeAgentNumber(string number, string target)
        {
            var contacts = _dictionaryByDeviceContactId.Values.Where(x => number.Equals(x.AgentNumber)).ToList();

            foreach (var ct in contacts)
            {
                ct.AgentNumber = target;
                Save(ct, false);

                Model.Entity.Device device = Device.GetInstance().Get(ct.DeviceID);
                device.ContactVersionNO++;
                Device.GetInstance().Save(device);

                //通知其他客户端更新通讯录
                List <Model.Entity.User> userList = UserDevice.GetInstance().GetUserByDeviceId(ct.DeviceID);
                Notification.GetInstance().Send(ct.DeviceID, 232, userList);
            }
        }
Ejemplo n.º 9
0
        public void Save(Model.Entity.Device obj)
        {
            lock (_dictionaryByDeviceId)
            {
                if (obj.DeviceID == 0 && _dictionaryByBindNumber.ContainsKey(obj.BindNumber))
                {
                    throw new Exception("绑定号已经存在");
                }

                try
                {
                    base.Save(obj);
                }
                catch (Exception e)
                {
                    Logger.Error("Save Device error,device=" + obj.ToString(), e);
                    throw e;
                }

                if (obj.DeviceID != 0)
                {
                    if (_dictionaryByDeviceId.ContainsKey(obj.DeviceID))
                    {
                        obj.UpdateTime = DateTime.Now;
                        if (obj != _dictionaryByDeviceId[obj.DeviceID])
                        {
                            base.CopyValue <Model.Entity.Device>(obj, _dictionaryByDeviceId[obj.DeviceID]);
                        }
                    }
                    else
                    {
                        obj.CreateTime = DateTime.Now;
                        obj.UpdateTime = DateTime.Now;
                        _dictionaryByDeviceId.TryAdd(obj.DeviceID, obj);
                        _dictionaryBySerialNumber.TryAdd(obj.SerialNumber, obj);
                        _dictionaryByBindNumber.TryAdd(obj.BindNumber, obj);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void SendCommand(Model.Entity.Device device, Socket.MySAE mySae, Model.SendType commandType, string Paramter)
        {
            switch (mySae.DeviceType)
            {
            case Model.DeviceType.YW:
                switch (commandType)
                {
                case Model.SendType.Voice:
                    _adapterOfYW.SendVoice(mySae, device);
                    break;

                case Model.SendType.Contact:
                    _adapterOfYW.SendContact(mySae, device);
                    break;

                case Model.SendType.Set:
                    _adapterOfYW.SendSet(mySae, device);
                    break;

                case Model.SendType.SMS:
                    _adapterOfYW.SendSMS(mySae, device);
                    break;

                case Model.SendType.Location:
                    _adapterOfYW.SendLocation(mySae, device);
                    break;

                case Model.SendType.Firmware:
                    _adapterOfYW.SendFirmware(mySae, device);
                    break;

                case Model.SendType.Monitor:
                    _adapterOfYW.SendMonitor(mySae, device, Paramter);
                    break;

                case Model.SendType.Find:
                    _adapterOfYW.SendFind(mySae, device);
                    break;

                case Model.SendType.PowerOff:
                    _adapterOfYW.SendPowerOff(mySae, device);
                    break;

                case Model.SendType.Init:
                    _adapterOfYW.SendInit(mySae, device, Paramter);
                    break;

                case Model.SendType.TakePhoto:
                    _adapterOfYW.SendTakePhoto(mySae, device, Paramter);
                    break;

                case Model.SendType.SleepCalculate:
                    _adapterOfYW.SendSleepCalculate(mySae, device, Paramter);
                    break;

                case Model.SendType.StepCalculate:
                    _adapterOfYW.SendStepCalculate(mySae, device, Paramter);
                    break;

                case Model.SendType.HrCalculate:
                    _adapterOfYW.SendHrCalculate(mySae, device, Paramter);
                    break;

                case Model.SendType.DeviceRecovery:
                    _adapterOfYW.SendDeviceRecovery(mySae, device, Paramter);
                    break;

                case Model.SendType.DeviceReset:
                    _adapterOfYW.SendDeviceReset(mySae, device, Paramter);
                    break;

                case Model.SendType.TqInfo:
                    _adapterOfYW.SendTqInfo(mySae, device, Paramter);
                    break;

                case Model.SendType.FriendsListNotify:
                    _adapterOfYW.SendFriendListNotity(mySae, device, Paramter);
                    break;

                case Model.SendType.DwInfo:
                    _adapterOfYW.SendDwInfo(mySae, device, Paramter);
                    break;

                case Model.SendType.GUARD:
                    _adapterOfYW.SendGuard(mySae, device, Paramter);
                    break;
                }
                break;

            default:
                break;
            }
        }