This is the TeamMentor interface with the file system. The main TM objects (ie its objects) are not aware of where (if at all) their data is saved into
Inheritance: System.MarshalByRefObject
Esempio n. 1
0
        public static TM_FileStorage    users_Load(this TM_FileStorage tmFileStorage)
        {
            var userData = tmFileStorage.UserData;

            if (userData.notNull())
            {
                userData.TMUsers = new List <TMUser>();

                var usersFolder = tmFileStorage.users_XmlFile_Location();
                if (usersFolder.isNull())
                {
                    "[TM_FileStorage] [users_Load] could not load users because users_XmlFile_Location() returned null".error();
                }
                else
                {
                    foreach (var file in usersFolder.files("*.userData.xml"))
                    {
                        var tmUser = file.load <TMUser>();
                        if (tmUser.notNull() && tmUser.UserID > 0)
                        {
                            userData.TMUsers.Add(tmUser);
                        }
                        else
                        {
                            "[TM_UserData_Ex_Users_Persistance] [users_Load] error loading tmUser file (or UserId < 1): {0}".error(file);
                        }
                    }
                }
            }
            return(tmFileStorage);
        }
        /*public static string                             path_XmlLibraries(this TM_Xml_Database tmXmlDatabase)
         * {
         *  return TM_FileStorage.Current.notNull() ?  TM_FileStorage.Current.Path_XmlLibraries : null;
         * }*/

        [Admin] public static TM_Xml_Database   tmXmlDatabase(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            return((tmFileStorage.notNull())
                        ? tmFileStorage.TMXmlDatabase
                        : null);
        }
Esempio n. 3
0
 public void setup()
 {
     this.tmProxy_Refresh();
     tmFileStorage = tmProxy.TmFileStorage.assert_Not_Null();
     tmServer      = tmProxy.TmServer.assert_Not_Null();
     path_SiteData = tmFileStorage.path_SiteData();
 }
 public void TM_hook_Events_TM_Xml_Database_RestrictedTo_Reader()
 {
     var tmFileStorage = new TM_FileStorage(loadData: false);
     Assert.NotNull(tmFileStorage);
     UserGroup.Reader.assert();
     var result = tmFileStorage.hook_Events_TM_Xml_Database();
 }
Esempio n. 5
0
        [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);
        }
Esempio n. 6
0
 [Admin] public static TM_Server         tmServer(this TM_FileStorage tmFileStorage)
 {
     UserRole.Admin.demand();
     return((tmFileStorage.notNull())
                 ? tmFileStorage.Server
                 : null);
 }
Esempio n. 7
0
        public static bool guidanceExplorer_Save(this guidanceExplorer guidanceExplorer, TM_FileStorage tmFileStorage)
        {
            var guidanceExplorersPaths= tmFileStorage.GuidanceExplorers_Paths;

            var libraryName = guidanceExplorer.library.caption;
            if (guidanceExplorersPaths.hasKey(guidanceExplorer).isFalse())
            {
                var libraryFolder = tmFileStorage.Path_XmlLibraries.pathCombine(libraryName).createDir();
                var libraryXmlFile = libraryFolder.pathCombine("{0}.xml".format(libraryName));
                guidanceExplorersPaths.add(guidanceExplorer, libraryXmlFile);
            }

            var libraryPath = guidanceExplorersPaths.value(guidanceExplorer);
            if (libraryPath.notNull())
            {
                "[xmlDB_Save_GuidanceExplorer] saving GuidanceExplorer '{0}' to {1}'".debug(libraryName, libraryPath);

                libraryPath.parentFolder().createDir();         // ensure library folder exists
                guidanceExplorer.SaveLibraryTo(libraryPath);
                //tmDatabase.triggerGitCommit();                //TODO:add saveToLibraryEvent (to allow TeamMentor.Git to trigger the git commit)
            }
            else
                return false;
            return true;
        }
Esempio n. 8
0
        public static bool library_Deleted(this TM_FileStorage tmFileStorage, TM_Library tmLibrary)
        {
            "[xmlDB_DeleteGuidanceExplorer] deleting library with caption: {0}".info(tmLibrary.Caption);
            var pathToLibraryFolder = tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary);

            // this is also the Library Root
            if (pathToLibraryFolder.notValid() || pathToLibraryFolder == tmFileStorage.path_XmlDatabase() ||
                pathToLibraryFolder == tmFileStorage.Path_XmlLibraries)
            {
                "[xmlDB_DeleteGuidanceExplorer] [Stopping delete] Something is wrong with the pathToLibrary to delete : {0}"
                .error(pathToLibraryFolder);
                return(false);
            }
            if (pathToLibraryFolder.contains(tmFileStorage.Path_XmlLibraries).isFalse())
            {
                "[xmlDB_DeleteGuidanceExplorer] [Stopping delete] the  pathToLibrary should contain tmDatabase.Path_XmlLibraries : {0}"
                .error(pathToLibraryFolder);
                return(false);
            }
            // the checks above are important since the line below is a recursive folder delete (which can delete a LOT of content is pointed to the wrong folder)
            if (Files.deleteFolder(pathToLibraryFolder, true).isFalse())
            {
                "[xmlDB_DeleteGuidanceExplorer] there was an error deleting the folder: {0}".error(
                    pathToLibraryFolder);
                return(false);
            }

            "[xmlDB_DeleteGuidanceExplorer] Library folder deleted OK: {0}".info(pathToLibraryFolder);
            tmFileStorage.reloadGuidanceExplorerObjects(); //reset these

            return(true);
        }
