Beispiel #1
0
        public static IRuntimeContextInstance Constructor(IValue factory)
        {
            XdtoFactory rawFactory = factory.GetRawValue() as XdtoFactory;

            if (rawFactory == null)
            {
                throw RuntimeException.InvalidArgumentType("factory");
            }

            var primitiveSerializer = new PrimitiveValuesSerializer();
            var serializer          = new XdtoSerializerImpl(rawFactory);

            serializer.RegisterXdtoSerializer(TypeManager.GetTypeByName("Число"), primitiveSerializer);
            serializer.RegisterXdtoSerializer(TypeManager.GetTypeByName("Булево"), primitiveSerializer);
            serializer.RegisterXdtoSerializer(TypeManager.GetTypeByName("Строка"), primitiveSerializer);
            serializer.RegisterXdtoSerializer(TypeManager.GetTypeByName("Дата"), primitiveSerializer);

            serializer.RegisterXdtoDeserializer(new XmlDataType("int"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("decimal"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("float"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("boolean"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("string"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("date"), primitiveSerializer);
            serializer.RegisterXdtoDeserializer(new XmlDataType("dateTime"), primitiveSerializer);

            return(serializer);
        }
Beispiel #2
0
        public IXdtoValue Set(int index, IValue value)
        {
            var pv     = new PrimitiveValuesSerializer();
            var xvalue = pv.SerializeXdto(value, null);

            _data[index] = xvalue;
            return(xvalue);
        }
Beispiel #3
0
        public IXdtoValue Add(IValue value)
        {
            var rawValue = value.GetRawValue();

            if (rawValue is IXdtoValue)
            {
                _data.Add(rawValue as IXdtoValue);
                return(rawValue as IXdtoValue);
            }
            var pv     = new PrimitiveValuesSerializer();
            var xvalue = pv.SerializeXdto(value, null);

            _data.Add(xvalue);
            return(xvalue);
        }
Beispiel #4
0
        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!");
        }