Skip to content

Commit c6e89ca

Browse files
Explicit parameter names.
1 parent a26d6f1 commit c6e89ca

File tree

13 files changed

+91
-74
lines changed

13 files changed

+91
-74
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ namespace Microsoft.Azure.Commands.Common.Strategies
2121
{
2222
public static class Extensions
2323
{
24+
/// <summary>
25+
/// Returns an empty sequence if the given parameter is null.
26+
/// </summary>
27+
/// <typeparam name="T"></typeparam>
28+
/// <param name="value"></param>
29+
/// <returns></returns>
2430
public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> value)
2531
=> value ?? Enumerable.Empty<T>();
2632

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static async Task<IState> GetStateAsync<TModel>(
3939
return context.Result;
4040
}
4141

42-
static Task GetStateAsyncDispatch(this StateOperationContext context, IResourceConfig config)
42+
static Task GetStateAsyncDispatch(
43+
this StateOperationContext context, IResourceConfig config)
4344
=> config.Accept(new GetStateAsyncVisitor(), context);
4445

4546
static async Task GetStateAsync<TModel>(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace Microsoft.Azure.Commands.Common.Strategies
1818
{
1919
/// <summary>
20-
/// Base interface for ResourceConfig and NestedResourceConfig.
20+
/// Base interface for ResourceConfig[TModel] and NestedResourceConfig[TModel, TParentModel].
2121
/// </summary>
2222
public interface IEntityConfig
2323
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public interface IEntityConfigVisitor<TModel, TContext, TResult>
3030
{
3131
TResult Visit(ResourceConfig<TModel> config, TContext context);
3232

33-
TResult Visit<TParentModel>(NestedResourceConfig<TModel, TParentModel> config, TContext context)
33+
TResult Visit<TParentModel>(
34+
NestedResourceConfig<TModel, TParentModel> config, TContext context)
3435
where TParentModel : class;
3536
}
3637
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class ProgressMap
2222
readonly Dictionary<IResourceConfig, Tuple<TimeSlot, int>> _Map
2323
= new Dictionary<IResourceConfig, Tuple<TimeSlot, int>>();
2424

25+
/// <summary>
26+
/// duration of all tasks (in seconds).
27+
/// </summary>
2528
readonly int _Duration;
2629

2730
public ProgressMap(Dictionary<IResourceConfig, Tuple<TimeSlot, int>> map, int duration)

src/ResourceManager/Compute/Commands.Compute/Strategies/Compute/ComputeStrategy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public static ResourceStrategy<TModel> Create<TModel, TOperations>(
3030
Func<TModel, int> createTime)
3131
where TModel : Resource
3232
=> ResourceStrategy.Create(
33-
type,
34-
new[] { "Microsoft.Compute", header },
35-
getOperations,
36-
getAsync,
37-
createOrUpdateAsync,
38-
config => config.Location,
39-
(config, location) => config.Location = location,
40-
createTime,
41-
true);
33+
type: type,
34+
headers: new[] { "Microsoft.Compute", header },
35+
getOperations: getOperations,
36+
getAsync: getAsync,
37+
createOrUpdateAsync: createOrUpdateAsync,
38+
getLocation: config => config.Location,
39+
setLocation: (config, location) => config.Location = location,
40+
createTime: createTime,
41+
compulsoryLocation: true);
4242
}
4343
}