Esempio n. 9
0
        /*[Admin] public static TM_FileStorage    load_TMServer(this TM_FileStorage tmFileStorage)
         * {
         *  return tmFileStorage.tmServer_Load();
         * }*/
        [Admin] public static TM_FileStorage    tmServer_Load(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            if (tmFileStorage.isNull())
            {
                return(tmFileStorage);
            }
            var tmServer = new TM_Server();

            tmServer.setDefaultData();


            var location = tmFileStorage.tmServer_Location();

            if (location.valid())
            {
                if (location.fileExists().isFalse())
                {
                    "[TM_Xml_Database][load_TMServer_Config] expected TM_Server file didn't exist, so creating it: {0}".info(location);
                    tmServer.saveAs(location);
                }
                var loadedTmServer = location.load <TM_Server>();
                if (loadedTmServer.isNull())
                {
                    "[TM_Xml_Database][load_TMServer_Config] Failed to load tmServer file: {0}   Default values will be used".error(location);
                }
                else
                {
                    tmServer = loadedTmServer;
                }
            }
            //tmDatabase.Events.After_TmServer_Load.raise();
            tmFileStorage.Server = tmServer;
            return(tmFileStorage);
        }
        public void set_Path_SiteData()
        {
            var tmFileStorage = new TM_FileStorage();

            var expectedPath  = tmFileStorage.path_XmlDatabase().pathCombine(TMConsts.TM_SERVER_DEFAULT_NAME_SITEDATA);

            tmFileStorage.set_Path_SiteData();

            Assert.AreEqual(tmFileStorage.Path_SiteData, expectedPath);
            Assert.True    (tmFileStorage.Path_SiteData.dirExists());

            // try with a different Name value
            var tempName = 10.randomLetters();
            tmFileStorage.Server.siteData_Config().Name = tempName;
            tmFileStorage.set_Path_SiteData();
            Assert.IsTrue(tmFileStorage.Path_SiteData.contains(tempName));

            //check bad data handling
            tmFileStorage.Server.siteData_Config().Name = null;
            tmFileStorage.set_Path_SiteData();
            Assert.IsTrue(tmFileStorage.Path_SiteData.contains(TMConsts.TM_SERVER_DEFAULT_NAME_SITEDATA));

            tmFileStorage.Server.siteData_Config().Name = "aaa:bbb"; // will fail to create the SiteData folder and force memory mode
            tmFileStorage.set_Path_SiteData();
            Assert.IsNull    (tmFileStorage.Path_SiteData);
        }
Esempio n. 11
0
        public static TM_FileStorage tmConfig_Load(this TM_FileStorage tmFileStorage)
        {
            if (tmFileStorage.isNull())
            {
                return(null);
            }

            var userConfigFile = tmFileStorage.tmConfig_Location();

            if (userConfigFile.fileExists())
            {
                var newConfig = userConfigFile.load <TMConfig>();    // to check that the new TMConfig is not corrupted
                if (newConfig.isNull())
                {
                    "[handleUserDataConfigActions] failed to load config file from: {0}".error(userConfigFile);
                    return(null);
                }
                TMConfig.Current = newConfig;
            }
            else
            {
                // if userConfigFile doesn't exist, create one and save it
                TMConfig.Current = new TMConfig();
                tmFileStorage.tmConfig_Save();
            }
            return(tmFileStorage);
        }
Esempio n. 12
0
 public static TMConfig tmConfig_Reload(this TM_FileStorage tmFileStorage)
 {
     TMConfig.Current = tmFileStorage.tmConfig_Location().fileExists()
                             ? tmFileStorage.tmConfig_Location().load <TMConfig>()
                             : new TMConfig();
     return(TMConfig.Current);
 }
Esempio n. 13
0
 [Admin] public static bool using_Custom_WebRoot(this TM_FileStorage tmFileStorage)
 {
     admin.demand();
     return(tmFileStorage.notNull() &&
            TM_FileStorage.Custom_WebRoot.notNull() &&
            TM_FileStorage.Custom_WebRoot == tmFileStorage.webRoot());
 }
Esempio n. 14
0
 public static string xmlDB_Path_Library_XmlFile(this TM_FileStorage tmFileStorage, TM_Library library)
 {
     if (library.isNull())
     {
         return(null);
     }
     return(tmFileStorage.xmlDB_Path_Library_XmlFile(library.Id));
 }
Esempio n. 15
0
        public void Setup()
        {
            context                         =  HttpContextFactory.Context.mock();
            handleUrlRequest                = new HandleUrlRequest();
            tmFileStorage                   = new TM_FileStorage(false) { Path_XmlDatabase = "_siteData".tempDir() };

            Assert.IsTrue(tmFileStorage.Path_XmlDatabase.dirExists());
        }
Esempio n. 16
0
 public static string            path_SiteData(this TM_FileStorage tmFileStorage)
 {
     if (tmFileStorage.notNull())
     {
         return(tmFileStorage.Path_SiteData);
     }
     return(null);
 }
Esempio n. 17
0
 public TM_UserData_Git(TM_FileStorage tmFileStorage)
 {
     Current             = this;
     FileStorage         = tmFileStorage;
     UserData            = tmFileStorage.userData();
     NGit_Author_Name    = TMConsts.NGIT_DEFAULT_AUTHOR_NAME;
     NGit_Author_Email   = TMConsts.NGIT_DEFAULT_AUTHOR_EMAIL;
 }
