| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Threading; |
| | | using HDL_ON.DAL.Server; |
| | | using Shared; |
| | |
| | | /// 主人token |
| | | /// </summary> |
| | | public string MasterToken; |
| | | |
| | | RegionInfoRes _residecenInfo; |
| | | /// <summary> |
| | | /// 住宅基础信息 |
| | | /// </summary> |
| | | public RegionInfoRes residecenInfo |
| | | public RegionInfoRes CurrentRegion |
| | | { |
| | | get |
| | | { |
| | | if (MainPage.NoLoginMode) |
| | | { |
| | | return new RegionInfoRes() { Name = "本地模式" , }; |
| | | return new RegionInfoRes() { Name = "本地模式" }; |
| | | } |
| | | else |
| | | { |
| | | var curRegion = UserInfo.Current.regionList.Find((obj) => obj.RegionID == UserInfo.Current.CurReginID); |
| | | if (curRegion == null) |
| | | if (_residecenInfo == null) |
| | | { |
| | | if (UserInfo.Current.regionList != null && UserInfo.Current.regionList.Count > 0) |
| | | { |
| | | UserInfo.Current.CurReginID = UserInfo.Current.regionList[0].RegionID; |
| | | return UserInfo.Current.regionList[0]; |
| | | _residecenInfo = UserInfo.Current.regionList[0]; |
| | | } |
| | | else |
| | | { |
| | | return new RegionInfoRes(); |
| | | _residecenInfo = new RegionInfoRes(); |
| | | HDLCommon.Current.Logout(); |
| | | } |
| | | } |
| | | return curRegion; |
| | | return _residecenInfo; |
| | | } |
| | | } |
| | | set |
| | | { |
| | | _residecenInfo = value; |
| | | } |
| | | } |
| | | |
| | |
| | | public List<ShowFunction> functionTypeList = new List<ShowFunction>(); |
| | | |
| | | static DB_ResidenceData instance; |
| | | public static DB_ResidenceData residenceData |
| | | public static DB_ResidenceData Instance |
| | | { |
| | | get |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | var residenceDataBytes = Common.FileUtlis.Files.ReadFile("DB_ResidenceData"); |
| | | var residenceDataBytes = ReadResidenceInfo(); |
| | | var userConfigString = System.Text.Encoding.UTF8.GetString(residenceDataBytes); |
| | | DB_ResidenceData temp = null; |
| | | |
| | |
| | | { |
| | | instance.functionTypeList.AddRange(new List<ShowFunction> { |
| | | ShowFunction.Light,ShowFunction.AC,ShowFunction.Curtain, |
| | | ShowFunction.FloorHeating,ShowFunction.DoorLock, |
| | | ShowFunction.Electric,ShowFunction.EnergyMonitoring, |
| | | ShowFunction.Environmental, |
| | | ShowFunction.FreshAir,ShowFunction.Music, |
| | | ShowFunction.Panel,ShowFunction.SecurityMonitoring, |
| | | ShowFunction.Sensor,ShowFunction.VideoIntercom |
| | | ShowFunction.FloorHeating,ShowFunction.Music, |
| | | ShowFunction.Electric,ShowFunction.Environmental, |
| | | //ShowFunction.EnergyMonitoring, |
| | | //ShowFunction.FreshAir,ShowFunction.DoorLock, |
| | | //ShowFunction.Panel,ShowFunction.SecurityMonitoring, |
| | | //ShowFunction.Sensor,ShowFunction.VideoIntercom |
| | | }); |
| | | instance.SaveResidenceData(); |
| | | } |
| | |
| | | instance = null; |
| | | ins_OidList = null; |
| | | HomeGateway = null; |
| | | SpatialInfo.CurrentSpatial.ClearRooms(); |
| | | SpatialInfo.CurrentSpatial.Clear(); |
| | | FunctionList.List.Clear(); |
| | | if (MainPage.IsRemote) |
| | | { |
| | |
| | | { |
| | | if (HomeGateway != null && !string.IsNullOrEmpty(HomeGateway.gatewayId)) |
| | | { |
| | | return true; |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | return true; |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public void SaveResidenceData() |
| | | { |
| | | if (this == null || this.residecenInfo == null) |
| | | if (this == null || this.CurrentRegion == null) |
| | | return; |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | Common.FileUtlis.Files.WriteFileByBytes("DB_ResidenceData", ssd); |
| | | WirteResidenceInfo(ssd); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public string CurFoor = Language.StringByID(StringId.All); |
| | | |
| | | ///// <summary> |
| | | ///// 房间列表 |
| | | ///// </summary> |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<Room> Rooms = SpatialInfo.CurrentSpatial.RoomList; |
| | | /// <summary> |
| | | /// 根目录 |
| | | /// </summary> |
| | | static string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/"; |
| | | /// <summary> |
| | | /// 读取ResidenceInfo文件 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | static byte[] ReadResidenceInfo() |
| | | { |
| | | var fileName = "DB_ResidenceData"; |
| | | 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> |
| | | /// 保存ResidenceInfo |
| | | /// </summary> |
| | | /// <param name="bytes"></param> |
| | | /// <returns></returns> |
| | | static bool WirteResidenceInfo(byte[] bytes) |
| | | { |
| | | var fileName = "DB_ResidenceData"; |
| | | 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> |
| | | static string CreateUserFloder(string userId) |
| | | { |
| | | var path = Path.Combine(RootPath, userId); |
| | | if (!Directory.Exists(path)) |
| | | { |
| | | Directory.CreateDirectory(path); |
| | | } |
| | | return path + "/"; |
| | | } |
| | | |
| | | |
| | | #region oid列表 a协议转bus协议控制使用 |
| | | /// <summary> |