Example #1
0
        public void Read_Properties_Without_Types_Specified_Test()
        {
            const string xsd = @"
<xs:schema targetNamespace=""http://schemas.sage.com/crmErp/2008""
           xmlns=""http://schemas.sage.com/crmErp/2008""
           xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
  <xs:complexType name=""tradingAccount--type"">
    <xs:all>
      <xs:element name=""active"" />
    </xs:all>
  </xs:complexType>
</xs:schema>";
            SDataSchema  schema;

            using (var reader = new StringReader(xsd))
            {
                schema = SDataSchema.Read(reader);
            }

            Assert.That(schema, Is.Not.Null);
            var resource = schema.ComplexTypes["tradingAccount--type"];

            Assert.That(resource, Is.Not.Null);
            Assert.That(resource.Properties.Count, Is.EqualTo(1));
            var property = resource.Properties[0];

            Assert.That(property, Is.Not.Null);
            Assert.That(property.Name, Is.EqualTo("active"));
            Assert.That(property.Type.QualifiedName.IsEmpty, Is.True);
        }
Example #2
0
        public void Read_Element_Then_List_Type_Then_Complex_Type_Test()
        {
            const string xsd = @"
<xs:schema targetNamespace=""http://schemas.sage.com/crmErp/2008""
           xmlns=""http://schemas.sage.com/crmErp/2008""
           xmlns:xs=""http://www.w3.org/2001/XMLSchema""
           xmlns:sme=""http://schemas.sage.com/sdata/sme/2007"">
  <xs:element name=""tradingAccount"" type=""tradingAccount--type"" sme:role=""resourceKind"" />
  <xs:complexType name=""tradingAccount--list"">
    <xs:sequence>
      <xs:element type=""tradingAccount--type"" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name=""tradingAccount--type"">
    <xs:all />
  </xs:complexType>
</xs:schema>";
            SDataSchema  schema;

            using (var reader = new StringReader(xsd))
            {
                schema = SDataSchema.Read(reader);
            }

            var resource = schema.ResourceTypes["tradingAccount"];

            Assert.That(resource, Is.Not.Null);
            Assert.That(resource.Name, Is.EqualTo("tradingAccount--type"));
            Assert.That(resource.ListName, Is.EqualTo("tradingAccount--list"));
        }
Example #3
0
        public void Read_Enum_Schema_Types_Support_List_Types_Test()
        {
            const string xsd = @"
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
  <xs:simpleType name=""test--enum"">
    <xs:restriction base=""xs:string"" />
  </xs:simpleType>
  <xs:complexType name=""test--list"">
    <xs:sequence>
      <xs:element name=""test"" type=""test--enum"" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>";
            SDataSchema  schema;

            using (var reader = new StringReader(xsd))
            {
                schema = SDataSchema.Read(reader);
            }

            var type = schema.Types["test--enum"];

            Assume.That(type, Is.InstanceOf <SDataSchemaEnumType>());
            Assert.That(type.ListName, Is.EqualTo("test--list"));
            Assert.That(type.ListItemName, Is.EqualTo("test"));
        }
Example #4
0
        private static SDataSchemaObject ReadSchema(ISDataResponse response)
        {
            var text = response.Content as string;

            if (text == null)
            {
                throw new SDataClientException("Unexpected content: " + response.Content);
            }

            using (var reader = new StringReader(text))
            {
                var schema = SDataSchema.Read(reader);

                if (!string.IsNullOrEmpty(response.Location))
                {
                    var targetElementName = new Uri(response.Location).Fragment.TrimStart('#');

                    if (!string.IsNullOrEmpty(targetElementName))
                    {
                        var resource = schema.ResourceTypes[targetElementName];

                        if (resource != null)
                        {
                            return(resource);
                        }
                    }
                }

                return(schema);
            }
        }
        private ISDataResults <T> CreateResults <T>(SDataResponse response)
        {
            TraceResponse(response);

            object obj = null;

            if (typeof(T) == typeof(byte[]))
            {
                var str = response.Content as string;
                if (str != null)
                {
                    obj = Encoding.UTF8.GetBytes(str);
                }
            }
            else if (typeof(T) == typeof(string))
            {
                var data = response.Content as byte[];
                if (data != null)
                {
                    obj = Encoding.UTF8.GetString(data);
                }
            }
#if !PCL && !NETFX_CORE && !SILVERLIGHT
            else if (typeof(T) == typeof(SDataSchema))
            {
                var str = response.Content as string;
                if (str != null)
                {
                    using (var memory = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                    {
                        obj = SDataSchema.Read(memory);
                    }
                }
            }
#endif
            T content;
            if (obj != null)
            {
                content = (T)obj;
            }
            else
            {
                content = ContentHelper.Deserialize <T>(response.Content, NamingScheme);
                var tracking = content as IChangeTracking;
                if (tracking != null)
                {
                    tracking.AcceptChanges();
                }
            }
            return(SDataResults.FromResponse(response, content));
        }
Example #6
0
        private static SDataSchemaObject ReadSchema(ISDataResponse response)
        {
            using (var reader = new StringReader((string)response.Content))
            {
                var schema = SDataSchema.Read(reader);

                if (!string.IsNullOrEmpty(response.Location))
                {
                    var targetElementName = new Uri(response.Location).Fragment.TrimStart('#');

                    if (!string.IsNullOrEmpty(targetElementName))
                    {
                        var resource = schema.ResourceTypes[targetElementName];

                        if (resource != null)
                        {
                            return(resource);
                        }
                    }
                }

                return(schema);
            }
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================

        #region Load(XPathNavigator source, XmlNamespaceManager manager)

        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SDataExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="SDataExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            var wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                var payloadNavigator = source.SelectSingleNode("sdata:payload/*", manager);
                if (payloadNavigator != null)
                {
                    var payload = new SDataPayload();
                    if (payload.Load(payloadNavigator, manager))
                    {
                        Payload   = payload;
                        wasLoaded = true;
                    }
                }

                var diagnosesNavigator = source.Select("sdata:diagnoses/sdata:diagnosis", manager);
                foreach (XPathNavigator item in diagnosesNavigator)
                {
                    var diagnosis = new Diagnosis();
                    if (diagnosis.Load(item, manager))
                    {
                        Diagnoses.Add(diagnosis);
                        wasLoaded = true;
                    }
                }

                var diagnosisNavigator = source.Select("sdata:diagnosis", manager);
                foreach (XPathNavigator item in diagnosisNavigator)
                {
                    var diagnosis = new Diagnosis();
                    if (diagnosis.Load(item, manager))
                    {
                        Diagnoses.Add(diagnosis);
                        wasLoaded = true;
                    }
                }

                var schemaNavigator = source.SelectSingleNode("sdata:schema", manager);
                if (schemaNavigator != null && !string.IsNullOrEmpty(schemaNavigator.InnerXml))
                {
                    schemaNavigator.MoveToFirstChild();

                    using (var reader = schemaNavigator.ReadSubtree())
                    {
                        reader.Read();
                        Schema = SDataSchema.Read(reader);
                    }

                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }