예제 #1
0
 public ExecutableResult Execute(string value)
 {
     try
     {
         Statics.ShouldPollXenStore = false;
         _logger.Log(String.Format("Updater Update value: {0}\r\nWill resume in 60 seconds", value));
         _sleeper.Sleep(60);
         _connectionChecker.Check();
         var agentUpdateInfo = _agentUpdateMessageHandler.Handle(value);
         _downloader.Download(agentUpdateInfo.url, Constants.UpdaterReleasePackage);
         _checksumValidator.Validate(agentUpdateInfo.signature, Constants.UpdaterReleasePackage);
         _unzipper.Unzip(Constants.UpdaterReleasePackage, Constants.UpdaterUnzipPath, "");
         _serviceStopper.Stop("RackspaceCloudServersAgentUpdater");
         _fileCopier.CopyFiles(Constants.UpdaterUnzipPath, Constants.UpdaterPath, _logger);
         _serviceStarter.Start("RackspaceCloudServersAgentUpdater");
         Statics.ShouldPollXenStore = true;
         return(new ExecutableResult());
     }
     catch (Exception ex)
     {
         _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
         return(new ExecutableResult {
             Error = new List <string> {
                 "Update failed"
             }, ExitCode = "1"
         });
     }
     finally
     {
         _finalizer.Finalize(new List <string> {
             Constants.UpdaterUnzipPath, Constants.UpdaterReleasePackage
         });
     }
 }
        public Task Start(bool isLoop = true)
        {
            return(Task.Run(() =>
            {
                do
                {
                    var setting = parameterHelper.GetSetting <CacheSettings>();

                    RetentionCategory[] categories =
                    {
                        new RetentionCategory(setting.RetentionSpanUsageCopyAb,              CacheRetentionCategory.UsageCopyAB),
                        new RetentionCategory(setting.RetentionSpanUsageCopyBarOrAS,         CacheRetentionCategory.UsageCopyBarOrAS),
                        new RetentionCategory(setting.RetentionSpanUsageCopyEb,              CacheRetentionCategory.UsageCopyEB),
                        new RetentionCategory(setting.RetentionSpanUsageCopyPublic,          CacheRetentionCategory.UsageCopyPublic),
                        new RetentionCategory(setting.RetentionSpanUsageCopyBenutzungskopie, CacheRetentionCategory.UsageCopyBenutzungskopie)
                    };

                    foreach (var category in categories.Where(c => c.RetentionSpan != TimeSpan.MaxValue))
                    {
                        var catDir = Path.Combine(Properties.CacheSettings.Default.BaseDirectory, category.CacheRetentionCategory.ToString());
                        try
                        {
                            foreach (var fileName in fileSystem.Directory.GetFiles(catDir))
                            {
                                var fi = fileSystem.FileInfo.FromFileName(fileName);
                                DateTime fileTime;

                                if (category.CacheRetentionCategory == CacheRetentionCategory.UsageCopyEB)
                                {
                                    fileTime = fi.LastAccessTime;
                                }
                                else
                                {
                                    fileTime = fi.CreationTime;
                                }

                                if (fileTime < DateTime.Now - category.RetentionSpan)
                                {
                                    try
                                    {
                                        fileSystem.File.Delete(fileName);
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Warning(ex, "Can't delete File '" + fileName + "'");
                                    }
                                }
                            }
                        }
                        catch (DirectoryNotFoundException)
                        {
                            Log.Warning("Directory not found: " + catDir);
                        }
                    }

                    sleeper.Sleep(TimeSpan.FromMinutes(15));
                } while (isLoop);
            }));
        }
예제 #3
0
 public override async Task AfterEnter()
 {
     // Expire after the specified amount of time
     await Task.Factory.StartNew(async() => {
         await _sleeper
         .Sleep(_timeout)
         .ContinueWith(previous => _projectionSystem.InvalidateProjection())
         .ConfigureAwait(false);
     }, CancellationToken.None, TaskCreationOptions.LongRunning, _taskScheduler)
     .ConfigureAwait(false);
 }
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();

                logger.LogInformation($"Running at: { DateTimeOffset.Now }");
                await sleeper.SleepAsync(cancellationToken);

                logger.LogInformation($"Running at: { DateTimeOffset.Now }");
                sleeper.Sleep();
            }
        }
예제 #5
0
 public ExecutableResult Execute(string value)
 {
     try
     {
         Statics.ShouldPollXenStore = false;
         _logger.Log(String.Format("XenTools Update value: {0}\r\nWill resume in 60 seconds", value));
         _sleeper.Sleep(60);
         var agentUpdateInfo = _agentUpdateMessageHandler.Handle(value);
         _downloader.Download(agentUpdateInfo.url, Constants.XenToolsReleasePackage);
         _checksumValidator.Validate(agentUpdateInfo.signature, Constants.XenToolsReleasePackage);
         _unzipper.Unzip(Constants.XenToolsReleasePackage, Constants.XenToolsUnzipPath, "");
         _installer.Install(new Dictionary <string, string>
         {
             { Constants.XenToolsSetupExecutablePath,
               String.Format("/S /norestart /D={0}", Constants.XenToolsPath) }
         });
         _serviceRestarter.Restart("xensvc");
         if (_serviceRestarter.ServiceExists("XenServerVssProvider"))
         {
             _serviceRestarter.Restart("XenServerVssProvider");
         }
         return(new ExecutableResult());
     }
     catch (Exception ex)
     {
         _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
         return(new ExecutableResult {
             Error = new List <string> {
                 "Update failed"
             }, ExitCode = "1"
         });
     }
     finally
     {
         Statics.ShouldPollXenStore = true;
         _finalizer.Finalize(new List <string> {
             Constants.XenToolsUnzipPath, Constants.XenToolsReleasePackage
         });
     }
 }
        public ExecutableResult Execute(string value)
        {
            try
            {
                Statics.ShouldPollXenStore = false;
                _logger.Log(String.Format("XenTools Update value: {0}\r\nWill resume in 60 seconds", value));
                _sleeper.Sleep(60);
                var agentUpdateInfo = _agentUpdateMessageHandler.Handle(value);
                _finalizer.Finalize(new List <string> {
                    Constants.XenToolsUnzipPath, Constants.XenToolsReleasePackage
                });
                _downloader.Download(agentUpdateInfo.url, Constants.XenToolsReleasePackage);
                _checksumValidator.Validate(agentUpdateInfo.signature, Constants.XenToolsReleasePackage);
                _unzipper.Unzip(Constants.XenToolsReleasePackage, Constants.XenToolsUnzipPath, "");

                if (IsCustomPackage())
                {
                    RunCustomPackage();
                }
                else
                {
                    RunLegacyUpdate();
                }

                return(new ExecutableResult());
            }
            catch (Exception ex)
            {
                _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
                return(new ExecutableResult {
                    Error = new List <string> {
                        "Update failed"
                    }, ExitCode = "1"
                });
            }
            finally
            {
                Statics.ShouldPollXenStore = true;
            }
        }
