Example #1
0
        async Task<DateTime?> IHtmlGetter.GetLastModifiedViaHead(string url, ProxySettings proxySettings)
        {
            HttpClient httpClient = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, url);
            HttpResponseMessage response = await httpClient.SendAsync(request);

            return response.Content.Headers.LastModified?.DateTime;
        }
        public CheckUrlHttpStatusIs200(string url, IUpdatePackage package, IHtmlGetter htmlGetter, ILogger logger, ProxySettings proxySettings = null)
        {
            _url = url;

            _package = package;
            _htmlGetter = htmlGetter;
            _logger = logger;

            _proxySettings = proxySettings;
        }
        private static ProxySettings CreateProxySettings(ServerSettings serverSettings)
        {
            ProxySettings proxySettings = null;
            if (serverSettings.CheckUrlProxySettings != null)
            {
                proxySettings = new ProxySettings();
                proxySettings.Address = serverSettings.CheckUrlProxySettings.Address;

                if (!String.IsNullOrEmpty(serverSettings.CheckUrlProxySettings.Password) && !String.IsNullOrEmpty(serverSettings.CheckUrlProxySettings.Username))
                {
                    proxySettings.Username = serverSettings.CheckUrlProxySettings.Username;
                    proxySettings.Password = serverSettings.CheckUrlProxySettings.Password;
                }
            }

            return proxySettings;
        }
Example #4
0
        HtmlDownload IHtmlGetter.DownloadFile(string url, ProxySettings proxySettings)
        {
            if (proxySettings == null)
            {
                return DownloadFile(url);
            }

            Action<WebClient> proxySettingsSetter = ((webClient) =>
            {
                webClient.Proxy = new WebProxy(proxySettings.Address);
                if (!String.IsNullOrEmpty(proxySettings.Username) && !String.IsNullOrEmpty(proxySettings.Password))
                {
                    webClient.Proxy.Credentials = new NetworkCredential(proxySettings.Username, proxySettings.Password);
                }
            });

            return DownloadFile(url, proxySettingsSetter);
        }
