public bool RemoveNamespace(NamespaceInfo nspace)
{
if(nspace == null) throw new ArgumentNullException("nspace");
lock(this) {
// Load all namespaces and remove the one to remove
List<NamespaceInfo> allNamespaces = new List<NamespaceInfo>(GetNamespaces());
NamespaceComparer comp = new NamespaceComparer();
int index = allNamespaces.FindIndex(delegate(NamespaceInfo x) { return comp.Compare(x, nspace) == 0; });
if(index >= 0) {
// Delete all categories
foreach(CategoryInfo cat in GetCategories(nspace)) {
RemoveCategory(cat);
}
// Delete all pages in the namespace (RemovePage removes the page from the search engine index)
nspace.DefaultPage = null; // TODO: Remove this trick (needed in order to delete the default page)
foreach(PageInfo page in GetPages(nspace)) {
RemovePage(page);
}
// Update namespaces file
allNamespaces.RemoveAt(index);
DumpNamespaces(allNamespaces.ToArray());
// Remove namespace folder
Directory.Delete(GetFullPathForPageContent(GetNamespacePartialPathForPageContent(nspace.Name)), true);
// Remove drafts folder
string oldDraftsFullPath = GetFullPathForPageDrafts(nspace.Name);
if(Directory.Exists(oldDraftsFullPath)) {
Directory.Delete(oldDraftsFullPath, true);
}
// Remove messages folder
Directory.Delete(GetFullPathForMessages(GetNamespacePartialPathForPageContent(nspace.Name)), true);
namespacesCache = null;
pagesCache = null;
categoriesCache = null;
return true;
}
else return false;
}
}