private static IEnumerable <AssemblyPart> GetDeploymentParts(Colosoft.IO.Compression.ZipArchive zipArchive) { var file = zipArchive.Files.Where(f => f.Name == "AppManifest.xaml").FirstOrDefault(); if (file == null) { throw new InvalidOperationException("AppManifest not found."); } var list = new List <AssemblyPart>(); System.IO.Stream resourceStream = null; try { using (var stream = file.OpenRead()) { resourceStream = new System.IO.MemoryStream(); var buffer = new byte[1024]; var read = 0; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { resourceStream.Write(buffer, 0, read); } resourceStream.Seek(0, System.IO.SeekOrigin.Begin); } using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(resourceStream)) { if (!reader.ReadToFollowing("AssemblyPart")) { return(list); } do { string attribute = reader.GetAttribute("Source"); if (attribute != null) { AssemblyPart item = new AssemblyPart(); item.Source = attribute; list.Add(item); } }while (reader.ReadToNextSibling("AssemblyPart")); } } finally { if (resourceStream != null) { resourceStream.Dispose(); } } return(list); }
/// <summary> /// Parse an ADXP from stream <paramref name="s"/> /// </summary> public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse CS ADXP retVal = base.Parse <ADXP>(s, result); // Now parse our data out... if (!s.IsEmptyElement) { if (s.GetAttribute("code") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { retVal.Code = s.GetAttribute("code"); } else if (s.GetAttribute("code") != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "code", "ADXP", s.ToString())); } // Read next for text elemnt string sName = s.Name; s.Read(); while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name)) { if (s.NodeType == System.Xml.XmlNodeType.Text) { retVal.Value = s.Value; } s.Read(); } } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; base.Validate(retVal, pathName, result); return(retVal); }
public override void ReadXML(System.Xml.XmlReader input) { if (!input.HasAttributes) { // Legacy Gibbed.Spore format var s = input.ReadString().Split(new char[] { ' ' }); if (s.Length != 13) { throw new FormatException("Legacy transform format incorrect."); } this.Flags = s[0].GetHexNumber(); for (int i = 0; i < 12; i++) { this.Matrix[i] = float.Parse(s[i + 1]); } return; } this.Flags = input.GetAttribute("flags").GetHexNumber(); parseV(input.GetAttribute("pos"), out Matrix[0], out Matrix[1], out Matrix[2]); parseV(input.GetAttribute("vx"), out Matrix[3], out Matrix[6], out Matrix[9]); parseV(input.GetAttribute("vy"), out Matrix[4], out Matrix[7], out Matrix[10]); parseV(input.GetAttribute("vz"), out Matrix[5], out Matrix[8], out Matrix[11]); }
/// <summary> /// Reads the attribute as nullable int. /// </summary> /// <param name="reader">The reader.</param> /// <param name="attributeName">Name of the attribute.</param> /// <returns></returns> public static int?ReadAttributeAsNullableInt(this System.Xml.XmlReader reader, string attributeName) { string attribute = reader.GetAttribute(attributeName); int result; if (string.IsNullOrEmpty(attribute) || !int.TryParse(attribute, System.Globalization.NumberStyles.Any , System.Globalization.NumberFormatInfo.InvariantInfo, out result)) { return(default(int?)); } return(result); }
/// <summary> /// Reads the XML. /// </summary> /// <param name="reader">The reader.</param> public override void ReadXml(System.Xml.XmlReader reader) { Label = reader.GetAttribute("Label"); //read attribute indicating if component should wait for all predecessors var wait = reader.GetAttribute("WaitsForAllPredecessors", String.Empty); if (String.IsNullOrEmpty(wait) || (wait != Boolean.TrueString && wait != Boolean.FalseString)) //if value has not been found set it to true { WaitsForAllPredecessors = true; //default value } else { WaitsForAllPredecessors = Convert.ToBoolean(wait); } XPathDocument doc = new XPathDocument(reader); XPathNavigator nav = doc.CreateNavigator(); XPathNavigator iter = nav.SelectSingleNode("/Metadata/DecisionCode"); DecisionCode = iter.Value; }
public object Deserialize(System.Xml.XmlReader xmlReader) { List <T> lista = new List <T>(); while (xmlReader.IsStartElement("Item")) { Type type = Type.GetType(xmlReader.GetAttribute("AssemblyQualifiedName")); ISerializer serial = SerializerProvider.GetSerializer(type); xmlReader.ReadStartElement("Item"); lista.Add((T)serial.Deserialize(xmlReader)); xmlReader.ReadEndElement(); } return(lista); }
private Dictionary <TKey, TValue> DeserializeDictionary <TKey, TValue>(System.Xml.XmlReader reader, Func <System.Xml.XmlReader, TValue> readFnc, string expectedName) { if (reader.NodeType != System.Xml.XmlNodeType.Element) { throw new System.Configuration.ConfigurationErrorsException("Expected Element node type", reader); } Dictionary <TKey, TValue> res = new Dictionary <TKey, TValue>(); if (reader.IsEmptyElement) { reader.Skip(); return(res); } string initialName = reader.Name; reader.ReadStartElement(); do { if (reader.NodeType == System.Xml.XmlNodeType.Element) { if (expectedName != null && reader.Name != expectedName) { throw new System.Configuration.ConfigurationErrorsException("Unexpected element name inside list: " + reader.Name, reader); } string strKey = reader.GetAttribute("key"); if (strKey == null) { throw new System.Configuration.ConfigurationErrorsException("Key not found for dictionary: " + reader.Name, reader); } TKey key = Parse <TKey>(strKey); TValue val = readFnc(reader); res.Add(key, val); } else { reader.Skip(); } }while (reader.NodeType != System.Xml.XmlNodeType.EndElement || reader.Name != initialName); reader.ReadEndElement(); return(res); }
private static IEnumerable <Assembly> getAssemblies(Stream stream) { if (stream == null) { return(null); } System.Windows.Resources.StreamResourceInfo xapStreamInfo = new System.Windows.Resources.StreamResourceInfo(stream, null); Uri uri = new Uri("AppManifest.xaml", UriKind.Relative); System.Windows.Resources.StreamResourceInfo resourceStream = Application.GetResourceStream(xapStreamInfo, uri); if (resourceStream == null) { return(null); } List <Assembly> list = null; using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(resourceStream.Stream)) { if (!reader.ReadToFollowing("AssemblyPart")) { return(list); } list = new List <Assembly>(); do { string attribute = reader.GetAttribute("Source"); if (attribute != null) { AssemblyPart item = new AssemblyPart(); item.Source = attribute; System.Windows.Resources.StreamResourceInfo assemblyResourceStream = Application.GetResourceStream(xapStreamInfo, new Uri(item.Source, UriKind.Relative)); if (assemblyResourceStream == null || assemblyResourceStream.Stream == null) { continue; } Assembly assembly = item.Load(assemblyResourceStream.Stream); if (assembly != null) { list.Add(assembly); } } }while (reader.ReadToNextSibling("AssemblyPart")); } return(list); }
void IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { if (reader.MoveToContent() == System.Xml.XmlNodeType.Element && reader.LocalName == "Value") { Name = reader.GetAttribute("name"); Value = reader.ReadString(); reader.Read(); } else { reader.ReadStartElement(); XmlSerializationHelper.ReadObjectProperties(reader, this); reader.ReadEndElement(); } }
/// <summary> /// Reads Xml when the <see cref="Line">Line</see> is to be deserialized /// from a stream.</summary> /// <param name="reader">The stream from which the object will be deserialized.</param> void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { _orientation = (LineOrientation)Enum.Parse(_orientation.GetType(), reader.GetAttribute("Orientation")); _length = int.Parse(reader.GetAttribute("Length")); string colour = reader.GetAttribute("Colour"); if (colour != null && colour.Length > 0) { _colour = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colour); } reader.Read(); if (reader.Name == "Location") { ((IXmlSerializable)_location).ReadXml(reader); } else { throw new InvalidOperationException("<Location> node missing from <Line> node."); } }
/// <summary> /// Lê os dados serializados. /// </summary> /// <param name="reader"></param> void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { _uid = reader.GetAttribute("Uid"); long.TryParse(reader.GetAttribute("Length"), out _length); reader.MoveToElement(); if (!reader.IsEmptyElement) { reader.ReadStartElement(); if (!reader.IsEmptyElement) { var set = new UploaderItemAttributeSet(); ((System.Xml.Serialization.IXmlSerializable)set).ReadXml(reader); _attributes = set; } else { reader.Skip(); } } else { reader.Skip(); } }
public void ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement("Item"); do { switch (reader.Name) { case "ItemHeader": Attr1 = reader.GetAttribute("Attr1"); reader.Read(); break; case "ItemDetails": Attr5 = reader.GetAttribute("Attr5"); reader.Read(); break; default: throw new XmlException(String.Format("{0} was not expected", reader.Name)); } } while (reader.Name != "Item"); reader.ReadEndElement(); }
/// <summary> /// /// </summary> /// <param name="reader"></param> public override void ReadXml(System.Xml.XmlReader reader) { Id = System.Convert.ToInt32(reader.GetAttribute(RedmineKeys.ID)); Name = reader.GetAttribute(RedmineKeys.NAME); Multiple = reader.ReadAttributeAsBoolean(RedmineKeys.MULTIPLE); reader.Read(); if (string.IsNullOrEmpty(reader.GetAttribute("type"))) { Values = new System.Collections.Generic.List <CustomFieldValue> { new CustomFieldValue { Info = reader.ReadElementContentAsString() } }; } else { System.Collections.Generic.List <CustomFieldValue> result = reader.ReadElementContentAsCollection <CustomFieldValue>(); Values = result; } }
void IXmlExportable.FromXml(XmlReader r) { if (r == null) throw new ArgumentNullException("reader"); if (this.IsReadOnly) throw new InvalidOperationException("Object is read-only."); r.Read(); // Add entries into the collection as <item> elements // with child <value> elements are found. while (r.IsStartElement("item")) { string name = r.GetAttribute("name"); bool isNull = r.IsEmptyElement; r.Read(); // <item> if (!isNull) { while (r.IsStartElement("value")) // <value ...> { string value = r.GetAttribute("string"); Add(name, value); r.Read(); } r.ReadEndElement(); // </item> } else { Add(name, null); } } r.ReadEndElement(); }
public static void ReadPath(System.Xml.XmlReader reader, Core.PlugIn plugIn) { if (reader.AttributeCount != 1) { throw new Exception(PlugInConst.Path + " node requires only one attribute."); } if (reader.IsEmptyElement) { return; } string name = reader.GetAttribute(0); ExtensionPath path = new ExtensionPath(name, plugIn); plugIn.Paths.Add(path.Name, path); while (reader.Read()) { switch (reader.NodeType) { case System.Xml.XmlNodeType.Element: string elementName = reader.LocalName; Codon newCodon = new Codon(path.PlugIn, elementName, Properties.ReadFromAttributes(reader)); path.Codons.Add(newCodon); if (!reader.IsEmptyElement) { ReadPath(reader, plugIn); } break; case System.Xml.XmlNodeType.EndElement: if (reader.LocalName == PlugInConst.Path) { return; } break; default: break; } } }
protected override void ReadXmlBase(System.Xml.XmlReader reader) { base.ReadXmlBase(reader); // CM: 21/08/09 This code doesn't support a section without items. // e.g. /** <items xsi:type="SECTION" archetype_node_id="at0002"> * <name> * <value>Mother</value> * </name> * </items> * * <items xsi:type="SECTION" archetype_node_id="at0002"> * <name> * <value>Mother</value> * </name> * <items/> * </items> * */ if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.LocalName == "items") { if (reader.IsEmptyElement) { reader.Skip(); } else { LocatableList <ContentItem> items = new LocatableList <ContentItem>(); do { string itemType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); ContentItem contentItem = ContentItem.GetLocatableObjectByType(itemType) as ContentItem; if (contentItem == null) { throw new InvalidOperationException("itemType must be type of ContentItem: " + itemType); } contentItem.ReadXml(reader); contentItem.Parent = this; items.Add(contentItem); } while (reader.LocalName == "items" && reader.NodeType == System.Xml.XmlNodeType.Element); this.items = items; } } }
/// <summary> /// Recupera os dados serializados. /// </summary> /// <param name="reader"></param> void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { ParameterName = reader.GetAttribute("Name"); ; reader.MoveToElement(); reader.ReadStartElement(); if (!reader.IsEmptyElement) { Value = reader.ReadString(); } else { reader.Skip(); } reader.ReadEndElement(); }
/// <summary> /// This method reads the promo url mapping and populates the PromoUrls dictionary object /// The key is name of the promo url and the value is an object of promourl. /// </summary> /// <param name="reader"></param> public void ReadXml(System.Xml.XmlReader reader) { XmlSerializer valueSerializer = new XmlSerializer(typeof(PromoUrl)); if (reader.IsEmptyElement) { return; } // Read to PromoUrls element reader.Read(); if (reader.IsEmptyElement) { return; } while (reader.Read()) { if (reader.LocalName == "PromoUrl") { //Create instance of promo url PromoUrl promoUrl = new PromoUrl(); string key = reader.GetAttribute("Name"); if (!string.IsNullOrEmpty(key)) { key = key.ToLower().Trim(); promoUrl.Name = key; reader.Read(); String mappedUrl = reader.ReadString(); if (string.IsNullOrEmpty(mappedUrl)) // If the mapped URL is missing, skip this one. { continue; } promoUrl.MappedTo = mappedUrl.Trim(); if (!PromoUrls.ContainsKey(key)) { PromoUrls.Add(key, promoUrl); } reader.ReadEndElement(); } else { throw new Exception("name attribute cannot be null for the Promo URL"); } } } }
protected override void ReadXmlBase(System.Xml.XmlReader reader) { base.ReadXmlBase(reader); DesignByContract.Check.Assert(reader.LocalName == "data", "Expected LocalName is 'data', but it is " + reader.LocalName); string dataType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); this.data = OpenEhr.RM.Common.Archetyped.Impl.Locatable.GetLocatableObjectByType(dataType) as ItemStructure; if (this.data == null) { throw new InvalidOperationException("data type must be type of ItemStructure: " + dataType); } this.data.ReadXml(reader); this.data.Parent = this; }
public void ReadXml(System.Xml.XmlReader xmlReader) { xmlReader.MoveToContent(); string VehicleType = xmlReader.GetAttribute("Name"); Name = VehicleType; bool isEmptyElement = xmlReader.IsEmptyElement; xmlReader.ReadStartElement(); if (!isEmptyElement) { if (VehicleType == "Sedan") { int intID = Convert.ToInt32(xmlReader.ReadElementString("id")); ID = (short)intID; VehicleName = xmlReader.ReadElementString("vehicleName"); int intDamage = Convert.ToInt32(xmlReader.ReadElementString("damagePercentage")); DamagePercentage = (short)intDamage; int intFuel = Convert.ToInt32(xmlReader.ReadElementString("fuelPercentage")); FuelPercentage = (short)intFuel; xmlReader.ReadEndElement(); } if (VehicleType == "Minivan") { int intID = Convert.ToInt32(xmlReader.ReadElementString("id")); ID = (short)intID; VehicleName = xmlReader.ReadElementString("vehicleName"); int intDamage = Convert.ToInt32(xmlReader.ReadElementString("damagePercentage")); DamagePercentage = (short)intDamage; int intFuel = Convert.ToInt32(xmlReader.ReadElementString("fuelPercentage")); FuelPercentage = (short)intFuel; xmlReader.ReadEndElement(); } } }
public override void ReadXml(System.Xml.XmlReader reader) { _name = reader.GetAttribute("name"); if (reader.IsEmptyElement) { reader.Read(); return; } var read = true; while (!read || reader.Read()) { read = true; switch (reader.NodeType) { case System.Xml.XmlNodeType.Element: switch (reader.LocalName) { case "info": base.ReadXml(reader); read = false; break; case "question": var question = new Question(); question.ReadXml(reader); Questions.Add(question); read = false; break; } break; case System.Xml.XmlNodeType.EndElement: if (reader.LocalName == "theme") { reader.Read(); return; } break; } } }
protected override void ReadXmlBase(System.Xml.XmlReader reader) { base.ReadXmlBase(reader); DesignByContract.Check.Assert(reader.LocalName == "narrative", "Expected LocalName is 'narrative', but it is " + reader.LocalName); string narrativeType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace); if (narrativeType != null) { this.narrative = new OpenEhr.RM.DataTypes.Text.DvCodedText(); } else { this.narrative = new OpenEhr.RM.DataTypes.Text.DvText(); } this.narrative.ReadXml(reader); if (reader.LocalName == "expiry_time") { this.expiryTime = new OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime(); this.expiryTime.ReadXml(reader); } if (reader.LocalName == "wf_definition") { this.wfDefinition = new OpenEhr.RM.DataTypes.Encapsulated.DvParsable(); this.wfDefinition.ReadXml(reader); } if (reader.LocalName == "activities") { AssumedTypes.Impl.LocatableList <Activity> activities = new OpenEhr.AssumedTypes.Impl.LocatableList <Activity>(); do { Activity activity = new Activity(); activity.ReadXml(reader); activity.Parent = this; activities.Add(activity); } while (reader.LocalName == "activities" && reader.NodeType == System.Xml.XmlNodeType.Element); this.activities = activities; } }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The XmlReader stream from which the object is deserialized. </param> public void ReadXml(System.Xml.XmlReader reader) { bool wasEmpty = reader.IsEmptyElement; if (wasEmpty) { return; } version = int.Parse(reader.GetAttribute("Version")); reader.Read(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { string stopword = reader.ReadElementContentAsString("Stopword", String.Empty); Add(stopword); } }
private static void ReadColorProperty(System.Xml.XmlReader reader, out KnownColor?knownColor, out Color color) { knownColor = null; color = default(Color); bool useSystemName = bool.Parse(reader.GetAttribute("UseSystemName")); string rawValue = reader.ReadElementString(); if (useSystemName) { knownColor = (KnownColor)Enum.Parse(typeof(KnownColor), rawValue); } else { color = Color.FromArgb(int.Parse(rawValue, System.Globalization.NumberStyles.HexNumber)); } }
public void ReadXml(System.Xml.XmlReader reader) { if (!reader.HasAttributes) { throw new FormatException("expected a type attribute!"); } string type = reader.GetAttribute("type"); reader.Read(); if (type.Equals("null")) { return; } XmlSerializer serializer = new XmlSerializer(Type.GetType(type)); this.Value = (T)serializer.Deserialize(reader); reader.ReadEndElement(); }
public void ReadXml(System.Xml.XmlReader reader) { if (reader.LocalName != "stateVariable" && !reader.ReadToDescendant("stateVariable")) { throw new InvalidDataException(); } if (reader.HasAttributes) { this.SendEvents = ((reader.GetAttribute("sendEvents") ?? "no") == "yes"); } XmlHelper.ParseXml(reader, new XmlParseSet { { "name", () => this.Name = reader.ReadString() }, { "dataType", () => this.DataType = reader.ReadString() } }); }
public void ReadXml(System.Xml.XmlReader reader) { if (!reader.HasAttributes) { throw new FormatException("expected a type attribute!"); } string type = reader.GetAttribute("type"); reader.Read(); // consume the value if (type == "null") { return;// leave T at default value } XmlSerializer serializer = new XmlSerializer(Type.GetType(type)); this.Value = (T)serializer.Deserialize(reader); reader.ReadEndElement(); }
public void ReadXml(System.Xml.XmlReader reader) { if (reader.IsEmptyElement) { return; } reader.Read(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { Debug.Assert(reader.Name == "Pair"); var key = int.Parse(reader.GetAttribute("key")); reader.ReadStartElement("Pair"); var val = reader.ReadContentAsBoolean(); reader.ReadEndElement(); this[key] = val; } }
public virtual Type GetType(System.Xml.XmlReader reader) { if (!reader.HasAttributes) { return(null); } var typeName = reader.GetAttribute("type"); if (typeName == null) { return(null); } var type = Type.GetType(this.GetType().Namespace + "." + typeName + "Person", false); return(type); }
public void ReadXml(System.Xml.XmlReader r, out DateTime?date) { r.MoveToContent(); if (r.HasAttributes) { date = Convert.ToDateTime(r.GetAttribute(0), System.Globalization.CultureInfo.InvariantCulture); } else { date = null; } r.Read(); r.MoveToContent(); Wood = Convert.ToInt32(Tools.XmlHelper.ReadXmlElement(r, "Wood")); Clay = Convert.ToInt32(Tools.XmlHelper.ReadXmlElement(r, "Clay")); Iron = Convert.ToInt32(Tools.XmlHelper.ReadXmlElement(r, "Iron")); r.Read(); }
// void affectMember(string name, string value){ // Type thisType = this.GetType (); // // if (string.IsNullOrEmpty (value)) // return; // // MemberInfo mi = thisType.GetMember (name).FirstOrDefault(); // if (mi == null) { // Debug.WriteLine ("XML: Unknown attribute in " + thisType.ToString() + " : " + name); // return; // } // if (mi.MemberType == MemberTypes.Event) { // this.Bindings.Add (new Binding (new MemberReference(this, mi), value)); // return; // } // if (mi.MemberType == MemberTypes.Property) { // PropertyInfo pi = mi as PropertyInfo; // // if (pi.GetSetMethod () == null) { // Debug.WriteLine ("XML: Read only property in " + thisType.ToString() + " : " + name); // return; // } // // XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute)); // if (xaa != null) { // if (!string.IsNullOrEmpty (xaa.AttributeName)) // name = xaa.AttributeName; // } // if (value.StartsWith("{",StringComparison.Ordinal)) { // //binding // if (!value.EndsWith("}", StringComparison.Ordinal)) // throw new Exception (string.Format("XML:Malformed binding: {0}", value)); // // this.Bindings.Add (new Binding (new MemberReference(this, pi), value.Substring (1, value.Length - 2))); // return; // } // if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null) // return; // if (xaa == null)//not define as xmlAttribute // return; // // if (pi.PropertyType == typeof(string)) { // pi.SetValue (this, value, null); // return; // } // // if (pi.PropertyType.IsEnum) { // pi.SetValue (this, Enum.Parse (pi.PropertyType, value), null); // } else { // MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) }); // pi.SetValue (this, me.Invoke (null, new string[] { value }), null); // } // } // } public virtual void ReadXml (System.Xml.XmlReader reader) { if (reader.HasAttributes) { style = reader.GetAttribute ("Style"); loadDefaultValues (); while (reader.MoveToNextAttribute ()) { if (reader.Name == "Style") continue; //affectMember (reader.Name, reader.Value); } reader.MoveToElement (); }else loadDefaultValues (); }