| | |
| | | m_Current = value;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 分享的设备文件(key:设备主键,value:设备文件)
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicShardDeviceFile = new Dictionary<string, string>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取分享文件_______________________
|
| | |
| | | /// </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 (memberShardInfo.Refresh == false)
|
| | | {
|
| | | //从本地获取成员的分享列表
|
| | | this.GetMemberShardContentListFromLocal(memberShardInfo);
|
| | | return true;
|
| | | }
|
| | | memberShardInfo.Refresh = false;
|
| | |
| | | ProgressBar.Close();
|
| | | return false;
|
| | | }
|
| | |
|
| | | //从本地获取成员的分享列表
|
| | | this.GetMemberShardContentListFromLocal(memberShardInfo);
|
| | |
|
| | | //关闭进度条
|
| | | ProgressBar.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);
|
| | | }
|
| | | }
|
| | | }
|