1
- using System . Linq ;
1
+ using System ;
2
2
using System . Threading ;
3
3
using System . Threading . Tasks ;
4
4
5
5
namespace Microsoft . Azure . Commands . Common . Strategies
6
6
{
7
+ /*
8
+ public static class CreateOrUpdateAsyncOperation
9
+ {
10
+ public static async Task<IState> CreateOrUpdateAsync<Model>(
11
+ this ResourceConfig<Model> config,
12
+ IClient client,
13
+ IState target,
14
+ CancellationToken cancellationToken)
15
+ where Model : class
16
+ {
17
+ var context = new Context(client, cancellationToken, target);
18
+ }
19
+
20
+ sealed class Context
21
+ {
22
+ public AsyncOperationContext OperationContext { get; } = new AsyncOperationContext();
23
+
24
+ public IClient Client { get; }
25
+
26
+ public IState Target { get; }
27
+
28
+ public CancellationToken CancellationToken { get; }
29
+
30
+ public Context(IClient client, CancellationToken cancellationToken, IState target)
31
+ {
32
+ Client = client;
33
+ CancellationToken = cancellationToken;
34
+ Target = target;
35
+ }
36
+ }
37
+
38
+ sealed class Visitor : IResourceBaseConfigVisitor<Context, Task>
39
+ {
40
+ public async Task Visit<Model>(ResourceConfig<Model> config, Context context)
41
+ where Model : class
42
+ {
43
+ var model = context.Target.Get(config);
44
+ if (model != null)
45
+ {
46
+ await context.OperationContext.GetOrAdd(
47
+ config,
48
+ async () =>
49
+ {
50
+ foreach (var d in config.Dependencies)
51
+ {
52
+ }
53
+ return await config.Strategy.CreateOrUpdateAsync(
54
+ context.Client,
55
+ CreateOrUpdateAsyncParams.Create(
56
+ config.ResourceGroupName,
57
+ config.Name,
58
+ model,
59
+ context.CancellationToken));
60
+ });
61
+ }
62
+ }
63
+
64
+ public Task Visit<Model, ParentModel>(NestedResourceConfig<Model, ParentModel> config, Context context)
65
+ where Model : class
66
+ where ParentModel : class
67
+ {
68
+ throw new NotImplementedException();
69
+ }
70
+ }
71
+ }
72
+
73
+ /*
74
+ public static class CreateOrUpdateAsyncOperation
75
+ {
76
+ public static async Task<IState> CreateOrUpdateAsync<Model>(
77
+ this ResourceConfig<Model> config,
78
+ IClient client,
79
+ IState target,
80
+ CancellationToken cancellationToken)
81
+ where Model : class
82
+ {
83
+ var context = new AsyncOperationContext();
84
+ var model = target.Get(config);
85
+ if (model != null)
86
+ {
87
+ await context.GetOrAdd(
88
+ config,
89
+ async () =>
90
+ {
91
+ // config.Dependencies
92
+ return await config.Strategy.CreateOrUpdateAsync(
93
+ client,
94
+ CreateOrUpdateAsyncParams.Create(
95
+ config.ResourceGroupName,
96
+ config.Name,
97
+ model,
98
+ cancellationToken));
99
+ });
100
+ }
101
+ return context.Result;
102
+ }
103
+
104
+ sealed class Context
105
+ {
106
+ AsyncOperationContext OperationContext { get; } = new AsyncOperationContext();
107
+
108
+ IClient Client { get; }
109
+
110
+ IState Target { get; }
111
+
112
+ CancellationToken CancellationToken { get; }
113
+
114
+ public async Task CreateOrUpdateAsync<Model>(ResourceConfig<Model> config)
115
+ where Model : class
116
+ {
117
+ var model = Target.Get(config);
118
+ if (model != null)
119
+ {
120
+ await OperationContext.GetOrAdd(
121
+ config,
122
+ async () =>
123
+ {
124
+ // config.Dependencies
125
+ return await config.Strategy.CreateOrUpdateAsync(
126
+ Client,
127
+ CreateOrUpdateAsyncParams.Create(
128
+ config.ResourceGroupName,
129
+ config.Name,
130
+ model,
131
+ CancellationToken));
132
+ });
133
+ }
134
+ }
135
+
136
+ public Context(IClient client, IState target, CancellationToken cancellationToken)
137
+ {
138
+ Client = client;
139
+ Target = target;
140
+ CancellationToken = cancellationToken;
141
+ }
142
+ }
143
+
144
+ sealed class Visitor : IResourceBaseConfigVisitor<Context, Task>
145
+ {
146
+ public Task Visit<Model>(ResourceConfig<Model> config, Context context)
147
+ where Model : class
148
+ {
149
+ throw new NotImplementedException();
150
+ }
151
+
152
+ public Task Visit<Model, ParentModel>(
153
+ NestedResourceConfig<Model, ParentModel> config, Context context)
154
+ where Model : class
155
+ where ParentModel : class
156
+ {
157
+ throw new NotImplementedException();
158
+ }
159
+ }
160
+ }
161
+
162
+ /*
7
163
public static class CreateOrUpdateAsyncOperation
8
164
{
9
165
/// <summary>
@@ -32,7 +188,7 @@ sealed class CreateAsyncVisitor : AsyncOperationVisitor
32
188
{
33
189
public override async Task<object> Visit<Model>(ResourceConfig<Model> config)
34
190
{
35
- var target = Target . GetOrNull ( config ) ;
191
+ var target = Target.Get (config);
36
192
if (target == null)
37
193
{
38
194
return null;
@@ -44,14 +200,14 @@ public override async Task<object> Visit<Model>(ResourceConfig<Model> config)
44
200
CreateOrUpdateAsyncParams.Create(
45
201
config.ResourceGroupName,
46
202
config.Name,
47
- Target . GetOrNull ( config ) ,
203
+ Target.Get (config),
48
204
CancellationToken));
49
205
}
50
206
51
207
public override async Task<object> Visit<Model, ParentModel>(
52
208
NestedResourceConfig<Model, ParentModel> config)
53
209
{
54
- var target = Target . GetOrNull ( config ) ;
210
+ var target = Target.GetNestedResourceModel (config);
55
211
if (target == null)
56
212
{
57
213
return null;
@@ -72,4 +228,5 @@ public CreateAsyncVisitor(
72
228
IState Target { get; }
73
229
}
74
230
}
231
+ */
75
232
}
0 commit comments