/// <summary>Initializes a new instance of RssGuid</summary> public RssGuid (System.Xml.XmlReader xmlTextReader): this() { bool emptyElement = xmlTextReader.IsEmptyElement; while(xmlTextReader.MoveToNextAttribute()) { XmlSerializationUtil.DecodeXmlTextReaderValue(this, xmlTextReader); } if(emptyElement) return; // xmlTextReader.MoveToElement(); XmlSerializationUtil.DecodeXmlTextReaderValue(this,this.GetType().GetProperty("Value"), xmlTextReader); }
public void DoSearch(string[] parts, ArrayList result, System.Xml.XmlReader reader, bool securityTrimmingEnabled) { if (reader.ReadToFollowing("category", ns) && reader.MoveToAttribute("name") && reader.Value == "Root" && reader.MoveToElement()) { int i = 1; if (i < parts.Length) { ReadSubElements(reader, parts, i, result, securityTrimmingEnabled); } else { ReadSubItems(reader, result, securityTrimmingEnabled); } } }
public void Read(out string id, out Domain domain, out string attribName, out Type attribType, out object defaultVal, System.Xml.XmlReader reader) { id = null; domain = Domain.all; attribName = null; attribType = null; defaultVal = null; reader.MoveToAttribute("id"); id = reader["id"]; reader.MoveToAttribute("for"); domain = (Domain)Enum.Parse(typeof(Domain), reader["for"]); reader.MoveToAttribute("attr.name"); attribName = reader["attr.name"]; reader.MoveToAttribute("attr.type"); attribType = GraphMLConvert.ToType(reader["attr.type"]); reader.MoveToElement(); // if there is a default value element, read it and convet if (reader.ReadToDescendant("default")) { string defaultValStr = null; ReadDefault(out defaultValStr, reader); defaultVal = ConvertDefaultValStr(defaultValStr, attribType); if (!reader.IsStartElement() && reader.Name=="default") reader.Read(); // read the end tag element of default } else { // default value is system default defaultVal = GetDefault( attribType); } }
// 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 (); }
/// <summary> /// Returns a key/value pair representing the attributes in the element. /// </summary> /// <param name="reader">The bufferred xml to analyze.</param> /// <returns>A sorted list of the attributes with the name as the key and the value as the value.</returns> /// <remarks>Executing this method querries the current node for the attributes without advancing to the next node.</remarks> private System.Collections.SortedList GetAttributes(System.Xml.XmlReader reader) { System.Collections.SortedList _List = new System.Collections.SortedList(); //FIX: December 9, 2005 - Fix to handle reading attributes from ReadXml routine if ((reader.NodeType != System.Xml.XmlNodeType.None) & (reader.MoveToFirstAttribute())) { do { if (reader.NodeType == System.Xml.XmlNodeType.Attribute) { _List.Add(reader.Name, reader.Value); } } while (reader.MoveToNextAttribute() | reader.NodeType != System.Xml.XmlNodeType.Attribute); } if (reader.NodeType == System.Xml.XmlNodeType.Attribute) { reader.MoveToElement(); } return _List; }
public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Create the types Type ivlType = typeof(IVL<>); Type ivlGenericType = ivlType.MakeGenericType(GenericArguments); // Sometimes there can be just a messy, unstructured value inline with this IVL (like in CCDA) so we still need to support that MemoryStream leftOvers = new MemoryStream(); XmlWriter leftoverWriter = XmlWriter.Create(leftOvers); leftoverWriter.WriteStartElement(s.LocalName, s.NamespaceURI); // Create an instance of rto from the rtoType object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); if (s.MoveToFirstAttribute()) { do { switch (s.LocalName) { case "nullFlavor": ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor)); break; case "operator": ivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null); break; case "specializationType": if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) ((ANY)instance).Flavor = s.GetAttribute("specializationType"); break; default: leftoverWriter.WriteAttributeString(s.Prefix, s.LocalName, s.NamespaceURI, s.Value); break; } } while (s.MoveToNextAttribute()); s.MoveToElement(); } // Get property information PropertyInfo lowProperty = ivlGenericType.GetProperty("Low"), highProperty = ivlGenericType.GetProperty("High"), widthProperty = ivlGenericType.GetProperty("Width"), centerProperty = ivlGenericType.GetProperty("Center"), lowClosedProperty = ivlGenericType.GetProperty("LowClosed"), highClosedProperty = ivlGenericType.GetProperty("HighClosed"), valueProperty = ivlGenericType.GetProperty("Value"); // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "low") // low value { if (!String.IsNullOrEmpty(s.GetAttribute("inclusive"))) lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null); var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); lowProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value { if (!String.IsNullOrEmpty(s.GetAttribute("inclusive"))) highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null); var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); highProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "center") // center { var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); centerProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "width") // width { var parseResult = Host.Parse(s, typeof(PQ)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); widthProperty.SetValue(instance, parseResult.Structure, null); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { leftoverWriter.WriteNode(s, true); //result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) s.Read(); } } } #endregion // Process any leftovers as Value !!! try { leftoverWriter.WriteEndElement(); leftoverWriter.Flush(); leftOvers.Seek(0, SeekOrigin.Begin); using (XmlReader xr = XmlReader.Create(leftOvers)) { xr.MoveToContent(); if (xr.AttributeCount > 1 || !xr.IsEmptyElement) { bool isNotEmpty = !xr.IsEmptyElement; if (xr.MoveToFirstAttribute()) do { isNotEmpty |= xr.Prefix != "xmlns" && xr.LocalName != "xmlns" && xr.NamespaceURI != DatatypeFormatter.NS_XSI; } while (!isNotEmpty && xr.MoveToNextAttribute()); xr.MoveToElement(); if (isNotEmpty) { var baseResult = base.Parse(xr, result); valueProperty.SetValue(instance, Util.FromWireFormat(baseResult, valueProperty.PropertyType), null); } } } } catch { } // Validate base.Validate(instance as ANY, s.LocalName, result); return instance; }
private CategoryDirectory ReadResult(System.Xml.XmlReader reader, bool securityTrimmingEnabled) { CategoryDirectory result = null; if (reader.NodeType == System.Xml.XmlNodeType.Element) { if (reader.LocalName == "category" && reader.NamespaceURI == ns) { if (DeterminVisible(reader) && DeterminSecure(securityTrimmingEnabled, reader)) { result = new CategoryDirectory(); if (reader.MoveToAttribute("name")) result.Name = reader.Value; if (reader.MoveToAttribute("title")) result.Title = reader.Value; reader.MoveToElement(); } } else if (reader.LocalName == "item" && reader.NamespaceURI == ns) { if (DeterminVisible(reader) && DeterminSecure(securityTrimmingEnabled, reader)) { result = new CategoryLink(); if (reader.MoveToAttribute("name")) result.Name = reader.Value; if (reader.MoveToAttribute("title")) result.Title = reader.Value; if (reader.MoveToAttribute("group")) ((CategoryLink)result).Group = reader.ReadContentAsInt(); if (reader.MoveToAttribute("href")) ((CategoryLink)result).Url = reader.Value; if (reader.MoveToAttribute("role")) ((CategoryLink)result).Role = reader.Value; if (reader.MoveToAttribute("feature")) ((CategoryLink)result).Feature = reader.Value; } } else if (reader.LocalName == "group" && reader.NamespaceURI == ns) { if (DeterminVisible(reader) && DeterminSecure(securityTrimmingEnabled, reader)) { result = new CategoryGroup(); if (reader.MoveToAttribute("name")) result.Name = reader.Value; if (reader.MoveToAttribute("title")) result.Title = reader.Value; reader.MoveToElement(); ArrayList list = new ArrayList(); ReadSubItems(reader, list, securityTrimmingEnabled); ((CategoryGroup)result).Categories = (CategoryDirectory[])list.ToArray(typeof(CategoryDirectory)); } else { var level = reader.Depth; while (reader.Read() && reader.Depth > level) { reader.Skip(); //跳过其任何子节点 } } } } reader.MoveToElement(); return result; }
private void ReadSubElements(System.Xml.XmlReader reader, string[] parts, int i, ArrayList result, bool securityTrimmingEnabled) { string nextName = parts[i]; int depth = reader.Depth + 1; while (reader.Read()) { if (reader.Depth == depth) { switch (reader.NodeType) { case System.Xml.XmlNodeType.Attribute: case System.Xml.XmlNodeType.CDATA: case System.Xml.XmlNodeType.Comment: case System.Xml.XmlNodeType.Whitespace: continue; case System.Xml.XmlNodeType.EndElement: break; case System.Xml.XmlNodeType.Element: break; default: throw new System.Xml.XmlException("读取到错误的节点"); } if (reader.NodeType == System.Xml.XmlNodeType.Element) { bool hit = false; if (reader.MoveToAttribute("name")) { hit = reader.Value == nextName; if (hit) hit = DeterminVisible(reader); reader.MoveToElement(); } if (hit) { i++; if (i < parts.Length) { ReadSubElements(reader, parts, i, result, securityTrimmingEnabled); } else { ReadSubItems(reader, result, securityTrimmingEnabled); } break; } else { //reader.Skip(); } } } else if (reader.Depth > depth) { reader.Skip(); } else { break; } } }
internal void UnpersistCore(IWorkSpace workSpace, System.Xml.XmlReader reader) { // Assumes reader has started the read of element "WorkSpace" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToAttribute("mode"); string modeStr = reader["mode"]; reader.MoveToElement(); workSpace.Id = new Guid(idStr); workSpace.ExecMode = (ExecutionModes)Enum.Parse(typeof(ExecutionModes), modeStr); // ------------------------- int startDepth = reader.Depth; // in expected order if (reader.ReadToDescendant("Settings")) { UnpersistSettingsMgr(workSpace.SettingsMgr, reader); if (reader.ReadToNextSibling("Options")) { UnpersistOptionsMgr(workSpace.OptionsMgr, reader); } if (reader.ReadToNextSibling("Variables")) { UnpersistVarMgr(workSpace.VarMgr, reader); } if (reader.ReadToNextSibling("Elements")) { UnpersistElements(workSpace.ElementsMgr, reader); } if (reader.ReadToNextSibling("Pipes")) { UnpersistPipes(workSpace.PipesMgr, reader); } if (reader.ReadToNextSibling("WorkSpaceProperties")) { UnpersistProperties(workSpace.WSProperties, reader); } // read up to the end "WorkSpace" tag if (reader.Depth > startDepth) { reader.Read(); } } }
internal void Read(System.Xml.XmlReader reader) { this.Name = reader.LocalName; bool isNull; if (bool.TryParse(reader.GetAttribute("null"), out isNull)) IsNull = isNull; if (!IsNull) { if (reader.HasAttributes) { reader.MoveToAttribute(0); if (reader.LocalName == "type") TypeName = reader.Value; reader.MoveToElement(); } while (reader.Read()) { if (reader.HasValue && !string.IsNullOrEmpty(reader.Value.Trim())) { this.Text = reader.Value; break; } } switch (TypeName) { case "Edm.Binary": MaterializedValue = Convert.FromBase64String(Text); break; case "Edm.Boolean": MaterializedValue = Convert.ToBoolean(Text); break; case "Edm.Byte": MaterializedValue = Convert.ToByte(Text); break; case "Edm.DateTime": MaterializedValue = Convert.ToDateTime(Text); break; case "Edm.Decimal": MaterializedValue = Convert.ToDecimal(Text); break; case "Edm.Double": MaterializedValue = Convert.ToDouble(Text); break; case "Edm.Guid": MaterializedValue = new Guid(Text); break; case "Edm.Int16": MaterializedValue = Convert.ToInt16(Text); break; case "Edm.Int32": MaterializedValue = Convert.ToInt32(Text); break; case "Edm.Int64": MaterializedValue = Convert.ToInt64(Text); break; case "Edm.SByte": MaterializedValue = Convert.ToSByte(Text); break; case "Edm.Single": MaterializedValue = Convert.ToSingle(Text); break; case "Edm.Time": MaterializedValue = TimeSpan.Parse(Text); break; case "Edm.DateTimeOffset": MaterializedValue = DateTimeOffset.Parse(Text); break; case "Edm.String": default: MaterializedValue = Text; break; } } }
internal void UnpersistOutPort(System.Xml.XmlReader reader, out Guid portId, out int portIndex) { // Assumes reader has started the read of element "OutputPort" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToAttribute("index"); string indexStr = reader["index"]; reader.MoveToElement(); portId = new Guid(idStr); portIndex = XmlConvert.ToInt32(indexStr); if (reader.ReadToDescendant("OutboundPipe")) { Guid pipeId; UnpersistOutboundPipe(reader, out pipeId); while (reader.ReadToNextSibling("OutboundPipe")) { UnpersistOutboundPipe(reader, out pipeId); } } if (reader.IsStartElement() && !reader.IsEmptyElement) { reader.Read(); } TicketBuilder.AddOutputPortId(portId, portIndex); }
internal void UnpersistOutboundPipe(System.Xml.XmlReader reader, out Guid outboundPipeId) { // Assumes reader has started the read of element "InboundPipe" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToElement(); if (reader.IsStartElement() && !reader.IsEmptyElement) { reader.Read(); } outboundPipeId = new Guid(idStr); }
internal void UnpersistFx( System.Xml.XmlReader reader) { // Assumes reader has started the read of element "Fx" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToElement(); if (reader.IsStartElement() && !reader.IsEmptyElement) { reader.Read(); } TicketBuilder.FxId = new Guid(idStr); }
internal void UnpersistCore(System.Xml.XmlReader reader, out IElement element) { element = null; // Assumes reader has started the read of element "Element" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToAttribute("typeId"); string typeIdStr = reader["typeId"]; reader.MoveToAttribute("typeName"); string typeName = reader["typeName"]; reader.MoveToElement(); TicketBuilder.ElementId = new Guid(idStr); TicketBuilder.TypeId = new Guid(typeIdStr); // ------------------------- int startDepth = reader.Depth; // in expected order if (reader.ReadToDescendant("Fx")) // Fx node must be there, it has an id to read in { UnpersistFx(reader); if (reader.ReadToNextSibling("InputPortMgr")) { UnpersistInPortMgr(reader); } if (reader.ReadToNextSibling("OutputPortMgr")) { UnpersistOutPortMgr(reader); } IElementTicket ticket = TicketBuilder.Ticket; element = ReConstitute(ticket); if (reader.ReadToNextSibling("Settings")) { UnpersistSettingsMgr(element, reader); } // Options are not currently being used or persisted //if (reader.ReadToNextSibling("Options")) //{ // UnpersistOptionsMgr(reader); //} if (reader.ReadToNextSibling("ParamMgr")) { UnpersistParamMgr(element, reader); } // read up to the end "Element" tag if (reader.Depth > startDepth) { reader.Read(); } } }
internal void UnpersistCore(System.Xml.XmlReader reader, out IPipe pipe) { // Assumes reader has started the read of element "Pipe" reader.MoveToAttribute("id"); string idStr = reader["id"]; reader.MoveToAttribute("type"); string contentTypeStr = reader["type"]; reader.MoveToAttribute("sourceId"); string srcElId = reader["sourceId"]; reader.MoveToAttribute("sourcePortId"); string srcPortId = reader["sourcePortId"]; reader.MoveToAttribute("destinationId"); string destElId = reader["destinationId"]; reader.MoveToAttribute("destinationPortId"); string destPortId = reader["destinationPortId"]; reader.MoveToElement(); if (reader.IsStartElement() && !reader.IsEmptyElement) { reader.Read(); } _ticketBuilder.PipeId = new Guid(idStr); _ticketBuilder.ContentType = (BlobType)Enum.Parse(typeof(BlobType), contentTypeStr); _ticketBuilder.SrcElementId = new Guid(srcElId); _ticketBuilder.SrcPortId = new Guid(srcPortId); _ticketBuilder.DestElementId = new Guid(destElId); _ticketBuilder.DestPortId = new Guid(destPortId); IPipeTicket ticket = TicketBuilder.Ticket; pipe = ReConstitute(ticket); }
internal void UnpersistLocation(System.Xml.XmlReader reader, out PointF location) { // Assumes reader has started the read of element "Location" reader.MoveToAttribute("x"); string xStr = reader["x"]; reader.MoveToAttribute("y"); string yStr = reader["y"]; reader.MoveToElement(); //if (reader.IsStartElement() && !reader.IsEmptyElement) //{ // reader.Read(); //} location = new PointF(float.Parse(xStr), float.Parse(yStr)); }
public static List<XmlReadInstructions> AnalyseXmlReader(System.Xml.XmlReader reader, bool globalUniqueColumnNames) { var root = new Node(); var current = root; var resultSets = new Dictionary<string, Node>(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: current = current.SubElement(reader.Name); if (reader.HasAttributes) { reader.MoveToFirstAttribute(); do { current.Attribute(reader.Name); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } if (current.CurrentCount > 1) { string xpath = current.AbsXPath; if (!resultSets.ContainsKey(xpath)) { resultSets[xpath] = current; current.IsRepetetive = true; } } if (reader.IsEmptyElement) current = current.Parent; break; case XmlNodeType.Text: if (!String.IsNullOrWhiteSpace(reader.Value)) { current.HasText = true; } break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: case XmlNodeType.Comment: continue; case XmlNodeType.EndElement: current = current.Parent; break; } } // remove repetetive parents. Remains only innermost repetetives foreach (var resultSet in resultSets.Values.ToList()) { var node = resultSet; node = node.Parent; while (node != null && !node.IsRepetetive) node = node.Parent; if (node != null) { resultSets.Remove(node.AbsXPath); node.IsRepetetive = false; } } if (!resultSets.Any()) { resultSets["/"] = root; } var res = new List<XmlReadInstructions>(); var addedColumns = new HashSet<string>(); var collectionNames = new HashSet<string>(); foreach (var resultSet in resultSets.Values) { var instruction = new XmlReadInstructions(); instruction.XPath = resultSet.AbsXPath ?? "/"; string collectionName = resultSet.Name; if (collectionNames.Contains(collectionName)) { int index = 2; while (collectionNames.Contains(collectionName + index)) index++; collectionName = collectionName + index; } instruction.CollectionName = collectionName; if (!globalUniqueColumnNames) addedColumns.Clear(); CollectColumns(instruction, root, addedColumns, resultSet); if (resultSet != root) { CollectColumns(instruction, resultSet, addedColumns, resultSet); } res.Add(instruction); } return res; }
/// <summary> /// Parses an instance of the specified type from the specified stream /// </summary> public object Parse(System.Xml.XmlReader s, Type useType, Type currentInteractionType, XmlIts1FormatterParseResult resultContext) { ConstructorInfo ci = useType.GetConstructor(Type.EmptyTypes); if(ci == null) throw new InvalidOperationException(String.Format("Cannot create an instance of type '{0}' as it defines no default constructor", useType.FullName)); // Create the instance object instance = ci.Invoke(null); PropertyInfo[] properties = useType.GetProperties(BindingFlags.Public | BindingFlags.Instance); // Move the reader to the first attribute if (s.MoveToFirstAttribute()) { // Now we read the attributes and match with the properties do { #if WINDOWS_PHONE PropertyInfo pi = properties.Find(o => o.GetCustomAttributes(true).Count(pa => pa is PropertyAttribute && (pa as PropertyAttribute).Name == s.LocalName) > 0); #else PropertyInfo pi = Array.Find<PropertyInfo>(properties, o => o.GetCustomAttributes(true).Count(pa => pa is PropertyAttribute && (pa as PropertyAttribute).Name == s.LocalName) > 0); #endif // Can we set the PI? if (s.LocalName == "ITSVersion" && s.Value != "XML_1.0") throw new System.InvalidOperationException(System.String.Format("This formatter can only parse XML_1.0 structures. This structure claims to be '{0}'.", s.Value)); else if (s.Prefix == "xmlns" || s.LocalName == "xmlns" || s.LocalName == "ITSVersion" || s.NamespaceURI == XmlIts1Formatter.NS_XSI) continue; else if (pi == null) { resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("@{0}", s.LocalName), s.NamespaceURI, s.ToString(), null)); continue; } var paList = pi.GetCustomAttributes(typeof(PropertyAttribute), true); // property attributes // VAlidate list of PA if(paList == null || paList.Length != 1) { resultContext.AddResultDetail(new ResultDetail(ResultDetailType.Warning, String.Format("Invalid number of PropertyAttributes on property '{0}', ignoring", pi.Name), s.ToString(), null)); continue; // not a property to be parsed } if (pi.GetSetMethod() == null) { if (!Util.ToWireFormat(pi.GetValue(instance, null)).Equals(s.Value)) resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(s.Value, pi.GetValue(instance, null).ToString(), true, s.ToString())); } else if (!String.IsNullOrEmpty((paList[0] as PropertyAttribute).FixedValue)) { if (!(paList[0] as PropertyAttribute).FixedValue.Equals(s.Value)) { resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(s.Value, (paList[0] as PropertyAttribute).FixedValue, false, s.ToString())); pi.SetValue(instance, Util.FromWireFormat(s.Value, pi.PropertyType), null); } } else pi.SetValue(instance, Util.FromWireFormat(s.Value, pi.PropertyType), null); } while (s.MoveToNextAttribute()); s.MoveToElement(); } // Nil? // BUG: Fixed, xsi:nil may also have a null-flavor String nil = s.GetAttribute("nil", XmlIts1Formatter.NS_XSI); if (!String.IsNullOrEmpty(nil) && Convert.ToBoolean(nil)) return instance; // Is reader at an empty element if (s.IsEmptyElement) return instance; // Read content string currentElementName = s.LocalName, lastElementRead = s.LocalName; while(true) { // End of stream or item not read if (lastElementRead == s.LocalName && !s.Read()) break; lastElementRead = s.LocalName; // Element is end element and matches the starting element namd if (s.NodeType == System.Xml.XmlNodeType.EndElement && s.LocalName == currentElementName) break; // Element is an end element //else if (s.NodeType == System.Xml.XmlNodeType.EndElement) // currentDepth--; // Element is a start element else if (s.NodeType == System.Xml.XmlNodeType.Element) { // Get the element choice property #if WINDOWS_PHONE PropertyInfo pi = properties.Find(o => o.GetCustomAttributes(true).Count(a => a is PropertyAttribute && (a as PropertyAttribute).Name == s.LocalName && ((a as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) > 0); #else PropertyInfo pi = Array.Find(properties, o => o.GetCustomAttributes(true).Count(a => a is PropertyAttribute && (a as PropertyAttribute).Name == s.LocalName && ((a as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) > 0); #endif if (pi == null) { resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); continue; } // Get the property attribute that defined the choice #if WINDOWS_PHONE PropertyAttribute pa = pi.GetCustomAttributes(true).Find(p => p is PropertyAttribute && (p as PropertyAttribute).Name == s.LocalName && ((p as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) as PropertyAttribute; #else PropertyAttribute pa = Array.Find(pi.GetCustomAttributes(true), p => p is PropertyAttribute && (p as PropertyAttribute).Name == s.LocalName && ((p as PropertyAttribute).InteractionOwner ?? currentInteractionType) == currentInteractionType) as PropertyAttribute; #endif // Can we set the PI? if (pi == null || !pi.CanWrite) continue; // Now time to set the PI if (String.IsNullOrEmpty(s.GetAttribute("specializationType")) && s is MARC.Everest.Xml.XmlStateReader && (this.Host.Settings & SettingsType.AllowFlavorImposing) == SettingsType.AllowFlavorImposing) (s as MARC.Everest.Xml.XmlStateReader).AddFakeAttribute("specializationType", pa.ImposeFlavorId); // Cannot deserialize this if (pa.Type == null && pi.PropertyType == typeof(System.Object)) resultContext.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, pi.Name, pa.NamespaceUri, s.ToString(), null)); // Simple deserialization if PA type has IGraphable or PI type has IGraphable and PA type not specified else if (pi.GetSetMethod() != null && (pa.Type != null && pa.Type.GetInterface(typeof(IGraphable).FullName, false) != null) || (pa.Type == null && pi.PropertyType.GetInterface(typeof(IGraphable).FullName, false) != null)) { object tempFormat = Host.ParseObject(s, pa.Type ?? pi.PropertyType, currentInteractionType, resultContext); if (!String.IsNullOrEmpty(pa.FixedValue) && !pa.FixedValue.Equals(Util.ToWireFormat(tempFormat)) && pa.PropertyType != PropertyAttribute.AttributeAttributeType.Traversable) resultContext.AddResultDetail(new FixedValueMisMatchedResultDetail(Util.ToWireFormat(tempFormat), pa.FixedValue, s.ToString())); pi.SetValue(instance, Util.FromWireFormat(tempFormat, pa.Type ?? pi.PropertyType), null); } // Call an Add method on a collection type else if (pi.PropertyType.GetMethod("Add") != null) // Collection type pi.PropertyType.GetMethod("Add").Invoke(pi.GetValue(instance, null), new object[] { Util.FromWireFormat(Host.ParseObject(s, pi.PropertyType.GetGenericArguments()[0], currentInteractionType, resultContext), pi.PropertyType.GetGenericArguments()[0]) }); // Call the ParseXML custom function on object else if (pi.GetSetMethod() != null && pi.PropertyType.GetMethod("ParseXml", BindingFlags.Public | BindingFlags.Static) != null) pi.SetValue(instance, pi.PropertyType.GetMethod("ParseXml").Invoke(instance, new object[] { s }), null); // Property type is a simple string else if (pi.GetSetMethod() != null && pi.PropertyType == typeof(string)) // Read content... pi.SetValue(instance, Util.FromWireFormat(s.ReadInnerXml(), typeof(String)), null); // No Set method is used, fixed value? else { object tempFormat = Host.ParseObject(s, pa.Type ?? pi.PropertyType, currentInteractionType, resultContext); if (tempFormat.ToString() != pi.GetValue(instance, null).ToString() && pa.PropertyType != PropertyAttribute.AttributeAttributeType.Traversable) resultContext.AddResultDetail(new MARC.Everest.Connectors.FixedValueMisMatchedResultDetail(tempFormat.ToString(), pi.GetValue(instance, null).ToString(), s.ToString())); } } } return instance; }