Exemplo n.º 1
0
 public PackageVersionsViewModel(string packageName, IEnumerable<string> inner, string currentInstalledVersion, InstallationTask currentInstallTask)
 {
     PackageName = packageName;
     CurrentInstalledVersion = currentInstalledVersion;
     CurrentInstallTask = currentInstallTask;
     CachedVersions = new List<string>(inner);
 }
Exemplo n.º 2
0
        public static AgentStatusReport BuildStatus(IPackagesList availablePackages, ILocalPackageCache packageCache, IInstalledPackageArchive installCache, RunningInstallationTaskList runningTasks, IAgentSettingsManager settingsManager, ICurrentlyDownloadingList currentlyDownloadingList, CompletedInstallationTaskList completedInstallations)
        {
            // copying these collections to variables because sometimes they get modified while building the status report object
            string[] updating = new string[currentlyDownloadingList != null ? currentlyDownloadingList.Count : 0];
            if (currentlyDownloadingList != null) currentlyDownloadingList.CopyTo(updating, 0);

            IPackage[] packages = new IPackage[availablePackages != null ? availablePackages.Count : 0];
            if (availablePackages != null) availablePackages.CopyTo(packages, 0);

            var watchedPackageList = availablePackages.GetWatched().ToList();
            IPackage[] watchedPackages = new IPackage[watchedPackageList != null ? watchedPackageList.Count : 0];
            if (watchedPackageList != null) watchedPackageList.CopyTo(watchedPackages);

            InstallationTask[] tasks=new InstallationTask[runningTasks != null ? runningTasks.Count : 0];
            if (runningTasks != null) runningTasks.CopyTo(tasks);

            var status = new AgentStatusReport
                       {
                           packages = BuildPackageInformation(watchedPackages, installCache, tasks, completedInstallations),
                           currentTasks = tasks.Select(t =>
                                                           {
                                                               var installation = new InstallTaskViewModel();
                                                               installation.Messages =
                                                                   t.ProgressReports.Select(pr => pr.Message).ToArray();
                                                               if (t.Task != null)
                                                               {
                                                                   installation.Status =
                                                                       Enum.GetName(typeof (TaskStatus), t.Task.Status);
                                                               }
                                                               installation.PackageId = t.PackageId;
                                                               installation.Version = t.Version;
                                                               installation.LastMessage = t.ProgressReports.Count > 0
                                                                                              ? t.ProgressReports.
                                                                                                    LastOrDefault().
                                                                                                    Message
                                                                                              : "";
                                                               return installation;
                                                           }).ToList(),
                           availableVersions = packages.Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s).ToList(),
                           environment = settingsManager.Settings.DeploymentEnvironment,
                           updating = updating.ToList(),
                           isUpdating = currentlyDownloadingList.Downloading
                       };

            status.OutOfDate =
                status.packages.Any(p => p.OutOfDate);

            return status;
        }
Exemplo n.º 3
0
        private void StartInstall(InstallationTask nextPendingInstall)
        {
            nextPendingInstall.Task = new Task<InstallationResult>(() =>
            {
                _deploymentService.InstallPackage(nextPendingInstall.PackageId, nextPendingInstall.Version, Guid.NewGuid().ToString(), new CancellationTokenSource(),
                                                    progressReport => HandleProgressReport(nextPendingInstall, progressReport));
                return new InstallationResult();
            });

            nextPendingInstall.Task
                .ContinueWith(RemoveFromRunningInstallationList)
                .ContinueWith(task => Logger.Error("Installation task failed.", task.Exception), TaskContinuationOptions.OnlyOnFaulted);

            nextPendingInstall.Task.Start();
        }
