using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shared.SimpleControl;
namespace Shared
{
///
/// 场景
///
[System.Serializable]
public class Scene : Common
{
public readonly static string GlobalSceneFilePath = "GlobalScene";
static Scene ()
{
Refresh ();
}
public static void Refresh()
{
if (null == Newtonsoft.Json.JsonConvert.DeserializeObject> (Encoding.UTF8.GetString (IO.FileUtils.ReadFile (GlobalSceneFilePath)))) {
//初始化房间列表
IO.FileUtils.WriteFileByBytes (GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new List ())));
}
}
public Scene ()
{
this.Type = DeviceType.Scene;
DeviceTextID = SimpleControl.R.MyInternationalizationString.Scenes;
}
///
/// 场景小图标
///
public string SceneIconPath = "";
///
/// 场景的背景图
///
public string BackgroundImagePath = "Scene/s1.png";
///
/// 根据场景路径恢复场景对象
///
/// The by file path.
/// Room file path.
public static Scene GetSceneByFilePath (string sceneFilePath)
{
try {
return Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (sceneFilePath)));
} catch {
return new Scene ();
}
}
///
/// 控制目标的文件路径,格式如:RoomScene100000000_+LightSwitch_Equipment_
///
public readonly List DeviceFilePathList = new List ();
///
/// 全局场景里所有的视图类型
///
public List GlobalSceneDeviceList = new List { };
///
/// 保存当前场景
///
/// Scence file path.
public void Save (string sceneFilePath)
{
IO.FileUtils.WriteFileByBytes (sceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this)));
}
///
/// bus上传的场景标识
///
public bool busScene = false;
public void initBusScene ()
{
//var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
//sceneFileList.Add ("GlobalScene_busScene");
//var ss = new Scene ();
//ss.Name = "busScene";
//ss.BackgroundImagePath = "Scene/s0.png";
//ss.GlobalSceneDeviceList.Add (new Common () { SubnetID = 1, DeviceID = 1, obj1 = 1, obj2 = 1, obj3 = 1, obj4 = 1, obj5 = 1, });
//ss.GlobalSceneDeviceList.Add (new Common () { SubnetID = 2, DeviceID = 2, obj1 = 2, obj2 = 2, obj3 = 2, obj4 = 2, obj5 = 2, });
//IO.FileUtils.WriteFileByBytes ("GlobalScene_busScene", CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (ss)));
//IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
//var ssfsdf = IO.FileUtils.ReadFile ("GlobalScene_busScene");
//var cp = CommonPage.MyEncodingUTF8.GetString (ssfsdf);
}
}
}