| | |
| | | m_Current = value;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 分享的设备文件(key:设备主键,value:设备文件)
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicShardDeviceFile = new Dictionary<string, string>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取分享文件_______________________
|
| | |
| | | /// </summary>
|
| | | /// <param name="listDistributedMark"></param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<string>> SetShardFileToLocation(List<string> listDistributedMark)
|
| | | private async Task<List<string>> SetShardFileToLocation(List<string> listDistributedMark)
|
| | | {
|
| | | if (listDistributedMark.Count == 0)
|
| | | {
|
| | | return new List<string>();
|
| | | }
|
| | | ProgressBar.SetMaxValue(listDistributedMark.Count);
|
| | | int listMarkCount = listDistributedMark.Count;
|
| | |
|
| | | List<string> listFile = new List<string>();
|
| | | //文件夹
|
| | |
| | | Shared.Common.CommonPage.BackKeyCanClick = false;
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | |
|
| | | foreach (string keys in listDistributedMark)
|
| | | for (int i = 0; i < listDistributedMark.Count; i++)
|
| | | {
|
| | | string keys = listDistributedMark[i];
|
| | | var dataPra = new { DistributedMark = keys, HouseDistributedMark = Common.Config.Instance.Home.Id, IsOtherAccountControl = Common.Config.Instance.isAdministrator };
|
| | | var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetOneShareData", false, dataPra);
|
| | | if (result == null)
|
| | |
| | | //保存到指定文件夹下
|
| | | Global.WriteFileToDirectoryByBytes(strDir, dataResult.ShareName, dataResult.ShareDataBytes);
|
| | | //设置进度值
|
| | | ProgressBar.SetValue(1);
|
| | | ProgressFormBar.Current.SetValue(i + 1, listMarkCount);
|
| | | }
|
| | |
|
| | | //允许按系统的返回键
|
| | |
| | | /// </summary>
|
| | | public void ClearShardDirectory()
|
| | | {
|
| | | this.dicShardDeviceFile.Clear();
|
| | | //创建文件夹
|
| | | string strDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DownLoadShardDirectory);
|
| | | Global.CreateEmptyDirectory(strDir, true);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取成员共享列表___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 从本地获取成员的分享列表
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享数据的缓存(调用这个函数会刷新这个变量的信息)</param>
|
| | | public void GetMemberShardContentListFromLocal(MemberShardInfoData memberShardInfo)
|
| | | {
|
| | | memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
|
| | |
|
| | | var listDeviceFile = new HashSet<string>();
|
| | | var listSceneFile = new HashSet<string>();
|
| | |
|
| | | var listFile = this.GetLocalAllShardFile();
|
| | | //先初始化房间
|
| | | foreach (string fileName in listFile)
|
| | | {
|
| | | if (fileName.StartsWith("Room_") == true)
|
| | | {
|
| | | //房间文件
|
| | | var byteData = this.GetShardFileContent(fileName);
|
| | | if (byteData != null)
|
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData);
|
| | | memberShardInfo.dicShardRoom[fileName] = roomTemp;
|
| | | }
|
| | | }
|
| | | else if (fileName == DirNameResourse.ShardFloorFile)
|
| | | {
|
| | | //楼层文件
|
| | | var byteData = this.GetShardFileContent(fileName);
|
| | | if (byteData != null)
|
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | memberShardInfo.dicShardFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(valueData);
|
| | | }
|
| | | }
|
| | | else if (fileName.StartsWith("Device_") == true)
|
| | | {
|
| | | //设备文件
|
| | | listDeviceFile.Add(fileName);
|
| | | }
|
| | | else if (fileName.StartsWith("Scene_") == true)
|
| | | {
|
| | | //场景文件
|
| | | listSceneFile.Add(fileName);
|
| | | }
|
| | | }
|
| | |
|
| | | //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
|
| | | foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //还原设备对象
|
| | | tempRoom.DeviceUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.DeviceUIFilePathList.Count; i++)
|
| | | {
|
| | | string deviceFile = tempRoom.DeviceUIFilePathList[i];
|
| | | //这个设备文件匹配得到房间
|
| | | listDeviceFile.Remove(deviceFile);
|
| | | if (this.IsFileExists(deviceFile) == false)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.DeviceUIFilePathList.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | }
|
| | | //还原场景对象
|
| | | tempRoom.SceneUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.SceneUIFilePathList.Count; i++)
|
| | | {
|
| | | string uiPath = tempRoom.SceneUIFilePathList[i];
|
| | | //这个场景文件匹配得到房间
|
| | | listSceneFile.Remove(uiPath);
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | if (byteData == null)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.SceneUIFilePathList.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | tempRoom.SceneUIList.Add(tempUi);
|
| | | }
|
| | | }
|
| | | //如果存在匹配不上的文件
|
| | | if (listDeviceFile.Count != 0 || listSceneFile.Count != 0)
|
| | | {
|
| | | //创建一个临时房间来存储
|
| | | var roomTemp = new Room();
|
| | | roomTemp.Id = "Other";
|
| | | roomTemp.FloorId = "Other";
|
| | | memberShardInfo.dicShardRoom[roomTemp.FileName] = roomTemp;
|
| | | roomTemp.Name = Language.StringByID(R.MyInternationalizationString.uSharedRoom);
|
| | | //还原设备对象
|
| | | foreach (string deviceFile in listDeviceFile)
|
| | | {
|
| | | roomTemp.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | }
|
| | | //还原场景对象
|
| | | foreach (string uiPath in listSceneFile)
|
| | | {
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | roomTemp.SceneUIList.Add(tempUi);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | //从云端获取下来文件
|
| | | if (listAddMark.Count > 0)
|
| | | {
|
| | | //强制指定文本附加信息:共享数据同步中
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing);
|
| | | //开启进度条
|
| | | ProgressBar.Show(msg);
|
| | | ProgressBar.SetAppendText(msg);
|
| | | //开启进度条 共享数据同步中
|
| | | ProgressFormBar.Current.Start();
|
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
|
| | |
|
| | | //将分享的数据存入本地(获取的是本地没有的)
|
| | | this.ClearShardDirectory();
|
| | |
| | | if (listDbFile == null)
|
| | | {
|
| | | //关闭
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | //只有成员才有这个概念
|
| | | return true;
|
| | | }
|
| | | //强制指定文本附加信息:共享数据同步中
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing);
|
| | | //开启进度条
|
| | | ProgressBar.Show(msg);
|
| | | ProgressBar.SetAppendText(msg);
|
| | | //开启进度条 共享数据同步中
|
| | | ProgressFormBar.Current.Start();
|
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardDataIsSynchronizing));
|
| | |
|
| | | if (dicUpdateTime == null)
|
| | | {
|
| | |
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | //关闭
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return false;
|
| | | }
|
| | | var listShardData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GetShardInfoResult>>(result);
|
| | |
| | | //保存全部分享文件的更新日期
|
| | | this.SaveAllShardFileAgoUpdateTime(dicUpdateTime);
|
| | | //关闭
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | /// <summary>
|
| | | /// 获取成员共享列表然后保存到本地(用完之后最好调用清空 ClearShardDirectory函数清空)
|
| | | /// </summary>
|
| | | /// <param name="SubAccountDistributedMark">成员列表接口返回的SubAccountDistributedMark</param>
|
| | | /// <param name="memberShardInfo">
|
| | | /// <para>成员的分享数据</para>
|
| | | /// <para>如果不知道这是什么东西,就New一个,然后缓存起来,调用其他函数都需要这个东西</para>
|
| | |
| | | {
|
| | | if (memberShardInfo.Refresh == false)
|
| | | {
|
| | | //从本地获取成员的分享列表
|
| | | this.GetMemberShardContentListFromLocal(memberShardInfo);
|
| | | return true;
|
| | | }
|
| | | memberShardInfo.Refresh = false;
|
| | |
|
| | | //打开进度条
|
| | | ProgressBar.Show();
|
| | | //正在获取分享数据
|
| | | ProgressFormBar.Current.Start();
|
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uShardContentGetting));
|
| | |
|
| | | var infoPra = new
|
| | | {
|
| | |
| | | if (result == null)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return false;
|
| | | }
|
| | | var listData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReceiveShardInfoResult>>(result);
|
| | |
| | | if (listFile == null)
|
| | | {
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | | return false;
|
| | | }
|
| | |
|
| | | //从本地获取成员的分享列表
|
| | | this.GetMemberShardContentListFromLocal(memberShardInfo);
|
| | |
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | ProgressFormBar.Current.Close();
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从本地获取成员的分享列表
|
| | | /// </summary>
|
| | | /// <param name="memberShardInfo">成员的分享数据的缓存(调用这个函数会刷新这个变量的信息)</param>
|
| | | private void GetMemberShardContentListFromLocal(MemberShardInfoData memberShardInfo)
|
| | | {
|
| | | memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
|
| | | this.dicShardDeviceFile.Clear();
|
| | |
|
| | | var listDeviceFile = new HashSet<string>();
|
| | | var listSceneFile = new HashSet<string>();
|
| | |
|
| | | var listFile = this.GetLocalAllShardFile();
|
| | | //先初始化房间
|
| | | foreach (string fileName in listFile)
|
| | | {
|
| | | if (fileName.StartsWith("Room_") == true)
|
| | | {
|
| | | //房间文件
|
| | | var byteData = this.GetShardFileContent(fileName);
|
| | | if (byteData != null)
|
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData);
|
| | | memberShardInfo.dicShardRoom[fileName] = roomTemp;
|
| | | }
|
| | | }
|
| | | else if (fileName == DirNameResourse.ShardFloorFile)
|
| | | {
|
| | | //楼层文件
|
| | | var byteData = this.GetShardFileContent(fileName);
|
| | | if (byteData != null)
|
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | memberShardInfo.dicShardFloor = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(valueData);
|
| | | }
|
| | | }
|
| | | else if (fileName.StartsWith("Device_") == true)
|
| | | {
|
| | | string[] Arry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(Arry[2], Convert.ToInt32(Arry[3]));
|
| | | this.dicShardDeviceFile[mainKeys] = fileName;
|
| | |
|
| | | //设备文件
|
| | | listDeviceFile.Add(fileName);
|
| | | }
|
| | | else if (fileName.StartsWith("Scene_") == true)
|
| | | {
|
| | | //场景文件
|
| | | listSceneFile.Add(fileName);
|
| | | }
|
| | | }
|
| | |
|
| | | //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
|
| | | foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
|
| | | {
|
| | | //还原设备对象
|
| | | tempRoom.DeviceUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.DeviceUIFilePathList.Count; i++)
|
| | | {
|
| | | string deviceFile = tempRoom.DeviceUIFilePathList[i];
|
| | | //这个设备文件匹配得到房间
|
| | | listDeviceFile.Remove(deviceFile);
|
| | | if (this.IsFileExists(deviceFile) == false)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.DeviceUIFilePathList.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | }
|
| | | //还原场景对象
|
| | | tempRoom.SceneUIList.Clear();
|
| | | for (int i = 0; i < tempRoom.SceneUIFilePathList.Count; i++)
|
| | | {
|
| | | string uiPath = tempRoom.SceneUIFilePathList[i];
|
| | | //这个场景文件匹配得到房间
|
| | | listSceneFile.Remove(uiPath);
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | if (byteData == null)
|
| | | {
|
| | | //移除掉这个不对劲的路径
|
| | | tempRoom.SceneUIFilePathList.RemoveAt(i);
|
| | | i--;
|
| | | continue;
|
| | | }
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | tempRoom.SceneUIList.Add(tempUi);
|
| | |
|
| | | //获取场景里面的全部目标(2019.11.05追加操作,有可能那个设备是由场景嵌套来的,所以它有可能不属于任何房间)
|
| | | foreach (var data in tempUi.AddSceneMemberDataList)
|
| | | {
|
| | | //设备
|
| | | if (data.Type == 0)
|
| | | {
|
| | | string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
|
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true )
|
| | | {
|
| | | //这个设备文件匹配得到
|
| | | listDeviceFile.Remove(dicShardDeviceFile[mainkey]);
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | | {
|
| | | var temp = new SceneUI();
|
| | | temp.Id = data.ElseScenesId;
|
| | | //这个场景文件匹配得到
|
| | | listSceneFile.Remove(temp.FileName);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | //如果存在匹配不上的文件
|
| | | if (listDeviceFile.Count != 0 || listSceneFile.Count != 0)
|
| | | {
|
| | | //创建一个临时房间来存储
|
| | | var roomTemp = new Room();
|
| | | roomTemp.Id = "Other";
|
| | | roomTemp.FloorId = "Other";
|
| | | memberShardInfo.dicShardRoom[roomTemp.FileName] = roomTemp;
|
| | | roomTemp.Name = Language.StringByID(R.MyInternationalizationString.uUnallocated);
|
| | | //还原设备对象
|
| | | foreach (string deviceFile in listDeviceFile)
|
| | | {
|
| | | roomTemp.DeviceUIFilePathList.Add(deviceFile);
|
| | | roomTemp.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(deviceFile));
|
| | | }
|
| | | //还原场景对象
|
| | | foreach (string uiPath in listSceneFile)
|
| | | {
|
| | | var byteData = this.GetShardFileContent(uiPath);
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | roomTemp.SceneUIList.Add(tempUi);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | listFile.Add(device.FilePath);
|
| | | this.AddShardFile(device.FilePath);
|
| | |
|
| | | //加点缓存
|
| | | this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
|
| | |
|
| | | //设备的UI
|
| | | var deviceUi = device.FilePath;
|
| | | if (roomTemp.DeviceUIFilePathList.Contains(deviceUi) == false)
|
| | |
| | | //设备
|
| | | listFile.Add(device.FilePath);
|
| | | this.AddShardFile(device.FilePath);
|
| | |
|
| | | //加点缓存
|
| | | this.dicShardDeviceFile[LocalDevice.Current.GetDeviceMainKeys(device)] = device.FilePath;
|
| | | }
|
| | |
|
| | | //场景
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从网关获取场景的目标设备列表
|
| | | /// 获取场景的目标设备列表(这个不能从分享数据中获取)
|
| | | /// </summary>
|
| | | /// <param name="scene">场景</param>
|
| | | /// <param name="listCheck">重复检测用</param>
|
| | |
| | | }
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | ;
|
| | | for (int i = 0; i < listDeleteFile.Count; i++)
|
| | | {
|
| | | string fileName = listDeleteFile[i];
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从场景对象里面获取全部的绑定目标的文件名字
|
| | | /// 从场景对象里面获取全部的绑定目标的文件名字(这里面的东西必须从分享数据中获取)
|
| | | /// </summary>
|
| | | /// <param name="scene">场景</param>
|
| | | /// <param name="listFile">文件列表(里面存的是设备UI文件和设备文件和场景文件)</param>
|
| | |
| | | //设备
|
| | | if (data.Type == 0)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
|
| | | if (device != null && listFile.Contains(device.FilePath) == false)
|
| | | string mainkey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
|
| | | if (dicShardDeviceFile.ContainsKey(mainkey) == true && listFile.Contains(dicShardDeviceFile[mainkey]) == false)
|
| | | {
|
| | | listFile.Add(device.FilePath);
|
| | | listFile.Add(dicShardDeviceFile[mainkey]);
|
| | | }
|
| | | }
|
| | | if (data.Type == 1)
|
| | |
| | | {
|
| | | string valueData = System.Text.Encoding.UTF8.GetString(byteData);
|
| | | var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.SceneUI>(valueData);
|
| | | if (roomTemp != null)
|
| | | dicBindScene[roomTemp.FileName] = roomTemp;
|
| | | if (listFile.Contains(roomTemp.FileName) == false)
|
| | | {
|
| | | dicBindScene[roomTemp.FileName] = roomTemp;
|
| | | if (listFile.Contains(roomTemp.FileName) == false)
|
| | | {
|
| | | listFile.Add(roomTemp.FileName);
|
| | | }
|
| | | listFile.Add(roomTemp.FileName);
|
| | | }
|
| | | }
|
| | | }
|