/// <summary> /// Removes a Navigation Path. /// </summary> /// <param name="path">The Navigation Path to remove.</param> /// <returns>True if the Path is removed successfully.</returns> /// <exception cref="ArgumentNullException">If <paramref name="path"/> is <c>null</c>.</exception> public bool RemoveNavigationPath(NavigationPath path) { if(path == null) throw new ArgumentNullException("path"); lock(this) { List<NavigationPath> paths = new List<NavigationPath>(GetAllNavigationPaths()); NavigationPathComparer comp = new NavigationPathComparer(); for(int i = 0; i < paths.Count; i++) { if(comp.Compare(path, paths[i]) == 0) { paths.Remove(paths[i]); DumpNavigationPaths(paths.ToArray()); return true; } } } return false; }
/// <summary> /// Adds a new Navigation Path. /// </summary> /// <param name="nspace">The target namespace (<c>null</c> for the root).</param> /// <param name="name">The Name of the Path.</param> /// <param name="pages">The Pages array.</param> /// <returns>The correct <see cref="T:NavigationPath" /> object.</returns> /// <exception cref="ArgumentNullException">If <paramref name="name"/> or <paramref name="pages"/> are <c>null</c>.</exception> /// <exception cref="ArgumentException">If <paramref name="name"/> or <paramref name="pages"/> are empty.</exception> public NavigationPath AddNavigationPath(string nspace, string name, PageInfo[] pages) { if(name == null) throw new ArgumentNullException("name"); if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name"); if(pages == null) throw new ArgumentNullException("pages"); if(pages.Length == 0) throw new ArgumentException("Pages cannot be empty"); lock(this) { NavigationPathComparer comp = new NavigationPathComparer(); NavigationPath temp = new NavigationPath(NameTools.GetFullName(nspace, name), this); if(Array.Find(GetAllNavigationPaths(), delegate(NavigationPath p) { return comp.Compare(p, temp) == 0; }) != null) return null; temp = null; foreach(PageInfo page in pages) { if(page == null) throw new ArgumentNullException("pages", "A page element cannot be null"); if(LoadLocalPageInfo(page) == null) throw new ArgumentException("Page not found", "pages"); } NavigationPath result = new NavigationPath(NameTools.GetFullName(nspace, name), this); List<string> tempPages = new List<string>(pages.Length); StringBuilder sb = new StringBuilder(500); sb.Append("\r\n"); sb.Append(result.FullName); for(int i = 0; i < pages.Length; i++) { if(pages[i].Provider == this) { sb.Append("|"); sb.Append(pages[i].FullName); tempPages.Add(pages[i].FullName); } } result.Pages = tempPages.ToArray(); File.AppendAllText(GetFullPath(NavigationPathsFile), sb.ToString()); return result; } }
/// <summary> /// Modifies an existing Navigation Path. /// </summary> /// <param name="path">The Navigation Path to modify.</param> /// <param name="pages">The new Pages array.</param> /// <returns>The correct <see cref="T:NavigationPath" /> object.</returns> /// <exception cref="ArgumentNullException">If <paramref name="path"/> or <paramref name="pages"/> are <c>null</c>.</exception> /// <exception cref="ArgumentException">If <paramref name="pages"/> is empty.</exception> public NavigationPath ModifyNavigationPath(NavigationPath path, PageInfo[] pages) { if(path == null) throw new ArgumentNullException("path"); if(pages == null) throw new ArgumentNullException("pages"); if(pages.Length == 0) throw new ArgumentException("Pages cannot be empty"); lock(this) { foreach(PageInfo page in pages) { if(page == null) throw new ArgumentNullException("pages", "A page element cannot be null"); if(LoadLocalPageInfo(page) == null) throw new ArgumentException("Page not found", "pages"); } NavigationPath[] paths = GetAllNavigationPaths(); NavigationPathComparer comp = new NavigationPathComparer(); for(int i = 0; i < paths.Length; i++) { if(comp.Compare(path, paths[i]) == 0) { paths[i].Pages = new string[0]; NavigationPath np = new NavigationPath(path.FullName, this); List<string> tempPages = new List<string>(pages.Length); for(int k = 0; k < pages.Length; k++) { if(pages[k].Provider == this) { tempPages.Add(pages[k].FullName); } } np.Pages = tempPages.ToArray(); paths[i] = np; DumpNavigationPaths(paths); return np; } } } return null; }