internal void ParseXml(XPathNavigator commonNav)
        {
            XPathNavigator sourceNav = commonNav.SelectSingleNode("source");

            if (sourceNav != null)
            {
                Source = sourceNav.Value;
            }

            XPathNavigator noteNav = commonNav.SelectSingleNode("note");

            if (noteNav != null)
            {
                Note = noteNav.Value;
            }

            // Please leave this code until the data-xml/common/tags gets removed.
            XPathNavigator tagsNav = commonNav.SelectSingleNode("tags");

            if (tagsNav != null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                Tags = tagsNav.Value;
#pragma warning restore CS0618 // Type or member is obsolete
            }

            XPathNodeIterator extensionIterator = commonNav.Select("extension");

            foreach (XPathNavigator extensionNav in extensionIterator)
            {
                ThingExtension extension = DeserializeExtension(extensionNav);

                if (extension != null)
                {
                    Extensions.Add(extension);
                }
            }

            XPathNodeIterator relationshipIterator =
                commonNav.Select("related-thing[./thing-id != '' or ./client-thing-id != '']");

            foreach (XPathNavigator relationshipNav in relationshipIterator)
            {
                ThingRelationship relationship =
                    new ThingRelationship();

                relationship.ParseXml(relationshipNav);

                RelatedItems.Add(relationship);
            }

            XPathNavigator clientIdNav = commonNav.SelectSingleNode("client-thing-id");
            if (clientIdNav != null)
            {
                ClientId = clientIdNav.Value;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deserializes the response XML for extensions into a
        /// <see cref="ThingExtension"/> or derived type based on the registered
        /// extension handler.
        /// </summary>
        ///
        /// <param name="extensionNav">
        /// The XML representation of the extension data.
        /// </param>
        ///
        /// <returns>
        /// The <see cref="ThingExtension"/> or derived class instance
        /// representing the data in the XML.
        /// </returns>
        ///
        /// <exception cref="System.Reflection.TargetInvocationException">
        /// If the constructor of the type being created throws an
        /// exception. The inner exception is the exception thrown by the
        /// constructor.
        /// </exception>
        ///
        /// <exception cref="MissingMethodException">
        /// The default constructor of the type being created is not public.
        /// If you registered the extension handler, be sure that the type you
        /// registered for the extension type class has a public default
        /// constructor.
        /// </exception>
        ///
        internal static ThingExtension DeserializeExtension(
            XPathNavigator extensionNav)
        {
            ThingExtension result;

            string source = extensionNav.GetAttribute("source", string.Empty);

            if (s_extensionHandlers.ContainsKey(source))
            {
                ThingTypeHandler handler = s_extensionHandlers[source];
                result =
                    (ThingExtension)Activator.CreateInstance(
                        handler.ItemTypeClass);
            }
            else
            {
                result = new ThingExtension(source);
            }

            result.ParseXml(extensionNav);
            return(result);
        }
        internal ThingExtension DeserializeExtension(XPathNavigator extensionNav)
        {
            ThingExtension result;
            string         source = extensionNav.GetAttribute("source", string.Empty);

            var thingTypeRegistrar = Ioc.Get <IThingTypeRegistrar>();

            var extensionHandlers = thingTypeRegistrar.RegisteredExtensionHandlers;

            if (extensionHandlers.ContainsKey(source))
            {
                Type handler = extensionHandlers[source];
                result = (ThingExtension)Activator.CreateInstance(handler);
            }
            else
            {
                result = new ThingExtension(source);
            }

            result.ParseXml(extensionNav);
            return(result);
        }