diff --git a/DeployD/Deployd.Agent/Deployd.Agent.csproj b/DeployD/Deployd.Agent/Deployd.Agent.csproj index c048bc9..7b282a3 100644 --- a/DeployD/Deployd.Agent/Deployd.Agent.csproj +++ b/DeployD/Deployd.Agent/Deployd.Agent.csproj @@ -139,6 +139,7 @@ Component + diff --git a/DeployD/Deployd.Agent/WebUi/Converters/RunningTasksToPackageListViewModelConverter.cs b/DeployD/Deployd.Agent/WebUi/Converters/RunningTasksToPackageListViewModelConverter.cs new file mode 100644 index 0000000..0fb28c1 --- /dev/null +++ b/DeployD/Deployd.Agent/WebUi/Converters/RunningTasksToPackageListViewModelConverter.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Deployd.Agent.WebUi.Models; +using Deployd.Core.Caching; +using Deployd.Core.Installation; + +namespace Deployd.Agent.WebUi.Converters +{ + public static class RunningTasksToPackageListViewModelConverter + { + public static PackageListViewModel Convert(INuGetPackageCache cache, RunningInstallationTaskList runningTasks, ICurrentInstalledCache installCache) + { + var model = new PackageListViewModel(); + + foreach(var packageId in cache.AvailablePackages) + { + var package = new LocalPackageInformation + { + PackageId = packageId, + LatestAvailableVersion = cache.GetLatestVersion(packageId).ToString() + }; + + var installedPackage = installCache.GetCurrentInstalledVersion(packageId); + package.InstalledVersion = installedPackage == null ? "" : installedPackage.ToString(); + + package.CurrentTask = runningTasks.Count > 0 ? runningTasks + .Where(t => t.PackageId == packageId) + .Select(t => + { + var lastOrDefault = t.ProgressReports.LastOrDefault(); + return lastOrDefault != null ? new InstallTaskViewModel + { + Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), + Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), + PackageId = t.PackageId, + Version = t.Version, + LastMessage = t.ProgressReports.Count > 0 ? lastOrDefault.Message : "" + } : null; + }).FirstOrDefault() + : null; + + model.Packages.Add(package); + } + + model.CurrentTasks = runningTasks + .Select(t => + { + var progressReport = t.ProgressReports.LastOrDefault(); + return progressReport != null + ? new InstallTaskViewModel + { + Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), + Status = Enum.GetName(typeof (TaskStatus), t.Task.Status), + PackageId = t.PackageId, + Version = t.Version, + LastMessage = + t.ProgressReports.Count > 0 ? progressReport.Message : "" + } + : null; + }).ToList(); + + + model.AvailableVersions = + cache.AllCachedPackages().Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s); + + return model; + } + } +} diff --git a/DeployD/Deployd.Agent/WebUi/Models/PackageListViewModel.cs b/DeployD/Deployd.Agent/WebUi/Models/PackageListViewModel.cs index 8821348..009c6ab 100644 --- a/DeployD/Deployd.Agent/WebUi/Models/PackageListViewModel.cs +++ b/DeployD/Deployd.Agent/WebUi/Models/PackageListViewModel.cs @@ -1,21 +1,18 @@ using System.Collections.Generic; -using System.Linq; -using Deployd.Core.Installation; -using NuGet; namespace Deployd.Agent.WebUi.Models { public class PackageListViewModel { public IList Packages { get; set; } - public IList CurrentTasks { get; set; } - public IEnumerable AvailableVersions { get; set; } public PackageListViewModel() { Packages = new List(); + CurrentTasks = new List(); + AvailableVersions = new List(); } } @@ -25,7 +22,11 @@ public class LocalPackageInformation public string InstalledVersion { get; set; } public string LatestAvailableVersion { get; set; } public List AvailableVersions { get; set; } - public InstallTaskViewModel CurrentTask { get; set; } + + public LocalPackageInformation() + { + AvailableVersions = new List(); + } } } \ No newline at end of file diff --git a/DeployD/Deployd.Agent/WebUi/Modules/PackagesModule.cs b/DeployD/Deployd.Agent/WebUi/Modules/PackagesModule.cs index 689a7a2..fd5d347 100644 --- a/DeployD/Deployd.Agent/WebUi/Modules/PackagesModule.cs +++ b/DeployD/Deployd.Agent/WebUi/Modules/PackagesModule.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Linq; +using Deployd.Agent.WebUi.Converters; using Deployd.Agent.WebUi.Models; using Deployd.Core.Caching; using Deployd.Core.Hosting; @@ -24,41 +24,8 @@ public PackagesModule(): base("/packages") { var cache = Container().GetType(); var runningTasks = Container().GetType(); - var installCache = Container().GetType(); - - var model = - new PackageListViewModel - { - Packages = cache.AvailablePackages.Select(name => new LocalPackageInformation() - { - PackageId = name, - InstalledVersion = installCache.GetCurrentInstalledVersion(name).ToString(), - LatestAvailableVersion = cache.GetLatestVersion(name).ToString(), - CurrentTask = runningTasks.Count > 0 ? runningTasks - .Where(t => t.PackageId == name) - .Select(t => new InstallTaskViewModel() - { - Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), - Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), - PackageId = t.PackageId, - Version = t.Version, - LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : "" - }).FirstOrDefault() - : null - }).ToArray(), - CurrentTasks = runningTasks - .Select(t => new InstallTaskViewModel() - { - Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), - Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), - PackageId = t.PackageId, - Version = t.Version, - LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : "" - }).ToList(), - AvailableVersions = cache.AllCachedPackages().Select(p=>p.Version.ToString()).Distinct().OrderByDescending(s=>s) - }; - - + var installCache = Container().GetType(); + var model = RunningTasksToPackageListViewModelConverter.Convert(cache, runningTasks, installCache); return this.ViewOrJson("packages.cshtml", model); }; diff --git a/DeployD/Deployd.Agent/WebUi/Views/index.cshtml b/DeployD/Deployd.Agent/WebUi/Views/index.cshtml index 412b7ac..3c7dc83 100644 --- a/DeployD/Deployd.Agent/WebUi/Views/index.cshtml +++ b/DeployD/Deployd.Agent/WebUi/Views/index.cshtml @@ -1,12 +1,3 @@ - - - - Deployd.Agent - - -

