Skip to content

Commit 88a5696

Browse files
new interfaces
1 parent 803c3c0 commit 88a5696

File tree

7 files changed

+29
-25
lines changed

7 files changed

+29
-25
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/CreateOrUpdateAsyncOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override async Task<object> Visit<Model, ParentModel>(
5757
return null;
5858
}
5959
var parent = await GetOrAdd(config.Parent);
60-
return config.Policy.Get(parent, config.Name);
60+
return config.Strategy.Get(parent, config.Name);
6161
}
6262

6363
public CreateAsyncVisitor(

src/ResourceManager/Common/Commands.Common.Strategies/GetAsyncOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override async Task<object> Visit<Model, ParentModel>(
5656
NestedResourceConfig<Model, ParentModel> config)
5757
{
5858
var parent = await GetOrAdd(config.Parent);
59-
return parent == null ? null : config.Policy.Get(parent, config.Name);
59+
return parent == null ? null : config.Strategy.Get(parent, config.Name);
6060
}
6161

6262
public Visitor(IClient client, CancellationToken cancellationToken)

src/ResourceManager/Common/Commands.Common.Strategies/IResourceBaseConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ namespace Microsoft.Azure.Commands.Common.Strategies
44
{
55
public interface IResourceBaseConfig
66
{
7+
IResourceBaseStrategy Strategy { get; }
8+
9+
string Name { get; }
10+
711
Result Apply<Result>(IResourceBaseConfigVisitor<Result> visitor);
812

913
IEnumerable<string> GetId(string subscription);

src/ResourceManager/Common/Commands.Common.Strategies/IState.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,33 @@ Model GetOrNull<Model>(IResourceBaseConfig<Model> config)
1111
object GetOrNullUntyped(IResourceBaseConfig config);
1212
}
1313

14-
/*
1514
public static class StateExtension
1615
{
1716
public static Model GetNestedOrNull<Model, ParentModel>(
1817
this IState state, NestedResourceConfig<Model, ParentModel> config)
1918
where Model : class
2019
where ParentModel : class
2120
{
22-
var parentModel = config.Parent.Apply(new GetOrNullVisitor(state)) as Model;
21+
var parentModel = config.Parent.Apply(new GetOrNullVisitor<ParentModel>(state));
22+
return config.Strategy.Get(parentModel, config.Name);
2323
}
2424

25-
sealed class GetOrNullVisitor : IResourceConfigVisitor<object>
25+
sealed class GetOrNullVisitor<Model> : IResourceBaseConfigVisitor<Model, Model>
26+
where Model : class
2627
{
2728
public GetOrNullVisitor(IState state)
2829
{
2930
State = state;
3031
}
3132

32-
public object Visit<Model>(ResourceConfig<Model> config) where Model : class
33+
public Model Visit(ResourceConfig<Model> config)
3334
=> State.GetOrNull(config);
3435

35-
public object Visit<Model, ParentModel>(NestedResourceConfig<Model, ParentModel> config)
36-
where Model : class
36+
public Model Visit<ParentModel>(NestedResourceConfig<Model, ParentModel> config)
3737
where ParentModel : class
3838
=> State.GetNestedOrNull(config);
3939

4040
IState State { get; }
4141
}
4242
}
43-
*/
44-
45-
/*
46-
public interface IState
47-
{
48-
Model GetOrNull<Model>(IResourceConfig<Model> config)
49-
where Model : class;
50-
51-
object GetOrNullUntyped(IResourceConfig config);
52-
}
53-
*/
5443
}

src/ResourceManager/Common/Commands.Common.Strategies/NestedResourceConfig.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ public sealed class NestedResourceConfig<Model, ParentModel> : IResourceBaseConf
2020
where Model : class
2121
where ParentModel : class
2222
{
23-
public NestedResourceStrategy<Model, ParentModel> Policy { get; }
23+
public NestedResourceStrategy<Model, ParentModel> Strategy { get; }
2424

2525
public string Name { get; }
2626

2727
public IResourceBaseConfig<ParentModel> Parent { get; }
2828

2929
public Func<Model> CreateModel { get; }
3030

31+
IResourceBaseStrategy IResourceBaseConfig.Strategy => Strategy;
32+
3133
public NestedResourceConfig(
32-
NestedResourceStrategy<Model, ParentModel> policy,
34+
NestedResourceStrategy<Model, ParentModel> strategy,
3335
IResourceBaseConfig<ParentModel> parent,
3436
string name,
3537
Func<Model> createModel)
3638
{
37-
Policy = policy;
39+
Strategy = strategy;
3840
Name = name;
3941
Parent = parent;
4042
CreateModel = createModel;
@@ -47,6 +49,6 @@ public Result Apply<Result>(IResourceBaseConfigVisitor<Model, Result> visitor)
4749
=> visitor.Visit(this);
4850

4951
public IEnumerable<string> GetId(string subscription)
50-
=> Parent.GetId(subscription).Concat(Policy.GetId(Name));
52+
=> Parent.GetId(subscription).Concat(Strategy.GetId(Name));
5153
}
5254
}

src/ResourceManager/Common/Commands.Common.Strategies/ResourceConfig.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55

66
namespace Microsoft.Azure.Commands.Common.Strategies
77
{
8-
public sealed class ResourceConfig<Model> : IResourceBaseConfig<Model>
8+
public interface IResourceConfig : IResourceBaseConfig
9+
{
10+
string ResourceGroupName { get; }
11+
12+
IEnumerable<IResourceBaseConfig> Dependencies { get; }
13+
}
14+
15+
public sealed class ResourceConfig<Model> : IResourceBaseConfig<Model>, IResourceConfig
916
where Model : class
1017
{
1118
public ResourceStrategy<Model> Strategy { get; }
@@ -18,6 +25,8 @@ public sealed class ResourceConfig<Model> : IResourceBaseConfig<Model>
1825

1926
public IEnumerable<IResourceBaseConfig> Dependencies { get; }
2027

28+
IResourceBaseStrategy IResourceBaseConfig.Strategy => Strategy;
29+
2130
public ResourceConfig(
2231
ResourceStrategy<Model> strategy,
2332
string resourceGroupName,

src/ResourceManager/Common/Commands.Common.Strategies/TargetState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public object Visit<Model, ParentModel>(
5757
where ParentModel : class
5858
{
5959
var model = config.CreateModel();
60-
config.Policy.Set(Get(config.Parent), config.Name, model);
60+
config.Strategy.Set(Get(config.Parent), config.Name, model);
6161
return model;
6262
}
6363

0 commit comments

Comments
 (0)