private TreeNode LoadNode(BasicElement element, TreeNode parent) { string elementName = (string)Type.GetType(element.InherentType).InvokeMember("ElementName", BindingFlags.GetProperty, null, element, null); TreeNode node = new TreeNode(elementName); if (element.Properties.Count > 0) { foreach (BasicProperty property in element.Properties) { string text = (string)Type.GetType(property.InherentType).InvokeMember("ToString", BindingFlags.InvokeMethod, null, property, null); TreeNode propertyNode = new TreeNode(); propertyNode.Text = text; node.Nodes.Add(propertyNode); } } if (element.ChildElements.Count > 0) { foreach (BasicElement child in element.ChildElements) { node.Nodes.Add(LoadNode(child, node)); } } return (node); }
public static bool DeleteBlock(BasicElement block) { string fileName = Utility.EncodeTo64UTF8(block.ToString()) + Constants.DEFAULTEXTENSION; string filePath = Path.Combine(Constants.DEFAULTSAVEPATH, fileName); if (File.Exists(filePath)) { File.Delete(filePath); } return (!File.Exists(filePath)); }
public static BasicElement LoadBuildFile(string path) { BasicElement ret = new BasicElement(""); XmlDocument doc = new XmlDocument(); using (Stream stream = File.OpenRead(path)) { doc.Load(stream); } ret = ParseBuildFile(doc); return (ret); }
private void LoadAllChildElements(BasicElement element) { if (element.ChildElements.Count > 0) { foreach (BasicElement child in element.ChildElements) { comboBox2.Items.Add(child); if (child.ChildElements.Count > 0) { LoadAllChildElements(child); } } } }
private void BlockForm_Load(object sender, EventArgs e) { comboBox2.Items.Clear(); comboBox1.Items.Clear(); if (Element == null) { Element = new BasicElement("New Element"); Element.Properties.Add(new BasicProperty("Argument", "somethingcool")); Element.Properties.Add(new BasicProperty("Argument", "somethingcrappy")); } comboBox2.Items.Add(Element); LoadAllChildElements(Element); comboBox2.SelectedItem = Element; }
private void LoadBlocks() { BasicElement[] blocks = Utility.LoadBlocks(); if (blocks.Length > 0) { foreach (BasicElement element in blocks) { BlocksListBox.Items.Add(element); } } else { BasicElement projectNode = new BasicElement("Project"); BasicProperty prop = new BasicProperty("name", "Octgn test build"); projectNode.Properties.Add(prop); prop = new BasicProperty("default", "Build"); projectNode.Properties.Add(prop); BlocksListBox.Items.Add(projectNode); } }
public static BasicElement[] LoadBlocks() { if (Directory.Exists(Constants.DEFAULTSAVEPATH)) { string[] files = Directory.GetFiles(Constants.DEFAULTSAVEPATH, Constants.SAVEDBLOCKSSEARCHPATTERN); BasicElement[] returnArray = new BasicElement[files.Length]; XmlSerializer serializer = new XmlSerializer(typeof(BasicElement)); for (int i = 0; i < files.Length; i++) { using (Stream stream = File.OpenRead(files[i])) { returnArray[i] = (BasicElement)serializer.Deserialize(stream); } } return (returnArray); } else { BasicElement[] returnArray = new BasicElement[0]; return (returnArray); } }
public static BasicElement ParseBuildElement(XmlNode node) { if (node.NodeType == XmlNodeType.CDATA) { CDataElement cdata = new CDataElement(); CDataValue prop = new CDataValue(); prop.Value = node.InnerText; cdata.Properties.Add(prop); return (cdata); } if (node.NodeType == XmlNodeType.Comment) { BasicElement comment = new BasicElement("Comment"); BasicProperty prop = new BasicProperty(); prop.Name = ""; prop.Value = node.InnerText; comment.Properties.Add(prop); return (comment); } BasicElement element = new BasicElement(); element.ElementName = node.Name; if (node.Attributes != null && node.Attributes.Count > 0) { foreach (XmlAttribute attribute in node.Attributes) { BasicProperty prop = new BasicProperty(); prop.Name = attribute.Name; prop.Value = attribute.Value; element.Properties.Add(prop); } } if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { element.ChildElements.Add(ParseBuildElement(child)); } } return (element); }
public static void SaveBlocks(BasicElement[] elementArray) { if (elementArray.Length > 0) { if (!Directory.Exists(Constants.DEFAULTSAVEPATH)) { Directory.CreateDirectory(Constants.DEFAULTSAVEPATH); } XmlSerializer serializer = new XmlSerializer(typeof(BasicElement)); foreach (BasicElement element in elementArray) { string fileName = Utility.EncodeTo64UTF8(element.ToString()) + Constants.DEFAULTEXTENSION; string savePath = Path.Combine(Constants.DEFAULTSAVEPATH, fileName); using (Stream stream = File.Open(savePath, FileMode.Create)) { serializer.Serialize(stream, element); } } } }
public static BasicElement ParseBuildFile(XmlDocument doc) { BasicElement root = new BasicElement(); root.ElementName = doc.DocumentElement.Name; if (doc.DocumentElement.HasAttributes) { foreach (XmlAttribute attribute in doc.DocumentElement.Attributes) { BasicProperty prop = new BasicProperty(); prop.Name = attribute.Name; prop.Value = attribute.Value; root.Properties.Add(prop); } } if (doc.DocumentElement.HasChildNodes) { foreach (XmlNode child in doc.DocumentElement.ChildNodes) { root.ChildElements.Add(ParseBuildElement(child)); } } return (root); }
private void SaveBlocks() { BasicElement[] array = new BasicElement[BlocksListBox.Items.Count]; BlocksListBox.Items.CopyTo(array, 0); Utility.SaveBlocks(array); }
private TreeNode LoadTree(BasicElement rootElement) { TreeNode rootNode = new TreeNode(rootElement.ElementName); if (rootElement.Properties.Count > 0) { foreach (BasicProperty property in rootElement.Properties) { TreeNode propertyNode = new TreeNode(); propertyNode.Text = property.ToString(); rootNode.Nodes.Add(propertyNode); } } if (rootElement.ChildElements.Count > 0) { foreach (BasicElement element in rootElement.ChildElements) { rootNode.Nodes.Add(LoadNode(element, rootNode)); } } return (rootNode); }