private void ReadVeiwFromXML(XmlNode viewNode) { SortedList <string, string> Properties = new SortedList <string, string>(); String[] elementNames; XmlNode itemNode; View curentWorkingView = null; Char delimiter = ','; String[] substrings = viewNode.Attributes["name"].InnerText.Split(delimiter); string propval, alpha, color; Brush randomColor; //We go through all the names listed in the Name attribute foreach (var substring in substrings) { //We check whether we have already created a view, if not created, create, if yes, take the existing if (views.Keys.IndexOf(substring.Trim()) > -1) { curentWorkingView = views[substring.Trim()]; } else { curentWorkingView = new View(substring.Trim(), parentCanvasWidth, parentCanvasHeight); } //We start filling in the elements for the current view for (int y = 0; y < viewNode.ChildNodes.Count; y++) { itemNode = viewNode.ChildNodes[y]; //Fill the properties for each element. Properties.Clear(); for (int z = 0; z < itemNode.ChildNodes.Count; z++) { propval = ""; alpha = ""; color = ""; propval = itemNode.ChildNodes[z].InnerText; if (itemNode.ChildNodes[z].Name.ToLower().Contains("color")) { if (propval.Length == 8) { //переносим альфа канал в начало строки цвета color = propval.Substring(0, 6); alpha = propval.Substring(6, propval.Length - 6); propval = "#" + alpha + color; } } Properties.Add(itemNode.ChildNodes[z].Name, propval); } //Fill the element with the properties obtained from the file or create a new element with the specified properties elementNames = itemNode.Attributes["name"].InnerText.Split(delimiter); string bgsound = "", background = "", logo = ""; foreach (var elementName in elementNames) { switch (viewNode.ChildNodes[y].Attributes["name"].InnerText) { case "bgsound": foreach (XmlNode childNodes in itemNode.ChildNodes) { if (childNodes.Name == "path") { bgsound = childNodes.InnerText; } } curentWorkingView.bgsound = bgsound; break; case "background": foreach (XmlNode childNodes in itemNode.ChildNodes) { if (childNodes.Name == "path") { background = childNodes.InnerText; } } curentWorkingView.background = background; break; default: if (viewNode.ChildNodes[y].Attributes["name"].InnerText == "logo") { foreach (XmlNode childNodes in itemNode.ChildNodes) { if (childNodes.Name == "path") { logo = childNodes.InnerText; } } curentWorkingView.logo = logo; //Для систем не создаем элемент лого. if (substring == "system") { continue; } } Element.types type; try { type = (Element.types)Enum.Parse(typeof(Element.types), itemNode.Name, true); } catch (Exception err) { Logger.Write(err); continue; } randomColor = SomeUtilities.GetRandomColor(); if (!curentWorkingView.elements.ContainsKey(elementName.Trim())) { curentWorkingView.elements.Add(elementName.Trim(), new Element(elementName.Trim(), type, Properties, parentCanvasWidth, parentCanvasHeight, randomColor)); } else { curentWorkingView.elements[elementName.Trim()].filligFromProperties(Properties, parentCanvasWidth, parentCanvasHeight, randomColor); } break; } } } //If the resulting view is not null, we save it if (curentWorkingView != null) { views.Remove(curentWorkingView.name); views.Add(curentWorkingView.name, curentWorkingView); } } }
private void btn_addCustomelement_Click(object sender, RoutedEventArgs e) { customElements.Add(tb_customelementName.Text, cb_customelementType.SelectedValue.ToString()); onElementCreate(tb_customelementName.Text, (Element.types)System.Enum.Parse(typeof(Element.types), cb_customelementType.SelectedValue.ToString()), SomeUtilities.GetRandomColor(), 1); cb_CustomeItem.Items.Add(tb_customelementName.Text); cb_SelectCreatedelement.Items.Add(tb_customelementName.Text); }