using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.Entity
{
public class Scene
{
///
/// 远端唯一ID
///
public string userSceneId = "";
///
/// 场景sid
///
public string sid = "";
///
/// 场景名称
///
public string name = "";
///
/// 网关ID
///
public string gatewayId = "";
///
/// 云端oss存储图片的路径
///
public string image = "";
///
/// 所属房间列表
///
public List roomIds = new List();
///
/// 延时
///
public int delay = 0;
///
/// 延时显示的文本
///
[Newtonsoft.Json.JsonIgnore]
public string delayText
{
get
{
string text = "";
switch (delay)
{
case 0:
text = Language.StringByID(StringId.NoDelay);
break;
case 30:
text = "30s";
break;
case 60:
text = "1min";
break;
case 120:
text = "2min";
break;
case 300:
text = "5min";
break;
}
return text;
}
}
///
/// 场景分组
///
public string group = "1";
///
/// 场景类型
///
public SceneType sceneType = SceneType.OrdinaryScenes;
///
/// 收藏标记
///
public bool collect = false;
///
/// 场景背景
///
public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png";
///
/// 场景功能列表
///
public List functions = new List();
///
/// 场景推送配置列表
///
public List pushConfigs = new List();
///
/// 生成场景sid
///
public void NewSid()
{
string sSceneid = "";
try
{
string sOidBeginsWith = "000101";//厂商 + 通讯方式
DateTime dt = DateTime.Now;
DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
long m = (long)((dt - startTime).TotalMilliseconds / 10);
string sTimeSpan = "00000000";
byte[] arry = new byte[4];
arry[0] = (byte)(m & 0xFF);
arry[1] = (byte)((m & 0xFF00) >> 8);
arry[2] = (byte)((m & 0xFF0000) >> 16);
arry[3] = (byte)((m >> 24) & 0xFF);
sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
if (sTimeSpan.Length > 8)
{
sTimeSpan = sTimeSpan.Substring(0, 8);
}
else
{
sTimeSpan = "00000000";
}
sSceneid = sOidBeginsWith + sTimeSpan;
sSceneid += "0A";
sSceneid += "0A01";
//0A01 物模型为场景, 0001 表示 1 号场景功能
int iTopSceneId = 1;
Random random = new Random();
iTopSceneId = random.Next(0, 255);
iTopSceneId += random.Next(0, 255);
sSceneid += iTopSceneId.ToString("X4");//场景号 两个byte
sSceneid += "1100";
sid = sSceneid;
}
catch
{
sid = sSceneid;
}
}
///
/// 获取设备添加到房间的房间名称
///
///
public string GetRoomListName()
{
string roomNameList = "";
foreach (var roomId in roomIds)
{
var findRoom = DB_ResidenceData.Rooms.Find(obj => obj.uid == roomId);
if (findRoom == null)
{
continue;
}
if (roomNameList != "")
{
roomNameList += ",";
}
roomNameList += findRoom.floorName + findRoom.roomName;
}
if (roomNameList == "" )
{
roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene);
}
return roomNameList;
}
///
/// 数据存储文件名
///
[Newtonsoft.Json.JsonIgnore]
public string savePath
{
get
{
return "SceneData_" + sid;
}
}
///
/// 保存功能数据
///
public void SaveSceneData()
{
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
FileUtils.WriteFileByBytes(savePath + this.sid, ssd);
MainPage.Log($"Save Scene Data : {this.sid}");
}
///
/// 更新时间
///
public DateTime refreshTime = DateTime.MinValue;
}
///
/// 场景功能对象
///
public class SceneFunction
{
public string sid = "";
public List status = new List();
///
/// 功能延时
///
public string delay = "0";
Function _localFunction;
///
/// 本地对应的功能
///
[Newtonsoft.Json.JsonIgnore]
public Function localFunction {
get
{
if(_localFunction == null)
{
_localFunction = ConvertFunctionObject();
}
return _localFunction;
}
}
///
/// 转换成功能对象
///
///
Function ConvertFunctionObject()
{
var localFunction = DB_ResidenceData.functionList.GetAllDeviceFunctionList().Find((obj) => obj.sid == sid);
foreach (var s in status)
{
localFunction.attributes.Add(new FunctionAttributes() { key = s.key, curValue = s.value, value = new List() { s.value } });
}
return localFunction;
}
}
///
/// 场景功能属性
///
public class SceneFunctionStatus
{
public string key = "";
public string value = "";
}
///
/// 场景推送配置
///
public class ScenePushConfig
{
///
/// 推送方式
///
public string pushMethod = "";
///
/// 推送内容
///
public string pushContent = "";
///
/// 推送目标集合
///
public List pushTarget = new List();
}
}