src/ResourceManager/Compute/Commands.Compute/Strategies/Compute/VirtualMachineStrategy.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ static class VirtualMachineStrategy
2424
{
2525
public static ResourceStrategy<VirtualMachine> Strategy { get; }
2626
= ComputePolicy.Create(
27-
"virtual machine",
28-
"virtualMachines",
29-
client => client.VirtualMachines,
30-
(o, p) => o.GetAsync(
27+
type: "virtual machine",
28+
header: "virtualMachines",
29+
getOperations: client => client.VirtualMachines,
30+
getAsync: (o, p) => o.GetAsync(
3131
p.ResourceGroupName, p.Name, null, p.CancellationToken),
32-
(o, p) => o.CreateOrUpdateAsync(
32+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
3333
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
34-
c => c.OsProfile.WindowsConfiguration != null ? 240 : 120);
34+
createTime: c => c.OsProfile.WindowsConfiguration != null ? 240 : 120);
3535

3636
public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
3737
this ResourceConfig<ResourceGroup> resourceGroup,
@@ -43,9 +43,9 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
4343
Image image,
4444
string size)
4545
=> Strategy.CreateResourceConfig(
46-
resourceGroup,
47-
name,
48-
subscription => new VirtualMachine
46+
resourceGroup: resourceGroup,
47+
name: name,
48+
createModel: subscription => new VirtualMachine
4949
{
5050
OsProfile = new OSProfile
5151
{
@@ -80,6 +80,6 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
8080
}
8181
},
8282
},
83-
new[] { networkInterface });
83+
dependencies: new[] { networkInterface });
8484
}
8585
}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ static class NetworkInterfaceStrategy
2323
{
2424
public static ResourceStrategy<NetworkInterface> Strategy { get; }
2525
= NetworkStrategy.Create(
26-
"network interface",
27-
"networkInterfaces",
28-
client => client.NetworkInterfaces,
29-
(o, p) => o.GetAsync(
26+
type: "network interface",
27+
header: "networkInterfaces",
28+
getOperations: client => client.NetworkInterfaces,
29+
getAsync: (o, p) => o.GetAsync(
3030
p.ResourceGroupName, p.Name, null, p.CancellationToken),
31-
(o, p) => o.CreateOrUpdateAsync(
31+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
3232
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
33-
_ => 5);
33+
createTime: _ => 5);
3434

3535
public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
3636
this ResourceConfig<ResourceGroup> resourceGroup,
@@ -39,9 +39,9 @@ public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
3939
ResourceConfig<PublicIPAddress> publicIPAddress,
4040
ResourceConfig<NetworkSecurityGroup> networkSecurityGroup = null)
4141
=> Strategy.CreateResourceConfig(
42-
resourceGroup,
43-
name,
44-
subscription => new NetworkInterface
42+
resourceGroup: resourceGroup,
43+
name: name,
44+
createModel: subscription => new NetworkInterface
4545
{
4646
IpConfigurations = new []
4747
{
@@ -62,6 +62,11 @@ public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig(
6262
Id = networkSecurityGroup.GetId(subscription).IdToString()
6363
}
6464
},
65-
new IEntityConfig[] { subnet, publicIPAddress, networkSecurityGroup });
65+
dependencies: new IEntityConfig[]
66+
{
67+
subnet,
68+
publicIPAddress,
69+
networkSecurityGroup
70+
});
6671
}
6772
}