Esempio n. 18
0
 public static bool          saveTmUser(this TM_FileStorage tmFileStorage, TMUser tmUser)
 {
     lock (tmUser)
     {
         var location = tmFileStorage.user_XmlFile_Location(tmUser);
         return(location.valid() && tmUser.saveAs(location));
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Forces tmFileStorage.WebRoot to be set to a specific folder
 ///
 /// Note: If <code>webRoot</code> folder doesn't exist, the value is not changed
 /// </summary>
 /// <param name="tmFileStorage"></param>
 /// <param name="webRoot"></param>
 /// <returns></returns>
 [Admin] public static TM_FileStorage   set_WebRoot(this TM_FileStorage tmFileStorage, string webRoot)
 {
     admin.demand();
     if (tmFileStorage.notNull() && webRoot.folderExists())
     {
         tmFileStorage.WebRoot = webRoot;
     }
     return(tmFileStorage);
 }
Esempio n. 20
0
        public TM_WebServices(bool disable_Csrf_Check)
        {
            tmXmlDatabase       = TM_Xml_Database.Current;
            tmFileStorage       = TM_FileStorage .Current;
            userData            = TM_UserData.Current;
            tmAuthentication	= new TM_Authentication(this).mapUserRoles(disable_Csrf_Check);

            GZip.setGZipCompression_forAjaxRequests();
        }
Esempio n. 21
0
        [Admin] public static bool using_Custom_Path_XmlDatabase(this TM_FileStorage tmFileStorage)
        {
            admin.demand();
            var tmStatus = TM_Status.Current;

            return(tmFileStorage.notNull() &&
                   TM_FileStorage.Custom_Path_XmlDatabase.notNull() &&
                   TM_FileStorage.Custom_Path_XmlDatabase == tmFileStorage.webRoot());
        }
Esempio n. 22
0
 /// <summary>
 /// returns value of tmFileStorage.WebRoot
 /// </summary>
 /// <param name="tmFileStorage"></param>
 /// <returns></returns>
 [Admin] public static string   webRoot(this TM_FileStorage tmFileStorage)
 {
     admin.demand();
     if (tmFileStorage.notNull())
     {
         return(tmFileStorage.WebRoot);
     }
     return(null);
 }
Esempio n. 23
0
        public static bool tmConfig_Save(this TM_FileStorage tmFileStorage)
        {
            var tmConfig = TMConfig.Current;
            var location = tmFileStorage.tmConfig_Location();

            return((tmConfig.notNull() && location.valid())
                        ? tmConfig.saveAs(location)
                        : false);
        }
Esempio n. 24
0
 /// <summary>
 /// Forces tmFileStorage.Path_XmlDatabase to be set to a specific folder
 ///
 /// Note: If <code>path_XmlDatabase</code> folder doesn't exist, the value is not changed
 /// </summary>
 /// <param name="tmFileStorage"></param>
 /// <param name="path_XmlDatabase"></param>
 /// <returns></returns>
 [Admin] public static TM_FileStorage   set_Path_XmlDatabase(this TM_FileStorage tmFileStorage, string path_XmlDatabase)
 {
     admin.demand();
     if (tmFileStorage.notNull() && path_XmlDatabase.folderExists())
     {
         tmFileStorage.Path_XmlDatabase = path_XmlDatabase;
     }
     return(tmFileStorage);
 }
 public void library_Deleted_LibraryNotExist()
 {
     UserGroup.Admin.assert();
     var tmFileStorage = new TM_FileStorage(loadData: false);
     Assert.NotNull(tmFileStorage);
     var lib = tmFileStorage.load_Libraries();
     var result= tmFileStorage.library_Deleted(new TM_Library());
     Assert.IsFalse(result);
 }
Esempio n. 26
0
 /// <summary>
 /// Forces tmFileStorage.Path_UserData to be set to a specific folder
 ///
 /// Note: If <code>path_SiteData</code> folder doesn't exist, the value is not changed
 /// </summary>
 /// <param name="tmFileStorage"></param>
 /// <param name="path_SiteData"></param>
 /// <returns></returns>
 [Admin] public static TM_FileStorage   set_Path_SiteData(this TM_FileStorage tmFileStorage, string path_SiteData)
 {
     admin.demand();
     if (tmFileStorage.notNull() && path_SiteData.folderExists())
     {
         tmFileStorage.Path_SiteData = path_SiteData;
     }
     return(tmFileStorage);
 }
Esempio n. 27
0
 public static string            users_XmlFile_Location(this TM_FileStorage tmFileStorage)
 {
     if (tmFileStorage.path_UserData().notNull())
     {
         return(tmFileStorage.path_UserData()
                .pathCombine(TMConsts.USERDATA_PATH_USER_XML_FILES)
                .createDir());
     }
     return(null);
 }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        [Admin] public static TM_FileStorage    load_Libraries(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            tmFileStorage.loadDataIntoMemory();

            tmXmlDatabase.Events.After_Load_Libraries.raise();

            return(tmFileStorage);
        }
Esempio n. 30
0
        public static bool            secretData_Save(this TM_FileStorage tmFileStorage)
        {
            var secretData = tmFileStorage.userData().SecretData;
            var location   = tmFileStorage.secretData_Location();

            return(location.valid() &&
                   secretData.notNull() &&
                   secretData.saveAs(location));
            //userData.triggerGitCommit();
            //userData.logTBotActivity("TM_SecretData saved","");
        }
Esempio n. 31
0
        [Admin] public static string            reloadData(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            var tmDatabase = tmFileStorage.TMXmlDatabase;

            "[TM_Xml_Database] In Reload data".info();
            tmFileStorage.clear_GuidanceItemsCache();                           // start by clearing the cache
            tmDatabase.setup();
            tmFileStorage.load_Libraries();
            return(tmDatabase.stats());
            // return some stats
        }
Esempio n. 32
0
        [Admin] public static TM_FileStorage                hook_Events_TM_UserData(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            var tmUserData = tmFileStorage.UserData;

            tmUserData.Events.After_TM_Config_Changed.add((userData) => tmFileStorage.tmConfig_Save());

            tmUserData.Events.User_Updated.add((userData, tmUser) => tmFileStorage.saveTmUser(tmUser));
            tmUserData.Events.User_Deleted.add((userData, tmUser) => tmFileStorage.tmUser_Delete(tmUser));

            return(tmFileStorage);
        }
        public void TM_hook_Events_TM_Xml_Database()
        {
            var tmFileStorage = new TM_FileStorage(loadData: false);
            Assert.NotNull(tmFileStorage);
            UserGroup.Admin.assert();
            var result = tmFileStorage.hook_Events_TM_Xml_Database();

            Assert.AreEqual(result.TMXmlDatabase.Events.Article_Deleted.Count, 1);
            Assert.AreEqual(result.TMXmlDatabase.Events.Article_Saved.Count, 1);
            Assert.AreEqual(result.TMXmlDatabase.Events.GuidanceExplorer_Save.Count, 1);
            Assert.AreEqual(result.TMXmlDatabase.Events.Articles_Cache_Updated.Count, 2);
        }
Esempio n. 34
0
        [Admin] public static bool              tmServer_Save(this TM_FileStorage tmFileStorage, TM_Server tmServer)
        {
            UserRole.Admin.demand();
            if (tmFileStorage.isNull() || tmServer.isNull())
            {
                return(false);
            }
            var location = tmFileStorage.tmServer_Location();

            return((location.valid()) &&
                   tmServer.saveAs(location));
        }
Esempio n. 35
0
 public void TM_FileStorage_Ctor_False()
 {
     var tmFileStorage = new TM_FileStorage(loadData : false);
     Assert.NotNull(tmFileStorage.Server);
     Assert.NotNull(tmFileStorage.TMXmlDatabase);
     Assert.NotNull(tmFileStorage.UserData);
     Assert.IsEmpty(tmFileStorage.GuidanceExplorers_Paths);
     Assert.IsEmpty(tmFileStorage.GuidanceItems_FileMappings);
     Assert.IsNull (tmFileStorage.WebRoot);
     Assert.IsNull (tmFileStorage.Path_XmlDatabase);
     Assert.IsNull (tmFileStorage.Path_UserData);
     Assert.IsNull (tmFileStorage.Path_XmlLibraries);
 }
Esempio n. 36
0
        /// <summary>
        /// Forces tmFileStorage.Path_UserData to be set to a specific folder
        ///
        /// Note: If <code>path_UserData</code> folder doesn't exist, the value is not changed
        /// </summary>
        /// <param name="tmFileStorage"></param>
        /// <param name="path_UserData"></param>
        /// <returns></returns>
        [Admin] public static TM_FileStorage   set_Path_UserData(this TM_FileStorage tmFileStorage, string path_UserData)
        {
            admin.demand();
            if (tmFileStorage.notNull() && path_UserData.folderExists())
            {
                tmFileStorage.Path_UserData = path_UserData;

                "TeamMentor.Git".assembly()
                .type("TM_UserData_Git_ExtensionMethods")
                .invokeStatic("setup_UserData_Git_Support", tmFileStorage);
            }
            return(tmFileStorage);
        }
Esempio n. 37
0
        public static string        user_XmlFile_Location(this TM_FileStorage tmFileStorage, TMUser tmUser)
        {
            if (tmFileStorage.isNull())
            {
                return(null);
            }

            var fileName = tmUser.user_XmlFile_Name();

            return(fileName.valid()
                        ? tmFileStorage.users_XmlFile_Location().pathCombine(fileName)
                        : null);
        }
Esempio n. 38
0
        public static bool xmlDB_Libraries_ImportFromZip(this TM_FileStorage tmFileStorage, string zipFileToImport, string unzipPassword)
        {
            UserRole.Admin.demand();

            var result = false;

            try
            {
                var currentLibraryPath = tmFileStorage.Path_XmlLibraries;
                if (currentLibraryPath.isNull())
                {
                    return(false);
                }
                if (zipFileToImport.isUri())
                {
                    "[xmlDB_Libraries_ImportFromZip] provided value was an URL so, downloading it: {0}".info(zipFileToImport);
                    zipFileToImport = new Web().downloadBinaryFile(zipFileToImport);
                }
                "[xmlDB_Libraries_ImportFromZip] importing library from: {0}".info(zipFileToImport);
                if (zipFileToImport.fileExists().isFalse())
                {
                    "[xmlDB_Libraries_ImportFromZip] could not find file to import".error(zipFileToImport);
                }
                else
                {
                    // handle the zips we get from GitHub

                    var tempDir = @"..\_".add_RandomLetters(3).tempDir(false).fullPath(); //trying to make the unzip path as small as possible
                    var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip {
                        Password = unzipPassword ?? ""
                    };

                    fastZip.ExtractZip(zipFileToImport, tempDir, "");

                    Files.copyFolder(tempDir, currentLibraryPath, true, true, "");          // just copy all files into Library path
                    Files.deleteFolder(tempDir, true);                                      // delete tmp folder created
                    result = true;
                }
            }
            catch (Exception ex)
            {
                ex.log("[xmlDB_Libraries_ImportFromZip]");
            }

            if (result)
            {
                tmFileStorage.reloadGuidanceExplorerObjects();
            }

            return(result);
        }
Esempio n. 39
0
        public TM_XmlDatabase_FileStorage()
        {
            SendEmails.Disable_EmailEngine = true;

            UserGroup.Admin.assert();
            tmFileStorage   = new TM_FileStorage();
            tmXmlDatabase   = tmFileStorage.TMXmlDatabase; //new TM_Xml_Database().setup();
            userData        = tmFileStorage.UserData;
            tmServer        = tmFileStorage.Server;
            tmConfig        = TMConfig.Current;

            CheckDatabaseSetup();
            UserGroup.None.assert();
        }
Esempio n. 40
0
        [Admin] public static TM_FileStorage   load_UserData(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();

            //   "TeamMentor.Git".assembly()
            //                   .type("TM_UserData_Git_ExtensionMethods")
            //                   .invokeStatic("setup_UserData_Git_Support", tmFileStorage);

            tmFileStorage//.tmConfig_Load()
            .secretData_Load()
            .users_Load();

            return(tmFileStorage);
        }
        public void set_Path_XmlDatabase__UsingFileStorage_On_Custom_WebRoot_without_Read_Privs()
        {
            admin.assert();

            var tmFileStorage = new TM_FileStorage(false);
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            var baseReadOnlyDir   = "_tmp_webRoot".tempDir();
            var webRootVirualPath = @"virtual/path";

            tmFileStorage.WebRoot     = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir();

            //Check that ensure we can write to baseReadOnlyDir
            Assert.IsTrue  (baseReadOnlyDir.dirExists());
            Assert.IsTrue  (tmFileStorage.WebRoot.dirExists());
            Assert.IsTrue  (tmFileStorage.WebRoot.contains(baseReadOnlyDir));
            Assert.IsTrue  (baseReadOnlyDir.canWriteToPath());
            Assert.AreEqual(tmFileStorage.WebRoot.parentFolder().parentFolder(), baseReadOnlyDir);

            //Now remote the write privileges for all users (on baseReadOnlyDir) while keeping  TM_Server.WebRoot writeable

            baseReadOnlyDir  .directoryInfo().deny_Write_Users();
            tmFileStorage.WebRoot.directoryInfo().allow_Write_Users();

            Assert.IsFalse(baseReadOnlyDir .canWriteToPath());
            Assert.IsTrue(tmFileStorage.WebRoot.canWriteToPath());

            //Since baseReadOnlyDir can be written, creating an TM_Xml_Database should now default to the App_Data folder (which is on webRootVirualPath )

            //            var tmXmlDatabase = new TM_Xml_Database().useFileStorage();

            tmFileStorage.set_Path_XmlDatabase();

            Assert.IsNotNull(tmFileStorage.path_XmlDatabase());

            none.assert();

            Assert.Ignore("TO FIX (Refactor Side Effect");
            Assert.IsTrue   (tmFileStorage.path_XmlDatabase().contains("App_Data"));
            Assert.IsTrue   (tmFileStorage.path_XmlDatabase().contains(tmFileStorage.WebRoot));
            Assert.IsTrue   (tmFileStorage.path_XmlDatabase().contains(PublicDI.config.O2TempDir));

            //Finally re enable write so that we can delete the folder
            baseReadOnlyDir.directoryInfo().allow_Write_Users();
            Assert.IsTrue(baseReadOnlyDir.canWriteToPath());
            Files.deleteFolder(baseReadOnlyDir, true);
            Assert.IsFalse  (baseReadOnlyDir.dirExists());
        }
Esempio n. 42
0
 /// <summary>
 /// Sets the tmFileStorage.WebRoot
 ///
 /// If the TM_FileStorage.Custom_WebRoot is set and the folder exists, then that value will be used.
 /// If not, TM_FileStorage.Custom_WebRoot will be set to AppDomain.CurrentDomain.BaseDirectory
 /// </summary>
 /// <param name="tmFileStorage"></param>
 /// <returns></returns>
 [Admin] public static TM_FileStorage   set_WebRoot(this TM_FileStorage tmFileStorage)
 {
     admin.demand();
     if (tmFileStorage.notNull())
     {
         if (TM_FileStorage.Custom_WebRoot.folderExists())
         {
             tmFileStorage.WebRoot = TM_FileStorage.Custom_WebRoot;
         }
         else
         {
             tmFileStorage.WebRoot = AppDomain.CurrentDomain.BaseDirectory;
         }
     }
     return(tmFileStorage);
 }
Esempio n. 43
0
        public void TM_FileStorage_Ctor_True()
        {
            UserGroup.Admin.assert();

            var tmFileStorage = new TM_FileStorage(loadData : true);
            Assert.NotNull(tmFileStorage.Server);
            Assert.NotNull(tmFileStorage.TMXmlDatabase);
            Assert.NotNull(tmFileStorage.UserData);
            Assert.NotNull(tmFileStorage.GuidanceExplorers_Paths);
            Assert.NotNull(tmFileStorage.GuidanceItems_FileMappings);
            Assert.NotNull(tmFileStorage.WebRoot);
            Assert.NotNull(tmFileStorage.Path_XmlDatabase);
            Assert.NotNull(tmFileStorage.Path_UserData);
            Assert.NotNull(tmFileStorage.Path_XmlLibraries);

            UserGroup.None.assert();
        }
        public void setup()
        {
            if (Tests_Consts.offline)
                Assert.Ignore("Ignoring Test because we are offline");

            admin.assert(()=>{
                                tmFileStorage = new TM_FileStorage(false);

                                TM_FileStorage.Custom_WebRoot = "Custom_WebRoot".tempDir();

                                tmFileStorage.set_WebRoot()
                                             .set_Path_XmlDatabase()
                                             .tmConfig_Load()
                                             .set_Path_XmlLibraries();

                                tmXmlDatabase = tmFileStorage.TMXmlDatabase;
                            });
        }
        public void load_UserData()
        {
            admin.assert();

            var tmFileStorage = new TM_FileStorage(false);              // create empty TM_FileStorage
            var tmServer      = tmFileStorage.Server;
            var userData      = tmFileStorage.UserData;

            Assert.IsNotNull(tmServer);
            Assert.IsNotNull(userData);

            //tmServer.Users_Create_Default_Admin = true;

            tmFileStorage.load_UserData();

            Assert.IsEmpty (userData.TMUsers);

            none.assert();

            Assert.Ignore("Add checks specific to the load_UserData method ");
        }
Esempio n. 46
0
        public void set_WebRoot()
        {
            TM_FileStorage.Custom_WebRoot = null;
            var custom_WebRoot            = "Custom_WebRoot".tempDir().assert_Folder_Exists();
            var expected_Path_XmlDatabase = custom_WebRoot.pathCombine(@"App_Data\TeamMentor");

            UserRole.Admin.assert();

            TM_FileStorage.Custom_WebRoot.assert_Null();
            var tmFileStorage = new TM_FileStorage(loadData: false);
            tmFileStorage.webRoot().assert_Null();
            tmFileStorage.set_WebRoot();
            tmFileStorage.webRoot().assert_Not_Null()
                                   .assert_Equal(AppDomain.CurrentDomain.BaseDirectory);

            TM_FileStorage.Custom_WebRoot = custom_WebRoot;
            tmFileStorage.webRoot().assert_Equal(AppDomain.CurrentDomain.BaseDirectory)     // should still point to the AppDomain base directory
                                   .assert_Not_Equal(custom_WebRoot);

            tmFileStorage.using_Custom_WebRoot().assert_False();                            // this should only be true when the values match

            tmFileStorage.set_WebRoot()                                                     // set WebRoot
                         .webRoot().assert_Equals(custom_WebRoot);                          // and confirm its location

            tmFileStorage.using_Custom_WebRoot().assert_True();                             // now it should be true
            tmFileStorage.path_XmlDatabase().assert_Null();                                 // confirm that not set
            tmFileStorage.set_Path_XmlDatabase();                                           // this should set the TM_Xml_Database inside the Web_Root
            tmFileStorage.path_XmlDatabase().contains(custom_WebRoot);
            tmFileStorage.path_XmlDatabase().assert_Is_Equal_To(expected_Path_XmlDatabase); // check that the current Path_XmlDatabase matches the expected location

            //reset values
            TM_FileStorage.Custom_WebRoot = null;

            tmFileStorage.set_WebRoot()
                         .webRoot().assert_Not_Equals(custom_WebRoot);

            Files.delete_Folder_Recursively(custom_WebRoot).assert_True();
            custom_WebRoot.assert_Folder_Doesnt_Exist();
        }
Esempio n. 47
0
        public void set_Path_XmlDatabase()
        {
            admin.assert();
            var custom_WebRoot = TM_FileStorage.Custom_WebRoot = "Custom_WebRoot".tempDir().assert_Folder_Exists();

            var tmFileStorage  = new TM_FileStorage(loadData: false)
                                       .set_WebRoot()
                                       .set_Path_XmlDatabase();

            var path_XmlDatabase = tmFileStorage.path_XmlDatabase().assert_Folder_Exists()
                                                                   .assert_Contains(custom_WebRoot);

            // check use of TM_FileStorage.Custom_Path_TM_Xml_Database

            TM_FileStorage.Custom_Path_XmlDatabase.assert_Null();

            TM_FileStorage.Custom_Path_XmlDatabase = 10.randomLetters();                       // with a random value
            tmFileStorage.set_Path_XmlDatabase()
                         .path_XmlDatabase().assert_Is_Equal_To(path_XmlDatabase);             // this value should not be changed

            var custom_Path_TM_Xml_Database = "Custom_Path_TM_Xml_Database".add_5_RandomLetters()
                                                                           .inTempDir()
                                                                           .assert_Folder_Doesnt_Exist();

            TM_FileStorage.Custom_Path_XmlDatabase = custom_Path_TM_Xml_Database;              // with a folder that doesn't exist

            tmFileStorage.set_Path_XmlDatabase()
                         .path_XmlDatabase().assert_Is_Equal_To(path_XmlDatabase);             // should still be unchanged

            custom_Path_TM_Xml_Database.createDir().assert_Folder_Exists();                    // create the folder
            tmFileStorage.set_Path_XmlDatabase()
                         .path_XmlDatabase().assert_Is_Equal_To(custom_Path_TM_Xml_Database);  // and the value should be set

            Files.delete_Folder_Recursively(custom_Path_TM_Xml_Database).assert_True();
            Files.delete_Folder_Recursively(custom_WebRoot             ).assert_True();

            none.assert();
        }
        public void set_Default_Values()
        {
            var tmFileStorage = new TM_FileStorage(false);
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            var events     = tmXmlDatabase.Events;           // this value should not change

            tmXmlDatabase.set_Default_Values();

            Assert.NotNull  (tmXmlDatabase);

            Assert.IsEmpty  (tmXmlDatabase.Cached_GuidanceItems);
            Assert.IsEmpty  (tmFileStorage.GuidanceItems_FileMappings);
            Assert.IsEmpty  (tmXmlDatabase.GuidanceExplorers_XmlFormat);
            Assert.IsEmpty  (tmXmlDatabase.VirtualArticles);
            Assert.AreEqual (tmXmlDatabase.Events, events);

            Assert.IsNull   (tmFileStorage.path_XmlDatabase());
            Assert.IsEmpty  (tmFileStorage.GuidanceExplorers_Paths);
            Assert.IsNull   (tmFileStorage.Path_XmlLibraries);
            Assert.IsNotNull(tmFileStorage.UserData);
            Assert.IsNotNull(tmFileStorage.Server);
        }
        public void tm_Server_Load__In_Memory()
        {
            var tmFileStorage           = new TM_FileStorage(false);
            var tmServer_defaultData    = new TM_Server();//.setDefaultData();

            Assert.NotNull (tmFileStorage.Server);
            Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_defaultData.toXml()); // check if the value matches a new object of type TM_Server
        }
Esempio n. 50
0
        public void Application_Start()
        {
            UserGroup.Admin.assert();                                   // impersonate an admin to load the database

            "[TM_StartUp] Application Start".info();

            TmFileStorage       = new TM_FileStorage();                 // this will trigger the load of all TM_Xml_Database data

            TmFileStorage.UserData.createDefaultAdminUser();            // ensures that there is an valid admin

            TrackingApplication   = new Tracking_Application(TmFileStorage.path_XmlDatabase());    // Enabled Application Tracking

            TM_REST.SetRouteTable();	                                // Set REST routes
            MVC5.MapDefaultRoutes();                                    // Map MVC 5 routes

            TrackingApplication.saveLog();                              // save log

            UserGroup.None.assert();                                    // revert admin user impersonation
        }
        public void set_Path_XmlDatabase__UsingFileStorage_On_Custom_WebRoot()
        {
            var tmFileStorage = new TM_FileStorage(false);

            //Assert.AreEqual(tmFileStorage.WebRoot, AppDomain.CurrentDomain.BaseDirectory);
            tmFileStorage.WebRoot = "_tmp_webRoot".tempDir().info();

            tmFileStorage.WebRoot.delete_Folder();
            Assert.IsFalse(tmFileStorage.WebRoot.dirExists());

            tmFileStorage.set_Path_XmlDatabase();

            Assert.IsTrue  (tmFileStorage.path_XmlDatabase().dirExists(), "db ctor should create a library folder");

            var usingAppDataFolder = TM_Status.Current.TM_Database_Location_Using_AppData;

            "*** DB path: {0}".info(tmFileStorage.path_XmlDatabase());
            "*** Lib path: {0}".info(tmFileStorage.Path_XmlLibraries);
            "*** Current WebRoot: {0}".debug(tmFileStorage.WebRoot);
            "*** Current WebRoot exists: {0}".debug(tmFileStorage.WebRoot.dirExists());
            "*** TM_Status.Current.TM_Database_Location_Using_AppData: {0}".debug(TM_Status.Current.TM_Database_Location_Using_AppData);

            Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists()       , "db ctor should not create a Web Root (if it doesn't exist)");
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains ("App_Data"));
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains (tmFileStorage.WebRoot));
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains (PublicDI.config.O2TempDir));

            tmFileStorage.delete_Database();

            Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists()  , "if not usingAppDataFolder the TM_Server.WebRoot shouldn't exist");
            Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists()          , "should had been deleted");
        }
        public void set_Path_XmlLibraries()
        {
            var tmFileStorage = new TM_FileStorage(false);

            TMConfig.Current = null;

            //this is the sequence that needs to be loaded in order to have a Path for Xml Libraries
            tmFileStorage.set_WebRoot()
                         .set_Path_XmlDatabase()
                         .tmServer_Load()
                         .set_Path_UserData()           //
                         .tmConfig_Load()               //
                         .set_Path_XmlLibraries();

            Assert.NotNull(tmFileStorage.path_XmlDatabase());
            Assert.NotNull(tmFileStorage.path_XmlLibraries());
            Assert.IsTrue (tmFileStorage.path_XmlDatabase().dirExists());
            Assert.IsTrue (tmFileStorage.path_XmlLibraries().dirExists());
            Assert.NotNull(TMConfig.Current);

            //test nulls
            tmFileStorage.Path_XmlLibraries =null;

            //in the scenarios below the tmFileStorage.Path_XmlLibraries should not be set
            if(TMConfig.Current.notNull())
                TMConfig.Current.TMSetup = null;
            tmFileStorage.set_Path_XmlLibraries();
            TMConfig.Current = null;
            tmFileStorage.set_Path_XmlLibraries();
            Assert.IsNull(tmFileStorage.Path_XmlLibraries);

            //tmXmlDatabase.delete_Database();
            //TMConfig.Current = new TMConfig();
        }
        public void tmConfig_Load()
        {
            var tmFileStorage = new TM_FileStorage(false);              // create empty TM_FileStorage
            //            var tmServer      = tmFileStorage.Server;
            //            var userData      = tmFileStorage.UserData;

            tmFileStorage.tmConfig_Load();

            //if Path_UserData is null, then tmConfig_Location is also null

            Assert.IsNull(tmFileStorage.Path_UserData);
            Assert.IsNull(tmFileStorage.tmConfig_Location());
            Assert.NotNull(TMConfig.Current);
        }
        public void tm_Server_Load_UsingFileStorage()
        {
            var tmFileStorage = new TM_FileStorage(false);

            var baseReadOnlyDir = "_tmp_webRoot".tempDir();
            var webRootVirualPath = @"site\wwwroot";        // simulates use of AppData
            tmFileStorage.WebRoot = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir();

            tmFileStorage.set_Path_XmlDatabase()
                         .set_Path_UserData()
                         .tmServer_Load();

            var tmServerFile     = tmFileStorage.tmServer_Location();
            var expectedLocation = tmFileStorage.Path_XmlDatabase.pathCombine(TMConsts.TM_SERVER_FILENAME);

            Assert.IsNotNull(tmFileStorage.path_XmlDatabase());
            Assert.IsTrue   (TM_Status.Current.TM_Database_Location_Using_AppData);
            Assert.NotNull  (tmFileStorage.Server);
            Assert.IsTrue   (tmServerFile.fileExists());
            Assert.AreEqual(tmServerFile, expectedLocation);

            //            Assert.Ignore("TO FIX (Refactor Side Effect");
             //       Assert.Ignore("TO FIX (Refactor Side Effect");
            var tmServer_withDefaultData = new TM_Server().setDefaultData();
            Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml());

            //make a change, saved it and ensure it gets loaded ok

            var tmpName1 = 10.randomLetters();
            var tmpName2 = 10.randomLetters();
            tmFileStorage.Server.UserData_Configs.first().Name = tmpName1;
            tmFileStorage.tmServer_Save();
            tmFileStorage.Server.UserData_Configs.first().Name = tmpName2;

            tmFileStorage.tmServer_Load();
            Assert.AreEqual   (tmFileStorage.Server.UserData_Configs.first().Name, tmpName1);
            Assert.AreNotEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml());

            //Try loading up an corrupted tmServer (whcih will default to load a default TM_Server
            "aaaa".saveAs(tmServerFile);
            tmFileStorage.tmServer_Load();
            Assert.AreNotEqual(tmFileStorage.Server.UserData_Configs.first().Name, tmpName1);
            Assert.AreEqual   (tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml());

            Files.deleteFolder(baseReadOnlyDir, true);
            Assert.IsFalse(baseReadOnlyDir.dirExists());

            //tmXmlDatabase.delete_Database();
        }
