Beispiel #1
0
 [Admin] public void             CheckIfServerIsOnline()
 {
     if (SkipServerOnlineCheck)
     {
         return;
     }
     ServerOnline = MiscUtils.online();              // only check this once
 }
Beispiel #2
0
        public static TM_UserData   load_UserData_FromGitRepo(this TM_UserData userData)
        {
            try
            {
                var gitConfig = userData.tmConfig().Git;
                if (gitConfig.UserData_Git_Enabled.isFalse())
                {
                    return(userData);
                }

                var gitLocation = TM_Xml_Database.Current.TM_Server_Config.getActive_UserData_Repo_GitPath();
                if (gitLocation.valid())
                {
                    //Adjust Path_UserData so that there is an unique folder per repo
                    var extraFolderName = "_Git_";

                    // extra mode to switch of multiple Git_Hosting in same server
                    extraFolderName += gitLocation.replace("\\", "/").split("/").last().remove(".git").safeFileName();

                    userData.Path_UserData = userData.Path_UserData_Base + extraFolderName;
                    //userData.Path_UserData.createDir();
                    "[handleExternalGitPull] userData.Path_UserData set to: {0}".debug(userData.Path_UserData);

                    if (MiscUtils.online().isFalse())
                    {
                        return(userData);
                    }

                    if (userData.Path_UserData.isGitRepository())
                    {
                        if (gitConfig.UserData_Auto_Pull.isFalse())     //skip if this is set
                        {
                            return(userData);
                        }

                        "[TM_UserData][GitPull]".info();
                        var nGit = userData.Path_UserData.git_Open();
                        nGit.pull();
                        //var nGit = userData.Path_UserData.git_Pull();
                        userData.pushUserRepository(nGit);
                    }
                    else
                    {
                        var start = DateTime.Now;
                        "[TM_UserData][GitClone] Start".info();
                        gitLocation.git_Clone(userData.Path_UserData);
                        "[TM_UserData][GitClone] in ".info(start.duration_To_Now());
                    }
                }
            }
            catch (Exception ex)
            {
                ex.log("[handleExternalGitPull]");
            }
            return(userData);
        }
Beispiel #3
0
        public static TM_UserData   handle_External_GitPull(this TM_UserData userData)
        {
            try
            {
                //var gitLocationFile = HttpContextFactory.Server.MapPath("gitUserData.config");
                var gitLocationFile = TMConfig.Current.getGitUserConfigFile();
                if (gitLocationFile.fileExists())
                {
                    "[TM_UserData][handleExternalGitPull] found gitConfigFile: {0}".info(gitLocationFile);
                    var gitLocation = gitLocationFile.fileContents();
                    if (gitLocation.notValid())
                    {
                        return(userData);
                    }
                    //if (userData.Path_UserData.dirExists() && userData.Path_UserData.files().empty())
                    //    userData.Path_UserData.delete_Folder();

                    //Adjust Path_UserData so that there is an unique folder per repo
                    var extraFolderName = "_Git_";

                    // extra mode to switch of multiple Git_Hosting in same server
                    extraFolderName += gitLocation.replace("\\", "/").split("/").last().remove(".git").safeFileName();

                    userData.Path_UserData = userData.Path_UserData_Base + extraFolderName;
                    //userData.Path_UserData.createDir();
                    "[handleExternalGitPull] userData.Path_UserData set to: {0}".debug(userData.Path_UserData);

                    if (MiscUtils.online().isFalse())
                    {
                        return(userData);
                    }

                    if (userData.Path_UserData.isGitRepository())
                    {
                        "[TM_UserData][GitPull]".info();
                        var nGit = userData.Path_UserData.git_Pull();
                        userData.pushUserRepository(nGit);
                    }
                    else
                    {
                        var start = DateTime.Now;
                        "[TM_UserData][GitClone] Start".info();
                        gitLocation.git_Clone(userData.Path_UserData);
                        "[TM_UserData][GitClone] in ".info(start.duration_to_Now());
                    }
                }
            }
            catch (Exception ex)
            {
                ex.log("[handleExternalGitPull]");
            }
            return(userData);
        }
Beispiel #4
0
        public static TM_Xml_Database setupGitSupport(this TM_Xml_Database tmDatabase)
        {
            if (tmDatabase.AutoGitCommit)
            {
                var online = MiscUtils.online();
                if (online)
                {
                    "[TM_Xml_Database] [setupGitSupport] we are online, so git Pull and Pull will be attempted".info();
                }
                else
                {
                    "[TM_Xml_Database] [setupGitSupport] we are offline, so no git Pull and Pulls".info();
                }
                foreach (var library in tmDatabase.tmLibraries())
                {
                    var libraryPath = tmDatabase.xmlDB_Path_Library_XmlFile(library).parentFolder();
                    if (libraryPath.isGitRepository())
                    {
                        var nGit = libraryPath.git_Open();
                        if (online)
                        {
                            try
                            {
                                "[TM_Xml_Database] [setupGitSupport] doing git Pull and Push for: {0}".debug(libraryPath.folderName());
                                nGit.pull();
                                nGit.push();
                            }
                            catch (Exception ex)
                            {
                                ex.log();
                            }
                        }
                        tmDatabase.NGits.Add(nGit);
                    }
                    else
                    {
                        "[TM_Xml_Database] [setupGitSupport]  library {0} is currently not a git repo".info(libraryPath.folderName());
                    }
                }
                tmDatabase.triggerGitCommit();

                /*tmDatabase.NGit = tmDatabase.Path_XmlLibraries.isGitRepository()
                 *                      ? tmDatabase.Path_XmlLibraries.git_Open()
                 *                      : tmDatabase.Path_XmlLibraries.git_Init();
                 * tmDatabase.triggerGitCommit();*/
            }
            return(tmDatabase);
        }
Beispiel #5
0
 public static TM_Xml_Database handle_UserData_GitLibraries(this TM_Xml_Database tmDatabase)
 {
     try
     {
         if (MiscUtils.online())
         {
             "[TM_Xml_Database] [handle_UserData_GitLibraries] online, so checking for TM UserData repos to clone".info();
         }
         else
         {
             "[TM_Xml_Database] [handle_UserData_GitLibraries] online".info();
         }
         foreach (var gitLibrary in tmDatabase.UserData.SecretData.Libraries_Git_Repositories)
         {
             if (gitLibrary.regEx("Lib_.*.git"))
             {
                 var libraryName  = gitLibrary.split("Lib_").last().remove(".git").replace("_", " ");
                 var targetFolder = tmDatabase.Path_XmlLibraries.pathCombine(libraryName);
                 if (targetFolder.dirExists().isFalse())
                 {
                     "[TM_Xml_Database] [handle_UserData_GitLibraries] cloning {0}".info(libraryName);
                     tmDatabase.clone_Library(gitLibrary, targetFolder);
                     //gitLibrary.git_Clone(targetFolder);
                 }
                 else
                 {
                     "[TM_Xml_Database] [handle_UserData_GitLibraries] skipping git clone since there was already a library called: {0}".info(libraryName);
                 }
             }
             else
             {
                 "[handle_UserData_GitLibraries] provided git library didn't fit expected format (it should be called Lib_{LibName}.git, and it was: {0}".error(gitLibrary);
             }
         }
     }
     catch (Exception ex)
     {
         ex.log("handle_UserData_GitLibraries");
     }
     return(tmDatabase);
 }
Beispiel #6
0
 public void Tests_Consts_Static_Value()
 {
     Assert.AreEqual(Tests_Consts.offline, MiscUtils.online().isFalse());
 }