[Admin] public static TM_FileStorage set_Path_SiteData(this TM_FileStorage tmFileStorage) { UserRole.Admin.demand(); var siteData_Config = tmFileStorage.tmServer().siteData_Config(); if (siteData_Config.isNull() || siteData_Config.Name.notValid()) { "[TM_FileStorage][set_Path_SiteData] set_Path_SiteData or its name was null or empty, so going to to use the default value of: {0}".debug(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA); siteData_Config = new TM_Server.Config() { Name = TMConsts.TM_SERVER_DEFAULT_NAME_SITEDATA }; } var xmlDatabasePath = tmFileStorage.path_XmlDatabase(); // all files are relative to this path var siteDataPath = xmlDatabasePath.pathCombine(siteData_Config.Name); // use the userData_Config.Name as the name of the folder to put UserData files siteDataPath.createDir(); // create if needed if (siteDataPath.dirExists()) { tmFileStorage.Path_SiteData = siteDataPath.createDir(); "[TM_FileStorage] [set_Path_SiteData] TMConfig.Current.UserDataPath: {0}".debug(siteDataPath); } else { tmFileStorage.Path_SiteData = null; "[TM_FileStorage] [set_Path_SiteData] failed to create the folder: {0}".error(siteDataPath); } return(tmFileStorage); }
[Test] public void add_UserData_Repo() { var tmServer = new TM_Server().setDefaultData(); var userData_Config1a = new TM_Server.Config { Name = 10.randomLetters() }; var userData_Config1b = new TM_Server.Config { Name = userData_Config1a.Name }; var userData_Config2 = new TM_Server.Config { Name = 10.randomLetters() }; Assert.IsNotEmpty(tmServer.UserData_Configs); // there should be at least one default UserData config tmServer.UserData_Configs.clear(); tmServer.add_UserData(userData_Config1a); Assert.AreEqual(tmServer.UserData_Configs.size(), 1); Assert.AreEqual(tmServer.UserData_Configs.first(), userData_Config1a); tmServer.add_UserData(userData_Config2); // should add userData_Config2 Assert.AreEqual(tmServer.UserData_Configs.size(), 2); Assert.AreEqual(tmServer.UserData_Configs.first(), userData_Config1a); Assert.AreEqual(tmServer.UserData_Configs.second(), userData_Config2); tmServer.add_UserData(userData_Config1b); // should reaplce userData_GitRepo1a with userData_GitRepo1b Assert.AreEqual(tmServer.UserData_Configs.size(), 2); Assert.AreEqual(tmServer.UserData_Configs.first(), userData_Config2); Assert.AreEqual(tmServer.UserData_Configs.second(), userData_Config1b); }
[Admin] public static TM_FileStorage set_Path_UserData(this TM_FileStorage tmFileStorage) { admin.demand(); var tmXmlDatabase = tmFileStorage.tmXmlDatabase(); //var userData = tmFileStorage.userData(); if (tmXmlDatabase.isNull()) { return(tmFileStorage); } var userData_Config = tmFileStorage.tmServer().userData_Config(); if (userData_Config.isNull() || userData_Config.Name.notValid()) { "[TM_Xml_Database][set_Path_UserData] userData_Config or its name was null or empty, so going to to use the default value of: {0}".debug(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA); userData_Config = new TM_Server.Config() { Name = TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA }; } var xmlDatabasePath = tmFileStorage.path_XmlDatabase(); // all files are relative to this path var userDataPath = xmlDatabasePath.pathCombine(userData_Config.Name); // use the userData_Config.Name as the name of the folder to put UserData files tmFileStorage.Path_UserData = userDataPath; // needed by Git Clone "TeamMentor.Git".assembly() .type("TM_UserData_Git_ExtensionMethods") .invokeStatic("setup_UserData_Git_Support", tmFileStorage); userDataPath.createDir(); // create if needed if (userDataPath.dirExists()) { tmFileStorage.Path_UserData = userDataPath.createDir(); "[TM_Xml_Database] [set_Path_UserData] TMConfig.Current.UserDataPath: {0}".debug(userDataPath); } else { tmFileStorage.Path_UserData = null; "[TM_Xml_Database] [set_Path_UserData] failed to create the folder: {0}".error(userDataPath); } return(tmFileStorage); }
[Test] public void getActive_UserData_Repo_Remote_GitPath() { var tmServer = new TM_Server(); var userData_Config = new TM_Server.Config { Name = 10.randomLetters(), Remote_GitPath = 10.randomLetters() }; tmServer.add_UserData(userData_Config); tmServer.active_UserData(userData_Config); var active_GitConfig = tmServer.userData_Config(); var remote_GitPath = tmServer.userData_Config().Remote_GitPath; Assert.NotNull(active_GitConfig); Assert.AreEqual(userData_Config, active_GitConfig); Assert.AreEqual(userData_Config.Remote_GitPath, remote_GitPath);; }
public void LoadAndSave_TMServer_To_Disk() { UserGroup.Admin.assert(); var saved_Path_XmlDatabase = tmFileStorage.path_XmlDatabase(); // save these so we can confirm that the restore worked as expected (at the end of the test) var saved_TmServerPath = tmFileStorage.tmServer_Location() .assert_File_Exists(); // confirm that it exists (before the Path_XmlLibraries path change) var saved_TmServer_ToXml = tmFileStorage.tmServer().toXml(); var temp_Path_XmlLibraries = "temp_Path_XmlLibraries".tempDir(); tmFileStorage.set_Path_XmlDatabase(temp_Path_XmlLibraries) // set the set_Path_XmlDatabase to temp_Path_XmlLibraries .path_XmlDatabase().assert_Equal_To(temp_Path_XmlLibraries); // and confirm that it was set var tmServerPath = tmFileStorage.tmServer_Location() // get the current path to the TM_Server object .assert_File_Not_Exists() // confirm it doesn't exist and that its parent folder is temp_Path_XmlLibraries .assert_File_Parent_Folder_Is(temp_Path_XmlLibraries); //create temp TM_Server, modify it and saved it tmFileStorage.tmServer(null).tmServer().assert_Null(); // remove the loaded TM_Server object (from TM_FileStorage) tmFileStorage.tmServer_Load(); // trigger the load of TM_Server, which in this case will create the file on tmServerPath tmFileStorage.tmServer().notNull(); // confirm that the TM_Server object is now set (inside TM_FileStorage) tmFileStorage.tmServer_Location().assert_File_Exists() // and that it exist on disk .assert_Equal_To(tmServerPath) .assert_Not_Equal_To(saved_TmServerPath); var temp_TmServer = tmFileStorage.tmServer(); var test_Config = new TM_Server.Config { Name = "Test_Config", // Local_GitPath = 10.randomLetters(), Remote_GitPath = 10.randomLetters() }; temp_TmServer.UserData_Configs.assert_Size_Is(1); // check that default UserData mapping is there temp_TmServer.userData_Config("User_Data").assert_Not_Null(); temp_TmServer.add_UserData(test_Config); temp_TmServer.UserData_Configs.assert_Size_Is(2); tmFileStorage.tmServer_Location().load <TM_Server>().UserData_Configs.assert_Size_Is(1); // before save there should only be one there tmFileStorage.tmServer_Save(); tmFileStorage.tmServer_Location().load <TM_Server>().UserData_Configs.assert_Size_Is(2); // after save we should have two tmFileStorage.tmServer_Location().load <TM_Server>().userData_Config("Test_Config") // load this value from disk and comparate it with the version in memory .toXml().assert_Is_Equal_To(test_Config.toXml()); // test load of saved file tmFileStorage.tmServer(null).tmServer().assert_Null(); tmFileStorage.tmServer_Load() // trigger reload .tmServer().userData_Config("Test_Config") // load this value from loaded version and comparate it with the original one .toXml().assert_Is_Equal_To(test_Config.toXml()); tmFileStorage.set_Path_XmlDatabase() // restore current mapped value of Path_XmlDatabase .path_XmlDatabase() // get it .assert_Equal_To(saved_Path_XmlDatabase); // confirms it is expected result tmFileStorage.tmServer_Location() .assert_Is_Equal_To(saved_TmServerPath); tmFileStorage.tmServer_Load() .tmServer() .toXml().assert_Is_Equal_To(saved_TmServer_ToXml); tmServer = tmFileStorage.tmServer(); // also restore this value (so that other tests in this TestFixture are not affected) temp_Path_XmlLibraries.assert_Folder_Deleted(); }