Esempio n. 55
0
        public void setUp()
        {
            UserGroup.Admin.assert();

            //create TM_FileStorage on temp Custom_WebRoot for this TestFixture
            TM_FileStorage.Custom_WebRoot = "custom_WebRoot".tempDir();

            tmFileStorage = new TM_FileStorage(false);
            tmFileStorage.set_WebRoot()
                         .set_Path_XmlDatabase()
                         .tmServer_Load()
                         .set_Path_UserData()
                         .load_UserData();
            tmFileStorage.hook_Events_TM_UserData();

            tmXmlDatabase = tmFileStorage.TMXmlDatabase   .assert_Not_Null();
            userData      = tmFileStorage.UserData        .assert_Not_Null();
            tmServer      = tmFileStorage.Server          .assert_Not_Null();

            tmFileStorage.Path_XmlDatabase.assert_Folder_Exists();
            tmFileStorage.Path_UserData   .assert_Folder_Exists();

            userDataGit = tmFileStorage   .setup_UserData_Git_Support();        // adds Git Support for UserData repos

            tmFileStorage.Path_UserData.isGitRepository().assert_True();

            Assert.NotNull(tmFileStorage.Server.userData_Config());

            userData .createDefaultAdminUser();

            userDataGit.triggerGitCommit();

            nGit     = userDataGit.NGit;

            nGit.commits().assert_Size_Is(2, "there should be two commits here");

            UserGroup.None.assert();
        }
        public void set_Path_UserData()
        {
            var tmFileStorage = new TM_FileStorage();

            var expectedPath  = tmFileStorage.path_XmlDatabase().pathCombine(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA);

            tmFileStorage.set_Path_UserData();
            var userData = tmFileStorage.UserData;

            //Assert.NotNull (tmServer);
            Assert.NotNull (userData);
            Assert.AreEqual(tmFileStorage.Path_UserData, expectedPath);
            Assert.True    (tmFileStorage.Path_UserData.dirExists());

            // try with a different Name value
            var tempName = 10.randomLetters();
            tmFileStorage.Server.userData_Config().Name = tempName;
            tmFileStorage.set_Path_UserData();
            Assert.IsTrue(tmFileStorage.Path_UserData.contains(tempName));

            tmFileStorage.delete_Database();
            Assert.False   (tmFileStorage.Path_UserData.dirExists());

            //check bad data handling
            tmFileStorage.Server.userData_Config().Name = null;
            tmFileStorage.set_Path_UserData();
            Assert.IsTrue(tmFileStorage.Path_UserData.contains(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA));

            tmFileStorage.Server.userData_Config().Name = "aaa:bbb"; // will fail to create the UserData folder and force memory mode
            tmFileStorage.set_Path_UserData();
            Assert.IsNotNull (tmFileStorage.UserData);
            Assert.IsNull    (tmFileStorage.Path_UserData);

            //test nulls
            tmFileStorage.Server         = null;
            tmFileStorage.UserData       = null;
            tmFileStorage.TMXmlDatabase  = null;
            tmFileStorage.set_Path_UserData();

            Assert.IsNull (tmFileStorage.Path_UserData);

            //Assert.IsNull (new TM_FileStorage(false).set_Path_UserData().Path_UserData);
        }
 public void TM_hook_Events_TM_Xml_Database_RestrictedTo_Anonymous()
 {
     var tmFileStorage = new TM_FileStorage(loadData: false);
     Assert.NotNull(tmFileStorage);
     var result = tmFileStorage.hook_Events_TM_Xml_Database();
 }