Exemplo n.º 4
0
        private void HandleProgressReport(InstallationTask installationTask, ProgressReport progressReport)
        {
            Level level;
            switch (progressReport.Level)
            {
                case "Debug":
                    level = Level.Debug;
                    break;
                case "Warn":
                    level = Level.Warn;
                    break;
                case "Error":
                    level = Level.Error;
                    break;
                case "Fatal":
                    level = Level.Fatal;
                    break;
                default:
                    level = Level.Info;
                    break;
            }

            progressReport.Context.GetLoggerFor(this).Logger.Log(
                progressReport.ReportingType,
                level,
                progressReport.Message,
                progressReport.Exception);

            installationTask.LogFileName = progressReport.Context.LogFileName;
            installationTask.ProgressReports.Add(progressReport);

            if (progressReport.Exception == null)
            {
                return;
            }

            installationTask.HasErrors = true;
            installationTask.Errors.Add(progressReport.Exception);
        }
        private void StartInstall(InstallationTask nextPendingInstall)
        {
            nextPendingInstall.Task = new Task<InstallationResult>(() =>
                _deploymentService.InstallPackage(nextPendingInstall.PackageId, nextPendingInstall.Version, Guid.NewGuid().ToString(), new CancellationTokenSource(),
                                                                                            progressReport => HandleProgressReport(nextPendingInstall, progressReport)));

            nextPendingInstall.Task
                .ContinueWith(RemoveFromRunningInstallationList)
                .ContinueWith(task => _logger.Error(task.Exception, "Installation task failed."), TaskContinuationOptions.OnlyOnFaulted);

            _logger.Debug("Installation task queued");
            _notificationService.NotifyAll(EventType.Installation, string.Format("{0} will install {1} (queued)",
                nextPendingInstall.PackageId,
                string.IsNullOrWhiteSpace(nextPendingInstall.Version) ? "latest version" : nextPendingInstall.Version));

            nextPendingInstall.Task.Start();
        }
        private void HandleProgressReport(InstallationTask installationTask, ProgressReport progressReport)
        {
            Level level;
            switch (progressReport.Level)
            {
                case "Debug":
                    level = Level.Debug;
                    break;
                case "Warn":
                    level = Level.Warn;
                    break;
                case "Error":
                    level = Level.Error;
                    break;
                case "Fatal":
                    level = Level.Fatal;
                    break;
                default:
                    level = Level.Info;
                    break;
            }

            progressReport.Context.GetLoggerFor(this).Logger.Log(
                progressReport.ReportingType,
                level,
                progressReport.Message,
                progressReport.Exception);

            installationTask.LogFileName = progressReport.Context.LogFileName;
            installationTask.ProgressReports.Add(progressReport);

            // update completed datetime in case an exception occurs
            installationTask.DateCompleted = DateTime.Now;

            if (progressReport.Exception == null)
            {
                _hubCommunicator.SendStatusToHubAsync(AgentStatusFactory.BuildStatus(_allPackagesList, _agentCache, _installCache, _runningTasks, _settingsManager, _currentlyDownloadingList, CompletedInstalls));
                return;
            }

            installationTask.HasErrors = true;
            installationTask.Errors.Add(progressReport.Exception);

            _hubCommunicator.SendStatusToHubAsync(AgentStatusFactory.BuildStatus(_allPackagesList, _agentCache, _installCache, _runningTasks, _settingsManager, _currentlyDownloadingList, CompletedInstalls));
        }
Exemplo n.º 7
0
        private static List<LocalPackageInformation> BuildPackageInformation(IEnumerable<IPackage> packages, IInstalledPackageArchive installCache, InstallationTask[] runningTasks, CompletedInstallationTaskList completedInstallations)
        {
            List<LocalPackageInformation> packageInformations = new List<LocalPackageInformation>();
            var packagesById = packages.GroupBy(p=>p.Id);
            foreach (var packageVersions in packagesById)
            {
                var installedPackage = installCache.GetCurrentInstalledVersion(packageVersions.Key);
                var latestAvailablePackage = packageVersions.OrderByDescending(p => p.Version).FirstOrDefault();
                var availablePackageVersions = packageVersions.OrderByDescending(p=>p.Version).Select(p => p.Version.ToString());
                IEnumerable<InstallationTask> currentTasks = null;
                if (runningTasks != null)
                {
                    currentTasks = runningTasks.Where(t => t.PackageId == packageVersions.Key);
                }

                var packageInfo = new LocalPackageInformation();
                packageInfo.PackageId = packageVersions.Key;

                if (installedPackage != null)
                    packageInfo.InstalledVersion = installedPackage.Version.ToString();

                if (latestAvailablePackage != null)
                    packageInfo.LatestAvailableVersion = latestAvailablePackage.Version.ToString();

                if (availablePackageVersions != null)
                    packageInfo.AvailableVersions = availablePackageVersions.ToList();

                if (currentTasks != null)
                    packageInfo.CurrentTask = currentTasks.Select(delegate(InstallationTask t)
                                    {
                                        var installation = new InstallTaskViewModel();
                                        installation.Messages = t.ProgressReports.Select(pr => pr.Message).ToArray();
                                        if (t.Task != null)
                                        {
                                            installation.Status = Enum.GetName(typeof (TaskStatus), t.Task.Status);
                                        }
                                        installation.PackageId = t.PackageId;
                                        installation.Version = t.Version;
                                        installation.LastMessage = t.ProgressReports.Count > 0
                                                               ? t.ProgressReports.LastOrDefault().Message
                                                               : "";
                            return installation;
                        }).FirstOrDefault();

                packageInfo.OutOfDate = false;
                if (installedPackage != null)
                {
                    if (latestAvailablePackage != null)
                    {
                        packageInfo.OutOfDate = installedPackage.Version < latestAvailablePackage.Version;
                    }
                } else
                {
                    if (latestAvailablePackage != null)
                    {
                        packageInfo.OutOfDate = true;
                    }
                }

                if (completedInstallations != null)
                {
                    var installationTask =
                        completedInstallations.OrderByDescending(i => i.DateStarted).FirstOrDefault(
                            i => i.PackageId == packageInfo.PackageId);
                    if (installationTask != null)
                    {
                        packageInfo.InstallationResult = installationTask.Result;
                    }
                }

                packageInformations.Add(packageInfo);
            }

            return packageInformations;
        }