public static TM_FileStorage guidanceExplorers_XmlFormat(this TM_FileStorage tmFileStorage, Dictionary <Guid, guidanceExplorer> guidanceExplorers) { if (tmFileStorage.tmXmlDatabase().notNull()) { tmFileStorage.tmXmlDatabase().GuidanceExplorers_XmlFormat = guidanceExplorers; } return(tmFileStorage); }
public static string Get_Path_To_File(this TM_FileStorage tmFileStorage, string fileKey) { UserRole.ReadArticles.demand(); var filePath = tmFileStorage.path_XmlLibraries().pathCombine("_Images").pathCombine(fileKey); if (filePath.fileExists()) { return(filePath); } var splitedFileKey = fileKey.split("/"); if (splitedFileKey.size() == 2) { var item = splitedFileKey[0].trim(); var fileName = splitedFileKey[1].trim(); if (item.isGuid()) { return(tmFileStorage.Get_Path_To_File(item.guid(), fileName)); } return(tmFileStorage.Get_Path_To_File(item, fileName)); } foreach (var library in tmFileStorage.tmXmlDatabase().tmLibraries()) { filePath = tmFileStorage.Get_Path_To_File(library.Caption, fileKey); if (filePath.notNull()) { return(filePath); } } return(null); }
public static TM_FileStorage delete_Database(this TM_FileStorage tmFileStorage) { tmFileStorage.assert_Not_Null() .path_XmlDatabase().assert_Not_Null() .assert_Is_Not_Equal_To(tmFileStorage.WebRoot); if (tmFileStorage.path_XmlDatabase().dirExists()) // check if the folder exists { //Assert.IsNotEmpty(tmDatabase.path_XmlDatabase().files()); tmFileStorage.path_XmlDatabase().files(true).files_Attribute_ReadOnly_Remove(); // make all files writable tmFileStorage.waitForComplete_Save_GuidanceItemsCache(); tmFileStorage.clear_GuidanceItemsCache(); Files.deleteFolder(tmFileStorage.path_XmlDatabase(), true); // delete all files recusively tmFileStorage.path_XmlDatabase().folder_Wait_For_Deleted(); tmFileStorage.path_XmlDatabase().assert_Folder_Doesnt_Exist(); Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists()); // ensure the deletion happened Assert.IsEmpty(tmFileStorage.path_XmlDatabase().files()); Assert.IsEmpty(tmFileStorage.tmXmlDatabase().Cached_GuidanceItems); Assert.IsFalse(tmFileStorage.getCacheLocation().fileExists()); "[Test][TM_Xml_Database][delete_Database]TM database files were deleted from: {0}".info(tmFileStorage.path_XmlDatabase()); } return(tmFileStorage); }
public static string getXmlFilePathForGuidanceId(this TM_FileStorage tmFileStorage, Guid guidanceItemId, Guid libraryId) { var tmFileStorate = TM_FileStorage.Current; //first see if we already have this mapping if (tmFileStorate.GuidanceItems_FileMappings.hasKey(guidanceItemId)) { //"in getXmlFilePathForGuidanceId, found id in current mappings: {0}".info( guidanceItemId); return(tmFileStorate.GuidanceItems_FileMappings[guidanceItemId]); } //then update the GuidanceItems_FileMappings dictionary if (libraryId == Guid.Empty) { "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem a libraryId must be provided".error(); return(null); } var tmLibrary = tmFileStorage.tmXmlDatabase().tmLibrary(libraryId); if (tmLibrary == null) { "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem could not find library for libraryId: {0}".error(libraryId); return(null); } var libraryPath = tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary); var newArticleFolder = libraryPath.pathCombine(TMConsts.DEFAULT_ARTICLE_FOLDER_NAME); var xmlPath = newArticleFolder.createDir() .pathCombine("{0}.xml".format(guidanceItemId)); "in getXmlFilePathForGuidanceId, no previous mapping found so adding new GuidanceItems_FileMappings for :{0}".info(xmlPath); tmFileStorate.GuidanceItems_FileMappings.add(guidanceItemId, xmlPath); //add it to the file_mappings dictionary so that we know it for next time return(xmlPath); }
public static TM_FileStorage saveVirtualArticles(this TM_FileStorage tmFileStorage) { var virtualArticlesFile = tmFileStorage.getVirtualArticlesFile(); var virtualArticles = tmFileStorage.tmXmlDatabase().getVirtualArticles().Values.toList(); virtualArticles.saveAs(virtualArticlesFile); return(tmFileStorage); }
public static string Get_Path_To_File(this TM_FileStorage tmFileStorage, Guid itemGuid, string fileName) { UserRole.ReadArticles.demand(); var library = tmFileStorage.tmXmlDatabase().tmLibrary(itemGuid); if (library.notNull()) { return(tmFileStorage.Get_Path_To_File(library.Caption, fileName)); } return(null); }
public static string Get_Path_To_File(this TM_FileStorage tmFileStorage, string libraryName, string fileName) { var library = tmFileStorage.tmXmlDatabase().tmLibrary(libraryName); if (library.notNull()) { var filePath = tmFileStorage.xmlDB_Path_Library_RootFolder(library).pathCombine("_Images").pathCombine(fileName); if (filePath.fileExists()) { return(filePath); } } return(null); }
public static TM_FileStorage loadVirtualArticles(this TM_FileStorage tmFileStorage) { var virtualArticles = tmFileStorage.tmXmlDatabase().VirtualArticles; virtualArticles.Clear(); var virtualArticles_ToMap = tmFileStorage.loadVirtualArticles_FromDisk(); foreach (var virtualArticle in virtualArticles_ToMap) { virtualArticles.add(virtualArticle.Id, virtualArticle); } return(tmFileStorage); }
public static bool upload_File_to_Library(this TM_FileStorage tmFileStorage, Guid libraryId, string filename, byte[] fileContents) { UserRole.Admin.demand(); var targetLibrary = tmFileStorage.tmXmlDatabase().tmLibrary(libraryId); if (targetLibrary.notNull()) { var targetFolder = tmFileStorage.xmlDB_Path_Library_RootFolder(targetLibrary) .pathCombine("_Images") .createDir(); var targetFile = targetFolder.pathCombine(filename.safeFileName()); return(fileContents.saveAs(targetFile).fileExists()); } return(false); }
public static TM_FileStorage save_GuidanceItemsToCache(this TM_FileStorage tmFileStorage) { var cacheFile = tmFileStorage.getCacheLocation(); var tmXmlDatabase = tmFileStorage.tmXmlDatabase(); if (cacheFile.notNull() && tmXmlDatabase.notNull()) { var o2Timer = new O2Timer("[TM_FileStorage] saveGuidanceItemsToCache").start(); lock (tmXmlDatabase.Cached_GuidanceItems) { tmXmlDatabase.Cached_GuidanceItems.Values.toList().saveAs(cacheFile); //tmDatabase.triggerGitCommit(); // TODO: add save_GuidanceItemsToCache event to allow GIT to support for saving XML data } o2Timer.stop(); } return(tmFileStorage); }
public static bool article_Delete(this TM_FileStorage tmFileStorage, TeamMentor_Article article) { editArticles.demand(); var guidanceItemId = article.Metadata.Id; var guidanceItemXmlPath = tmFileStorage.removeGuidanceItemFileMapping(guidanceItemId); "removing GuidanceItem with Id:{0} located at {1}".info(guidanceItemId, guidanceItemXmlPath); if (guidanceItemXmlPath.valid()) { Files.deleteFile(guidanceItemXmlPath); } tmFileStorage.tmXmlDatabase().Events.Articles_Cache_Updated.raise(); //tmDatabase.queue_Save_GuidanceItemsCache(); //TM_Xml_Database.mapGuidanceItemsViews(); return(true); }
public static TM_FileStorage load_GuidanceItemsFromCache(this TM_FileStorage tmFileStorage) { var tmDatabase = tmFileStorage.tmXmlDatabase(); if (tmDatabase.isNull()) { return(tmFileStorage); } var chacheFile = tmFileStorage.getCacheLocation(); if (chacheFile.fileExists().isFalse()) { "[TM_Xml_Database] [load_GuidanceItemsFromCache] cached file not found: {0}".debug(chacheFile); tmFileStorage.xmlDB_Load_GuidanceItems_and_Create_CacheFile(); } else { var o2Timer = new O2Timer("[TM_Xml_Database] [loadGuidanceItemsFromCache] loaded cache ").start(); var loadedGuidanceItems = chacheFile.load <List <TeamMentor_Article> >(); o2Timer.stop(); if (loadedGuidanceItems.isNull()) //if we couldn't load it , delete it { Files.deleteFile(chacheFile); } else { o2Timer = new O2Timer("[TM_Xml_Database] [loadGuidanceItemsFromCache] loading files ").start(); foreach (var loadedGuidanceItem in loadedGuidanceItems) { if (loadedGuidanceItem.notNull()) { tmDatabase.Cached_GuidanceItems.add(loadedGuidanceItem.Metadata.Id, loadedGuidanceItem); } } o2Timer.stop(); } tmFileStorage.populateGuidanceItemsFileMappings(); } return(tmFileStorage); }
public static TM_FileStorage clear_GuidanceItemsCache(this TM_FileStorage tmFileStorage) { var tmXmlDatabase = tmFileStorage.tmXmlDatabase(); if (tmFileStorage.isNull() || tmXmlDatabase.isNull()) { return(tmFileStorage); } "[TM_Xml_Database] clear_GuidanceItemsCache".info(); var cacheFile = tmFileStorage.getCacheLocation(); if (cacheFile.notNull() && cacheFile.fileExists()) { Files.deleteFile(cacheFile); "cache file deleted OK:{0}".info(cacheFile.fileExists().isFalse()); } tmXmlDatabase.Cached_GuidanceItems.Clear(); return(tmFileStorage); }
public static TM_FileStorage xmlDB_Load_GuidanceItems_and_Create_CacheFile(this TM_FileStorage tmFileStorage) { var tmXmlDatabase = tmFileStorage.tmXmlDatabase(); if (tmFileStorage.isNull() || tmXmlDatabase.isNull()) { return(tmFileStorage); } var pathXmlLibraries = tmFileStorage.Path_XmlLibraries; if (pathXmlLibraries.notNull() && pathXmlLibraries.notNull()) { lock (pathXmlLibraries) { "[TM_FileStorage] in xmlDB_Load_GuidanceItems, creating cache file".debug(); var o2Timer = new O2Timer("[TM_FileStorage] loaded GuidanceItems from disk").start(); //Load GuidanceItem from the disk foreach (var item in tmFileStorage.GuidanceExplorers_Paths) { var guidanceExplorer = item.Key; var pathToLibraryGuidanceItems = item.Value.parentFolder(); var libraryId = guidanceExplorer.library.name.guid(); "libraryId: {0} : {1}".info(libraryId, pathToLibraryGuidanceItems); var filesToLoad = pathToLibraryGuidanceItems.files(true, "*.xml"); tmXmlDatabase.xmlDB_Load_GuidanceItemsV3(libraryId, filesToLoad); } //save it to the local cache file (reduces load time from 8s to 0.5s) tmFileStorage.save_GuidanceItemsToCache(); tmXmlDatabase.ensureFoldersAndViewsIdsAreUnique(); tmXmlDatabase.removeMissingGuidanceItemsIdsFromViews(); o2Timer.stop(); } } return(tmFileStorage); }
public static string install_LibraryFromZip(this TM_FileStorage tmFileStorage, string pathToGitHubZipBall, string libraryName) { UserGroup.Admin.assert(); try { var tmXmlDatabase = tmFileStorage.tmXmlDatabase(); if (tmFileStorage.isNull() || tmXmlDatabase.isNull()) { return(null); } var tmLibrary = tmXmlDatabase.tmLibrary(libraryName); if (tmLibrary.notNull()) { "[Install_LibraryFromZip] Skyping library {0} because it already existed".debug(libraryName); return(tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary)); } var tmLibraries_Before = tmXmlDatabase.tmLibraries(); var result = tmFileStorage.xmlDB_Libraries_ImportFromZip(pathToGitHubZipBall, ""); var tmLibraries_After = tmXmlDatabase.tmLibraries(); var installedLibrary = tmXmlDatabase.tmLibrary(libraryName); Assert.IsTrue(result, "xmlDB_Libraries_ImportFromZip"); Assert.IsNotEmpty(tmLibraries_After, "Libraries should be there after install"); Assert.AreNotEqual(tmLibraries_After.size(), tmLibraries_Before.size(), "Libraries size should be different before and after"); Assert.IsNotNull(installedLibrary, "Could not find installed library: {0}".format(libraryName)); Assert.AreEqual(installedLibrary.Caption, libraryName, "After install library names didn't match"); return(tmFileStorage.xmlDB_Path_Library_RootFolder(installedLibrary)); } finally { UserGroup.None.assert(); } }
public static Dictionary <Guid, guidanceExplorer> guidanceExplorers_XmlFormat(this TM_FileStorage tmFileStorage) { return(tmFileStorage.tmXmlDatabase().notNull() ? tmFileStorage.tmXmlDatabase().GuidanceExplorers_XmlFormat : new Dictionary <Guid, guidanceExplorer>()); }