Ejemplo n.º 1
0
        private void addNewItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewSectionItemForm newSectionItemForm = new NewSectionItemForm(_bank);

            Bank.Key selectedKey = GetSelectedKey();
            if (selectedKey != null)
            {
                newSectionItemForm.Section = selectedKey.Section;
            }

            if (newSectionItemForm.ShowDialog() == DialogResult.OK)
            {
                Bank.Section selectedSection = newSectionItemForm.Section;
                Bank.Key     bankKey         = new Bank_Stuffs.Bank.Key();
                bankKey.Name    = newSectionItemForm.ItemName;
                bankKey.Section = selectedSection;
                bankKey.Type    = "string";
                bankKey.Value   = "";
                selectedSection.Keys.Add(bankKey);
                SaveBank();
                RefreshBankProperties();
            }
        }
Ejemplo n.º 2
0
        private Bank CreateBank(XDocument xmlDocument)
        {
            Bank bank = new Bank();

            //Check for bank-tag
            var bankNode = xmlDocument.Descendants("Bank").FirstOrDefault();

            if (bankNode == null)
            {
                return(null);
            }

            //Check for version
            var versionAttribute = bankNode.Attribute("version");

            if (versionAttribute != null)
            {
                bank.Version = versionAttribute.Value;
            }

            //Add sections
            XAttribute nameAttribute;

            foreach (var sectionNode in bankNode.Descendants("Section"))
            {
                Bank.Section section = new Bank.Section();
                bank.Sections.Add(section);

                nameAttribute = sectionNode.Attribute("name");
                if (nameAttribute != null)
                {
                    section.Name = nameAttribute.Value;
                }

                //Add keys
                foreach (var keyNode in sectionNode.Descendants("Key"))
                {
                    Bank.Key key = new Bank.Key();
                    key.Section = section;
                    section.Keys.Add(key);

                    nameAttribute = keyNode.Attribute("name");
                    if (nameAttribute != null)
                    {
                        key.Name = nameAttribute.Value;
                    }

                    //Key type/value are stored in the attributes of a single child "Value" node

                    foreach (var item in keyNode.Descendants())
                    {
                        var valueAttribute = item.Attributes().FirstOrDefault();
                        var tag            = item.Name.ToString();
                        var type           = valueAttribute.Name.ToString();
                        var value          = valueAttribute.Value;
                        key.Items.Add(new Bank.Item {
                            Name = tag, Type = type, Value = value
                        });
                    }
                }
            }

            return(bank);
        }
Ejemplo n.º 3
0
 private XElement CreateKey(Bank.Key key)
 {
     return(new XElement("Key", new XAttribute("name", key.Name), CreateItems(key.Items)));
 }
Ejemplo n.º 4
0
 private XElement CreateKey(Bank.Key key)
 {
     return(new XElement("Key", new XAttribute("name", key.Name),
                         new XElement("Value", new XAttribute(key.Type, key.Value))));
 }