wei
2021-07-01 2835fe50d3e194c21b16fec1c53ff905dd3a3ceb
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
using Shared;
 
namespace HDL_ON
{
    [System.Serializable]
    public class UserInfo
    {
        /// <summary>
        /// 通用方法
        /// </summary>
        private static UserInfo m_Current = null;
        /// <summary>
        /// 通用方法
        /// </summary>
        public static UserInfo Current
        {
            get
            {
                //Dome模式
                if (MainPage.NoLoginMode)
                {
                    if (Language.CurrentLanguage == "Chinese")
                    {
                        m_Current = new UserInfo()
                        {
                            ID = "1234567890",
                            userName = "体验账号",
                            AccountString = "体验账号",
                            userMobileInfo = "体验账号",
                            userEmailInfo = "体验账号",
                            language = "Chinese",
                            areaCode = "86",
                            headImagePagePath = "LoginIcon/2.png",
                        };
                    }
                    else
                    {
                        m_Current = new UserInfo()
                        {
                            ID = "1234567890",
                            userName = "Trial account",
                            AccountString = "Trial account",
                            userMobileInfo = "Trial account",
                            userEmailInfo = "Trial account",
                            language = "English",
                            areaCode = "86",
                            headImagePagePath = "LoginIcon/2.png",
                        };
                    }
                    return m_Current;
                }
                if (m_Current == null)
                {
 
                    try
                    {
                        UserInfo temp = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(
                            Encoding.UTF8.GetString(ReadUserInfo()));
                        if (temp == null)
                        {
                            m_Current = new UserInfo() { };
                            Utlis.WriteLine("UserInfo null");
                        }
                        else
                        {
                            m_Current = temp;
                            Utlis.WriteLine("UserInfo Current");
                        }
                    }
                    catch
                    {
                        m_Current = new UserInfo() { };
                        Utlis.WriteLine("UserInfo null");
                    }
                }
                return m_Current;
            }
        }
        /// <summary>
        /// 清除缓存数据
        /// </summary>
        public void ClearUserInfo()
        {
            m_Current = null;
        }
 
 
        #region 用户数据
        /// <summary>
        /// 用户ID
        /// </summary>
        public string ID;
        /// <summary>
        /// 用户名称
        /// </summary>
        public string userName = "";
        /// <summary>
        /// 用户
        /// </summary>
        public string AccountString = "";
        /// <summary>
        /// 用户手机号码
        /// </summary>
        public string userMobileInfo = "";
        /// <summary>
        /// 用户邮箱信息
        /// </summary>
        public string userEmailInfo = "";
        /// <summary>
        /// 用户选择显示的语言
        /// </summary>
        public string language = "Chinese";
        /// <summary>
        /// 用户区域
        /// </summary>
        public string areaCode = "86";
        /// <summary>
        /// 用户头像图片
        /// </summary>
        public string headImagePagePath = "LoginIcon/2.png";
        ///// <summary>
        ///// 用户头像byte数据
        ///// </summary>
        //public byte[] headImagePageBytes = null;
        /// <summary>
        /// 
        /// </summary>
        public string LoginTokenString;
        /// <summary>
        /// 
        /// </summary>
        public string RefreshToken;
        /// <summary>
        /// UserType B端账号 C端账号 
        /// </summary>
        public string userType = "USER_C";
        /// <summary>
        /// 用户住宅列表
        /// </summary>
        public List<RegionInfoRes> regionList = new List<RegionInfoRes>();
        /// <summary>
        /// 上一次登录时间
        /// </summary>
        public DateTime LastTime = DateTime.MinValue;
        /// <summary>
        /// 是否是登录状态
        /// </summary>
        public bool IsLogin
        {
            get
            {
                return (DateTime.Now - LastTime).TotalDays < 7;
            }
        }
 
        #endregion
 
        /// <summary>
        /// 保存用户数据
        /// </summary>
        public void SaveUserInfo()
        {
            WirteUserinfo(Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
        }
 
        /// <summary>
        /// 软件解锁界面
        /// 1:启动时
        /// 2:布防撤防时
        /// 3:远程开锁时
        /// </summary>
        public List<string> appUnlockPage = new List<string>();
        /// <summary>
        /// 软件解锁方式
        /// 1:数字密码
        /// 2:手势密码
        /// 3:指纹密码
        /// 4:面容ID
        /// </summary>
        public List<string> appUnlockType = new List<string>();
        /// <summary>
        /// 软件解锁密码
        /// </summary>
        public string appUnlockPasswrod = "";
        /// <summary>
        /// 解锁时间
        /// </summary>
        public DateTime unlockTime = DateTime.MinValue;
 
 
        /// <summary>
        /// 根目录
        /// </summary>
        static string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/";
        /// <summary>
        /// 读取userInfo文件
        /// </summary>
        /// <returns></returns>
        static byte[] ReadUserInfo()
        {
            var fileName = "UserInfo_File";
            FileStream fs = null;
            try
            {
                var temp = CreateUserFloder(OnAppConfig.Instance.LastLoginUserId);
                if (File.Exists(Path.Combine(temp, fileName)))
                {
                    fs = new FileStream(Path.Combine(temp, fileName), FileMode.Open, FileAccess.Read);
                }
                else if (File.Exists(fileName))
                {
                    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    return new byte[0];
                }
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                return bytes;
            }
            catch
            {
                return new byte[0];
            }
            finally
            {
                try
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                catch
                {
 
                }
            }
 
        }
        /// <summary>
        /// 保存userInfo
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        static bool WirteUserinfo(byte[] bytes)
        {
            var fileName = "UserInfo_File";
            FileStream fs = null;
 
            try
            {
 
                var temp = CreateUserFloder(OnAppConfig.Instance.LastLoginUserId);
                fs = new FileStream(Path.Combine(temp, fileName), FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                MainPage.Log("SaveFile:" + fileName);
                return true;
            }
            catch (Exception ex)
            {
                MainPage.Log("FileUtiles Code 113:" + ex.ToString());
                return false;
            }
            finally
            {
                try
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log("FileUtils Code 121 :" + ex.ToString());
                }
            }
        }
        /// <summary>
        /// 创建一个住宅的账号文件夹
        /// </summary>
        public static string CreateUserFloder(string userId)
        {
            var path = Path.Combine(RootPath, userId);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return path + "/";
        }
 
    }
}