示例#1
0
 public static void UpdateIfOld()
 {
     try
     {
         var isEnabledSelfUpdate = CementSettingsRepository.Get().IsEnabledSelfUpdate;
         if (isEnabledSelfUpdate.HasValue && !isEnabledSelfUpdate.Value)
         {
             return;
         }
         var lastUpdate = Helper.GetLastUpdateTime();
         var now        = DateTime.Now;
         var diff       = now - lastUpdate;
         if (diff <= TimeSpan.FromHours(5))
         {
             return;
         }
         isAutoUpdate = true;
         var exitCode = new SelfUpdateCommand().Run(new[] { "self-update" });
         if (exitCode != 0)
         {
             Log.LogError("Auto update cement failed. 'self-update' exited with code '{Code}'", exitCode);
             ConsoleWriter.Shared.WriteWarning("Auto update failed. Check previous warnings for details");
         }
     }
     catch (Exception exception)
     {
         Log.LogError(exception, "Auto update failed, error: '{ErrorMessage}'", exception.Message);
         ConsoleWriter.Shared.WriteWarning("Auto update failed. Check logs for details");
     }
 }
示例#2
0
    private static void SearchAndSaveBranchInSettings(ref string server, ref string branch)
    {
        var settings = CementSettingsRepository.Get();

        if (branch != null)
        {
            settings.SelfUpdateTreeish = branch;
        }
        else
        {
            branch = settings.SelfUpdateTreeish;
        }

        if (server != null)
        {
            var uri = new Uri(server);
            settings.CementServer = uri.ToString();
        }
        else
        {
            server = settings.CementServer;
        }

        CementSettingsRepository.Save(settings);
    }
示例#3
0
        protected override int Execute()
        {
            var cmd = CementSettingsRepository.Get().UserCommands[arguments[0]];

            Log.LogDebug("Run command " + arguments[0] + ": '" + cmd + "'");
            if (arguments.Length > 1)
            {
                arguments = arguments.Skip(1).ToArray();
                cmd       = string.Format(cmd, arguments);
            }

            return(Run(cmd));
        }
示例#4
0
        private static int Run(string[] args)
        {
            var commands = CommandsList.Commands;

            if (commands.ContainsKey(args[0]))
            {
                return(commands[args[0]].Run(args));
            }

            if (CementSettingsRepository.Get().UserCommands.ContainsKey(args[0]))
            {
                return(new UserCommand().Run(args));
            }

            ConsoleWriter.Shared.WriteError("Bad command: '" + args[0] + "'");
            return(-1);
        }
示例#5
0
        private void UpdateCementServerIfRequestWasRedirected(Uri requestUri, Uri effectiveRequestUri)
        {
            if (requestUri == effectiveRequestUri)
            {
                return;
            }

            log.LogDebug("Request was redirected, '{RequestUri}' -> '{NewRequestUri}'", requestUri, effectiveRequestUri);

            var newServerUri = effectiveRequestUri.GetLeftPart(UriPartial.Authority);

            log.LogDebug("New server url: {CementServerUri}", newServerUri);

            var settings = CementSettingsRepository.Get();

            settings.CementServer = newServerUri;

            CementSettingsRepository.Save(settings);

            consoleWriter.WriteInfo($"CementServer has been updated: {Name} => {newServerUri}");
            Name = newServerUri;
        }
示例#6
0
 public BuildSectionParser()
     : this(CementSettingsRepository.Get())
 {
 }