-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRepositoryViewModel.cs
More file actions
89 lines (69 loc) · 2.51 KB
/
RepositoryViewModel.cs
File metadata and controls
89 lines (69 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Autofac;
using Docker.Registry.DotNet.Models;
using Docker.Registry.DotNet.Registry;
using DockerExplorer.Extensions;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
namespace DockerRegistryExplorer.ViewModel
{
public class RepositoryViewModel : ViewModelBase
{
private readonly ILifetimeScope _lifetimeScope;
private readonly IRegistryClient _registryClient;
private TagViewModel[] _tags;
public RepositoryViewModel(
string name,
RegistryViewModel parent,
IRegistryClient registryClient,
ILifetimeScope lifetimeScope)
{
this.Parent = parent ?? throw new ArgumentNullException(nameof(parent));
this._registryClient = registryClient ?? throw new ArgumentNullException(nameof(registryClient));
this._lifetimeScope = lifetimeScope ?? throw new ArgumentNullException(nameof(lifetimeScope));
this.Name = name;
this.Refresh();
this.RefreshCommand = new RelayCommand(this.Refresh);
}
public ICommand RefreshCommand { get; }
public TagViewModel[] Tags
{
get => this._tags;
private set
{
this._tags = value;
this.RaisePropertyChanged();
}
}
public string Name { get; }
public AsyncExecutor Executor { get; } = new AsyncExecutor();
public RegistryViewModel Parent { get; }
public void Refresh()
{
if (!this.CanRefresh()) return;
this.Executor.ExecuteAsync(this.ListImagesTags).IgnoreAsync();
}
private async Task ListImagesTags()
{
var tags = await this._registryClient.Tags.ListTags(
this.Name,
new ListTagsParameters());
if (tags.Tags == null) this.Tags = new TagViewModel[] { };
else
this.Tags = tags.Tags.Select(
t => this._lifetimeScope.Resolve<TagViewModel>(
new NamedParameter("repository", this.Name),
new NamedParameter("tag", t),
new TypedParameter(this.GetType(), this)))
.OrderByDescending(t => t.Tag)
.ToArray();
}
private bool CanRefresh()
{
return !this.Executor.IsBusy;
}
}
}