using System;
using System.Collections.Generic;
using Shared.Phone;
using Shared.Phone.UserCenter;
namespace Shared.Common
{
///
/// 住宅文件
///
[System.Serializable]
public class House
{
#region ◆ 变量____________________________
///
/// 住宅文件
///
/// The file path.
[Newtonsoft.Json.JsonIgnore]
public string FileName
{
get
{
return $"House_{Id}.json";
}
}
///
/// 住宅id--使用云端提供的住宅唯一Id
///
public string Id = string.Empty;
///
/// 住宅名称
///
public string Name = string.Empty;
///
/// 是否为其他主用户分享过来的住宅
///
public bool IsOtherShare;
///
/// 该住宅是否是虚拟的,true的话代表网关和设备都是虚拟的(默认为false)
///
public bool IsVirtually = false;
///
/// 仅子账号登陆的时候使用,当【IsOthreShare】为"true",并且【AccountType】为"1"时,该账号拥有管理员权限
///
public int AccountType;
///
/// 经度
///
public double Longitude = 0;
///
/// 纬度
///
public double Latitude = 0;
///
/// 是否拥有远程控制权限
///
public bool IsRemoteControl = false;
///
/// 住宅所在的地理位置的名称
///
public string ResidenceAddressName = string.Empty;
///
/// 楼层字典
/// key:FloorId
/// value:FloorName
///
public Dictionary FloorDics = new Dictionary { };
///
/// -1:未配置(需要重新选择) 1:无模板有设备 2:有模板有设备 3:无模板无设备(请无视这个变量)
///
public int TemplateMode = -1;
///
/// 该住宅是否是展示模板(此变量是给查看模板数据时使用的,请无视这个变量)
///
[Newtonsoft.Json.JsonIgnore]
public bool IsShowTemplate = false;
///
/// 当前住宅选择的模板名字(请无视这个变量)
///
public string SelectTemplate = string.Empty;
///
/// 自定义单元的标题名称(与ListUintContent个数匹配,请无视这个变量)
///
public List ListUintName = new List();
///
/// 自定义单元的内容(与ListUintName个数匹配,请无视这个变量)
///
public List ListUintContent = new List();
///
/// 最后编辑的事件(2020.05.26追加) 1970/12/31 23:59格式
///
public string LastEditorTime = "1970/12/31 23:59";
///
/// 标识此住宅的数据是否已经发送过模板数据给网关(只针对TemplateMode=2,请无视这个变量)
///
public bool SendTemplateSuccess = false;
///
/// 这个住宅下所拥有的网关id(2020.05.26追加,null代表没有处理过,请无视这个变量)
///
[Newtonsoft.Json.JsonIgnore]
public List listGatewayId = null;
///
/// 标识住宅数据的区分(文件读取时配置,请无视这个变量):
/// 1:本身自己的数据(文件夹名字为住宅id)
/// 2:自己手动创建的保存在本机的备份(文件夹名字以【BackupResidenceData】开头)
/// 3:此数据从云端下载而来(文件夹名字以【DownLoadResidenceData】开头)
///
[Newtonsoft.Json.JsonIgnore]
public int HouseDataDiv = 1;
///
/// 当前住宅的在线状态 -1:虚拟 0:离线 1:本地 2:远程 3:读取中(请无视这个变量)
///
[Newtonsoft.Json.JsonIgnore]
public string NowHomeOnlineStatu = "3";
///
/// 当前存放住宅数据的文件夹名字(此变量是给本机备份,或者云端下载备份使用的,请无视这个变量)
///
[Newtonsoft.Json.JsonIgnore]
public string SaveDirctoryName = string.Empty;
#endregion
#region ◆ 楼层____________________________
///
/// GetCurrentFloorName
///
///
[Newtonsoft.Json.JsonIgnore]
public string GetCurrentFloorName
{
get
{
return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId);
}
}
///
/// 当前楼层id
///
private string m_CurrentFloorId = string.Empty;
///
/// 当前楼层Id
///
[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 ◆ 保存____________________________
///
/// 保存
///
/// 是否备份
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
}
}