public void CreateLibrary_DirectlyOnDatabase_CheckExpectedPaths() { admin.assert(); var libraryId = Guid.NewGuid(); var libraryName = "test_Library".add_RandomLetters(4); var newGuidanceExplorer = new guidanceExplorer {library = {name = libraryId.str(), caption = libraryName}}; //manually add the new newGuidanceExplorer to the database tmXmlDatabase.GuidanceExplorers_XmlFormat.add(libraryId, newGuidanceExplorer); newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(tmXmlDatabase); var tmLibrary = tmXmlDatabase.tmLibrary(libraryId); Assert.IsNotNull(tmLibrary, "tmLibrary was null for libraryId: {0}".format(libraryId)); Assert.AreEqual(tmLibrary.Id, libraryId, "tmLibrary.Id"); Assert.AreEqual(tmLibrary.Caption, libraryName, "tmLibrary.Caption"); var libraryXml_Via_LibraryId = tmFileStorage.xmlDB_Path_Library_XmlFile(libraryId); var libraryXml_Via_GuidanceExplorer = tmFileStorage.xmlDB_Path_Library_XmlFile(newGuidanceExplorer); var libraryRootFolder = tmFileStorage.xmlDB_Path_Library_RootFolder(newGuidanceExplorer); Assert.IsTrue(libraryXml_Via_LibraryId.valid(), "libraryXml_Via_LibraryId"); Assert.AreEqual(libraryXml_Via_LibraryId, libraryXml_Via_GuidanceExplorer, "libraryXml_Via_LibraryId and libraryXml_Via_GuidanceExplorer"); Assert.AreEqual(libraryName, libraryXml_Via_LibraryId.fileName_WithoutExtension(), libraryXml_Via_LibraryId.fileName_WithoutExtension()); Assert.AreEqual(libraryName, libraryRootFolder.folderName(), libraryRootFolder.folderName()); none.assert(); }
public static guidanceExplorer xmlDB_NewGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId, string caption) { "[TM_Xml_Database][xmlDB_NewGuidanceExplorer] Creating new Library with id {0} and caption {1}".info(libraryId, caption); if (caption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database][xmlDB_NewGuidanceExplorer] provided caption didn't pass validation regex".error(); throw new Exception("Provided Library name didn't pass validation regex"); } if (tmDatabase.tmLibrary(caption).notNull()) { "[TM_Xml_Database] in xmlDB_NewGuidanceExplorer, a library with that name already existed: {0}".error(caption); return null; } if (libraryId == Guid.Empty) libraryId = Guid.NewGuid(); var newGuidanceExplorer = new urn.microsoft.guidanceexplorer.guidanceExplorer(); newGuidanceExplorer.library = new urn.microsoft.guidanceexplorer.Library(); newGuidanceExplorer.library.items = new urn.microsoft.guidanceexplorer.Items(); newGuidanceExplorer.library.libraryStructure = new urn.microsoft.guidanceexplorer.LibraryStructure(); //newGuidanceExplorer.library.libraryStructure.folder = new List<urn.microsoft.guidanceexplorer.Folder>(); //newGuidanceExplorer.library.libraryStructure.view = new List<urn.microsoft.guidanceexplorer.View>(); newGuidanceExplorer.library.name = libraryId.str(); newGuidanceExplorer.library.caption = caption; "xmlLibraryPath: {0}".info(TM_Xml_Database.Path_XmlLibraries); //var newLibraryPath = TM_Xml_Database.Path_XmlLibraries.pathCombine("{0}.xml".format(caption)); newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); //"saving new library to: {0}".info(newLibraryPath); //newGuidanceExplorer.Save(newLibraryPath); //tmDatabase.setGuidanceExplorerObjects(); // reload these values return newGuidanceExplorer; }
public void CreateArticle_OnLibraryWithDiferentNameThanFolder() { UserGroup.Admin.assert(); var libraryId = Guid.NewGuid(); var libraryName = "library_Name".add_RandomLetters(4); var libraryFolderAndXmlFile = "FolderXml_Name".add_RandomLetters(4); var newGuidanceExplorer = new guidanceExplorer { library = { name = libraryId.str(), caption = libraryName } }; var newGuidanceExplorerXmlFile = tmFileStorage.path_XmlLibraries().pathCombine(@"{0}\{0}.xml".format(libraryFolderAndXmlFile)); //manually add the new newGuidanceExplorer to the database tmXmlDatabase.GuidanceExplorers_XmlFormat.add(libraryId, newGuidanceExplorer); //manually add the new guidanceExplorer Path tmFileStorage.guidanceExplorers_Paths().add(newGuidanceExplorer, newGuidanceExplorerXmlFile); //save guidanceExplorer (which should save in the new path) tmXmlDatabase.xmlDB_Save_GuidanceExplorer(libraryId); //get new values var libraryXmlFile = tmFileStorage.xmlDB_Path_Library_XmlFile (libraryId); var libraryRootFolder = tmFileStorage.xmlDB_Path_Library_RootFolder(newGuidanceExplorer); Assert.IsTrue (newGuidanceExplorerXmlFile.fileExists(), "newGuidanceExplorerXmlFile.fileExists()"); Assert.IsTrue (libraryRootFolder.dirExists() , "libraryRootFolder.dirExists()"); Assert.AreEqual (libraryXmlFile, newGuidanceExplorerXmlFile, "libraryXmlFile and libraryFolderAndXmlFile"); Assert.AreNotEqual(libraryXmlFile.fileName_WithoutExtension(), libraryName); //Now that we have confirmed that the library Name is different from the folder name, we can add an article //which was not working ok in 3.3. ( https://github.com/TeamMentor/Master/issues/482 ) var newArticle = tmXmlDatabase.xmlDB_RandomGuidanceItem(libraryId); var articlesInLibrary = tmXmlDatabase.getGuidanceItems_from_LibraryFolderOrView(libraryId); var articlePath = tmFileStorage.xmlDB_guidanceItemPath(newArticle.Metadata.Id); var articlePath_Manual = libraryRootFolder.pathCombine(TMConsts.DEFAULT_ARTICLE_FOLDER_NAME).pathCombine("{0}.xml".format(newArticle.Metadata.Id)); Assert.NotNull (newArticle , "newArticle was null"); Assert.AreEqual (1, articlesInLibrary.size() , "There should be one article in this Library"); Assert.IsTrue (articlePath.fileExists() , "articlePath.fileExists()"); Assert.IsTrue (articlePath_Manual.fileExists(), "articlePath_Manual.fileExists()"); Assert.AreEqual (articlePath, articlePath_Manual, "articlePath vs articlePath_Manual"); articlePath.info(); articlePath_Manual.info(); UserGroup.None.assert(); }
public static guidanceExplorer xmlDB_NewGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId, string caption) { "[TM_Xml_Database][xmlDB_NewGuidanceExplorer] Creating new Library with id {0} and caption {1}".info(libraryId, caption); if (caption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database][xmlDB_NewGuidanceExplorer] provided caption didn't pass validation regex".error(); throw new Exception("Provided Library name didn't pass validation regex"); } if (tmDatabase.tmLibrary(caption).notNull()) { "[TM_Xml_Database] in xmlDB_NewGuidanceExplorer, a library with that name already existed: {0}".error(caption); return(null); } if (libraryId == Guid.Empty) { libraryId = Guid.NewGuid(); } var newGuidanceExplorer = new urn.microsoft.guidanceexplorer.guidanceExplorer(); newGuidanceExplorer.library = new urn.microsoft.guidanceexplorer.Library(); newGuidanceExplorer.library.items = new urn.microsoft.guidanceexplorer.Items(); newGuidanceExplorer.library.libraryStructure = new urn.microsoft.guidanceexplorer.LibraryStructure(); //newGuidanceExplorer.library.libraryStructure.folder = new List<urn.microsoft.guidanceexplorer.Folder>(); //newGuidanceExplorer.library.libraryStructure.view = new List<urn.microsoft.guidanceexplorer.View>(); newGuidanceExplorer.library.name = libraryId.str(); newGuidanceExplorer.library.caption = caption; //"xmlLibraryPath: {0}".info(TM_Xml_Database.Path_XmlLibraries); //var newLibraryPath = TM_Xml_Database.Path_XmlLibraries.pathCombine("{0}.xml".format(caption)); newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); //"saving new library to: {0}".info(newLibraryPath); //newGuidanceExplorer.Save(newLibraryPath); //tmDatabase.setGuidanceExplorerObjects(); // reload these values return(newGuidanceExplorer); }
public static Dictionary<Guid, guidanceExplorer> addGuidanceExplorerObject(this Dictionary<Guid, guidanceExplorer> guidanceExplorers, guidanceExplorer newGuidanceExplorer, string xmlFile) { if (newGuidanceExplorer.notNull()) { try { var libraryGuid = newGuidanceExplorer.library.name.guid(); //check if the name is already there foreach(guidanceExplorer guidanceExplorer in guidanceExplorers.Values) { if (guidanceExplorer.library.caption == newGuidanceExplorer.library.caption) { "[addGuidanceExplorerObject]: Skipping load due to duplicate Library name '{0}' was in both library {1} and {2}".error(guidanceExplorer.library.caption, guidanceExplorer.library.name, newGuidanceExplorer.library.name); return guidanceExplorers; } } //check if the guid is already there if (guidanceExplorers.hasKey(libraryGuid)) { "[addGuidanceExplorerObject]: for {0} , duplicate LibraryID detected, assiging a new Library Id: {0}".error(newGuidanceExplorer.library.caption, libraryGuid); libraryGuid = Guid.NewGuid(); newGuidanceExplorer.library.name = libraryGuid.str(); "[addGuidanceExplorerObject]: new ID for library {0} is now {1}".error(newGuidanceExplorer.library.caption, libraryGuid); newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(TM_Xml_Database.Current);//, false); } TM_Xml_Database.Current.GuidanceExplorers_Paths.add(newGuidanceExplorer, xmlFile); // add this mapping so that we can find it base on name guidanceExplorers.Add(libraryGuid, newGuidanceExplorer); } catch//(Exception ex) { "[addGuidanceExplorerObject] error importing guidanceExplorer: {0}".error(newGuidanceExplorer); } } return guidanceExplorers; }
public static string xmlDB_Path_Library_XmlFile(this TM_FileStorage tmFileStorage, guidanceExplorer guidanceExplorer) { if (tmFileStorage.notNull()) { return tmFileStorage.guidanceExplorers_Paths().value(guidanceExplorer); } return null; }
public static string xmlDB_Path_Library_RootFolder(this TM_FileStorage tmFileStorage, guidanceExplorer guidanceExplorer) { var libraryPath = tmFileStorage.xmlDB_Path_Library_XmlFile(guidanceExplorer); if (libraryPath.notNull()) { return libraryPath.directoryName(); // from 3.3 the library path is the parent folder of the Library's Xml file } return null; }
public static guidanceExplorer xmlDB_RenameGuidanceExplorer(this TM_Xml_Database tmDatabase, guidanceExplorer guidanceExplorer, string newCaption) { if (newCaption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database][xmlDB_RenameGuidanceExplorer] provided caption didn't pass validation regex".error(); throw new Exception("Provided Library name didn't pass validation regex"); } "[xmlDB_RenameGuidanceExplorer]".info(); if(guidanceExplorer.notNull()) { var existingCaption = guidanceExplorer.library.caption; var existingLibraryPath = tmDatabase.xmlDB_LibraryPath(existingCaption); // TM_Xml_Database.Path_XmlLibraries.pathCombine("{0}.xml".format(guidanceExplorer.library.caption)); if(existingLibraryPath.fileExists().isFalse()) "[xmlDB_RenameGuidanceExplorer] something is wrong since existingLibraryPath was not there: {0}".error(existingLibraryPath); else { var newLibraryPath = tmDatabase.xmlDB_LibraryPath(newCaption); if (newLibraryPath.fileExists()) "[xmlDB_RenameGuidanceExplorer] there was already a library and/or file with that name, so stopping rename): {0}".error(newLibraryPath); else { var pathToGuidanceItems_Existing = tmDatabase.xmlDB_LibraryPath_GuidanceItems(existingCaption); var pathToGuidanceItems_New = tmDatabase.xmlDB_LibraryPath_GuidanceItems(newCaption); "pathToGuidanceItems_Existing: {0}".error(pathToGuidanceItems_Existing); "pathToGuidanceItems_New: {0}".error(pathToGuidanceItems_New); if(pathToGuidanceItems_Existing.dirExists()) { "RENAMING {0}-> {1}".error(pathToGuidanceItems_Existing, pathToGuidanceItems_New); Files.renameFolder(pathToGuidanceItems_Existing, pathToGuidanceItems_New); tmDatabase.updateGuidanceItems_FileMappings_withNewPath(pathToGuidanceItems_Existing,pathToGuidanceItems_New); } guidanceExplorer.library.caption = newCaption; //xmlDB_LibraryPath_GuidanceItems if (Files.deleteFile(existingLibraryPath).isFalse()) "[xmlDB_RenameGuidanceExplorer] could not delete existing library file: {0}".error(existingLibraryPath); else { guidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); return guidanceExplorer; } } return guidanceExplorer; } } return null; }
public static bool xmlDB_RenameGuidanceExplorer(this TM_Xml_Database tmDatabase, guidanceExplorer guidanceExplorer, string newCaption) { if (newCaption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database] [xmlDB_RenameGuidanceExplorer] provided caption didn't pass validation regex".error(); //throw new Exception("Provided Library name didn't pass validation regex"); } else if(guidanceExplorer.notNull()) { guidanceExplorer.library.caption = newCaption; // update in memory library name value return guidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); // save it /*if (tmDatabase.usingFileStorage()) // soft try to rename the library (disabled for now) { try { var current_LibraryRootFolder = tmDatabase.xmlDB_Path_Library_RootFolder(guidanceExplorer); var new_LibraryRootFolder = tmDatabase.Path_XmlLibraries.pathCombine(newCaption); Files.renameFolder(current_LibraryRootFolder, new_LibraryRootFolder); if (new_LibraryRootFolder.dirExists()) tmDatabase.GuidanceExplorers_Paths.add(guidanceExplorer, new_LibraryRootFolder); } catch (Exception ex) { ex.log("[xmlDB_RenameGuidanceExplorer] in trying to rename the library folder"); } }*/ } return false; }
public static guidanceExplorer xmlDB_NewGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId, string caption) { if (caption.isNull() || caption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database] [xmlDB_NewGuidanceExplorer] provided caption didn't pass validation regex".error(); throw new Exception("Provided Library name didn't pass validation regex"); } if (tmDatabase.tmLibrary(caption).notNull()) { "[TM_Xml_Database] in xmlDB_NewGuidanceExplorer, a library with that name already existed: {0}".error(caption); return null; } if (libraryId == Guid.Empty) libraryId = Guid.NewGuid(); var newGuidanceExplorer = new guidanceExplorer { library = new urn.microsoft.guidanceexplorer.Library { items = new Items(), libraryStructure = new LibraryStructure(), name = libraryId.str(), caption = caption } }; TM_Xml_Database.Current.GuidanceExplorers_XmlFormat.add(libraryId, newGuidanceExplorer); //add to in memory database newGuidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); "[TM_Xml_Database] [xmlDB_NewGuidanceExplorer] Created new Library with id {0} and caption {1}".info(libraryId, caption); return newGuidanceExplorer; }
public static string xmlDB_Path_Library_XmlFile(this TM_Xml_Database tmDatabase, guidanceExplorer guidanceExplorer) { if (tmDatabase.UsingFileStorage) { return tmDatabase.GuidanceExplorers_Paths.value(guidanceExplorer); /*if (guidanceExplorer.notNull()) if (tmDatabase.GuidanceExplorers_Paths.hasKey(guidanceExplorer)) return tmDatabase.GuidanceExplorers_Paths[guidanceExplorer];*/ } return null; }
public static guidanceExplorer xmlDB_RenameGuidanceExplorer(this TM_Xml_Database tmDatabase, guidanceExplorer guidanceExplorer, string newCaption) { if (newCaption.isValidGuidanceExplorerName().isFalse()) { "[TM_Xml_Database][xmlDB_RenameGuidanceExplorer] provided caption didn't pass validation regex".error(); throw new Exception("Provided Library name didn't pass validation regex"); } //"[xmlDB_RenameGuidanceExplorer]".info(); if(guidanceExplorer.notNull()) { if (tmDatabase.UsingFileStorage.isFalse()) { guidanceExplorer.library.caption = newCaption; // update in memory library name value return guidanceExplorer; } var existingCaption = guidanceExplorer.library.caption; var existingLibraryPath = tmDatabase.xmlDB_LibraryPath(existingCaption); // TM_Xml_Database.Current.Path_XmlLibraries.pathCombine("{0}.xml".format(guidanceExplorer.library.caption)); if(existingLibraryPath.fileExists().isFalse()) "[xmlDB_RenameGuidanceExplorer] something is wrong since existingLibraryPath was not there: {0}".error(existingLibraryPath); else { var newLibraryPath = tmDatabase.xmlDB_LibraryPath(newCaption); if (newLibraryPath.fileExists()) "[xmlDB_RenameGuidanceExplorer] there was already a library and/or file with that name, so stopping rename): {0}".error(newLibraryPath); else { var pathToGuidanceItems_Existing = tmDatabase.xmlDB_LibraryPath_GuidanceItems(existingCaption); //var pathToGuidanceItems_New = tmDatabase.xmlDB_LibraryPath_GuidanceItems(newCaption); if(pathToGuidanceItems_Existing.dirExists()) { //"xmlDB_RenameGuidanceExplorer {0}-> {1}".info(pathToGuidanceItems_Existing, pathToGuidanceItems_New); //Renaming workflow: //Files.deleteFile(existingLibraryPath); // delete original xml library file //Files.renameFolder(pathToGuidanceItems_Existing, pathToGuidanceItems_New); // rename folders guidanceExplorer.library.caption = newCaption; // update in memory library name value guidanceExplorer.xmlDB_Save_GuidanceExplorer(tmDatabase); // save into new path //tmDatabase.updateGuidanceItems_FileMappings_withNewPath(pathToGuidanceItems_Existing,pathToGuidanceItems_New); //update article's cache mappings return guidanceExplorer; } "[xmlDB_RenameGuidanceExplorer] could find dir with library to rename".error( pathToGuidanceItems_Existing); } } } return null; }