CreateNavigator() public method

public CreateNavigator ( ) : XPathNavigator
return XPathNavigator
Example #1
0
 public Package(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     this.m_Attributes = new Interface.WATFDictionary<string, string>();
     XPathNavigator copyXPathNavigator = xPathNavigator.CreateNavigator();
     if(copyXPathNavigator.MoveToFirstAttribute())
     {
         if(copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.Executive.Path))
         {
             this.m_Attributes.Add(copyXPathNavigator.Name, Path.Value(xPathNavigator));
         }
         else if(copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.Executive.Prefix))
         {
             this.m_Attributes.Add(copyXPathNavigator.Name, Prefix.Value(xPathNavigator));
         }
         while (copyXPathNavigator.MoveToNextAttribute())
         {
             if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.Executive.Path))
             {
                 this.m_Attributes.Add(copyXPathNavigator.Name, Path.Value(xPathNavigator));
             }
             else if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.Executive.Prefix))
             {
                 this.m_Attributes.Add(copyXPathNavigator.Name, Prefix.Value(xPathNavigator));
             }
         }
     }
 }
Example #2
0
 public Load(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     this.m_Attributes = new WATF.Compiler.Interface.WATFDictionary<string, string>();
     XPathNavigator copyXPathNavigator = xPathNavigator.CreateNavigator();
     if (copyXPathNavigator.MoveToFirstAttribute())
     {
         if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.ConfigFile.Name))
         {
             this.m_Attributes.Add(GlobalDefine.Keyword.ConfigFile.Name, Name.Value(xPathNavigator));
         }
         else if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.ConfigFile.Path))
         {
             this.m_Attributes.Add(GlobalDefine.Keyword.ConfigFile.Path, Path.Value(xPathNavigator));
         }
         while (copyXPathNavigator.MoveToNextAttribute())
         {
             if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.ConfigFile.Name))
             {
                 this.m_Attributes.Add(GlobalDefine.Keyword.ConfigFile.Name, Name.Value(xPathNavigator));
             }
             else if (copyXPathNavigator.Name.Equals(GlobalDefine.Keyword.ConfigFile.Path))
             {
                 this.m_Attributes.Add(GlobalDefine.Keyword.ConfigFile.Path, Path.Value(xPathNavigator));
             }
         }
     }
 }
Example #3
0
 internal Element(XPathNavigator node)
     : this(node.Name)
 {
     XPathNavigator navigator = node.CreateNavigator();
     if (navigator.MoveToFirstAttribute())
     {
         do
         {
             AddAttribute(navigator.Name, navigator.Value);
         } while (navigator.MoveToNextAttribute());
     }
 }
Example #4
0
 public Test(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     m_TestChilds = new Interface.WATFDictionary<string, Interface.WATFPathNavigator>();
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     while (xPathNodeIterator.MoveNext())
     {
         if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Step))
         {
             m_TestChilds.Add(GlobalDefine.Keyword.Executive.Step, new Step.Step(xPathNodeIterator.Current));
         }
     }
 }
Example #5
0
 private ConfigFile(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     m_ConfigFileNodes = new Interface.WATFDictionary<string, Interface.WATFPathNavigator>();
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     while (xPathNodeIterator.MoveNext())
     {
         if(xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.ConfigFile.Load))
         {
             m_ConfigFileNodes.Add(GlobalDefine.Keyword.ConfigFile.Load, new Load.Load(xPathNodeIterator.Current));
         }
     }
 }
Example #6
0
 public Import(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     this.m_ImportChilds = new Interface.WATFDictionary<String, WATF.Compiler.Interface.WATFPathNavigator>();
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     while (xPathNodeIterator.MoveNext())
     {
         if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Package))
         {
             m_ImportChilds.Add(xPathNodeIterator.Current.LocalName, new Package.Package(xPathNodeIterator.Current));
         }
     }
 }
Example #7
0
 public Var(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     this.m_Attributes = new Interface.WATFDictionary<string, string>();
     XPathNavigator copyXPathNavigator = xPathNavigator.CreateNavigator();
     if (copyXPathNavigator.MoveToFirstAttribute())
     {
         this.m_Attributes.Add(copyXPathNavigator.Name, copyXPathNavigator.Value);
         while (copyXPathNavigator.MoveToNextAttribute())
         {
             this.m_Attributes.Add(copyXPathNavigator.Name, copyXPathNavigator.Value);
         }
     }
 }
Example #8
0
 public Action(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     m_ActionChilds = new Interface.WATFDictionary<string, Interface.WATFPathNavigator>();
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     while (xPathNodeIterator.MoveNext())
     {
         if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Action))
         {
             m_ActionChilds.Add(GlobalDefine.Keyword.Executive.Action, new Action(xPathNodeIterator.Current));
         }
     }
     this.m_Attributes = new Interface.WATFDictionary<string, string>();
     XPathNavigator copyXPathNavigator = xPathNavigator.CreateNavigator();
     if (copyXPathNavigator.MoveToFirstAttribute())
     {
         this.m_Attributes.Add(copyXPathNavigator.Name, copyXPathNavigator.Value);
         while (copyXPathNavigator.MoveToNextAttribute())
         {
             this.m_Attributes.Add(copyXPathNavigator.Name,copyXPathNavigator.Value);
         }
     }
 }
