コード例 #1
0
        protected override async Task OnTimer()
        {
            try
            {
                //Skip if network not available
                if (!NetworkStatus.CanDownload(_downloadNetworkPriority))
                {
                    _logger?.LogInformation($"Skip package download due to network not allowed to download.");
                    return;
                }

                _logger?.LogDebug($"Running package updater. Downloading {this.PackageVersion}.");
                PackageVersionInfo packageVersion = await GetPackageVersionInformation();

                var     desiredVersion   = UpdateUtility.ParseVersion(packageVersion.Version);
                Version installedVersion = GetInstalledVersion();
                if (desiredVersion.CompareTo(installedVersion) != 0)
                {
                    _logger?.LogInformation($"The desired version of {desiredVersion} is different to installed version {installedVersion}.");
                    await DownloadAndInstallNewVersionAsync(packageVersion);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError($"Error download {this.PackageVersion}. Exception: {ex.ToMinimized()}");
            }
        }
コード例 #2
0
        internal async Task <PackageVersionInfo> GetPackageVersionInformation()
        {
            string packageVersionString;

            if (!this.PackageVersion.Contains("execute-api")) // check if using AutoUpdate service
            {
                var packageVersionDownloader = UpdateUtility.CreateDownloaderFromUrl(this.PackageVersion, _context);
                packageVersionString = await packageVersionDownloader.ReadFileAsStringAsync(this.PackageVersion);
            }
            else
            {
                var autoUpdateServiceClient = new AutoUpdateServiceClient(this.httpClient);
                var request = new GetVersionRequest
                {
                    AgentId    = Utility.HostName, // use fqdn as unique agent id
                    ProductKey = this.productKey,
                    Ring       = this.ring,
                    Version    = this.GetInstalledVersion().ToString()
                };
                packageVersionString = await autoUpdateServiceClient.GetVersionAsync(this.PackageVersion, request, this.region, this.credential);
            }

            var packageVersion = UpdateUtility.ParsePackageVersion(packageVersionString);

            return(packageVersion);
        }
コード例 #3
0
        /// <summary>
        /// Get the latest version information based on the PackageVersion location.
        /// </summary>
        /// <returns>an instance of <see cref="PackageVersionInfo"/> object.</returns>
        internal async Task <PackageVersionInfo> GetPackageVersionInformation()
        {
            string packageVersionString;

            if (!PackageVersion.Contains("execute-api")) // check if using AutoUpdate service
            {
                var packageVersionDownloader = UpdateUtility.CreateDownloaderFromUrl(PackageVersion, _context);
                packageVersionString = await packageVersionDownloader.ReadFileAsStringAsync(PackageVersion);
            }
            else
            {
                var autoUpdateServiceClient = new AutoUpdateServiceClient(httpClient);
                var request = new GetVersionRequest
                {
                    TenantId       = productKey,
                    AutoUpdateLane = deploymentStage
                };

                packageVersionString = await autoUpdateServiceClient.GetVersionAsync(PackageVersion, request, region, credential);
            }

            var packageVersion = UpdateUtility.ParsePackageVersion(packageVersionString);

            return(packageVersion);
        }
コード例 #4
0
        protected async override Task OnTimer()
        {
            try
            {
                //Skip if network not available
                if (_networkStatus?.CanDownload(_downloadNetworkPriority) != true)
                {
                    _logger?.LogInformation($"Skip configuration download due to network not allowed to download.");
                    return;
                }

                _logger?.LogDebug($"Running config updater. Downloading {this.Source}.");
                var    configDownloader = UpdateUtility.CreateDownloaderFromUrl(this.Source, _context);
                string newConfig        = await configDownloader.ReadFileAsStringAsync(this.Source);

                string configPath = UpdateUtility.ResolvePath(this.Destination);
                if (!File.Exists(configPath) || !newConfig.Equals(File.ReadAllText(configPath)))
                {
                    _logger?.LogInformation($"Config file changed. Updating configuration file.");
                    File.WriteAllText(configPath, newConfig);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError($"Error download {this.Source}. Exception: {ex.ToMinimized()}");
            }
        }
コード例 #5
0
        private async Task <PackageVersionInfo> GetPackageVersionInformation()
        {
            var    packageVersionDownloader = UpdateUtility.CreateDownloaderFromUrl(this.PackageVersion, _context);
            string packageVersionString     = await packageVersionDownloader.ReadFileAsStringAsync(this.PackageVersion);

            var packageVersion = UpdateUtility.ParsePackageVersion(packageVersionString);

            return(packageVersion);
        }
コード例 #6
0
 /// <summary>
 /// Check for agent update. It will trigger agent update if the desired version is different than the current running version.
 /// </summary>
 internal async Task CheckAgentUpdates()
 {
     _logger?.LogDebug($"Running package updater. Downloading {this.PackageVersion}.");
     PackageVersionInfo packageVersion = await GetPackageVersionInformation();
     var desiredVersion = UpdateUtility.ParseVersion(packageVersion.Version);
     Version installedVersion = GetInstalledVersion();
     if (desiredVersion.CompareTo(installedVersion) != 0)
     {
         _logger?.LogInformation($"The desired version of {desiredVersion} is different to installed version {installedVersion}.");
         await this.packageInstaller.DownloadAndInstallNewVersionAsync(packageVersion);
     }
 }
コード例 #7
0
 private Version GetInstalledVersion()
 {
     try
     {
         //Enhance this method if we want to use it to install program other than KinesisTap.
         //We will need a new mechanism to check if the package is installed and get the installed version
         return(UpdateUtility.ParseVersion(ProgramInfo.GetKinesisTapVersion().FileVersion));
     }
     catch (Exception e)
     {
         _logger?.LogError($"Failed to get installed version: '{e}'");
         return(new Version("1.0.0")); // This is for TestIntegrationWithAutoUpdateService Unit test to pass
     }
 }
コード例 #8
0
        protected override async Task OnTimer()
        {
            try
            {
                _logger?.LogDebug($"Running package updater. Downloading {this.PackageVersion}.");
                PackageVersionInfo packageVersion = await GetPackageVersionInformation();

                var     desiredVersion   = UpdateUtility.ParseVersion(packageVersion.Version);
                Version installedVersion = GetInstalledVersion();
                if (desiredVersion.CompareTo(installedVersion) != 0)
                {
                    _logger?.LogInformation($"The desired version of {desiredVersion} is different to installed version {installedVersion}.");
                    await DownloadAndInstallNewVersionAsync(packageVersion);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError($"Error download {this.PackageVersion}. Exception: {ex.ToAsyncString()}");
            }
        }
コード例 #9
0
        protected async override Task OnTimer()
        {
            try
            {
                _logger?.LogDebug($"Running config updater. Downloading {this.Source}.");
                var    configDownloader = UpdateUtility.CreateDownloaderFromUrl(this.Source, _context);
                string newConfig        = await configDownloader.ReadFileAsStringAsync(this.Source);

                string configPath = UpdateUtility.ResolvePath(this.Destination);
                if (!File.Exists(configPath) || !newConfig.Equals(File.ReadAllText(configPath)))
                {
                    _logger?.LogInformation($"Config file changed. Updating configuration file.");
                    File.WriteAllText(configPath, newConfig);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError($"Error download {this.Source}. Exception: {ex.ToMinimized()}");
            }
        }
コード例 #10
0
        /// <summary>
        /// Download the new version of KinesisTap build using package Url and install it.
        /// </summary>
        /// <param name="packageVersion">an instance of <see cref="PackageVersionInfo"/> object.</param>
        public async Task DownloadAndInstallNewVersionAsync(PackageVersionInfo packageVersion)
        {
            //Upload the new version
            string packageUrl = packageVersion.PackageUrl.Replace("{Version}", packageVersion.Version);
            string extension  = Path.GetExtension(packageUrl).ToLower();

            if (!IsExtensionSuportedByPlatform(extension))
            {
                _logger.LogWarning($"Extension {extension} is not supported on {Utility.Platform}");
                return;
            }
            _logger?.LogInformation($"Downloading {packageVersion.Name} version {packageVersion.Version} from {packageUrl}...");

            IFileDownloader downloader = UpdateUtility.CreateDownloaderFromUrl(packageUrl, this._context);

            string updateDirectory = Path.Combine(Utility.GetKinesisTapProgramDataPath(), "update");

            if (!Directory.Exists(updateDirectory))
            {
                Directory.CreateDirectory(updateDirectory);
            }
            string downloadPath = Path.Combine(updateDirectory, Path.GetFileName(packageUrl));

            if (File.Exists(downloadPath))
            {
                File.Delete(downloadPath);
            }
            await downloader.DownloadFileAsync(packageUrl, downloadPath);

            _logger?.LogInformation($"Package downloaded to {downloadPath}. Expanding package...");

            if (EXT_NUPKG.Equals(extension))
            {
                await InstallNugetPackageAsync(downloadPath);
            }
            else
            {
                await InstallPackageAsync(downloadPath);
            }
        }
コード例 #11
0
        private async Task DownloadAndInstallNewVersionAsync(PackageVersionInfo packageVersion)
        {
            //Upload the new version
            string packageUrl = packageVersion.PackageUrl.Replace("{Version}", packageVersion.Version);

            _logger?.LogInformation($"Downloading {packageVersion.Name} version {packageVersion.Version} from {packageUrl}...");
            IFileDownloader downloader      = UpdateUtility.CreateDownloaderFromUrl(packageUrl, this._context);
            string          updateDirectory = Path.Combine(Utility.GetKinesisTapProgramDataPath(), "update");

            if (!Directory.Exists(updateDirectory))
            {
                Directory.CreateDirectory(updateDirectory);
            }
            string downloadPath = Path.Combine(updateDirectory, $"KinesisTap.{packageVersion.Version}.nupkg");

            if (File.Exists(downloadPath))
            {
                File.Delete(downloadPath);
            }
            await downloader.DownloadFileAsync(packageUrl, downloadPath);

            _logger?.LogInformation($"Package downloaded to {downloadPath}. Expanding package...");

            //Expand the new version
            string expandDirectory = downloadPath.Substring(0, downloadPath.Length - 6); //less ".nupkg"

            if (Directory.Exists(expandDirectory))
            {
                Directory.Delete(expandDirectory, true);
            }
            ZipFile.ExtractToDirectory(downloadPath, expandDirectory);

            //Execute the ChocoInstall.ps1 out of process so that it can restart KinesisTap
            string installScriptPath = Path.Combine(expandDirectory, @"tools\chocolateyinstall.ps1");

            _logger?.LogInformation($"Executing installation script {installScriptPath}...");
            await ExecutePowershellOutOfProcessAsync(installScriptPath);
        }
コード例 #12
0
 private Version GetInstalledVersion()
 {
     //Enhance this method if we want to use it to install program other than KinesisTap.
     //We will need a new mechanism to check if the package is installed and get the installed version
     return(UpdateUtility.ParseVersion(ProgramInfo.GetKinesisTapVersion().FileVersion));
 }