Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// Sets (after calculation) the value of tmFileStorage.Path_XmlDatabas
        ///
        /// The logic is a bit complicated since it takes into account the different execution locations of NCrunch, Resharper and IIS
        ///
        /// There is support for using the special ASP.NET App_Data folder (also used when the current running used does not have priviledges
        /// the mapped tmFileStorage.Path_XmlDatabase value)
        /// </summary>
        /// <param name="tmFileStorage"></param>
        /// <returns></returns>

        [Admin] public static TM_FileStorage   set_Path_XmlDatabase(this TM_FileStorage tmFileStorage)
        {
            admin.demand();
            var tmStatus = TM_Status.Current;

            try
            {
                if (tmFileStorage.isNull())
                {
                    return(null);
                }

                if (TM_FileStorage.Custom_Path_XmlDatabase.folder_Exists())
                {
                    "[TM_Server][set_Path_XmlDatabase] using TM_FileStorage.Custom_Path_XmlDatabase value".info();
                    tmFileStorage.Path_XmlDatabase = TM_FileStorage.Custom_Path_XmlDatabase;
                    return(tmFileStorage);
                }

                var webRoot = tmFileStorage.WebRoot;

                tmFileStorage.Path_XmlDatabase = null;

                var usingAppData = webRoot.contains(@"TeamMentor.UnitTests\bin") ||             // when running UnitTests under NCrunch
                                   webRoot.contains(@"site\wwwroot") ||                         // when running from Azure (or directly on IIS)
                                   tmFileStorage.using_Custom_WebRoot();                        // when the TM_FileStorage.Custom_WebRoot has been set


                if (usingAppData.isFalse())
                {
                    //calculate location and see if we can write to it

                    var xmlDatabasePath = webRoot.pathCombine(TMConsts.VIRTUAL_PATH_MAPPING)
                                          .pathCombine(TMConsts.XML_DATABASE_VIRTUAL_PATH_LEGACY)          //use by default the 'Library_Data\\XmlDatabase" value due to legacy support (pre 3.3)
                                          .fullPath();

                    if (xmlDatabasePath.createDir().dirExists() && xmlDatabasePath.canWriteToPath())
                    {
                        tmFileStorage.Path_XmlDatabase = xmlDatabasePath;                        // if can write it then make it the Path_XmlDatabase
                        tmStatus.TM_Database_Location_Using_AppData = false;
                        return(tmFileStorage);
                    }
                    "[TM_Server][set_Path_XmlDatabase] It was not possible to write to mapped folder: {0}".error(xmlDatabasePath);
                }

                var appData_Path = webRoot.pathCombine("App_Data")
                                   .pathCombine(TMConsts.XML_DATABASE_VIRTUAL_PATH)               // inside App_Data we can use the folder value 'TeamMentor'
                                   .fullPath();
                if (appData_Path.createDir().dirExists() && appData_Path.canWriteToPath())
                {
                    tmFileStorage.Path_XmlDatabase = appData_Path;                        // if can write it then make it the Path_XmlDatabase
                    tmStatus.TM_Database_Location_Using_AppData = true;
                    return(tmFileStorage);
                }

                "[TM_Server][set_Path_XmlDatabase] It was not possible to write to App_Data folder: {0}".error(appData_Path);
                //TM_Server.UseFileStorage = false;
                return(tmFileStorage);
            }
            finally
            {
                "[TM_Server][set_Path_XmlDatabase] Path_XmlDatabase set to: {0}".info(tmFileStorage.Path_XmlDatabase);
                "[TM_Server][set_Path_XmlDatabase] tmStatus.TM_Database_Location_Using_AppData:{0}".info(tmStatus.TM_Database_Location_Using_AppData);
            }
        }