| | |
| | | // DeviceName = common.Name, DeviceID = common.DeviceID, Id = 1, DeviceType = common.Type.ToString (), LoopID = common.LoopID, |
| | | // MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.RegionID, SubnetID = common.SubnetID |
| | | //}); |
| | | |
| | | |
| | | if (common != null) { |
| | | var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == common.Type.ToString ()); |
| | | var commonType = common.Type.ToString (); |
| | | if (commonType == "CurtainModel") { |
| | | commonType = "CurtainModule"; |
| | | } else if (commonType == "LightEnergySwitch" || commonType == "LightSwitchSocket" || commonType == "LightEnergySocket") { |
| | | commonType = "LightSwitch"; |
| | | } else if (commonType == "ACInfrared") { |
| | | commonType = "HVAC"; |
| | | } |
| | | var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == commonType); |
| | | if (oldDevice == null) { |
| | | var isSuccess = AddDevice (common); |
| | | if (!isSuccess) { |
| | | //跳出循环 |
| | | break; |
| | | } |
| | | } else { |
| | | //2020-07-21 如果已经存在 匹配设备备注是否需要更新 |
| | | if (oldDevice.DeviceName != common.Name) { |
| | | //Utlis.WriteLine ("名字不匹配,提交更新:" + common.Name); |
| | | var oldName = oldDevice.DeviceName; |
| | | oldDevice.DeviceName = common.Name; |
| | | var isSuccess = UpdateDevice (oldDevice); |
| | | if (!isSuccess) { |
| | | //还原 |
| | | oldDevice.DeviceName = oldName; |
| | | //Utlis.WriteLine ("更新失败!!!!"); |
| | | } else { |
| | | //Utlis.WriteLine ("更新成功!"); |
| | | } |
| | | } else { |
| | | //Utlis.WriteLine ("名字一样不用更新:"+ common.Name); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | foreach (var oldDevice in alexaDeviceLista) { |
| | | var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ()); |
| | | |
| | | if (!roomDeviceFilePathList.Contains (oldDevicePath)) { |
| | | var roomDeviceFilePathListNew = new List<string> (); |
| | | foreach (var path in roomDeviceFilePathList) { |
| | | var deviceFilePath = path; |
| | | if (deviceFilePath.Contains ("LightEnergySocket")) { |
| | | deviceFilePath = deviceFilePath.Replace ("LightEnergySocket", "LightSwitch"); |
| | | } else if (deviceFilePath.Contains ("LightEnergySwitch")) { |
| | | deviceFilePath = deviceFilePath.Replace ("LightEnergySwitch", "LightSwitch"); |
| | | } else if (deviceFilePath.Contains ("LightSwitchSocket")) { |
| | | deviceFilePath = deviceFilePath.Replace ("LightSwitchSocket", "LightSwitch"); |
| | | } else if (deviceFilePath.Contains ("ACInfrared")) { |
| | | deviceFilePath = deviceFilePath.Replace ("ACInfrared", "HVAC"); |
| | | } else if (deviceFilePath.Contains ("CurtainModel")) { |
| | | deviceFilePath = deviceFilePath.Replace ("CurtainModel", "CurtainModule"); |
| | | } |
| | | roomDeviceFilePathListNew.Add (deviceFilePath); |
| | | } |
| | | |
| | | foreach (var oldDevice in alexaDeviceLista) { |
| | | var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ()); |
| | | if (!roomDeviceFilePathListNew.Contains (oldDevicePath)) { |
| | | DelDevice (oldDevice.Id); |
| | | Utlis.WriteLine ("delDevice " + oldDevice.DeviceName); |
| | | } |
| | |
| | | var tempRoom = new Room (); |
| | | foreach (var device in alexaDeviceLista) {//特殊处理服务器与本地设备类型不一样的设备 |
| | | var deviceTypeSaveString = device.DeviceType; |
| | | if (deviceTypeSaveString == "CurtainModule") { |
| | | deviceTypeSaveString = "CurtainModel"; |
| | | if (deviceTypeSaveString == "CurtainModel") { |
| | | deviceTypeSaveString = "CurtainModule"; |
| | | } else if (deviceTypeSaveString == "LightEnergySwitch") { |
| | | deviceTypeSaveString = "LightSwitch"; |
| | | } else if (deviceTypeSaveString == "LightEnergySocket") { |
| | |
| | | deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UpdateDeviceObj>> (revertObj.ResponseData.ToString ()); |
| | | } else { |
| | | //2020-06-29 弹窗提示错误 |
| | | |
| | | ShowErrorInfo (revertObj.StateCode); |
| | | |
| | | } |
| | | return deviceList; |
| | |
| | | /// 上传设备 错误提示 |
| | | /// </summary> |
| | | /// <param name="stateCodeStr"></param> |
| | | void ShowUploadDevicesInfo (string stateCodeStr) |
| | | void ShowUploadDevicesInfo (string stateCodeStr,bool bUpload = true) |
| | | { |
| | | string mes = ""; |
| | | if (stateCodeStr == "NoRecord") { |
| | |
| | | } |
| | | if (!string.IsNullOrEmpty (mes)) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.AddTip (ErrorCode.AddFailed + " " + mes); |
| | | if (bUpload) { |
| | | MainPage.AddTip (ErrorCode.AddFailed + " " + mes); |
| | | } else { |
| | | MainPage.AddTip ("Update failed! " + mes); |
| | | } |
| | | |
| | | //new Alert ("", ErrorCode.AddFailed + " " + mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 错误提醒 |
| | | /// </summary> |
| | | /// <param name="stateCodeStr"></param> |
| | | void ShowErrorInfo (string stateCodeStr) |
| | | { |
| | | string mes = ""; |
| | | if (stateCodeStr == ErrorCode.NetworkError) { |
| | | mes = ErrorCode.NetworkError; |
| | | } else { |
| | | mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; |
| | | |
| | | } |
| | | if (!string.IsNullOrEmpty (mes)) { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.AddTip (ErrorCode.OperationFailed + " " + mes); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新设备名字 |
| | | /// </summary> |
| | | public bool UpdateDevice (UpdateDeviceObj mUpdateDeviceObj) |
| | | { |
| | | var mUpdateAlexaDeviceObj = new UpdateAlexaDeviceObj () { |
| | | Id = mUpdateDeviceObj.Id, |
| | | DeviceType = mUpdateDeviceObj.DeviceType, |
| | | SubnetID = mUpdateDeviceObj.SubnetID, |
| | | DeviceID = mUpdateDeviceObj.DeviceID, |
| | | LoopID = mUpdateDeviceObj.LoopID, |
| | | DeviceName = mUpdateDeviceObj.DeviceName, |
| | | MAC = mUpdateDeviceObj.MAC, |
| | | RegionID = UserConfig.Instance.CurrentRegion.Id, |
| | | }; |
| | | |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mUpdateAlexaDeviceObj); |
| | | var revertObj = MainPage.RequestHttps (API.UpdateDevice, requestJson); |
| | | if (revertObj.StateCode.ToUpper () == "SUCCESS") { |
| | | return true; |
| | | } else if (revertObj.StateCode == "Exist") { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.AddTip ("Update failed!" + " " + ErrorCode.NameExist + " ( " + mUpdateDeviceObj.DeviceName + " )"); |
| | | }); |
| | | return true; |
| | | } else { |
| | | //2020-06-29 弹出提示错误 |
| | | ShowUploadDevicesInfo (revertObj.StateCode, false); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return true; |
| | | } else { |
| | | //2020-06-29 弹窗提示错误 |
| | | |
| | | ShowErrorInfo (revertObj.StateCode); |
| | | } |
| | | return false; |
| | | } |
| | |
| | | sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SceneByRegion>> (revertObj.ResponseData.ToString ()); |
| | | } else { |
| | | //2020-06-29 弹窗提示错误 |
| | | ShowErrorInfo (revertObj.StateCode); |
| | | } |
| | | return sceneList; |
| | | } |
| | |
| | | return true; |
| | | } else { |
| | | //2020-06-29 弹窗提示错误 |
| | | |
| | | ShowErrorInfo (revertObj.StateCode); |
| | | } |
| | | return false; |
| | | } |