Skip to content

Commit 803c3c0

Browse files
renaming.
1 parent e03403e commit 803c3c0

19 files changed

+121
-64
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Microsoft.Azure.Commands.Common.Strategies
88
/// It's a base class for asynchronous operation visitors, such as
99
/// CreateOrUpdateAsyncOperation and GetAsyncOperation visitors.
1010
/// </summary>
11-
abstract class AsyncOperationVisitor : IResourceConfigVisitor<Task<object>>
11+
abstract class AsyncOperationVisitor : IResourceBaseConfigVisitor<Task<object>>
1212
{
1313
public IClient Client { get; }
1414

1515
public CancellationToken CancellationToken { get; }
1616

1717
public State Result { get; } = new State();
1818

19-
public async Task<object> GetOrAddUntyped(IResourceConfig config)
19+
public async Task<object> GetOrAddUntyped(IResourceBaseConfig config)
2020
=> await TaskMap.GetOrAdd(
2121
config.DefaultIdStr(),
2222
async _ =>
@@ -29,7 +29,7 @@ public async Task<object> GetOrAddUntyped(IResourceConfig config)
2929
return model;
3030
});
3131

32-
public async Task<Model> GetOrAdd<Model>(IResourceConfig<Model> config)
32+
public async Task<Model> GetOrAdd<Model>(IResourceBaseConfig<Model> config)
3333
where Model : class
3434
{
3535
var model = await GetOrAddUntyped(config);

src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
<Compile Include="GetAsyncParams.cs" />
7878
<Compile Include="IClient.cs" />
7979
<Compile Include="IReport.cs" />
80-
<Compile Include="IResourceConfig.cs" />
81-
<Compile Include="IResourceConfigVisitor.cs" />
82-
<Compile Include="IResourceStrategy.cs" />
80+
<Compile Include="IResourceBaseConfig.cs" />
81+
<Compile Include="IResourceBaseConfigVisitor.cs" />
82+
<Compile Include="IResourceBaseStrategy.cs" />
8383
<Compile Include="IState.cs" />
8484
<Compile Include="NestedResourceConfig.cs" />
8585
<Compile Include="NestedResourceStrategy.cs" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class CreateOrUpdateAsyncOperation
1717
/// <param name="cancellationToken"></param>
1818
/// <returns>An Azure state.</returns>
1919
public static async Task<IState> CreateOrUpdateAsync<Model>(
20-
this IResourceConfig<Model> config,
20+
this IResourceBaseConfig<Model> config,
2121
IClient client,
2222
IState target,
2323
CancellationToken cancellationToken)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class GetAsyncOperation
1717
/// <param name="cancellationToken"></param>
1818
/// <returns>An Azure state.</returns>
1919
public static async Task<IState> GetAsync<Model>(
20-
this IResourceConfig<Model> resourceConfig,
20+
this IResourceBaseConfig<Model> resourceConfig,
2121
IClient client,
2222
CancellationToken cancellationToken)
2323
where Model : class

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public interface IReport
44
{
5-
void Start(IResourceConfig config);
6-
void Done(IResourceConfig config);
5+
void Start(IResourceBaseConfig config);
6+
void Done(IResourceBaseConfig config);
77
}
88
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace Microsoft.Azure.Commands.Common.Strategies
4+
{
5+
public interface IResourceBaseConfig
6+
{
7+
Result Apply<Result>(IResourceBaseConfigVisitor<Result> visitor);
8+
9+
IEnumerable<string> GetId(string subscription);
10+
}
11+
12+
public interface IResourceBaseConfig<Model> : IResourceBaseConfig
13+
where Model : class
14+
{
15+
Result Apply<Result>(IResourceBaseConfigVisitor<Model, Result> visitor);
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Microsoft.Azure.Commands.Common.Strategies
2+
{
3+
public interface IResourceBaseConfigVisitor<Result>
4+
{
5+
Result Visit<Model>(ResourceConfig<Model> config)
6+
where Model : class;
7+
8+
Result Visit<Model, ParentModel>(NestedResourceConfig<Model, ParentModel> config)
9+
where Model : class
10+
where ParentModel : class;
11+
}
12+
13+
public interface IResourceBaseConfigVisitor<Model, Result>
14+
where Model : class
15+
{
16+
Result Visit(ResourceConfig<Model> config);
17+
18+
Result Visit<ParentModel>(NestedResourceConfig<Model, ParentModel> config)
19+
where ParentModel : class;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Microsoft.Azure.Commands.Common.Strategies
22
{
3-
public interface IResourceStrategy
3+
public interface IResourceBaseStrategy
44
{
55
}
66
}

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,51 @@
44
/// An Azure state which is a dictionary of models.
55
/// </summary>
66
public interface IState
7+
{
8+
Model GetOrNull<Model>(IResourceBaseConfig<Model> config)
9+
where Model : class;
10+
11+
object GetOrNullUntyped(IResourceBaseConfig config);
12+
}
13+
14+
/*
15+
public static class StateExtension
16+
{
17+
public static Model GetNestedOrNull<Model, ParentModel>(
18+
this IState state, NestedResourceConfig<Model, ParentModel> config)
19+
where Model : class
20+
where ParentModel : class
21+
{
22+
var parentModel = config.Parent.Apply(new GetOrNullVisitor(state)) as Model;
23+
}
24+
25+
sealed class GetOrNullVisitor : IResourceConfigVisitor<object>
26+
{
27+
public GetOrNullVisitor(IState state)
28+
{
29+
State = state;
30+
}
31+
32+
public object Visit<Model>(ResourceConfig<Model> config) where Model : class
33+
=> State.GetOrNull(config);
34+
35+
public object Visit<Model, ParentModel>(NestedResourceConfig<Model, ParentModel> config)
36+
where Model : class
37+
where ParentModel : class
38+
=> State.GetNestedOrNull(config);
39+
40+
IState State { get; }
41+
}
42+
}
43+
*/
44+
45+
/*
46+
public interface IState
747
{
848
Model GetOrNull<Model>(IResourceConfig<Model> config)
949
where Model : class;
1050
1151
object GetOrNullUntyped(IResourceConfig config);
1252
}
53+
*/
1354
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ public static class NestedResourceConfig
88
{
99
public static NestedResourceConfig<Model, ParentModel> CreateConfig<Model, ParentModel>(
1010
this NestedResourceStrategy<Model, ParentModel> strategy,
11-
IResourceConfig<ParentModel> parent,
11+
IResourceBaseConfig<ParentModel> parent,
1212
string name,
1313
Func<Model> create)
1414
where Model : class
1515
where ParentModel : class
1616
=> new NestedResourceConfig<Model, ParentModel>(strategy, parent, name, create);
1717
}
1818

19-
public sealed class NestedResourceConfig<Model, ParentModel> : IResourceConfig<Model>
19+
public sealed class NestedResourceConfig<Model, ParentModel> : IResourceBaseConfig<Model>
2020
where Model : class
2121
where ParentModel : class
2222
{
2323
public NestedResourceStrategy<Model, ParentModel> Policy { get; }
2424

2525
public string Name { get; }
2626

27-
public IResourceConfig<ParentModel> Parent { get; }
27+
public IResourceBaseConfig<ParentModel> Parent { get; }
2828

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

3131
public NestedResourceConfig(
3232
NestedResourceStrategy<Model, ParentModel> policy,
33-
IResourceConfig<ParentModel> parent,
33+
IResourceBaseConfig<ParentModel> parent,
3434
string name,
3535
Func<Model> createModel)
3636
{
@@ -40,7 +40,10 @@ public NestedResourceConfig(
4040
CreateModel = createModel;
4141
}
4242

43-
public Result Apply<Result>(IResourceConfigVisitor<Result> visitor)
43+
public Result Apply<Result>(IResourceBaseConfigVisitor<Result> visitor)
44+
=> visitor.Visit(this);
45+
46+
public Result Apply<Result>(IResourceBaseConfigVisitor<Model, Result> visitor)
4447
=> visitor.Visit(this);
4548

4649
public IEnumerable<string> GetId(string subscription)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.Azure.Commands.Common.Strategies
55
{
6-
public sealed class NestedResourceStrategy<Model, ParentModel> : IResourceStrategy
6+
public sealed class NestedResourceStrategy<Model, ParentModel> : IResourceBaseStrategy
77
{
88
public Func<string, IEnumerable<string>> GetId { get; }
99

src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkInterfaceStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
4343
Id = networkSecurityGroup.GetId(subscription).IdToString()
4444
}
4545
},
46-
new IResourceConfig[] { subnet, publicIPAddress, networkSecurityGroup });
46+
new IResourceBaseConfig[] { subnet, publicIPAddress, networkSecurityGroup });
4747
}
4848
}

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

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

66
namespace Microsoft.Azure.Commands.Common.Strategies
77
{
8-
public sealed class ResourceConfig<Model> : IResourceConfig<Model>
8+
public sealed class ResourceConfig<Model> : IResourceBaseConfig<Model>
99
where Model : class
1010
{
1111
public ResourceStrategy<Model> Strategy { get; }
@@ -16,14 +16,14 @@ public sealed class ResourceConfig<Model> : IResourceConfig<Model>
1616

1717
public Func<string, Model> CreateModel { get; }
1818

19-
public IEnumerable<IResourceConfig> Dependencies { get; }
19+
public IEnumerable<IResourceBaseConfig> Dependencies { get; }
2020

2121
public ResourceConfig(
2222
ResourceStrategy<Model> strategy,
2323
string resourceGroupName,
2424
string name,
2525
Func<string, Model> createModel,
26-
IEnumerable<IResourceConfig> dependencies)
26+
IEnumerable<IResourceBaseConfig> dependencies)
2727
{
2828
Strategy = strategy;
2929
ResourceGroupName = resourceGroupName;
@@ -32,7 +32,10 @@ public ResourceConfig(
3232
Dependencies = dependencies;
3333
}
3434

35-
public Result Apply<Result>(IResourceConfigVisitor<Result> visitor)
35+
public Result Apply<Result>(IResourceBaseConfigVisitor<Result> visitor)
36+
=> visitor.Visit(this);
37+
38+
public Result Apply<Result>(IResourceBaseConfigVisitor<Model, Result> visitor)
3639
=> visitor.Visit(this);
3740

3841
public IEnumerable<string> GetId(string subscription)
@@ -53,7 +56,7 @@ public static ResourceConfig<Model> CreateConfig<Model>(
5356
string resourceGroupName,
5457
string name,
5558
Func<string, Model> createModel = null,
56-
IEnumerable<IResourceConfig> dependencies = null)
59+
IEnumerable<IResourceBaseConfig> dependencies = null)
5760
where Model : class, new()
5861
=> new ResourceConfig<Model>(
5962
strategy,
@@ -67,7 +70,7 @@ public static ResourceConfig<Model> CreateConfig<Model>(
6770
ResourceConfig<ResourceGroup> resourceGroup,
6871
string name,
6972
Func<string, Model> createModel = null,
70-
IEnumerable<IResourceConfig> dependencies = null)
73+
IEnumerable<IResourceBaseConfig> dependencies = null)
7174
where Model : class, new()
7275
=> strategy.CreateConfig(
7376
resourceGroup.Name,
@@ -78,7 +81,7 @@ public static ResourceConfig<Model> CreateConfig<Model>(
7881
public static string IdToString(this IEnumerable<string> id)
7982
=> "/" + string.Join("/", id);
8083

81-
public static string DefaultIdStr(this IResourceConfig config)
84+
public static string DefaultIdStr(this IResourceBaseConfig config)
8285
=> config.GetId(string.Empty).IdToString();
8386
}
8487
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.Azure.Commands.Common.Strategies
88
{
9-
public sealed class ResourceStrategy<Model> : IResourceStrategy
9+
public sealed class ResourceStrategy<Model> : IResourceBaseStrategy
1010
{
1111
public Func<string, IEnumerable<string>> GetId { get; }
1212

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ namespace Microsoft.Azure.Commands.Common.Strategies
55
{
66
sealed class State : IState
77
{
8-
public object GetOrNullUntyped(IResourceConfig config)
8+
public object GetOrNullUntyped(IResourceBaseConfig config)
99
=> Map.GetOrNull(config.DefaultIdStr());
1010

11-
public Model GetOrNull<Model>(IResourceConfig<Model> config)
11+
public Model GetOrNull<Model>(IResourceBaseConfig<Model> config)
1212
where Model : class
1313
=> GetOrNullUntyped(config) as Model;
1414

15-
public Model GetOrAdd<Model>(IResourceConfig<Model> config, Func<Model> f)
15+
public Model GetOrAdd<Model>(IResourceBaseConfig<Model> config, Func<Model> f)
1616
where Model : class
1717
=> GetOrAddUntyped(config, f) as Model;
1818

19-
public object GetOrAddUntyped(IResourceConfig config, Func<object> f)
19+
public object GetOrAddUntyped(IResourceBaseConfig config, Func<object> f)
2020
=> Map.GetOrAdd(config.DefaultIdStr(), _ => f());
2121

2222
ConcurrentDictionary<string, object> Map { get; }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Azure.Commands.Common.Strategies
55
{
66
public static class StateLocation
77
{
8-
public static string GetLocation(this IState state, IResourceConfig config)
8+
public static string GetLocation(this IState state, IResourceBaseConfig config)
99
=> config.Apply(new Visitor(state))?.Location;
1010

1111
class DependencyLocation
@@ -41,7 +41,7 @@ static DependencyLocation Merge(this DependencyLocation a, DependencyLocation b)
4141
return a.Location == b.Location ? a : new DependencyLocation(null, a.IsCompulsory);
4242
}
4343

44-
sealed class Visitor : IResourceConfigVisitor<DependencyLocation>
44+
sealed class Visitor : IResourceBaseConfigVisitor<DependencyLocation>
4545
{
4646
public DependencyLocation Visit<Model>(ResourceConfig<Model> config)
4747
where Model : class

0 commit comments

Comments
 (0)