예제 #7
0
        public ExecutableResult Execute(string value)
        {
            var backupCreated = false;

            try
            {
                Statics.ShouldPollXenStore = false;
                string         versionNumber = _versionChecker.Check(Version.AGENT_UPDATER_PATH);
                System.Version version;

                try
                {
                    version = new System.Version(versionNumber);
                }
                catch (Exception ex)
                {
                    _logger.Log(string.Format("Version check failed, installing embedded updater.  Version Reported: {0}  Stack Trace: {1}", versionNumber, ex));
                    version = new System.Version("0.0.0.0");
                }

                if (version < UpdaterFiles.Updater.MinimumVersion)
                {
                    _logger.Log(String.Format("Updating the Agent Updater... \r\nWill resume in 10 seconds..."));
                    _sleeper.Sleep(10);
                    _extractEmbededResource.Extract(SvcConfiguration.AgentVersionUpdatesPath, Constants.UpdaterEmbeddedReleasePackagePath, Constants.UpdaterReleasePackageName);
                    _logger.Log("Waiting to unzip package.");
                    _unzipper.Unzip(Constants.UpdaterReleasePackage, Constants.UpdaterUnzipPath, "");
                    _serviceStopper.Stop("RackspaceCloudServersAgentUpdater");
                    _backupUpdater.Backup(Constants.UpdaterPath, Constants.UpdaterBackupPath);
                    backupCreated = true;
                    _fileCopier.CopyFiles(Constants.UpdaterUnzipPath, Constants.UpdaterPath, _logger);
                }
                else
                {
                    _logger.Log(string.Format("Agent Updater Version: {0}  detected, not updating updater.", version));
                }

                return(new ExecutableResult());
            }
            catch (Exception ex)
            {
                try
                {
                    if (backupCreated)
                    {
                        _serviceStopper.Stop("RackspaceCloudServersAgentUpdater");
                        _backupUpdater.Restore(Constants.UpdaterPath, Constants.UpdaterBackupPath);
                    }
                }
                catch (Exception exRestore)
                {
                    _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", exRestore.Message, exRestore.StackTrace));
                }

                _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
                return(new ExecutableResult {
                    Error = new List <string> {
                        "Update failed"
                    }, ExitCode = "1"
                });
            }
            finally
            {
                Statics.ShouldPollXenStore = true;
                _serviceStarter.Start("RackspaceCloudServersAgentUpdater");
                _finalizer.Finalize(new List <string> {
                    Constants.UpdaterUnzipPath, Constants.UpdaterReleasePackage
                });
            }
        }
예제 #8
0
        public void Write(string text)
        {
            _console.CursorVisible = false;

            _console.ForegroundColour = AppSettings.Instance.ColourScheme.Normal;

            for (var i = 0; i < text.Length; i++)
            {
                var j = 0;

                while (i + j < text.Length && text[i + j] != ' ')
                {
                    j++;
                }

                if (_console.CursorLeft + j >= _console.WindowWidth)
                {
                    _console.Write('\n');
                }

                if (text[i] == '<')
                {
                    if (text[i + 1] == '/')
                    {
                        while (text[i] != '>')
                        {
                            i++;
                        }

                        _console.ForegroundColour = AppSettings.Instance.ColourScheme.Normal;

                        continue;
                    }

                    i++;

                    var markup = new StringBuilder();

                    while (text[i] != '>')
                    {
                        markup.Append(text[i]);

                        i++;
                    }

                    ConsoleColor colour;

                    switch (markup.ToString().ToLower())
                    {
                    case "b":
                        colour = AppSettings.Instance.ColourScheme.Bold;
                        break;

                    case "i":
                        colour = AppSettings.Instance.ColourScheme.Italic;
                        break;

                    case "u":
                        colour = AppSettings.Instance.ColourScheme.Underline;
                        break;

                    case "c":
                        colour = AppSettings.Instance.ColourScheme.Caps;
                        break;

                    case "br":
                        _console.Write("\n\n");

                        while (i + 1 < text.Length && text[i + 1] == ' ')
                        {
                            i++;
                        }

                        continue;

                    default:
                        colour = AppSettings.Instance.ColourScheme.Normal;
                        break;
                    }

                    _console.ForegroundColour = colour;

                    continue;
                }

                _console.Write(text[i]);

                if (!_console.KeyAvailable)
                {
                    _sleeper.Sleep(text[i] == '\n'
                                       ? AppSettings.Instance.LineBreakDelay
                                       : AppSettings.Instance.TextDelay);
                }
            }
        }