public IXdtoValue ReadXml(XmlReaderImpl reader, IXdtoType expectedType, XdtoFactory factory) { var lexicalValue = reader.Value; var value = ValueFactory.Create(lexicalValue); return(new XdtoDataValue(expectedType as XdtoValueType, lexicalValue, value)); }
public IXdtoValue Create(IXdtoType type, IValue value = null) { if (type is XdtoObjectType) { return(new XdtoDataObject(type as XdtoObjectType, null, null)); } var valueType = type as XdtoValueType; if (valueType == null) { throw RuntimeException.InvalidArgumentType(nameof(type)); } if (value == null) { throw RuntimeException.InvalidArgumentType(nameof(value)); } if (value.DataType == DataType.String) { return(new XdtoDataValue(valueType, value.AsString(), value)); } return(new XdtoDataValue(valueType, value.AsString(), value)); }
public XdtoValueType(XmlSchemaSimpleType xmlType, XdtoFactory factory) { NamespaceUri = xmlType.QualifiedName.Namespace; Name = xmlType.QualifiedName.Name; if (xmlType.BaseXmlSchemaType is XmlSchemaSimpleType) { _baseType = new XdtoValueType(xmlType.BaseXmlSchemaType as XmlSchemaSimpleType, factory); } var memberTypes = new List <XdtoValueType> (); var facets = new List <XdtoFacet> (); if (xmlType.Content is XmlSchemaSimpleTypeUnion) { } if (xmlType.Content is XmlSchemaSimpleTypeList) { } if (xmlType.Content is XmlSchemaSimpleTypeRestriction) { var restriction = xmlType.Content as XmlSchemaSimpleTypeRestriction; _baseType = new TypeResolver(factory, restriction.BaseTypeName); } MemberTypes = new XdtoValueTypeCollection(memberTypes); Facets = new XdtoFacetCollection(facets); ListItemType = new UndefinedOr <XdtoValueType> (null); Reader = this; }
public IXdtoValue ReadXml(XmlReaderImpl reader, IXdtoType type, XdtoFactory factory) { var lexicalValue = reader.Value; var internalValue = ValueFactory.Create(lexicalValue); return(new XdtoDataValue(this, lexicalValue, internalValue)); }
public IXdtoValue ReadXml(XmlReaderImpl reader, IXdtoType expectedType, XdtoFactory factory) { var lexicalValue = reader.Value; var xmlDateTimeValue = XmlConvert.ToDateTime(lexicalValue, XmlDateTimeSerializationMode.Unspecified); var value = ValueFactory.Create(xmlDateTimeValue); return(new XdtoDataValue(expectedType as XdtoValueType, lexicalValue, value)); }
internal ReturnValue(IXdtoType type = null, string messagePartName = "", bool nillable = false, string documentation = "") { Type = type; Nillable = nillable; Documentation = documentation; MessagePartName = messagePartName; }
internal XdtoProperty(XmlFormEnum form, string namespaceUri, string localName, IXdtoType type = null) { NamespaceURI = namespaceUri; LocalName = localName; Name = localName; Form = form; LowerBound = 1; UpperBound = 1; _type = type; }
internal XdtoProperty(IXdtoType ownerType, XdtoDataObject ownerObject, XmlFormEnum form, string namespaceUri, string localName, int lowerBound = 1, int upperBound = 1, IXdtoType type = null) { NamespaceURI = namespaceUri; LocalName = localName; Name = localName; Form = form; _ownerType = ownerType; OwnerObject = ownerObject; LowerBound = lowerBound; UpperBound = upperBound; _type = type; }
public IXdtoValue SerializeXdto(IValue value, IXdtoType requestedType) { var rawValue = value?.GetRawValue(); if (rawValue == null) { return(null); } if (requestedType == null) { requestedType = GetPrimitiveValueType(value); } if (rawValue.DataType == DataType.Undefined) { return(null); } if (rawValue.DataType == DataType.Boolean) { return(new XdtoDataValue(requestedType as XdtoValueType, XmlConvert.ToString(rawValue.AsBoolean()), value)); } if (rawValue.DataType == DataType.Date) { return(new XdtoDataValue(requestedType as XdtoValueType, XmlConvert.ToString(rawValue.AsDate(), "yyyy-MM-ddTHH:mm:ss"), value)); } if (rawValue.DataType == DataType.Number) { return(new XdtoDataValue(requestedType as XdtoValueType, XmlConvert.ToString(rawValue.AsNumber()), value)); } if (rawValue.DataType == DataType.String) { return(new XdtoDataValue(requestedType as XdtoValueType, rawValue.AsString(), value)); } // Non-primitive value return(null); }
public IValue ReadXml(XmlReaderImpl reader, IXdtoType type = null) { if (reader.MoveToContent() == null) { // TODO: бросить исключение?? return(null); } if (type == null) { var explicitType = reader.GetAttribute(ValueFactory.Create("type"), XmlNs.xsi); if (explicitType.DataType == DataType.Undefined) { type = new XdtoObjectType(); } else { var defaultNamespace = reader.NamespaceContext.DefaultNamespace; // Задан тип - пытаемся его распознать var sType = explicitType.AsString(); var nameElements = sType.Split(':'); var typeUri = nameElements.Count() > 1 ? nameElements [0] : defaultNamespace; var typeName = nameElements.Count() > 1 ? nameElements [1] : nameElements [0]; var nsMapping = reader.NamespaceContext.LookupNamespaceUri(typeUri); if (nsMapping != null && nsMapping.DataType == DataType.String) { typeUri = nsMapping.AsString(); } type = this.Type(typeUri, typeName); } } if (type is XdtoObjectType) { return(ValueFactory.Create(type.Reader.ReadXml(reader, type, this))); } var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance(); var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.Element); var xmlElementEnd = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.EndElement); if (type is XdtoValueType) { if (reader.NodeType.Equals(xmlElementStart)) { reader.Read(); } var result = type.Reader.ReadXml(reader, type, this); if (!reader.NodeType.Equals(xmlElementEnd)) { reader.Skip(); } var pd = new PrimitiveValuesSerializer(); return(pd.DeserializeXdto(result)); } throw new NotSupportedException("Неожиданный тип XDTO!"); }
public IXdtoValue ReadXml(XmlReaderImpl reader, IXdtoType expectedType, XdtoFactory factory) { // TODO: дублирование кода в трёх ветках var result = new XdtoDataObject(this, null, null); // TODO: Перевести XML на простые перечисления var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance(); var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.Element); var xmlText = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.Text); var xmlElementEnd = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.EndElement); while (reader.ReadAttribute()) { if (reader.NamespaceURI.Equals("http://www.w3.org/2000/xmlns/") || reader.NamespaceURI.Equals(XmlNs.xsi) && reader.LocalName.Equals("type")) { continue; } var propertyName = reader.LocalName; var attributeNamespace = reader.NamespaceURI; var attributeProperty = AllProperties().FirstOrDefault(p => p.Form == XmlFormEnum.Attribute && p.LocalName.Equals(propertyName) && p.NamespaceURI.Equals(attributeNamespace)); if (attributeProperty == null) { if (!Open) { throw new XdtoException($"Ошиба разбора XDTO: Получили неизвестный атрибут {propertyName}"); } var type = factory.Type(new XmlDataType("string")); attributeProperty = new XdtoProperty(null, result, XmlFormEnum.Attribute, NamespaceUri, propertyName, 1, -1, type); // TODO: lower / upper для открытого типа } var attributeValue = attributeProperty.Type.Reader.ReadXml(reader, attributeProperty.Type, factory); result.Set(attributeProperty, ValueFactory.Create(attributeValue)); } while (reader.Read()) { if (reader.NodeType.Equals(xmlElementEnd)) { // TODO: result.Validate() return(result); } if (reader.NodeType.Equals(xmlText)) { // надо найти свойство с Form=Text // оно должно быть одно var textProperty = AllProperties().FirstOrDefault((p) => p.Form == XmlFormEnum.Text); IXdtoType type; IValue textValue; if (textProperty == null) { if (!Open) { throw new XdtoException($"Ошибка разбора XDTO: Текст {reader.Value} в неположенном месте при разборе типа {this}!"); } textProperty = new XdtoProperty(null, result, XmlFormEnum.Text, NamespaceUri, "#text"); type = factory.Type(new XmlDataType("string")); textValue = ValueFactory.Create(reader.Value); } else { type = textProperty.Type; textValue = ValueFactory.Create(type.Reader.ReadXml(reader, type, factory)); } if (Sequenced) { result.Sequence().Add(textValue.AsString()); } else { result.Set(textProperty, textValue); } } else if (reader.NodeType.Equals(xmlElementStart)) { var localName = reader.LocalName; var ns = reader.NamespaceURI; var property = AllProperties().FirstOrDefault((p) => p.LocalName.Equals(localName) && p.NamespaceURI.Equals(ns) && p.Form == XmlFormEnum.Element); if (property == null) { if (!Open) { throw new XdtoException($"Ошибка разбора XDTO: Получили неизвестный элемент {localName}"); } // TODO: lower / upper для открытого типа property = new XdtoProperty(null, result, XmlFormEnum.Element, ns, localName, 1, 1); } var elementValue = factory.ReadXml(reader, property.Type); // TODO: Разбор anyType if (property.UpperBound != 1) { // TODO: проверка на null - на отсутствие/наличие списка (result.GetList(property) as XdtoList).Add(elementValue); } else { result.Set(property, elementValue); } } } throw new XdtoException("Ошибка разбора XDTO!"); }