Exemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Package object.</summary> 
        /// <param name="node">Package node</param>
        /// <param name="parser">AtomFeedParser to use</param>
        /// <returns>the created Package object</returns>
        //////////////////////////////////////////////////////////////////////
        public static Package ParsePackage(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            Package package = null;
            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;
            // Ensure that the namespace is correct.
            if (String.Compare(node.NamespaceURI,
                GCodeSearchParserNameTable.CSNamespace, true) == 0)
            {
                if (localname.Equals(GCodeSearchParserNameTable.EVENT_PACKAGE))
                {
                    package = new Package();
                    if (node.Attributes != null)
                    {
                        package.name =
                            node.Attributes[
                            GCodeSearchParserNameTable.ATTRIBUTE_NAME].Value;
                        package.uri =
                            node.Attributes[
                            GCodeSearchParserNameTable.ATTRIBUTE_URI].Value;
                    }
                    else 
                    {
                        throw new ArgumentNullException(
                            BaseNameTable.gBatchNamespace +
                            ":" + GCodeSearchParserNameTable.EVENT_PACKAGE +
                            " must contain the attributes " +
                            GCodeSearchParserNameTable.ATTRIBUTE_NAME + " and " +
                            GCodeSearchParserNameTable.ATTRIBUTE_URI);
                    }
                }
            }
            return package;
        }
       //////////////////////////////////////////////////////////////////////
        /// <summary>parses the inner state of the element</summary>
        /// <param name="e">the Event arguments</param>
        /// <param name="parser">the atomFeedParser that called this</param>
        //////////////////////////////////////////////////////////////////////
        public override void Parse(ExtensionElementEventArgs e, AtomFeedParser parser)
        {
            XmlNode eventNode = e.ExtensionElement;

            Tracing.TraceMsg(eventNode.LocalName);
            // Ensure that the namespace is correct.
            if (String.Compare(eventNode.NamespaceURI,
                GCodeSearchParserNameTable.CSNamespace, true) == 0)
            {
                // Parse a File Element
                if (eventNode.LocalName == GCodeSearchParserNameTable.EVENT_FILE)
                {
                    file = File.ParseFile(eventNode, parser);
                    e.DiscardEntry = true;
                }
                    // Parse a Package Element
                else if ((eventNode.LocalName == GCodeSearchParserNameTable.EVENT_PACKAGE))
                {
                    package = Package.ParsePackage(eventNode, parser);
                    e.DiscardEntry = true;
                }
                    // Parse Match Elements 
                else if (eventNode.LocalName == GCodeSearchParserNameTable.EVENT_MATCH)
                {
                    matches.Add(Match.ParseMatch(eventNode, parser));
                    e.DiscardEntry = true;
                } 
            }
        }