private void PopulatePageLst(DisplayPageSerialise[] displayPages) { XMLConverter xml = new XMLConverter(); foreach (DisplayPageSerialise d in displayPages) { DisplayPage dS = new DisplayPage(d.name); if (d.buttonList.Count > 0) { foreach (CustomButtonSerialise c in d.buttonList) { CustomButton cS = new CustomButton(c.poly, 0); cS.SetPageLink(c.pageLink); dS.AddCompletedButton(cS); } } if (d.circleBtnLst.Count > 0) { foreach (CircleButtonSerialise c in d.circleBtnLst) { dS.AddCircleButton(c.centre, c.radius, c.pageLink); } } Image bgI = xml.GetImageFromBase64(d.backgroundImage); bgI.Save(AppDomain.CurrentDomain.BaseDirectory + @"\images\" + d.name + ".png"); dS.AddBackgroundImage(bgI); dS.AddImagePath(AppDomain.CurrentDomain.BaseDirectory + @"\images\" + d.name + ".png"); pageLst.Add(dS); } }
/// <summary> /// /// </summary> private void Save() { List <DisplayPageSerialise> displayLstS = new List <DisplayPageSerialise>(); XMLConverter xml = new XMLConverter(); //Directory.CreateDirectory(saveFolder + @"\images"); foreach (DisplayPage d in pageLst) { DisplayPageSerialise dS = new DisplayPageSerialise(); dS.name = d.displayPageName; dS.backgroundImage = d.GetByteArrayFromBachgroundImage(); dS.buttonList = new List <CustomButtonSerialise>(); dS.circleBtnLst = new List <CircleButtonSerialise>(); if (d.GetButtonList().Count > 0) { foreach (CustomButton c in d.GetButtonList()) { CustomButtonSerialise cS = new CustomButtonSerialise(); cS.btnType = c.GetButtonType(); cS.pageLink = c.GetPageLink(); cS.poly = c.GetPoly(); dS.buttonList.Add(cS); } } if (d.GetCircleBtnLst().Count > 0) { foreach (CircleButton c in d.GetCircleBtnLst()) { CircleButtonSerialise cS = new CircleButtonSerialise(); cS.centre = c.GetCentre(); cS.pageLink = c.GetPageLink(); cS.radius = c.GetRadius(); dS.circleBtnLst.Add(cS); } } displayLstS.Add(dS); } File.WriteAllText(saveFolder, xml.ToXml(displayLstS)); }
public string FormatToXML(List <DisplayPage> dLst) { List <DisplayPageSerialise> displayLstS = new List <DisplayPageSerialise>(); XMLConverter xml = new XMLConverter(); foreach (DisplayPage d in dLst) { DisplayPageSerialise dS = new DisplayPageSerialise(); dS.name = d.displayPageName; dS.backgroundImage = d.GetBackgroundImage(); dS.buttonList = new List <CustomButtonSerialise>(); dS.circleBtnLst = new List <CircleButtonSerialise>(); if (d.GetButtonList().Count > 0) { foreach (CustomButton c in d.GetButtonList()) { CustomButtonSerialise cS = new CustomButtonSerialise(); cS.btnType = c.GetButtonType(); cS.pageLink = c.GetPageLink(); cS.poly = c.GetPoly(); dS.buttonList.Add(cS); } } if (d.GetCircleBtnLst().Count > 0) { foreach (CircleButton c in d.GetCircleBtnLst()) { CircleButtonSerialise cS = new CircleButtonSerialise(); cS.centre = c.GetCentre(); cS.pageLink = c.GetPageLink(); cS.radius = c.GetRadius(); } } displayLstS.Add(dS); } return(xml.ToXml(displayLstS)); }
private void loadProjectToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult discard = DialogResult.No; bool userCurrentlyCreatingProject = true; if (projectDisplaySize != new Size(0, 0)) { userCurrentlyCreatingProject = true; } else { userCurrentlyCreatingProject = false; } if (userCurrentlyCreatingProject == true) { discard = MessageBox.Show("Do you want to discard your old project?", "Discard Old Project", MessageBoxButtons.YesNo); } if (discard == DialogResult.Yes || userCurrentlyCreatingProject == false) { XMLConverter xml = new XMLConverter(); ResetAllVars(); string filePath = ""; using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Open Project"; dlg.Filter = "hen files (*.hen)|*.hen"; if (dlg.ShowDialog() == DialogResult.OK) { filePath = dlg.FileName; } } try { string xmlText = File.ReadAllText(filePath); PopulatePageLst(xml.FromXml <DisplayPageSerialise[]>(xmlText)); Image main = null; foreach (DisplayPage d in pageLst) { if (d.displayPageName == "Main Page") { main = d.GetBackgroundImage(); } } if (main != null) { int screenWidth = main.Width; int screenHeight = main.Height; projectDisplaySize = new Size(screenWidth, screenHeight); } foreach (DisplayPage d in pageLst) { CreateNewTab(d.displayPageName, d.GetImagePath(), true); } } catch (Exception ex) { MessageBox.Show("Error could not load the project", "Project load error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }