This repository was archived by the owner on Apr 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathDkrCmdlet.cs
85 lines (68 loc) · 2.36 KB
/
DkrCmdlet.cs
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
using System.Management.Automation;
using Docker.DotNet;
using System.Threading;
using System.Threading.Tasks;
using Docker.PowerShell.Support;
namespace Docker.PowerShell.Cmdlets
{
/// <summary>
/// Contains strings commonly used as parameter set names.
/// </summary>
internal class CommonParameterSetNames
{
public const string Default = "Default";
public const string ContainerObject = "ContainerObject";
public const string ContainerName = "ContainerName";
public const string ImageObject = "ImageObject";
public const string ConfigObject = "ConfigObject";
}
public abstract class DkrCmdlet : PSCmdlet
{
#region Private members
private CancellationTokenSource CancelSignal = new CancellationTokenSource();
protected CancellationToken CmdletCancellationToken => CancelSignal.Token;
protected DockerClient DkrClient
{
get
{
if (dkrClient == null)
{
dkrClient = DockerFactory.CreateClient(HostAddress, CertificateLocation);
}
return dkrClient;
}
}
private DockerClient dkrClient;
#endregion
#region Parameters
/// <summary>
/// The common parameter for specifying the address of the host to operate on.
/// </summary>
[Parameter(ParameterSetName = CommonParameterSetNames.Default)]
[ValidateNotNullOrEmpty]
public string HostAddress { get; set; }
///<summary>
/// The common parameter for specifying the location to find certificates for use in secure
/// connections.
///</summary>
[Parameter]
[ValidateNotNullOrEmpty]
public string CertificateLocation { get; set; }
#endregion
#region Overrides
/// <summary>
/// Common StopProcessing code, that signals the CancellationToken. This may or may
/// not be used be child classes in http calls to docker.
/// </summary>
protected override void StopProcessing()
{
CancelSignal.Cancel();
}
protected sealed override void ProcessRecord()
{
AsyncPump.Run(ProcessRecordAsync);
}
protected abstract Task ProcessRecordAsync();
#endregion
}
}