Example #5
0
        IEnumerable<Command> ICommandBuilder.GetCommands(string workFolder, IEnumerable<IUpdatePackage> updatePackages, IEnumerable<INotificationReceiver> notificationReceivers)
        {
            var commands = new Queue<Command>();

            foreach (var package in updatePackages)
            {
                _logger.Debug("Building commands for {PackageName}", package.PackageName);

                var checkIfNewer = new CheckIfNewer(workFolder, package, _singleFile);
                var getFile = new DeleteOldAndGetNewFile(workFolder, package, _singleFile, _logger);
                var unzipFile = new UnzipFile(workFolder, package);
                var cleanupOldUnpackedFiles = new CleanupOldUnpackedFiles(workFolder, package, _directory, _logger);

                checkIfNewer.RunAfterCompletedWithResultTrue = getFile;

                getFile.RunAfterCompletedWithResultTrue = cleanupOldUnpackedFiles;
                getFile.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, getFile, _blackboard);

                cleanupOldUnpackedFiles.RunAfterCompletedWithResultTrue = unzipFile;
                cleanupOldUnpackedFiles.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, cleanupOldUnpackedFiles, _blackboard);

                Command finalCommand = unzipFile;

                if (!package.Settings.DownloadOnly)
                {
                    var runInstallerCommand = new RunInstallerCommand(package.Settings.InstallerCommand, package.Settings.InstallerCommandArguments, workFolder,
                        package, _runExternalCommand, _logger);

                    unzipFile.RunAfterCompletedWithResultTrue = runInstallerCommand;
                    unzipFile.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, unzipFile, _blackboard);

                    finalCommand = runInstallerCommand;

                    Command updateDatabase = null;
                    if (!package.Settings.SkipDatabaseUpdate)
                    {
                        updateDatabase = new UpdateDatabase(
                            package.Settings.DatabaseUpdaterCommand, package.Settings.DatabaseUpdaterCommandArguments, package.Settings.ConnectionString,
                            workFolder,
                            package, _runExternalCommand, _logger);

                        runInstallerCommand.RunAfterCompletedWithResultTrue = updateDatabase;
                        runInstallerCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, runInstallerCommand, _blackboard);

                        finalCommand = updateDatabase;
                    }

                    if (package.Settings.CheckUrlsAfterInstallation != null)
                    {
                        ProxySettings proxySettings = null;
                        if (package.Settings.CheckUrlProxySettings != null)
                        {
                            proxySettings = new ProxySettings();
                            proxySettings.Address = package.Settings.CheckUrlProxySettings.Address;

                            if (!String.IsNullOrEmpty(package.Settings.CheckUrlProxySettings.Password) && !String.IsNullOrEmpty(package.Settings.CheckUrlProxySettings.Username))
                            {
                                proxySettings.Username = package.Settings.CheckUrlProxySettings.Username;
                                proxySettings.Password = package.Settings.CheckUrlProxySettings.Password;
                            }
                        }

                        foreach (var url in package.Settings.CheckUrlsAfterInstallation)
                        {
                            var checkUrlHttpStatusIs200 = new CheckUrlHttpStatusIs200(url, package, _htmlGetter, _logger, proxySettings);
                            finalCommand.RunAfterCompletedWithResultTrue = checkUrlHttpStatusIs200;
                            finalCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, finalCommand.Copy(), _blackboard);
                            finalCommand = checkUrlHttpStatusIs200;
                        }
                    }

                    // ggf. Versionsinfo Datei auslesen
                    if (!string.IsNullOrEmpty(package.Settings.ReadVersionInfoFrom))
                    {
                        var getVersionInfo = new GetVersionInfo(workFolder, package, package.Settings.ReadVersionInfoFrom, _singleFile, _blackboard);
                        finalCommand.RunAfterCompletedWithResultTrue = getVersionInfo;
                        finalCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, finalCommand.Copy(), _blackboard);
                        finalCommand = getVersionInfo;
                    }
                }

                // Entpacktes Verzeichnis löschen (anhängen immer an finalCommand)
                var cleanupOldAfterDeployment = new CleanupOldUnpackedFiles(workFolder, package, _directory, _logger);
                finalCommand.RunAfterCompletedWithResultTrue = cleanupOldAfterDeployment;
                finalCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, finalCommand.Copy(), _blackboard);
                finalCommand = cleanupOldAfterDeployment;

                // Abschließende Nachricht verschicken (anhängen immer an finalCommand)
                var sendNotifications = new SendNotifications(notificationReceivers, package.Settings.DownloadOnly, package.Settings.SkipDatabaseUpdate, package, _nowGetter, _blackboard);
                finalCommand.RunAfterCompletedWithResultTrue = sendNotifications;
                finalCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, finalCommand.Copy(), _blackboard);
                finalCommand = sendNotifications;

                // Blackboard aufräumen für unser package
                var cleanupBlackboard = new CleanupBlackboard(package, _blackboard);
                finalCommand.RunAfterCompletedWithResultTrue = cleanupBlackboard;
                finalCommand.RunAfterCompletedWithResultFalse = new SendErrorNotifications(notificationReceivers, finalCommand.Copy(), _blackboard);
                finalCommand = cleanupBlackboard;

                commands.Enqueue(checkIfNewer); // mit checkIfNewer beginnt die Abarbeitungskette
            }

            return commands;
        }
 IUpdatePackageAccess IUpdatePackageAccessFactory.CreateHttpDownloadAccess(string url, IHtmlGetter htmlGetter, ProxySettings proxySettings)
 {
     return new HttpDownloadAccess(url, htmlGetter, proxySettings);
 }
 IUpdatePackageAccess IUpdatePackageAccessFactory.CreateHttpDownloadAccess(string url, IHtmlGetter htmlGetter, ProxySettings proxySettings)
 {
     ++CreateHttpDownloadAccessCalled;
     return CreateHttpDownloadAccess[url];
 }
 public HttpDownloadAccess(string url, IHtmlGetter htmlGetter, ProxySettings proxySettings = null)
 {
     _url = url;
     _htmlGetter = htmlGetter;
     _proxySettings = proxySettings;
 }