public static void Save(KNXApp knxApp) { // var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; var jsonData = JsonConvert.SerializeObject(knxApp, Formatting.None, settings); File.WriteAllText(Path.Combine(MyCache.ProjectFolder, MyConst.KnxUiMetaDataFile), jsonData, Encoding.UTF8); }
public static KNXApp TestCase2() { var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.Auto; string json = File.ReadAllText(TestFile); KNXApp app = JsonConvert.DeserializeObject <KNXApp>(json, settings); KNXArea a = app.Areas[0]; KNXRoom b = a.Rooms[0]; KNXPage c = b.Pages[0]; KNXGrid d = c.Grids[0]; var e = d.Controls[0]; return(app); }
public AppNode(KNXApp knx) : base(knx) { string FileDefaultIcon = Path.Combine(MyCache.ProjImagePath, MyConst.DefaultIcon); if (!File.Exists(FileDefaultIcon)) { File.Copy(Path.Combine(MyCache.ProjectResImgDir, MyConst.DefaultIcon), Path.Combine(MyCache.ProjImagePath, MyConst.DefaultIcon)); } this.Name = ImageKey = SelectedImageKey = MyConst.View.KnxAppType; this.Text = knx.Text; this.About = knx.About; this.Logo = knx.Logo; this.Symbol = knx.Symbol; //this.DefaultLanguage = knx.DefaultLanguage; }
public static KNXApp TestCase1() { // 应用 KNXApp app = new KNXApp(); app.Areas = new List <KNXArea>(); app.About = "Data Structure Test"; app.DefaultLanguage = Language.Chinese; app.Symbol = "res/img/default_app.png"; app.Logo = "res/img/default_app.png"; app.Text = "ayControl Demo"; // 楼层 KNXArea groundFloor = new KNXArea(); groundFloor.Rooms = new List <KNXRoom>(); KNXArea firstFloor = new KNXArea(); firstFloor.Rooms = new List <KNXRoom>(); KNXArea secondFloor = new KNXArea(); secondFloor.Rooms = new List <KNXRoom>(); KNXArea general = new KNXArea(); general.Rooms = new List <KNXRoom>(); app.Areas.Add(groundFloor); app.Areas.Add(firstFloor); app.Areas.Add(secondFloor); app.Areas.Add(general); groundFloor.Text = "Ground Floor"; firstFloor.Text = "First Floor"; secondFloor.Text = "Second Floor"; general.Text = "General"; // 底层 KNXRoom home = new KNXRoom(); home.Pages = new List <KNXPage>(); KNXRoom entrance = new KNXRoom(); entrance.Pages = new List <KNXPage>(); KNXRoom outdoor = new KNXRoom(); outdoor.Pages = new List <KNXPage>(); groundFloor.Rooms.Add(home); groundFloor.Rooms.Add(entrance); groundFloor.Rooms.Add(outdoor); home.Text = "Home"; home.Symbol = "res/img/default_app.png"; entrance.Text = "Entrance"; entrance.Symbol = "res/img/default_app.png"; outdoor.Text = "Outdoor"; outdoor.Symbol = "res/img/default_app.png"; // 一层 KNXRoom livingRoom = new KNXRoom(); KNXRoom bedRoom = new KNXRoom(); firstFloor.Rooms.Add(livingRoom); firstFloor.Rooms.Add(bedRoom); livingRoom.Text = "Living Room"; livingRoom.Symbol = "res/img/default_app.png"; bedRoom.Text = "Bedroom"; bedRoom.Symbol = "res/img/default_app.png"; // 二层 KNXRoom bedRoom2 = new KNXRoom(); secondFloor.Rooms.Add(bedRoom2); bedRoom2.Text = "Bedroom"; bedRoom2.Symbol = "res/img/default_app.png"; // 其他 KNXRoom energy = new KNXRoom(); KNXRoom securityPin = new KNXRoom(); KNXRoom climate = new KNXRoom(); general.Rooms.Add(energy); general.Rooms.Add(securityPin); general.Rooms.Add(climate); energy.Text = "Energy"; energy.Symbol = "res/img/default_app.png"; securityPin.Text = "Security Pin123"; securityPin.Symbol = "res/img/default_app.png"; climate.Text = "Climate"; climate.Symbol = "res/img/default_app.png"; // home KNXPage homePage = new KNXPage(); homePage.Grids = new List <KNXGrid>(); home.Pages.Add(homePage); homePage.Text = "Page"; homePage.BackgroudImage = "res/image/backup_image.png"; homePage.ColumnCount = 1; homePage.RowCount = 9; KNXGrid top = new KNXGrid(); top.Controls = new List <KNXControlBase>(); KNXGrid bottom = new KNXGrid(); bottom.Controls = new List <KNXControlBase>(); homePage.Grids.Add(top); homePage.Grids.Add(bottom); top.Column = 0; top.Row = 0; top.ColumnSpan = 1; top.RowSpan = 4; bottom.Column = 0; bottom.Row = 5; bottom.ColumnSpan = 1; bottom.RowSpan = 4; KNXButton comingHome = new KNXButton(); KNXButton leavingTheHouse = new KNXButton(); top.Controls.Add(comingHome); top.Controls.Add(leavingTheHouse); comingHome.Text = "Coming Home"; comingHome.Column = 0; comingHome.Row = 0; leavingTheHouse.Text = "Leaving teh House"; leavingTheHouse.Column = 0; leavingTheHouse.Row = 1; KNXButton goingToSleep = new KNXButton(); KNXButton gettingUp = new KNXButton(); bottom.Controls.Add(goingToSleep); bottom.Controls.Add(gettingUp); goingToSleep.Text = "Going to Sleep"; goingToSleep.Column = 0; goingToSleep.Row = 0; gettingUp.Text = "Getting Up"; gettingUp.Column = 0; gettingUp.Row = 1; var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.Auto; string json = JsonConvert.SerializeObject(app, Formatting.Indented, settings); json.Replace("$Type", "@class"); File.WriteAllText(TestFile, json); return(app); }
public KNXApp ToKnx() { KNXApp knx = new KNXApp(); base.ToKnx(knx); knx.About = this.About; knx.Logo = this.Logo; knx.Symbol = this.Symbol; knx.Areas = new System.Collections.Generic.List<KNXArea>(); return knx; }
/// <summary> /// 导出树形结构为json文件 /// </summary> /// <param name="tvwAppdata"></param> /// <param name="fileName"></param> public static KNXApp ExportTreeView(TreeView tvwAppdata) { KNXApp app = new KNXApp(); if (tvwAppdata.Nodes.Count > 0) { // 生成应用 var appNode = tvwAppdata.Nodes[0] as AppNode; if (appNode != null) { app = appNode.ToKnx(); if (appNode.Nodes.Count > 0) { foreach (TreeNode it1 in appNode.Nodes) { #region 添加区域 if (MyConst.View.KnxAreaType == it1.Name) { var areaNode = it1 as AreaNode; if (areaNode != null) { var area = areaNode.ToKnx(); app.Areas.Add(area); if (it1.Nodes.Count > 0) { #region 添加房间 foreach (TreeNode it2 in it1.Nodes) { if (MyConst.View.KnxRoomType == it2.Name) { var roomNode = it2 as RoomNode; if (roomNode != null) { var room = roomNode.ToKNX(); area.Rooms.Add(room); if (it2.Nodes.Count > 0) { #region 添加页面 foreach (TreeNode it3 in it2.Nodes) { if (MyConst.View.KnxPageType == it3.Name) { var pageNode = it3 as PageNode; if (pageNode != null) { #region 添加页面 var page = pageNode.ToKnx(); room.Pages.Add(page); if (it3.Nodes.Count > 0) { // 添加 grid foreach (TreeNode it4 in it3.Nodes) { ExportControls(page, it4); //if (MyConst.View.KnxGroupBoxType == it4.Name) //{ // #region 添加控件 // var gridNode = it4 as GroupBoxNode; // if (gridNode != null) // { // var grid = gridNode.ToKnx(); // page.GroupBoxs.Add(grid); // if (it4.Nodes.Count > 0) // { // // 添加控件 // foreach (TreeNode it5 in it4.Nodes) // { // ExportControls(grid, it5); // } // } // } // #endregion //} //else //{ // #region 添加控件 // ExportControls(page, it4); // #endregion //} } } #endregion } } } #endregion } } } } #endregion } } } #endregion } } //// 写 Json 文件 //var settings = new JsonSerializerSettings(); //settings.TypeNameHandling = TypeNameHandling.Auto; //string json = JsonConvert.SerializeObject(app, Formatting.Indented, settings); //File.WriteAllText(fileName, json); } } return app; }
/// <summary> /// 导入 JSON 文件,生成 Treeview 节点 /// </summary> /// <param name="app"></param> /// <param name="tvwAppdata"></param> public static AppNode ImportNode(KNXApp app/*, TreeView tv, UIEditor.Entity.ViewNode.PropertiesChangedDelegate proChangedDelegate*/) { AppNode appNode = null; if (app != null) { //tvwAppdata.BeginUpdate(); //tvwAppdata.Nodes.Clear(); appNode = new AppNode(app); //tvwAppdata.Nodes.Add(appNode); if (app.Areas != null && app.Areas.Count > 0) { foreach (KNXArea itemArea in app.Areas) { var areaNode = new AreaNode(itemArea); appNode.Nodes.Add(areaNode); if (itemArea.Rooms != null && itemArea.Rooms.Count > 0) { foreach (KNXRoom itemRoom in itemArea.Rooms) { var roomNode = new RoomNode(itemRoom); areaNode.Nodes.Add(roomNode); if (itemRoom.Pages != null && itemRoom.Pages.Count > 0) { foreach (KNXPage itemPage in itemRoom.Pages) { var pageNode = new PageNode(itemPage); //pageNode.PropertiesChangedEvent += proChangedDelegate; roomNode.Nodes.Add(pageNode); // 给页面添加控件 if (itemPage.Controls != null && itemPage.Controls.Count > 0) { foreach (var item in itemPage.Controls) { AddControlNode(pageNode, item/*, proChangedDelegate*/); } } } } } } } } //tvwAppdata.EndUpdate(); } return appNode; }
public static KNXApp TestCase1() { // 应用 KNXApp app = new KNXApp(); app.Areas = new List<KNXArea>(); app.About = "Data Structure Test"; app.DefaultLanguage = Language.Chinese; app.Symbol = "res/img/default_app.png"; app.Logo = "res/img/default_app.png"; app.Text = "ayControl Demo"; // 楼层 KNXArea groundFloor = new KNXArea(); groundFloor.Rooms = new List<KNXRoom>(); KNXArea firstFloor = new KNXArea(); firstFloor.Rooms = new List<KNXRoom>(); KNXArea secondFloor = new KNXArea(); secondFloor.Rooms = new List<KNXRoom>(); KNXArea general = new KNXArea(); general.Rooms = new List<KNXRoom>(); app.Areas.Add(groundFloor); app.Areas.Add(firstFloor); app.Areas.Add(secondFloor); app.Areas.Add(general); groundFloor.Text = "Ground Floor"; firstFloor.Text = "First Floor"; secondFloor.Text = "Second Floor"; general.Text = "General"; // 底层 KNXRoom home = new KNXRoom(); home.Pages = new List<KNXPage>(); KNXRoom entrance = new KNXRoom(); entrance.Pages = new List<KNXPage>(); KNXRoom outdoor = new KNXRoom(); outdoor.Pages = new List<KNXPage>(); groundFloor.Rooms.Add(home); groundFloor.Rooms.Add(entrance); groundFloor.Rooms.Add(outdoor); home.Text = "Home"; home.Symbol = "res/img/default_app.png"; entrance.Text = "Entrance"; entrance.Symbol = "res/img/default_app.png"; outdoor.Text = "Outdoor"; outdoor.Symbol = "res/img/default_app.png"; // 一层 KNXRoom livingRoom = new KNXRoom(); KNXRoom bedRoom = new KNXRoom(); firstFloor.Rooms.Add(livingRoom); firstFloor.Rooms.Add(bedRoom); livingRoom.Text = "Living Room"; livingRoom.Symbol = "res/img/default_app.png"; bedRoom.Text = "Bedroom"; bedRoom.Symbol = "res/img/default_app.png"; // 二层 KNXRoom bedRoom2 = new KNXRoom(); secondFloor.Rooms.Add(bedRoom2); bedRoom2.Text = "Bedroom"; bedRoom2.Symbol = "res/img/default_app.png"; // 其他 KNXRoom energy = new KNXRoom(); KNXRoom securityPin = new KNXRoom(); KNXRoom climate = new KNXRoom(); general.Rooms.Add(energy); general.Rooms.Add(securityPin); general.Rooms.Add(climate); energy.Text = "Energy"; energy.Symbol = "res/img/default_app.png"; securityPin.Text = "Security Pin123"; securityPin.Symbol = "res/img/default_app.png"; climate.Text = "Climate"; climate.Symbol = "res/img/default_app.png"; // home KNXPage homePage = new KNXPage(); homePage.Grids = new List<KNXGrid>(); home.Pages.Add(homePage); homePage.Text = "Page"; homePage.BackgroudImage = "res/image/backup_image.png"; homePage.ColumnCount = 1; homePage.RowCount = 9; KNXGrid top = new KNXGrid(); top.Controls = new List<KNXControlBase>(); KNXGrid bottom = new KNXGrid(); bottom.Controls = new List<KNXControlBase>(); homePage.Grids.Add(top); homePage.Grids.Add(bottom); top.Column = 0; top.Row = 0; top.ColumnSpan = 1; top.RowSpan = 4; bottom.Column = 0; bottom.Row = 5; bottom.ColumnSpan = 1; bottom.RowSpan = 4; KNXButton comingHome = new KNXButton(); KNXButton leavingTheHouse = new KNXButton(); top.Controls.Add(comingHome); top.Controls.Add(leavingTheHouse); comingHome.Text = "Coming Home"; comingHome.Column = 0; comingHome.Row = 0; leavingTheHouse.Text = "Leaving teh House"; leavingTheHouse.Column = 0; leavingTheHouse.Row = 1; KNXButton goingToSleep = new KNXButton(); KNXButton gettingUp = new KNXButton(); bottom.Controls.Add(goingToSleep); bottom.Controls.Add(gettingUp); goingToSleep.Text = "Going to Sleep"; goingToSleep.Column = 0; goingToSleep.Row = 0; gettingUp.Text = "Getting Up"; gettingUp.Column = 0; gettingUp.Row = 1; var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.Auto; string json = JsonConvert.SerializeObject(app, Formatting.Indented, settings); json.Replace("$Type", "@class"); File.WriteAllText(TestFile, json); return app; }