Esempio n. 1
0
 public static bool LoadPropertiesFromStream(string fileName)
 {
     if (!File.Exists(fileName))
     {
         return(false);
     }
     try {
         using (LockPropertyFile()) {
             using (XmlTextReader reader = new XmlTextReader(fileName)) {
                 while (reader.Read())
                 {
                     if (reader.IsStartElement())
                     {
                         if (reader.LocalName == propertyXmlRootNodeName)
                         {
                             properties.ReadProperties(reader, propertyXmlRootNodeName);
                             return(true);
                         }
                     }
                 }
             }
         }
     } catch (XmlException ex) {
         MessageService.ShowError("Error loading properties: " + ex.Message + "\nSettings have been restored to default values.");
     }
     return(false);
 }
Esempio n. 2
0
 internal void ReadProperties(XmlReader reader, string endElement)
 {
     if (reader.IsEmptyElement)
     {
         return;
     }
     while (reader.Read())
     {
         XmlNodeType nodeType = reader.NodeType;
         if (nodeType != XmlNodeType.Element)
         {
             if (nodeType == XmlNodeType.EndElement && reader.LocalName == endElement)
             {
                 return;
             }
         }
         else
         {
             string text = reader.LocalName;
             if (text == "Properties")
             {
                 text = reader.GetAttribute(0);
                 Properties properties = new Properties();
                 properties.ReadProperties(reader, "Properties");
                 this.properties[text] = properties;
             }
             else
             {
                 if (text == "Array")
                 {
                     text = reader.GetAttribute(0);
                     this.properties[text] = this.ReadArray(reader);
                 }
                 else
                 {
                     if (text == "SerializedValue")
                     {
                         text = reader.GetAttribute(0);
                         this.properties[text] = new Properties.SerializedValue(reader.ReadInnerXml());
                     }
                     else
                     {
                         this.properties[text] = (reader.HasAttributes ? reader.GetAttribute(0) : null);
                     }
                 }
             }
         }
     }
 }
        internal void ReadProperties(XmlReader reader, string endElement)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == endElement)
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    string propertyName = reader.LocalName;
                    if (propertyName == "Properties")
                    {
                        propertyName = reader.GetAttribute(0);
                        Properties p = new Properties();
                        p.ReadProperties(reader, "Properties");
                        properties[propertyName] = p;
                    }
                    else if (propertyName == "Array")
                    {
                        propertyName             = reader.GetAttribute(0);
                        properties[propertyName] = ReadArray(reader);
                    }
                    else if (propertyName == "SerializedValue")
                    {
                        propertyName             = reader.GetAttribute(0);
                        properties[propertyName] = new SerializedValue(reader.ReadInnerXml());
                    }
                    else
                    {
                        properties[propertyName] = reader.HasAttributes ? reader.GetAttribute(0) : null;
                    }
                    break;
                }
            }
        }
 public static Properties Load(XmlReader reader)
 {
     using (reader) {
         while (reader.Read())
         {
             if (reader.IsStartElement())
             {
                 switch (reader.LocalName)
                 {
                 case "Properties":
                     Properties properties = new Properties();
                     properties.ReadProperties(reader, "Properties");
                     return(properties);
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 5
0
 public static Properties Load(string fileName)
 {
     if (!System.IO.File.Exists(fileName))
     {
         return(null);
     }
     using (XmlTextReader xmlTextReader = new XmlTextReader(fileName))
     {
         while (xmlTextReader.Read())
         {
             string localName;
             if (xmlTextReader.IsStartElement() && (localName = xmlTextReader.LocalName) != null && localName == "Properties")
             {
                 Properties properties = new Properties();
                 properties.ReadProperties(xmlTextReader, "Properties");
                 return(properties);
             }
         }
     }
     return(null);
 }
Esempio n. 6
0
//		public void BinarySerialize(BinaryWriter writer)
//		{
//			writer.Write((byte)properties.Count);
//			foreach (KeyValuePair<string, object> entry in properties) {
//				writer.Write(AddInTree.GetNameOffset(entry.Key));
//				writer.Write(AddInTree.GetNameOffset(entry.Value.ToString()));
//			}
//		}

        public static Properties Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }
            using (XmlTextReader reader = new XmlTextReader(fileName)) {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.LocalName)
                        {
                        case "Properties":
                            Properties properties = new Properties();
                            properties.ReadProperties(reader, "Properties");
                            return(properties);
                        }
                    }
                }
            }
            return(null);
        }