Esempio n. 58
0
        public void Create_And_Delete_Article()
        {
            UserGroup.Admin.assert();

            var tmFileStorage = new TM_FileStorage(loadData:true);
            tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            var library = tmXmlDatabase.new_TmLibrary(library_Name);
            //Create folders
            var newFolderInLibrary = tmXmlDatabase.xmlDB_Add_Folder(library.Id, folder_In_Library_Name);
            var newViewInLibrary = tmXmlDatabase.xmlDB_NewView(new View { library = library.Id.str(), caption = view_In_Library_Name });
            var newViewInFolder = tmXmlDatabase.xmlDB_NewView(newFolderInLibrary.folderId.guid(), new View { library = library.Id.str(), caption = view_In_Folder_Name });

            //Check that they are there
            var tmView1 = tmXmlDatabase.tmView(newViewInLibrary.id.guid());
            var tmView2 = tmXmlDatabase.tmView(newViewInFolder.id.guid());
            Assert.AreEqual(tmView1.caption, newViewInLibrary.caption, "tmView1.caption");
            Assert.AreEqual(tmView2.caption, newViewInFolder.caption, "tmView2.caption");

            Assert.IsTrue(tmView1.guidanceItems.count()==0);

            var Id = Guid.Parse("40D29566-1CA9-4C4A-938E-283B2274FB10");
            tmXmlDatabase.xmlDB_AddGuidanceItemToView(tmView1.viewId, Id);
            tmXmlDatabase.Cached_GuidanceItems.Add(Id, new TeamMentor_Article());
            tmXmlDatabase.save();
            tmXmlDatabase.xmlDB_Delete_GuidanceItem(Id);
            tmXmlDatabase.save();
            Assert.IsTrue(tmXmlDatabase.Events.Article_Deleted.count()==1);

            //Delete and check that they are not there
            var result1 = tmXmlDatabase.xmlDB_RemoveView(library, tmView1.viewId);
            var result2 = tmXmlDatabase.xmlDB_RemoveView(tmView1.libraryId, tmView2.viewId);
            var tmView1_AfterDelete = tmXmlDatabase.tmView(newViewInLibrary.id.guid());
            var tmView2_AfterDelete = tmXmlDatabase.tmView(newViewInFolder.id.guid());

            Assert.IsTrue(result1, "result 1 was false");
            Assert.IsTrue(result2, "result 2 was false");
            Assert.IsNull(tmView1_AfterDelete, "tmView1 was still there after delete");
            Assert.IsNull(tmView2_AfterDelete, "tmView2 was still there after delete");
            tmXmlDatabase.delete_Library(library);
        }
