黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using Shared.Phone;
using Shared.Phone.UserCenter;
 
namespace Shared.Common
{
    /// <summary>
    /// 住宅文件
    /// </summary>
    [System.Serializable]
    public class House
    {
        #region ◆ 变量____________________________
        /// <summary>
        /// 住宅文件
        /// </summary>
        /// <value>The file path.</value>
        [Newtonsoft.Json.JsonIgnore]
        public string FileName
        {
            get
            {
                return $"House_{Id}.json";
            }
        }
        /// <summary>
        /// 住宅id--使用云端提供的住宅唯一Id
        /// </summary>
        public string Id = string.Empty;
        /// <summary>
        /// 住宅名称
        /// </summary>
        public string Name = string.Empty;
        /// <summary>
        /// 是否为其他主用户分享过来的住宅
        /// </summary>
        public bool IsOtherShare;
        /// <summary>
        /// 该住宅是否是虚拟的,true的话代表网关和设备都是虚拟的(默认为false)
        /// </summary>
        public bool IsVirtually = false;
        /// <summary>
        /// 仅子账号登陆的时候使用,当【IsOthreShare】为"true",并且【AccountType】为"1"时,该账号拥有管理员权限
        /// </summary>
        public int AccountType;
        /// <summary>
        /// 经度
        /// </summary>
        public double Longitude = 0;
        /// <summary>
        /// 纬度
        /// </summary>
        public double Latitude = 0;
        /// <summary>
        /// 是否拥有远程控制权限
        /// </summary>
        public bool IsRemoteControl = false;
        /// <summary>
        /// 住宅所在的地理位置的名称
        /// </summary>
        public string ResidenceAddressName = string.Empty;
        /// <summary>
        /// 楼层字典
        /// key:FloorId
        /// value:FloorName
        /// </summary>
        public Dictionary<string,string> FloorDics = new Dictionary<string,string> { };
        /// <summary>
        /// -1:未配置(需要重新选择) 1:无模板有设备  2:有模板有设备  3:无模板无设备(请无视这个变量)
        /// </summary>
        public int TemplateMode = -1;
        /// <summary>
        /// 该住宅是否是展示模板(此变量是给查看模板数据时使用的,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public bool IsShowTemplate = false;
        /// <summary>
        /// 当前住宅选择的模板名字(请无视这个变量)
        /// </summary>
        public string SelectTemplate = string.Empty;
        /// <summary>
        /// 自定义单元的标题名称(与ListUintContent个数匹配,请无视这个变量)
        /// </summary>
        public List<string> ListUintName = new List<string>();
        /// <summary>
        /// 自定义单元的内容(与ListUintName个数匹配,请无视这个变量)
        /// </summary>
        public List<string> ListUintContent = new List<string>();
        /// <summary>
        /// 最后编辑的事件(2020.05.26追加) 1970/12/31 23:59格式
        /// </summary>
        public string LastEditorTime = "1970/12/31 23:59";
        /// <summary>
        /// 标识此住宅的数据是否已经发送过模板数据给网关(只针对TemplateMode=2,请无视这个变量)
        /// </summary>
        public bool SendTemplateSuccess = false;
        /// <summary>
        /// 这个住宅下所拥有的网关id(2020.05.26追加,null代表没有处理过,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<string> listGatewayId = null;
        /// <summary>
        /// <para>标识住宅数据的区分(文件读取时配置,请无视这个变量):</para>
        /// <para>1:本身自己的数据(文件夹名字为住宅id)</para>
        /// <para>2:自己手动创建的保存在本机的备份(文件夹名字以【BackupResidenceData】开头)</para>
        /// <para>3:此数据从云端下载而来(文件夹名字以【DownLoadResidenceData】开头)</para>
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int HouseDataDiv = 1;
        /// <summary>
        /// 当前住宅的在线状态 -1:虚拟 0:离线 1:本地 2:远程 3:读取中(请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string NowHomeOnlineStatu = "3";
        /// <summary>
        /// 当前存放住宅数据的文件夹名字(此变量是给本机备份,或者云端下载备份使用的,请无视这个变量)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string SaveDirctoryName = string.Empty;
 
        #endregion
 
        #region ◆ 楼层____________________________
 
        /// <summary>
        /// GetCurrentFloorName
        /// </summary>
        /// <returns></returns>
        [Newtonsoft.Json.JsonIgnore]
        public string GetCurrentFloorName
        {
            get
            {
                return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId);
            }
        }
        /// <summary>
        /// 当前楼层id
        /// </summary>
        private string m_CurrentFloorId = string.Empty;
        /// <summary>
        /// 当前楼层Id
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string CurrentFloorId
        {
            //来回切换备份,会出现问题,楼层id没清除
            get
            {
                //没有楼层
                if (this.FloorDics.Count == 0) { return string.Empty; }
 
                if (this.FloorDics.ContainsKey(m_CurrentFloorId) == true)
                {
                    //当前的楼层id没问题
                    return m_CurrentFloorId;
                }
                //如果当前设置的楼层id并不存在的话,重新设置
                m_CurrentFloorId = string.Empty;
                var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
                foreach (var floorId in dicFloor.Keys)
                {
                    //给一个过去即可
                    m_CurrentFloorId = floorId;
                    break;
                }
                return m_CurrentFloorId;
            }
            set { m_CurrentFloorId = value; }
        }
 
        #endregion
 
        #region ◆ 保存____________________________
 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="autoBackup">是否备份</param>
        public void Save(bool autoBackup = true)
        {
            //如果当前是展示模板,则不允许保存
            if (this.IsShowTemplate == true)
            {
                return;
            }
            //修改时间
            this.LastEditorTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, Id);
            //如果没有存在住宅目录,先创建
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            path = System.IO.Path.Combine(path, FileName);
            HdlFileLogic.Current.SaveFileContent(path, this);
 
            if (autoBackup == true && Id == Config.Instance.HomeId)
            {
                HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(FileName);
            }
        }
        #endregion
    }
}