From 48ba446936b51fffafa7c3600c0dadc6ac0e8c20 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 七月 2020 10:52:13 +0800
Subject: [PATCH] 2020-07-10-01
---
ZigbeeApp/Shared/Common/House.cs | 382 +++++++----------------------------------------------
1 files changed, 54 insertions(+), 328 deletions(-)
diff --git a/ZigbeeApp/Shared/Common/House.cs b/ZigbeeApp/Shared/Common/House.cs
index 29609c6..d368109 100755
--- a/ZigbeeApp/Shared/Common/House.cs
+++ b/ZigbeeApp/Shared/Common/House.cs
@@ -23,17 +23,14 @@
return $"House_{Id}.json";
}
}
-
/// <summary>
/// 浣忓畢id--浣跨敤浜戠鎻愪緵鐨勪綇瀹呭敮涓�Id
/// </summary>
public string Id = string.Empty;
-
/// <summary>
/// 浣忓畢鍚嶇О
/// </summary>
public string Name = string.Empty;
-
/// <summary>
/// 鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�
/// </summary>
@@ -42,361 +39,90 @@
/// 褰撳墠浣忓畢鏄叾浠栦富甯愬彿鍒嗕韩杩囨潵鐨勪富甯愬彿鐨勫垎甯冨紡Id
/// </summary>
public string MainUserDistributedMark;
-
+ /// <summary>
+ /// 璇ヤ綇瀹呮槸鍚︽槸铏氭嫙鐨�,true鐨勮瘽浠h〃缃戝叧鍜岃澶囬兘鏄櫄鎷熺殑(榛樿涓篺alse)
+ /// </summary>
+ public bool IsVirtually = false;
/// <summary>
/// 浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺
/// </summary>
- public int AccountType;
-
- /// <summary>
- /// 鎴块棿璺緞鍒楄〃
+ public int AccountType;
+ /// <summary>
+ /// 缁忓害
+ /// </summary>
+ public double Longitude = 0;
+ /// <summary>
+ /// 绾害
+ /// </summary>
+ public double Latitude = 0;
+ /// <summary>
+ /// 浣忓畢鎵�鍦ㄧ殑鍦扮悊浣嶇疆鐨勫悕绉�
/// </summary>
- public List<string> RoomFilePathList = new List<string> { };
-
+ public string ResidenceAddressName = string.Empty;
/// <summary>
- /// 鍏ㄥ眬鍦烘櫙璺緞鍒楄〃---澶囩敤
+ /// 鎴块棿鍒楄〃(鎴块棿鐨処D)
/// </summary>
- public List<string> SceneFilePathList = new List<string> { };
+ public List<string> ListRooms = new List<string>();
/// <summary>
- /// 璁惧璺緞鍒楄〃---澶囩敤
+ /// 妤煎眰瀛楀吀
+ /// key:FloorId
+ /// value:FloorName
/// </summary>
- public List<string> DeviceFilePathList = new List<string> { };
+ public Dictionary<string,string> FloorDics = new Dictionary<string,string> { };
/// <summary>
- /// 鍔熻兘璺緞鍒楄〃---澶囩敤
+ /// 褰撳墠妤煎眰Id
/// </summary>
- public List<string> FunctionFilePathList = new List<string> { };
- /// <summary>
- /// 閫氱敤鏍囪瘑--澶囩敤
- /// </summary>
- public object Tag;
- /// <summary>
- /// 鏈熴�佹爧銆佸眰绛夊尯鍩�---澶囩敤
- /// </summary>
- public Dictionary<string, string> LocationInfoList = new Dictionary<string, string> { };
+ public string CurrentFloorId = string.Empty;
#endregion
- #region 鈼� 浣忓畢____________________________
-
- #region 鈼� 娣诲姞浣忓畢_________________________
+ #region 鈼� 妤煎眰____________________________
/// <summary>
- /// 娣诲姞浣忓畢
+ /// GetCurrentFloorName
/// </summary>
- /// <param name="houseId">浣忓畢id</param>
- /// <param name="houseName">浣忓畢鍚嶇О.</param>
- /// <param name="numHomeId">浣忓畢鏁板瓧鍨媔d</param>
- public static void AddHouse(string houseId, string houseName, int numHomeId)
+ /// <returns></returns>
+ [Newtonsoft.Json.JsonIgnore]
+ public string GetCurrentFloorName
{
- AddHouse(houseId, houseName, false, 0);
- }
-
- /// <summary>
- /// 娣诲姞浣忓畢
- /// </summary>
- /// <param name="houseId">浣忓畢id</param>
- /// <param name="houseName">浣忓畢鍚嶇О.</param>
- /// <param name="isOthreShare">鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�</param>
- /// <param name="accountType">浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺</param>
- public static void AddHouse(string houseId, string houseName, bool isOthreShare, int accountType)
- {
- var home = new House
+ get
{
- Id = houseId,
- Name = houseName,
- IsOthreShare = isOthreShare,
- AccountType = accountType
- };
- //鍒涘缓鏂囦欢澶�
- Global.CreateHomeDirectory(houseId);
- home.Save();
- Config.Instance.HomeFilePathList.Add(home.FileName);
- Config.Instance.Save();
- }
-
-
- #endregion
-
- #region 鈼� 鍒犻櫎浣忓畢_________________________
-
- /// <summary>
- /// 鍒犻櫎浣忓畢
- /// </summary>
- /// <param name="filePath">File path.</param>
- public static void DeleteHouse(string filePath)
- {
- var delPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath));
- if (System.IO.Directory.Exists(delPath) == false)
- {
- return;
+ return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId);
}
- var fileList = GetHouseFileListByFilePath(filePath);
- foreach (var file in fileList)
- {
- //鍒犻櫎鏂囦欢
- System.IO.File.Delete(System.IO.Path.Combine(delPath, file));
- }
- //鍒犻櫎鏂囦欢澶�
- System.IO.Directory.Delete(delPath, true);
- //HomeFilePathList涓垹闄よ鍒楄〃
- Common.Config.Instance.HomeFilePathList.RemoveAll((obj) => obj == filePath);
- Config.Instance.Save();
}
/// <summary>
- /// 鍒犻櫎浣忓畢
+ /// 璁剧疆褰撳墠妤煎眰鐨処D
/// </summary>
- /// <param name="houseId">House identifier.</param>
- public static void DeleteHouseByHouseId(string houseId)
+ public void SetCurrentFloorId()
{
- DeleteHouse(GetHouseFilePathByHouseId(houseId));
- }
-
- #endregion
-
- #region 鈼� 淇敼浣忓畢_________________________
-
- /// <summary>
- /// 淇敼浣忓畢.
- /// </summary>
- /// <param name="houseId">House identifier.</param>
- /// <param name="houseName">House name.</param>
- public static void EditorHouseByHouseId(string houseId, string houseName)
- {
- var home = GetHouseByHouseId(houseId);
- if (home == null)
+ if (Config.Instance.Home.FloorDics.Count > 0 && string.IsNullOrEmpty(CurrentFloorId))
{
- return;
- }
- home.Name = houseName;
- home.Save();
- }
-
- #endregion
-
- #region 鈼� 鑾峰彇浣忓畢_________________________
- /// <summary>
- /// 閫氳繃銆恑d銆戣幏鍙栦綇瀹�
- /// </summary>
- /// <returns>The house by house identifier.</returns>
- /// <param name="houseId">浣忓畢id</param>
- public static House GetHouseByHouseId(string houseId)
- {
- var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json");
- var file = Shared.IO.FileUtils.ReadFile(path);
- if (file == null)
- {
- return null;
- }
- return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file));
- }
-
- /// <summary>
- /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹�
- /// </summary>
- /// <returns>The house by file path.</returns>
- /// <param name="filePath">鏂囦欢璺緞</param>
- public static House GetHouseByFilePath(string filePath)
- {
- var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath);
- var file = Shared.IO.FileUtils.ReadFile(path);
- if (file == null)
- {
- return null;
- }
- return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file));
- }
-
- #endregion
-
- #region 鈼� 鑾峰彇浣忓畢鍒楄〃_____________________
- /// <summary>
- /// Gets the home lists.鑾峰彇浣忓畢鍒楄〃
- /// </summary>
- public static async System.Threading.Tasks.Task<List<string>> GetHomeLists()
- {
- //娓呯┖褰撳墠浣忓畢鍒楄〃
- Config.Instance.HomeFilePathList.Clear();
- var pageSetting = new SendDataToServer.ResidenceListPageSettingObj()
- {
- PageSize = CommonPage.PageSize
- };
-
- var reqDto = new SendDataToServer.ResidenceListObj()
- {
- LoginAccessToken = Config.Instance.Token,
- PageSetting = pageSetting
- };
- var requestObj = new SendDataToServer.ResidenceListReqDto()
- {
- ReqDto = reqDto,
- RequestVersion = CommonPage.RequestVersion,
- };
- try
- {
- var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
- var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson));
- if (revertObj == null)
+ foreach (var floor in Config.Instance.Home.FloorDics)
{
- return null;
- }
- if (revertObj.StateCode.ToUpper() == "SUCCESS")
- {
- var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResidenceRes>(revertObj.ResponseData.ToString());
- if (responseDataObj.TotalCount == 0)
- {
- //褰撲綇瀹呬负绌烘椂鍏堟彁绀虹敤鎴锋柊寤轰綇瀹�
- var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CurrentlyTheUserIshHouseIsEmptyPleaseBuildANewHouseFirst), Language.StringByID(R.MyInternationalizationString.Close), Language.StringByID(R.MyInternationalizationString.OK));
- alert.Show();
- alert.ResultEventHandler += (sender, e) =>
- {
- if (e)
- {
- //
- }
- };
- }
- else
- {
- foreach (var residence in responseDataObj.PageData)
- {
- Config.Instance.HomeFilePathList.Add($"House_{residence.Id}.json");
- var house = GetHouseByHouseId(residence.Id);
- if (house == null)
- {
- house = new House
- {
- Id = residence.Id,
- Name = residence.Name,
- IsOthreShare = residence.IsOthreShare,
- AccountType = residence.AccountType,
- MainUserDistributedMark = residence.MainUserDistributedMark
- };
- }
- else
- {
- house.Id = residence.Id;
- house.Name = residence.Name;
- house.IsOthreShare = residence.IsOthreShare;
- house.AccountType = residence.AccountType;
- house.MainUserDistributedMark = residence.MainUserDistributedMark;
- }
- Global.CreateHomeDirectory(residence.Id);
- house.Save();
- }
- //鍖归厤褰撳墠浣忓畢
- if (Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null)
- {
- Config.Instance.HomeId = GetHouseIdByFilePath(Config.Instance.HomeFilePathList[0]);
- }
- Config.Instance.Save();
- }
+ CurrentFloorId = floor.Key;
+ Save(false);
+ return;
}
}
- catch (Exception ex)
- {
- System.Console.WriteLine($"鑾峰彇澶辫触{ex.Message}");
- }
- finally
- {
- }
- return Config.Instance.HomeFilePathList;
}
#endregion
-
- #region 鈼� 鑾峰彇浣忓畢id_______________________
- /// <summary>
- /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹卛d
- /// </summary>
- /// <returns>The house identifier by file path.</returns>
- /// <param name="filePath">鏂囦欢璺緞</param>
- public static string GetHouseIdByFilePath(string filePath)
- {
- string[] sArray = filePath.Split(new string[] { "House_", ".json" }, StringSplitOptions.RemoveEmptyEntries);
- if (sArray.Length >= 1)
- {
- return sArray[0];
- }
- return null;
- }
-
- #endregion
-
- #region 鈼� 鑾峰彇浣忓畢璺緞_____________________
- /// <summary>
- /// 閫氳繃銆愪綇瀹卛d銆戣幏鍙栦綇瀹呰矾寰�
- /// </summary>
- /// <returns>The house identifier by file path.</returns>
- /// <param name="houseId">浣忓畢id</param>
- public static string GetHouseFilePathByHouseId(string houseId)
- {
- if (string.IsNullOrEmpty(houseId))
- {
- return null;
- }
- return $"House_{houseId}.json";
- }
-
- #endregion
-
- #region 鈼� 鑾峰彇璇ヤ綇瀹呯殑鏂囦欢鍒楄〃______________
-
- /// <summary>
- /// 閫氳繃銆恏ouseId銆戣幏鍙栬浣忓畢鐨勬枃浠跺垪琛�
- /// </summary>
- /// <returns>The house file list by home identifier.</returns>
- /// <param name="houseId">House identifier.</param>
- public static List<string> GetHouseFileListByHomeId(string houseId)
- {
- var list = new List<string> { };
- var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId);
- if (!System.IO.Directory.Exists(path))
- {
- return new List<string> { };
- }
- var files = System.IO.Directory.GetFiles(path);
- foreach (var file in files)
- {
- var f = file.Substring(path.Length + 1);
- System.Console.WriteLine(f);
- list.Add(f);
- }
- return list;
- }
-
- /// <summary>
- /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹呬笅鏂囦欢鍒楄〃
- /// </summary>
- /// <returns>The house file list by file path.</returns>
- /// <param name="filePath">File path.</param>
- public static List<string> GetHouseFileListByFilePath(string filePath)
- {
- return GetHouseFileListByHomeId(GetHouseIdByFilePath(filePath));
- }
-
- #endregion
-
- #endregion
-
- #region 鈼� 鎴块棿____________________________
#region 鈼� 娣诲姞鎴块棿璺緞_________________________
/// <summary>
- /// 娣诲姞銆愭埧闂磋矾寰勩�戝埌鎴块棿璺緞鍒楄〃
+ /// 娣诲姞鎴块棿ID
/// </summary>
/// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns>
/// <param name="roomFilePath">Room file path.</param>
- public bool AddRoomListFilePath(string roomFilePath)
+ public void AddRoomId(string roomId)
{
- if (RoomFilePathList.Contains(roomFilePath))
- {
- return false;
+ if (ListRooms.Contains(roomId) == false)
+ {
+ ListRooms.Add(roomId);
+ this.Save();
}
- RoomFilePathList.Add(roomFilePath);
- Save();
- return true;
}
#endregion
@@ -404,22 +130,18 @@
#region 鈼� 鍒犻櫎鎴块棿璺緞_________________________
/// <summary>
- /// 绉婚櫎鎴块棿璺緞
+ /// 绉婚櫎鎴块棿Id
/// </summary>
/// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns>
/// <param name="roomFilePath">Room file path.</param>
- public bool RemoveRoomListFilePath(string roomFilePath)
+ public void RemoveRoomId(string roomId)
{
- if (!RoomFilePathList.Contains(roomFilePath))
- {
- return false;
+ if (ListRooms.Contains(roomId)==true)
+ {
+ ListRooms.Remove(roomId);
+ Save();
}
- RoomFilePathList.Remove(roomFilePath);
- Save();
- return true;
}
-
- #endregion
#endregion
@@ -439,6 +161,10 @@
}
path = System.IO.Path.Combine(path, FileName);
Shared.IO.FileUtils.WriteFileByBytes(path, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+ if (autoBackup == true && Id == Config.Instance.HomeId)
+ {
+ HdlAutoBackupLogic.AddOrEditorFile(FileName);
+ }
}
#endregion
}
--
Gitblit v1.8.0