src/ResourceManager/Compute/Commands.Compute/Strategies/Network/NetworkSecurityGroupPolicy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ static class NetworkSecurityGroupStrategy
2424
{
2525
public static ResourceStrategy<NetworkSecurityGroup> Strategy { get; }
2626
= NetworkStrategy.Create(
27-
"network security group",
28-
"networkSecurityGroups",
29-
client => client.NetworkSecurityGroups,
30-
(o, p) => o.GetAsync(
27+
type: "network security group",
28+
header: "networkSecurityGroups",
29+
getOperations: client => client.NetworkSecurityGroups,
30+
getAsync: (o, p) => o.GetAsync(
3131
p.ResourceGroupName, p.Name, null, p.CancellationToken),
32-
(o, p) => o.CreateOrUpdateAsync(
32+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
3333
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
34-
_ => 15);
34+
createTime: _ => 15);
3535

3636
public static ResourceConfig<NetworkSecurityGroup> CreateNetworkSecurityGroupConfig(
3737
this ResourceConfig<ResourceGroup> resourceGroup, string name, int[] openPorts)
3838
=> Strategy.CreateResourceConfig(
39-
resourceGroup,
40-
name,
41-
_ => new NetworkSecurityGroup
39+
resourceGroup: resourceGroup,
40+
name: name,
41+
createModel: _ => new NetworkSecurityGroup
4242
{
4343
SecurityRules = openPorts
4444
.Select((port, index) => new SecurityRule

src/ResourceManager/Compute/Commands.Compute/Strategies/Network/PublicIPAddressStrategy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ static class PublicIPAddressStrategy
2323
{
2424
public static ResourceStrategy<PublicIPAddress> Strategy { get; }
2525
= NetworkStrategy.Create(
26-
"public IP address",
27-
"publicIPAddresses",
28-
client => client.PublicIPAddresses,
29-
(o, p) => o.GetAsync(
26+
type: "public IP address",
27+
header: "publicIPAddresses",
28+
getOperations: client => client.PublicIPAddresses,
29+
getAsync: (o, p) => o.GetAsync(
3030
p.ResourceGroupName, p.Name, null, p.CancellationToken),
31-
(o, p) => o.CreateOrUpdateAsync(
31+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
3232
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
33-
_ => 15);
33+
createTime: _ => 15);
3434

3535
public static ResourceConfig<PublicIPAddress> CreatePublicIPAddressConfig(
3636
this ResourceConfig<ResourceGroup> resourceGroup,
3737
string name,
3838
string domainNameLabel,
3939
string allocationMethod)
4040
=> Strategy.CreateResourceConfig(
41-
resourceGroup,
42-
name,
43-
_ => new PublicIPAddress
41+
resourceGroup: resourceGroup,
42+
name: name,
43+
createModel: _ => new PublicIPAddress
4444
{
4545
PublicIPAllocationMethod = allocationMethod,
4646
DnsSettings = new PublicIPAddressDnsSettings

src/ResourceManager/Compute/Commands.Compute/Strategies/Network/SubnetStrategy.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ static class SubnetPolicy
2222
{
2323
public static NestedResourceStrategy<Subnet, VirtualNetwork> Strategy { get; }
2424
= NestedResourceStrategy.Create<Subnet, VirtualNetwork>(
25-
"subnets",
26-
(vn, name) => vn.Subnets?.FirstOrDefault(s => s?.Name == name),
27-
(vn, name, subnet) =>
25+
header: "subnets",
26+
get: (vn, name) => vn.Subnets?.FirstOrDefault(s => s?.Name == name),
27+
createOrUpdate: (vn, name, subnet) =>
2828
{
2929
subnet.Name = name;
3030
if (vn.Subnets == null)
@@ -47,8 +47,8 @@ static class SubnetPolicy
4747
public static NestedResourceConfig<Subnet, VirtualNetwork> CreateSubnet(
4848
this ResourceConfig<VirtualNetwork> virtualNetwork, string name, string addressPrefix)
4949
=> Strategy.CreateConfig(
50-
virtualNetwork,
51-
name,
52-
() => new Subnet { Name = name, AddressPrefix = addressPrefix });
50+
parent: virtualNetwork,
51+
name: name,
52+
createModel: () => new Subnet { Name = name, AddressPrefix = addressPrefix });
5353
}
5454
}

src/ResourceManager/Compute/Commands.Compute/Strategies/Network/VirtualNetworkStrategy.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ static class VirtualNetworkStrategy
2323
{
2424
public static ResourceStrategy<VirtualNetwork> Strategy { get; }
2525
= NetworkStrategy.Create(
26-
"virtual network",
27-
"virtualNetworks",
28-
client => client.VirtualNetworks,
29-
(o, p) => o.GetAsync(
26+
type: "virtual network",
27+
header: "virtualNetworks",
28+
getOperations: client => client.VirtualNetworks,
29+
getAsync: (o, p) => o.GetAsync(
3030
p.ResourceGroupName, p.Name, null, p.CancellationToken),
31-
(o, p) => o.CreateOrUpdateAsync(
31+
createOrUpdateAsync: (o, p) => o.CreateOrUpdateAsync(
3232
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken),
33-
_ => 15);
33+
createTime: _ => 15);
3434

3535
public static ResourceConfig<VirtualNetwork> CreateVirtualNetworkConfig(
3636
this ResourceConfig<ResourceGroup> resourceGroup,
3737
string name,
3838
string addressPrefix)
3939
=> Strategy.CreateResourceConfig(
40-
resourceGroup,
41-
name,
42-
_ => new VirtualNetwork
40+
resourceGroup: resourceGroup,
41+
name: name,
42+
createModel: _ => new VirtualNetwork
4343
{
4444
AddressSpace = new AddressSpace
4545
{

src/ResourceManager/Compute/Commands.Compute/Strategies/ResourceManager/ResourceGroupStrategy.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ static class ResourceGroupStrategy
2222
{
2323
public static ResourceStrategy<ResourceGroup> Strategy { get; }
2424
= ResourceStrategy.Create(
25-
"resource group",
26-
_ => Enumerable.Empty<string>(),
27-
(ResourceManagementClient client) => client.ResourceGroups,
28-
(o, p) => o.GetAsync(p.Name, p.CancellationToken),
29-
(o, p) => o.CreateOrUpdateAsync(p.Name, p.Model, p.CancellationToken),
30-
model => model.Location,
31-
(model, location) => model.Location = location,
32-
_ => 3,
33-
false);
25+
type: "resource group",
26+
headers: Enumerable.Empty<string>(),
27+
getOperations: (ResourceManagementClient client) => client.ResourceGroups,
28+
getAsync: (o, p) => o.GetAsync(p.Name, p.CancellationToken),
29+
createOrUpdateAsync: (o, p)
30+
=> o.CreateOrUpdateAsync(p.Name, p.Model, p.CancellationToken),
31+
getLocation: model => model.Location,
32+
setLocation: (model, location) => model.Location = location,
33+
createTime: _ => 3,
34+
compulsoryLocation: false);
3435

3536
public static ResourceConfig<ResourceGroup> CreateResourceGroupConfig(string name)
3637
=> Strategy.CreateConfig(name, name);

0 commit comments

Comments
 (0)