Example #9
0
 public Step(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     m_StepChilds = new Interface.WATFDictionary<string, Interface.WATFPathNavigator>();
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     while (xPathNodeIterator.MoveNext())
     {
         if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Var))
         {
             m_StepChilds.Add(GlobalDefine.Keyword.Executive.Var, new Var.Var(xPathNodeIterator.Current));
         }
         else if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Action))
         {
             m_StepChilds.Add(GlobalDefine.Keyword.Executive.Action, new Action.Action(xPathNodeIterator.Current));
         }
     }
 }
Example #10
0
 public Executive(XPathNavigator xPathNavigator)
     : base(xPathNavigator)
 {
     XPathNodeIterator xPathNodeIterator = xPathNavigator.CreateNavigator().SelectChildren(XPathNodeType.Element);
     m_ExeChilds = new Interface.WATFDictionary<string, Interface.WATFPathNavigator>();
     while (xPathNodeIterator.MoveNext())
     {
         if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Import))
         {
             m_ExeChilds.Add(xPathNodeIterator.Current.LocalName, new Import.Import(xPathNodeIterator.Current));
         }
         else if (xPathNodeIterator.Current.LocalName.Equals(GlobalDefine.Keyword.Executive.Test))
         {
             m_ExeChilds.Add(xPathNodeIterator.Current.LocalName, new Test.Test(xPathNodeIterator.Current));
         }
     }
 }
		public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
		{
			IDictionary<string, IAttachmentHandler> attachments = _explorer.Map<IAttachmentHandler>(item.GetContentType());
			
			foreach(XPathNavigator attachmentElement in EnumerateChildren(navigator))
			{
				string name = attachmentElement.GetAttribute("name", string.Empty);
				if(attachments.ContainsKey(name))
				{
					XPathNavigator attachmentContents = navigator.CreateNavigator();
					attachmentContents.MoveToFirstChild();
					Attachment a = attachments[name].Read(attachmentContents, item);
					if(a != null)
						journal.Report(a);
				}
			}
		}
        public IList<string> GrabBackDropUrls(XPathNavigator nav)
        {
            List<string> urls = new List<string>();
            XPathNodeIterator nIter = nav.SelectChildren("backdrop", "");
            if (nav.MoveToFollowing("backdrop", ""))
            {
                XPathNavigator localNav = nav.CreateNavigator();
                nav.MoveToParent();
                for (int i = 0; i < nIter.Count; i++)
                {
                    if (localNav.GetAttribute("size", "").ToUpperInvariant().Equals("original".ToUpperInvariant()))
                        urls.Add(localNav.Value);

                    localNav.MoveToNext();
                }
            }
            return urls;
        }
 private void ReadComponents(XPathNavigator manifestNav)
 {
     foreach (XPathNavigator componentNav in manifestNav.CreateNavigator().Select("components/component"))
     {
         int order = ComponentInstallers.Count;
         string type = componentNav.GetAttribute("type", "");
         if (InstallMode == InstallMode.Install)
         {
             string installOrder = componentNav.GetAttribute("installOrder", "");
             if (!string.IsNullOrEmpty(installOrder))
             {
                 order = int.Parse(installOrder);
             }
         }
         else
         {
             string unInstallOrder = componentNav.GetAttribute("unInstallOrder", "");
             if (!string.IsNullOrEmpty(unInstallOrder))
             {
                 order = int.Parse(unInstallOrder);
             }
         }
         if (Package.InstallerInfo != null)
         {
             Log.AddInfo(Util.DNN_ReadingComponent + " - " + type);
         }
         ComponentInstallerBase installer = InstallerFactory.GetInstaller(componentNav, Package);
         if (installer == null)
         {
             Log.AddFailure(Util.EXCEPTION_InstallerCreate);
         }
         else
         {
             ComponentInstallers.Add(order, installer);
             this.Package.InstallerInfo.AllowableFiles += ", " + installer.AllowableFiles;
         }
     }
 }
        private void loadDataFromNavigatorToTitle(ref XPathNavigator navigator, ref OMLSDKTitle newTitle)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] Loading data for a new title");
            newTitle.MetadataSourceID = GetChildNodesValue(navigator, "WebServiceID");

            #region covers
            SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Covers");
            if (navigator.MoveToChild("Covers", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Covers found, processing");
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Front");
                if (navigator.MoveToChild("Front", ""))
                {
                    string imagePath = navigator.Value;
                    string finalImagePath = FindFinalImagePath(imagePath);
                    SDKUtilities.DebugLine("[MyMoviesImporter] Final image path is: {0}", finalImagePath);
                    if (File.Exists(finalImagePath))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] This file appears to be valid, we'll set it on the title");
                        newTitle.FrontCoverPath = finalImagePath;
                    }
                    navigator.MoveToParent();
                }
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Back");
                if (navigator.MoveToChild("Back", ""))
                {
                    string imagePath = navigator.Value;
                    if (File.Exists(imagePath))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Found Back cover image");
                        newTitle.BackCoverPath = imagePath;
                    }
                    navigator.MoveToParent();
                }

                navigator.MoveToParent();
            }
            #endregion

            newTitle.Synopsis = GetChildNodesValue(navigator, "Description");

            #region production year
            if (navigator.MoveToChild("ProductionYear", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Found production year, I hope the format is something we can read");
                try
                {
                    string year = navigator.Value;
                    if (!string.IsNullOrEmpty(year))
                    {
                        DateTime rls_date = new DateTime(int.Parse(year), 1, 1);
                        if (rls_date != null)
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] Got it, loading the production year");
                            newTitle.ReleaseDate = rls_date;
                        }
                    }
                    navigator.MoveToParent();
                }
                catch (Exception e)
                {
                    navigator.MoveToParent();
                    SDKUtilities.DebugLine("[MyMoviesImporter] error reading ProductionYear: " + e.Message);
                }
            }
            #endregion

            #region parental rating (mpaa rating)
            if (navigator.MoveToChild("ParentalRating", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for the ParentalRating");
                if (navigator.HasChildren)
                {
                    string ratingId = GetChildNodesValue(navigator, "Value");
                    if (!string.IsNullOrEmpty(ratingId))
                    {
                        int mmRatingId;
                        if (int.TryParse(ratingId, out mmRatingId))
                            switch (mmRatingId)
                            {
                                case 0:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be unrated");
                                    newTitle.ParentalRating = "Unrated";
                                    break;
                                case 1:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated G");
                                    newTitle.ParentalRating = "G";
                                    break;
                                case 2:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] I have no idea what rating this is");
                                    break;
                                case 3:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated PG");
                                    newTitle.ParentalRating = "PG";
                                    break;
                                case 4:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated PG13");
                                    newTitle.ParentalRating = "PG13";
                                    break;
                                case 5:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] I have NO idea what rating this is");
                                    break;
                                case 6:
                                    SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated R");
                                    newTitle.ParentalRating = "R";
                                    break;
                            }
                        else
                            SDKUtilities.DebugLine("[MyMoviesImporter] Error parsing rating: {0} not a number", ratingId);
                    }
                    string ratingReason = GetChildNodesValue(navigator, "Description");
                    if (!string.IsNullOrEmpty(ratingReason))
                        newTitle.ParentalRatingReason = ratingReason;
                }
                navigator.MoveToParent();
            }
            #endregion

            newTitle.Runtime = Int32.Parse(GetChildNodesValue(navigator, "RunningTime"));

            #region persons
            if (navigator.MoveToChild("Persons", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Beginning the long, painful process of scanning people");
                if (navigator.HasChildren)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Person", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            string name = GetChildNodesValue(localNav, "Name");
                            string role = GetChildNodesValue(localNav, "Role");
                            string type = GetChildNodesValue(localNav, "Type");

                            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(type))
                            {
                                switch (type)
                                {
                                    case "Actor":
                                        SDKUtilities.DebugLine("[MyMoviesImporter] actor {0}, {1}", name, role);

                                        newTitle.AddActingRole(name, role);
                                        break;
                                    case "Director":
                                        SDKUtilities.DebugLine("[MyMoviesImporter] director {0}", name);

                                        newTitle.AddDirector(new OMLSDKPerson(name));
                                        break;

                                    default:
                                        break;
                                }
                            }
                            localNav.MoveToNext("Person", "");
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region studio (s)
            if (navigator.MoveToChild("Studios", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Ahh... Studios (pssst.. we only copy the last entry from here... dont tell anyone)");
                if (navigator.HasChildren)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Studio", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            newTitle.Studio = localNav.Value;
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            newTitle.CountryOfOrigin = GetChildNodesValue(navigator, "Country");
            newTitle.AspectRatio = GetChildNodesValue(navigator, "AspectRatio");
            newTitle.VideoStandard = GetChildNodesValue(navigator, "VideoStandard");
            newTitle.OriginalName = GetChildNodesValue(navigator, "OriginalTitle");
            newTitle.SortName = GetChildNodesValue(navigator, "SortTitle");

            #region genres
            if (navigator.MoveToChild("Genres", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Genres... good old genres");
                XPathNodeIterator nIter = navigator.SelectChildren("Genre", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    navigator.MoveToParent();
                    for (int i = 0; i < nIter.Count; i++)
                    {
                        newTitle.AddGenre(localNav.Value);
                        localNav.MoveToNext("Genre", "");
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region audio tracks
            if (navigator.MoveToChild("AudioTracks", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] AudioTracks.. yeah, like you can even change them anyway");
                XPathNodeIterator nIter = navigator.SelectChildren("AudioTrack", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    navigator.MoveToParent();
                    for (int i = 0; i < nIter.Count; i++)
                    {
                        string audioLanguage = localNav.GetAttribute("Language", "");
                        string audioType = localNav.GetAttribute("Type", "");
                        string audioChannels = localNav.GetAttribute("Channels", "");

                        if (!string.IsNullOrEmpty(audioLanguage))
                        {
                            string audioTrackString = audioLanguage;
                            if (!string.IsNullOrEmpty(audioType))
                                audioTrackString += string.Format(", {0}", audioType);

                            if (!string.IsNullOrEmpty(audioChannels))
                                audioTrackString += string.Format(", {0}", audioChannels);

                            SDKUtilities.DebugLine("[MyMoviesImporter] Got one: {0}, {1}, {2}", audioLanguage, audioType, audioChannels);
                            newTitle.AddAudioTrack(audioTrackString);
                        }
                        localNav.MoveToNext("AudioTrack", "");
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region watched status (Submitted by yodine from our forums)
            if (navigator.MoveToChild("Watched", ""))
            {
                navigator.MoveToParent(); // move back, we just wanted to know this field existed.
                SDKUtilities.DebugLine("[MyMoviesImporter] Found Watched status. Trying to decode");
                string watched = GetChildNodesValue(navigator, "Watched");
                if (!string.IsNullOrEmpty(watched))
                {
                    if (Boolean.Parse(watched))
                        newTitle.WatchedCount++;
                }
            }
            #endregion

            #region subtitles
            if (navigator.MoveToChild("Subtitles", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Subtitles here we come!");
                if (navigator.GetAttribute("NotPresent", "").CompareTo("False") == 0)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Subtitle", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            string subtitleLanguage = localNav.GetAttribute("Language", "");
                            if (!string.IsNullOrEmpty(subtitleLanguage))
                            {
                                SDKUtilities.DebugLine("[MyMoviesImporter] Subtitle {0}", subtitleLanguage);
                                newTitle.AddSubtitle(subtitleLanguage);
                            }

                            localNav.MoveToNext("Subtitle", "");
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region discs
            if (navigator.MoveToChild("Discs", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Discs... ok here is the good one, we'll passing this off to some other method to handle.");
                XPathNodeIterator nIter = navigator.SelectChildren("Disc", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    extractDisksFromXML(nIter, localNav, newTitle);
                    navigator.MoveToParent();
                }
                navigator.MoveToParent();
            }
            #endregion
        }
        private static void WriteElement(TextWriter writer, XPathNavigator nav, int depth, string leadIn)
        {
            writer.Write(leadIn);
            writer.WriteLine(nav.Name);

            WriteNamespaces(writer, nav, leadIn);

            if (nav.HasAttributes)
                WriteAttributes(writer, nav, leadIn);

            if (!nav.HasChildren)
                return;

            var childNav = nav.CreateNavigator();
            childNav.MoveToFirstChild();
            Traverse(writer, childNav, depth + 1);
        }
Example #16
0
        private static void AreXPathNavigatorsEqual(XPathNavigator nav1, XPathNavigator nav2, string message) {
            while (true) {
                if (nav1.Name != nav2.Name) {
                    Assert.Fail("Expected element <{0}>. Actual element <{1}>.{2}", nav1.Name, nav2.Name, message);
                }
                var anav1 = nav1.CreateNavigator();
                var anav2 = nav2.CreateNavigator();
                var attr1 = new List<string>();
                var attr2 = new List<string>();

                if (anav1.MoveToFirstAttribute()) {
                    do {
                        attr1.Add(string.Format("{0}=\"{1}\"", anav1.Name, anav1.Value));
                    } while (anav1.MoveToNextAttribute());
                }
                if (anav2.MoveToFirstAttribute()) {
                    do {
                        attr2.Add(string.Format("{0}=\"{1}\"", anav2.Name, anav2.Value));
                    } while (anav2.MoveToNextAttribute());
                }

                AssertUtil.ContainsExactly(attr2, attr1);

                var cnav1 = nav1.CreateNavigator();
                var cnav2 = nav2.CreateNavigator();
                if (cnav1.MoveToFirstChild()) {
                    if (cnav2.MoveToFirstChild()) {
                        AreXPathNavigatorsEqual(cnav1, cnav2, message);
                    } else {
                        Assert.Fail("Expected element {0}.{1}", GetFullPath(cnav1), message);
                    }
                } else if (cnav2.MoveToFirstChild()) {
                    Assert.Fail("Unexpected element {0}.{1}", GetFullPath(cnav2), message);
                }

                if (nav1.MoveToNext()) {
                    if (nav2.MoveToNext()) {
                        continue;
                    } else {
                        Assert.Fail("Expected element {0}.{1}", GetFullPath(nav1), message);
                    }
                } else if (nav2.MoveToNext()) {
                    Assert.Fail("Unexpected element {0}.{1}", GetFullPath(nav2), message);
                }
                break;
            }
        }
Example #17
0
        private static string GetFullPath(XPathNavigator nav) {
            nav = nav.CreateNavigator();
            var names = new Stack<string>();

            names.Push(nav.Name);
            while (nav.MoveToParent()) {
                names.Push(nav.Name);
            }

            return "/" + string.Join("/", names);
        }
Example #18
0
        /// <summary>
        /// Loads this <see cref="OpmlOutline"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="OpmlOutline"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="OpmlOutline"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                XPathNavigator attributesNavigator = source.CreateNavigator();
                if (attributesNavigator.MoveToFirstAttribute())
                {
                    //------------------------------------------------------------
                    //	Extract first attribute
                    //------------------------------------------------------------
                    if (this.LoadAttribute(attributesNavigator))
                    {
                        wasLoaded       = true;
                    }

                    //------------------------------------------------------------
                    //	Enumerate through additional attributes
                    //------------------------------------------------------------
                    while (attributesNavigator.MoveToNextAttribute())
                    {
                        if (this.LoadAttribute(attributesNavigator))
                        {
                            wasLoaded   = true;
                        }
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator outlinesIterator = source.Select("outline");
                if (outlinesIterator != null && outlinesIterator.Count > 0)
                {
                    while (outlinesIterator.MoveNext())
                    {
                        OpmlOutline outline = new OpmlOutline();
                        if (outline.Load(outlinesIterator.Current, settings))
                        {
                            this.Outlines.Add(outline);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
 public override void ReadManifest(XPathNavigator manifestNav)
 {
     Package.Name = Util.ReadAttribute(manifestNav, "name", Log, Util.EXCEPTION_NameMissing);
     Package.PackageType = Util.ReadAttribute(manifestNav, "type", Log, Util.EXCEPTION_TypeMissing);
     if (Package.PackageType == "Skin" || Package.PackageType == "Container")
     {
         Package.PortalID = Package.InstallerInfo.PortalID;
     }
     CheckSecurity();
     if (!IsValid)
     {
         return;
     }
     InstalledPackage = PackageController.GetPackageByName(Package.PortalID, Package.Name);
     Package.IsSystemPackage = bool.Parse(Util.ReadAttribute(manifestNav, "isSystem", false, Log, "", bool.FalseString));
     string strVersion = Util.ReadAttribute(manifestNav, "version", Log, Util.EXCEPTION_VersionMissing);
     ValidateVersion(strVersion);
     if (!IsValid)
     {
         return;
     }
     Log.AddInfo(Util.DNN_ReadingPackage + " - " + Package.PackageType + " - " + Package.Name);
     Package.FriendlyName = Util.ReadElement(manifestNav, "friendlyName", Package.Name);
     Package.Description = Util.ReadElement(manifestNav, "description");
     XPathNavigator authorNav = manifestNav.SelectSingleNode("owner");
     if (authorNav != null)
     {
         Package.Owner = Util.ReadElement(authorNav, "name");
         Package.Organization = Util.ReadElement(authorNav, "organization");
         Package.Url = Util.ReadElement(authorNav, "url");
         Package.Email = Util.ReadElement(authorNav, "email");
     }
     XPathNavigator licenseNav = manifestNav.SelectSingleNode("license");
     if (licenseNav != null)
     {
         string licenseSrc = Util.ReadAttribute(licenseNav, "src");
         if (string.IsNullOrEmpty(licenseSrc))
         {
             Package.License = licenseNav.Value;
         }
         else
         {
             Package.License = ReadTextFromFile(licenseSrc);
         }
     }
     if (string.IsNullOrEmpty(Package.License))
     {
         Package.License = Util.PACKAGE_NoLicense;
     }
     XPathNavigator relNotesNav = manifestNav.SelectSingleNode("releaseNotes");
     if (relNotesNav != null)
     {
         string relNotesSrc = Util.ReadAttribute(relNotesNav, "src");
         if (string.IsNullOrEmpty(relNotesSrc))
         {
             Package.ReleaseNotes = relNotesNav.Value;
         }
         else
         {
             Package.ReleaseNotes = ReadTextFromFile(relNotesSrc);
         }
     }
     if (string.IsNullOrEmpty(Package.License))
     {
         Package.License = Util.PACKAGE_NoReleaseNotes;
     }
     IDependency dependency = null;
     foreach (XPathNavigator dependencyNav in manifestNav.CreateNavigator().Select("dependencies/dependency"))
     {
         dependency = DependencyFactory.GetDependency(dependencyNav);
         if (!dependency.IsValid)
         {
             Log.AddFailure(dependency.ErrorMessage);
             return;
         }
     }
     ReadComponents(manifestNav);
 }
        private void WriteNextNode(XmlWriter writer, XPathNavigator nav, bool iterateSiblings)
        {
            if (nav.Name == "ScatterFile")
            {
                writer.WriteStartElement(nav.Name, nav.NamespaceURI);
            }
            else
            {
                writer.WriteStartElement(nav.Name);
            }

            XPathNavigator attrib = nav.CreateNavigator();
            if (attrib.MoveToFirstAttribute())
            {
                do
                {
                    writer.WriteAttributeString(attrib.Name, attrib.Value);
                }
                while (attrib.MoveToNextAttribute());
            }

            if (nav.Name == "LoadRegion")
            {
                string lrName = nav.GetAttribute("Name", "");

                foreach (ExecRegion er in (m_execRegionOrderMap[lrName] as SortedList).Values)
                {
                    WriteNextNode(writer, m_execRegionsToNavNode[lrName + ":" + er.Name] as XPathNavigator, false);
                }
            }
            /*
            else if (nav.Name == "ExecRegion")
            {
                string erName = nav.GetAttribute("Name", "");

                foreach (FileMapping fm in (m_symOrderMap[erName] as SortedList).Values)
                {
                    WriteNextNode(writer, m_symToNavNode[erName + ":" + fm.Name] as XPathNavigator, false);
                }
            }
            */
            else
            {
                XPathNodeIterator children = nav.SelectChildren(XPathNodeType.Element);
                while (children.MoveNext())
                {
                    WriteNextNode(writer, children.Current, iterateSiblings);
                }
            }
            writer.WriteEndElement();

            if (iterateSiblings && nav.MoveToNext())
            {
                WriteNextNode(writer, nav, iterateSiblings);
            }
        }
Example #21
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The ReadManifest method reads the manifest file and parses it into components.
        /// </summary>
        /// <history>
        /// 	[cnurse]	07/24/2007  created
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void ReadManifest(XPathNavigator manifestNav)
        {
            //Get Name Property
            Package.Name = Util.ReadAttribute(manifestNav, "name", Log, Util.EXCEPTION_NameMissing);

            //Get Type
            Package.PackageType = Util.ReadAttribute(manifestNav, "type", Log, Util.EXCEPTION_TypeMissing);

            //If Skin or Container then set PortalID
            if (Package.PackageType == "Skin" || Package.PackageType == "Container")
            {
                Package.PortalID = Package.InstallerInfo.PortalID;
            }
            CheckSecurity();
            if (!IsValid)
            {
                return;
            }
			
            //Attempt to get the Package from the Data Store (see if its installed)
            _installedPackage = PackageController.GetPackageByName(Package.PortalID, Package.Name);

            //Get IsSystem
            Package.IsSystemPackage = bool.Parse(Util.ReadAttribute(manifestNav, "isSystem", false, Log, "", bool.FalseString));

            //Get Version
            string strVersion = Util.ReadAttribute(manifestNav, "version", Log, Util.EXCEPTION_VersionMissing);
            ValidateVersion(strVersion);
            if (!IsValid)
            {
                return;
            }
            Log.AddInfo(Util.DNN_ReadingPackage + " - " + Package.PackageType + " - " + Package.Name);
            Package.FriendlyName = Util.ReadElement(manifestNav, "friendlyName", Package.Name);
            Package.Description = Util.ReadElement(manifestNav, "description");

            XPathNavigator foldernameNav = null;
            Package.FolderName = String.Empty;
            switch (Package.PackageType)
            {
                case "Module":
                    //In Dynamics moduels, a component:type=File can have a basePath pointing to the App_Conde folder. This is not a correct FolderName
                    //To ensure that FolderName is DesktopModules...
                    var folderNameValue = getSpecificFolderName(manifestNav, "components/component/files", "basePath", "DesktopModules");
                    if (!String.IsNullOrEmpty(folderNameValue)) Package.FolderName = folderNameValue.Replace('\\', '/');
                    break;
                case "Auth_System":
                    foldernameNav = manifestNav.SelectSingleNode("components/component/files");
                    if (foldernameNav != null) Package.FolderName = Util.ReadElement(foldernameNav, "basePath").Replace('\\', '/');
                    break;
                case "Container":
                    foldernameNav = manifestNav.SelectSingleNode("components/component/containerFiles");
                    if (foldernameNav != null) Package.FolderName = Globals.glbContainersPath +  Util.ReadElement(foldernameNav, "containerName").Replace('\\', '/');
                    break;
                case "Skin":
                    foldernameNav = manifestNav.SelectSingleNode("components/component/skinFiles");
                    if (foldernameNav != null) Package.FolderName = Globals.glbSkinsPath + Util.ReadElement(foldernameNav, "skinName").Replace('\\', '/');
                    break;
                default:
                    break;
            }

            //Get Icon
            XPathNavigator iconFileNav = manifestNav.SelectSingleNode("iconFile");
            if (iconFileNav != null)
            {
                if (iconFileNav.Value != string.Empty)
                {
                    if (iconFileNav.Value.StartsWith("~/"))
                    {
                        Package.IconFile = iconFileNav.Value;
                    }
                    else
                    {
                        Package.IconFile = (String.IsNullOrEmpty(Package.FolderName) ? "" :  Package.FolderName + "/") + iconFileNav.Value;
                        Package.IconFile = (!Package.IconFile.StartsWith("~/")) ? "~/" + Package.IconFile : Package.IconFile;
                    }
                }
            }
			//Get Author
            XPathNavigator authorNav = manifestNav.SelectSingleNode("owner");
            if (authorNav != null)
            {
                Package.Owner = Util.ReadElement(authorNav, "name");
                Package.Organization = Util.ReadElement(authorNav, "organization");
                Package.Url = Util.ReadElement(authorNav, "url");
                Package.Email = Util.ReadElement(authorNav, "email");
            }
			
            //Get License
            XPathNavigator licenseNav = manifestNav.SelectSingleNode("license");
            if (licenseNav != null)
            {
                string licenseSrc = Util.ReadAttribute(licenseNav, "src");
                if (string.IsNullOrEmpty(licenseSrc))
                {
					//Load from element
                    Package.License = licenseNav.Value;
                }
                else
                {
                    Package.License = ReadTextFromFile(licenseSrc);
                }
            }
            if (string.IsNullOrEmpty(Package.License))
            {
				//Legacy Packages have no license
                Package.License = Util.PACKAGE_NoLicense;
            }
			
            //Get Release Notes
            XPathNavigator relNotesNav = manifestNav.SelectSingleNode("releaseNotes");
            if (relNotesNav != null)
            {
                string relNotesSrc = Util.ReadAttribute(relNotesNav, "src");
                if (string.IsNullOrEmpty(relNotesSrc))
                {
					//Load from element
                    Package.ReleaseNotes = relNotesNav.Value;
                }
                else
                {
                    Package.ReleaseNotes = ReadTextFromFile(relNotesSrc);
                }
            }
            if (string.IsNullOrEmpty(Package.ReleaseNotes))
            {
				//Legacy Packages have no Release Notes
				Package.ReleaseNotes = Util.PACKAGE_NoReleaseNotes;
            }
			
            //Parse the Dependencies
            IDependency dependency = null;
            foreach (XPathNavigator dependencyNav in manifestNav.CreateNavigator().Select("dependencies/dependency"))
            {
                dependency = DependencyFactory.GetDependency(dependencyNav);
                if (!dependency.IsValid)
                {
                    Log.AddFailure(dependency.ErrorMessage);
                    return;
                }
            }
			
            //Read Components
            ReadComponents(manifestNav);
        }
        /// <summary>
        /// Returns the <see cref="SyndicationContentFormat"/> of the syndicated resource represented by the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="navigator">A <see cref="XPathNavigator"/> that represents the XML data for the syndicated resource.</param>
        /// <returns>
        ///     A <see cref="SyndicationContentFormat"/> enumeration value indicating the format of the syndicated resource. 
        ///     If unable to determine format, returns <see cref="SyndicationContentFormat.None"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception>
        public static SyndicationContentFormat SyndicationContentFormatGet(XPathNavigator navigator)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            SyndicationContentFormat syndicationFormat  = SyndicationContentFormat.None;
            XPathNavigator source                       = null;

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

            //------------------------------------------------------------
            //	Move to document element
            //------------------------------------------------------------
            source  = navigator.CreateNavigator();
            if (String.IsNullOrEmpty(source.LocalName))
            {
                source.MoveToRoot();
                source.MoveToChild(XPathNodeType.Element);
            }

            //------------------------------------------------------------
            //	Determine syndication format based on root element name
            //------------------------------------------------------------
            string rootElementName  = source.LocalName;

            foreach (System.Reflection.FieldInfo fieldInfo in typeof(SyndicationContentFormat).GetFields())
            {
                if (fieldInfo.FieldType == typeof(SyndicationContentFormat))
                {
                    SyndicationContentFormat format = (SyndicationContentFormat)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[] customAttributes       = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(rootElementName, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            syndicationFormat = format;
                            break;
                        }
                    }
                }
            }

            return syndicationFormat;
        }
        /// <summary>
        /// Updates the node replacing inheritdoc node with comments found.
        /// </summary>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        /// <param name="contentNodeNavigator">Navigator for content</param>
        private void UpdateNode(XPathNavigator inheritDocNodeNavigator, XPathNavigator contentNodeNavigator)
        {
            // retrieve the selection filter if specified.
            string selectValue = inheritDocNodeNavigator.GetAttribute("select", string.Empty);

            if(!string.IsNullOrEmpty(selectValue))
                sourceExpression = XPathExpression.Compile(selectValue);

            inheritDocNodeNavigator.MoveToParent();

            if(inheritDocNodeNavigator.LocalName != "comments" && inheritDocNodeNavigator.LocalName != "element")
                sourceExpression = XPathExpression.Compile(inheritDocNodeNavigator.LocalName);
            else
                inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));

            XPathNodeIterator sources = (XPathNodeIterator)contentNodeNavigator.CreateNavigator().Evaluate(sourceExpression);
            inheritDocNodeNavigator.DeleteSelf();

            // append the source nodes to the target node
            foreach(XPathNavigator source in sources)
                inheritDocNodeNavigator.AppendChild(source);
        }
Example #24
0
        /// <summary>
        /// Constructs a new <see cref="IXmlRpcValue"/> object from the specified <see cref="XPathNavigator"/>. 
        /// Parameters specify the XML data source and the variable where the new <see cref="IXmlRpcValue"/> object is returned.
        /// </summary>
        /// <param name="source">A <see cref="XPathNavigator"/> that represents the XML data source to be parsed.</param>
        /// <param name="value">
        ///     When this method returns, contains an object that represents the <see cref="IXmlRpcValue"/> specified by the <paramref name="source"/>, or <b>null</b> if the conversion failed. 
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns>
        ///     <b>true</b> if <paramref name="source"/> was converted successfully; otherwise, <b>false</b>. 
        ///     This operation returns <b>false</b> if the <paramref name="source"/> parameter is a null reference (Nothing in Visual Basic), 
        ///     or represents XML data that is not in the expected format.
        /// </returns>
        /// <remarks>
        ///     The <paramref name="source"/> is expected to represent an XML-RPC <b>value</b> node.
        /// </remarks>
        public static bool TryParseValue(XPathNavigator source, out IXmlRpcValue value)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            if (source == null || String.Compare(source.Name, "value", StringComparison.OrdinalIgnoreCase) != 0)
            {
                value   = null;
                return false;
            }

            //------------------------------------------------------------
            //	Attempt to perform conversion
            //------------------------------------------------------------
            if(source.HasChildren)
            {
                XPathNavigator navigator    = source.CreateNavigator();
                if (navigator.MoveToFirstChild())
                {
                    if (String.Compare(navigator.Name, "i4", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        int scalar;
                        if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar))
                        {
                            value   = new XmlRpcScalarValue(scalar);
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "int", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        int scalar;
                        if (Int32.TryParse(navigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out scalar))
                        {
                            value   = new XmlRpcScalarValue(scalar);
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "boolean", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bool scalar;
                        if (XmlRpcClient.TryParseBoolean(navigator.Value, out scalar))
                        {
                            value   = new XmlRpcScalarValue(scalar);
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "string", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        value   = new XmlRpcScalarValue(navigator.Value);
                        return true;
                    }
                    else if (String.Compare(navigator.Name, "double", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        double scalar;
                        if (Double.TryParse(navigator.Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out scalar))
                        {
                            value   = new XmlRpcScalarValue(scalar);
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "dateTime.iso8601", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DateTime scalar;
                        if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(navigator.Value, out scalar))
                        {
                            value   = new XmlRpcScalarValue(scalar);
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "base64", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if(!String.IsNullOrEmpty(navigator.Value))
                        {
                            try
                            {
                                byte[] data = Convert.FromBase64String(navigator.Value);
                                value       = new XmlRpcScalarValue(data);
                                return true;
                            }
                            catch(FormatException)
                            {
                                value = null;
                                return false;
                            }
                        }
                    }
                    else if (String.Compare(navigator.Name, "struct", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        XmlRpcStructureValue structure  = new XmlRpcStructureValue();
                        if (structure.Load(source))
                        {
                            value   = structure;
                            return true;
                        }
                    }
                    else if (String.Compare(navigator.Name, "array", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        XmlRpcArrayValue array  = new XmlRpcArrayValue();
                        if (array.Load(source))
                        {
                            value   = array;
                            return true;
                        }
                    }
                }
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                value   = new XmlRpcScalarValue(source.Value);
                return true;
            }

            //------------------------------------------------------------
            //	Conversion failed, so set result as null and return false
            //------------------------------------------------------------
            value   = null;
            return false;
        }
Example #25
0
        public Vector GetVector(XPathNavigator root)
        {
            XmlNamespaceManager nsm = FhirNamespaceManager.CreateManager(root);
            Structure structure = specification.GetStructureByName(root.Name);
            XPathNavigator node = root.CreateNavigator();

            return Vector.Create(structure, node, nsm);
        }
Example #26
0
        private void ProcessElement(XPathNavigator navigator)
        {
            //TODO: prob a better way of doing this using the navigator
            if (!isFirstElement)
            {
                textWriter.Write(Environment.NewLine);
            }
            isFirstElement = false;
            WriteIndent();
            if (navigator.LocalName.ToLower() == "pre")
            {
                isInsidePre = true;
            }
            if (navigator.LocalName == "div")
            {
                var temp = navigator.CreateNavigator();
                if (temp.MoveToAttribute("id", null))
                {
                    textWriter.Write("#");
                    textWriter.Write(temp.Value);
                }
                else if (temp.MoveToAttribute("class", null))
                {
                    var strings = temp.Value.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var s in strings)
                    {
                        textWriter.Write(".");
                        textWriter.Write(s);
                    }
                }
                else
                {
                    textWriter.Write("%div");
                }
            }
            else if (navigator.Prefix == string.Empty)
            {
                textWriter.Write("%{0}", navigator.LocalName);
                CheckForAndAppendClass(navigator);
            }
            //else
            //{
                //TODO:
                //Console.Write(" <{0}:{1}>",oNavigator.Prefix,oNavigator.LocalName);
                //Console.WriteLine("\t" + oNavigator.NamespaceURI);
            //}

            var attributeNavigator = navigator.CreateNavigator();
            ProcessAttributes(attributeNavigator);

            indent++;
        }