Load() public method

public Load ( XPathNavigator source, XmlNamespaceManager manager ) : bool
source System.Xml.XPath.XPathNavigator
manager System.Xml.XmlNamespaceManager
return bool
        public static SDataPayload LoadPayload(string xml)
        {
            var payload = new SDataPayload();

            using (var strReader = new StringReader(xml))
            using (var xmlReader = XmlReader.Create(strReader))
            {
                var doc = new XPathDocument(xmlReader);
                var source = doc.CreateNavigator();
                var manager = new XmlNamespaceManager(source.NameTable);
                source.MoveToFirstChild();
                payload.Load(source, manager);
            }

            return payload;
        }
        private bool LoadItem(string name, IEnumerable<XPathNavigator> items, XmlNamespaceManager manager)
        {
            object value;

            if (items.Count() > 1)
            {
                var collection = new SDataPayloadCollection();

                if (!collection.Load(items, manager))
                {
                    return false;
                }

                value = collection;
            }
            else
            {
                var item = items.First();

                switch (InferItemType(item))
                {
                    case ItemType.Property:
                    {
                        string nilValue;

                        if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out nilValue) && XmlConvert.ToBoolean(nilValue))
                        {
                            value = null;
                        }
                        else
                        {
                            value = item.Value;
                        }

                        break;
                    }
                    case ItemType.Object:
                    {
                        var obj = new SDataPayload();

                        if (!obj.Load(item, manager))
                        {
                            return false;
                        }

                        value = obj;
                        break;
                    }
                    case ItemType.PayloadCollection:
                    {
                        var collection = new SDataPayloadCollection();

                        if (!collection.Load(item, manager))
                        {
                            return false;
                        }

                        value = collection;
                        break;
                    }
                    case ItemType.SimpleCollection:
                    {
                        var collection = new SDataSimpleCollection();

                        if (!collection.Load(item))
                            return false;

                        value = collection;
                        break;
                    }
                    default:
                        return false;
                }
            }

            Values.Add(name, value);
            return true;
        }
        //============================================================
        //	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);
        }
        private bool LoadItem(string name, IEnumerable <XPathNavigator> items, XmlNamespaceManager manager)
        {
            object value;

            if (items.Count() > 1)
            {
                var collection = new SDataPayloadCollection();

                if (!collection.Load(items, manager))
                {
                    return(false);
                }

                value = collection;
            }
            else
            {
                var item = items.First();

                switch (InferItemType(item))
                {
                case ItemType.Property:
                {
                    string nilValue;

                    if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out nilValue) && XmlConvert.ToBoolean(nilValue))
                    {
                        value = null;
                    }
                    else
                    {
                        value = item.Value;
                    }

                    break;
                }

                case ItemType.Object:
                {
                    var obj = new SDataPayload();

                    if (!obj.Load(item, manager))
                    {
                        return(false);
                    }

                    value = obj;
                    break;
                }

                case ItemType.PayloadCollection:
                {
                    var collection = new SDataPayloadCollection();

                    if (!collection.Load(item, manager))
                    {
                        return(false);
                    }

                    value = collection;
                    break;
                }

                case ItemType.SimpleCollection:
                {
                    var collection = new SDataSimpleCollection();

                    if (!collection.Load(item))
                    {
                        return(false);
                    }

                    value = collection;
                    break;
                }

                default:
                    return(false);
                }
            }

            Values.Add(name, value);
            return(true);
        }
        /// <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", manager);
                foreach (XPathNavigator item in diagnosesNavigator)
                {
                    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.Value))
                {
                    Schema = schemaNavigator.Value;
                    wasLoaded = true;
                }
            }

            return wasLoaded;
        }