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 void CheckDatabaseSetup() { UserGroup.Admin.assert(); Assert.NotNull(tmXmlDatabase); Assert.NotNull(userData); Assert.NotNull(tmServer); Assert.NotNull(tmConfig); if (tmXmlDatabase.tmLibraries().notEmpty()) // temp while refactoring { tmFileStorage.delete_Database(); } if (tmFileStorage.getCacheLocation().fileExists()) { tmFileStorage.clear_GuidanceItemsCache(); } if (userData.tmUsers().notEmpty()) { userData.delete_All_Users(); } // userData.createDefaultAdminUser(); Assert.NotNull(tmFileStorage.path_XmlDatabase(), "path_XmlDatabase()"); // null since we are running TM memory (default setting) Assert.NotNull(tmFileStorage.path_XmlLibraries(), "Path_XmlLibraries"); // null since we are running TM memory (default setting) Assert.IsEmpty(tmXmlDatabase.Cached_GuidanceItems, "Cached_GuidanceItems"); Assert.IsEmpty(userData.validSessions(), "ActiveSessions"); Assert.AreEqual(userData.TMUsers.size(), 0, "TMUsers"); // there should be no users UserGroup.None.assert(); }
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 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); }