Esempio n. 59
0
        public void setup_UserData_Git_Support()
        {
            admin.assert();
            TM_UserData_Git.Current = null;

            var tmFileStorage = new TM_FileStorage(false);

            // check reflection based invocation of setup_UserData_Git_Support
            "TeamMentor.Git".assembly()                                               .assert_Not_Null()
                            .type("TM_UserData_Git_ExtensionMethods")                 .assert_Not_Null()
                            .invokeStatic("setup_UserData_Git_Support", tmFileStorage).assert_Not_Null()
                                                                                      .assert_Instance_Of<TM_UserData_Git>()
                                                                                      .assert_Is(TM_UserData_Git.Current)
                                                                                      .FileStorage.assert_Not_Null()
                                                                                                  .assert_Is(tmFileStorage);

            //check that tmFileStorage.load_UserData  also sets TM_UserData_Git.Current
            TM_UserData_Git.Current = null;
            var temp_UserData = "temp_UserData".temp_Dir();

            temp_UserData.isGitRepository().assert_False();

            tmFileStorage = new TM_FileStorage(false);

            tmFileStorage.set_Path_UserData(temp_UserData)
                         .load_UserData();

            TM_UserData_Git.Current    .assert_Not_Null()
                           .FileStorage.assert_Not_Null()
                                       .assert_Is(tmFileStorage);

            temp_UserData.isGitRepository().assert_True();

            Files.delete_Folder_Recursively(temp_UserData)
                 .assert_True();
        }
        public void tm_Server_Save()
        {
            var tmFileStorage = new TM_FileStorage();

            Assert.NotNull(tmFileStorage.path_XmlDatabase());

            var tmServerLocation         = tmFileStorage.tmServer_Location();

            var tmServer_withDefaultData = new TM_Server().setDefaultData();

            Assert.IsTrue(tmServerLocation.fileExists());

               // Assert.Ignore("TO FIX (Refactor Side Effect");

            Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml());

            var tmpName1 = 10.randomLetters();

            tmFileStorage.Server.UserData_Configs.first().Name = tmpName1;
            Assert.IsTrue(tmFileStorage.tmServer_Save());
            Assert.AreEqual(tmServerLocation.load<TM_Server>().UserData_Configs.first().Name, tmpName1);   //check that it was  saved

            /*
             // this works but makes the test run in 10s (and the test being done is if there is no exception)

                var tmpName2 = 10.randomLetters();
                tmServerLocation.fileInfo()
                        .setAccessControl("Users", FileSystemRights.Write, AccessControlType.Deny);

                tmXmlDatabase.Server.UserData_Configs.first().Name = tmpName2;

                Assert.IsFalse(tmXmlDatabase.tmServer_Save());

                Assert.AreEqual(tmServerLocation.load<TM_Server>().UserData_Configs.first().Name, tmpName1);   //check that it was not saved

                Assert.IsTrue(tmServerLocation.delete_File());
                Assert.IsFalse(tmServerLocation.fileExists());
             */
            tmFileStorage.delete_Database();
            Assert.IsFalse(tmServerLocation.fileExists());
            Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists());

            //check when not UsingFileStorage

            //check for nulls
            tmFileStorage.Path_XmlDatabase = null;
            Assert.IsFalse(tmFileStorage.tmServer_Save());
            Assert.IsFalse(new TM_FileStorage(false).tmServer_Save());
        }