Deployd.Agent

- - Packages - - - \ No newline at end of file +@{ + Layout = "layout.cshtml"; +} \ No newline at end of file diff --git a/DeployD/Deployd.Agent/WebUi/Views/installations.cshtml b/DeployD/Deployd.Agent/WebUi/Views/installations.cshtml index 9eb4036..19abfd7 100644 --- a/DeployD/Deployd.Agent/WebUi/Views/installations.cshtml +++ b/DeployD/Deployd.Agent/WebUi/Views/installations.cshtml @@ -1,29 +1,17 @@ - - - - Deployd.Agent - - - -

Deployd.Agent - @Environment.MachineName

- - +@{ + Layout = "layout.cshtml"; +} -

Task Queue

- - @foreach (var task in Model.TaskQueue) - { -

@task.PackageId @task.Version

- } - -

Running Tasks

+

Task Queue

- @foreach (var task in Model.RunningTasks) - { -

@task.PackageId @task.Version @task.LastMessage

- } - - \ No newline at end of file +@foreach (var task in Model.TaskQueue) +{ +

@task.PackageId @task.Version

+} + +

Running Tasks

+ +@foreach (var task in Model.RunningTasks) +{ +

@task.PackageId @task.Version @task.LastMessage

+} \ No newline at end of file diff --git a/DeployD/Deployd.Agent/WebUi/Views/layout.cshtml b/DeployD/Deployd.Agent/WebUi/Views/layout.cshtml index bdb7d03..3045f3b 100644 --- a/DeployD/Deployd.Agent/WebUi/Views/layout.cshtml +++ b/DeployD/Deployd.Agent/WebUi/Views/layout.cshtml @@ -4,7 +4,7 @@ Deployd.Agent -

Deployd.Agent

+

Deployd.Agent - @Environment.MachineName

  • Packages
  • diff --git a/DeployD/Deployd.Agent/WebUi/Views/package-details.cshtml b/DeployD/Deployd.Agent/WebUi/Views/package-details.cshtml index 1d0239e..5a79410 100644 --- a/DeployD/Deployd.Agent/WebUi/Views/package-details.cshtml +++ b/DeployD/Deployd.Agent/WebUi/Views/package-details.cshtml @@ -1,24 +1,17 @@ - - - - Deployd.Agent - - -

    Deployd.Agent

    - -
    - -
    +@{ + Layout = "layout.cshtml"; +} -

    Available Package Versions for @Model.PackageName

    -
    - -
    +
    + +
    - - \ No newline at end of file +

    Available Package Versions for @Model.PackageName

    +
    + +
    \ No newline at end of file diff --git a/DeployD/Deployd.Agent/WebUi/Views/packages.cshtml b/DeployD/Deployd.Agent/WebUi/Views/packages.cshtml index 94bd47a..95df169 100644 --- a/DeployD/Deployd.Agent/WebUi/Views/packages.cshtml +++ b/DeployD/Deployd.Agent/WebUi/Views/packages.cshtml @@ -1,60 +1,46 @@ @using Deployd.Agent.WebUi.Models @{ + Layout = "layout.cshtml"; +} +

    Available Packages

    - - - - Deployd.Agent - - -

    Deployd.Agent - @Environment.MachineName

    - - +
    + +
    -

    Available Packages

    - -
    - -
    +@foreach(LocalPackageInformation package in Model.Packages) +{ +
    + @package.PackageId

    + @if (package.CurrentTask != null) + { + @package.CurrentTask.Status: @package.CurrentTask.LastMessage
    + } - @foreach(LocalPackageInformation package in Model.Packages) - { -
    - @package.PackageId

    - @if (package.CurrentTask != null) - { - @package.CurrentTask.Status: @package.CurrentTask.LastMessage
    - } + @if(!string.IsNullOrWhiteSpace(package.LatestAvailableVersion)) + { + Latest: @package.LatestAvailableVersion
    + } + @if (!string.IsNullOrWhiteSpace(package.InstalledVersion)) + { + Installed: @package.InstalledVersion + } + else + { + Not installed + } +
    +
    + +} - @if(!string.IsNullOrWhiteSpace(package.LatestAvailableVersion)) - { - Latest: @package.LatestAvailableVersion
    - } - @if (!string.IsNullOrWhiteSpace(package.InstalledVersion)) - { - Installed: @package.InstalledVersion - } - else - { - Not installed - } -
    -
    - - } - - @foreach (InstallTaskViewModel task in Model.CurrentTasks) - { -

    @task.PackageId @task.Version @task.Status @task.LastMessage

    - } - - \ No newline at end of file +@foreach (InstallTaskViewModel task in Model.CurrentTasks) +{ +

    @task.PackageId @task.Version @task.Status @task.LastMessage

    +} \ No newline at end of file