Skip to content

Commit 74ffdeb

Browse files
a lot
1 parent bd12545 commit 74ffdeb

24 files changed

+269
-626
lines changed

experiments/Azure.Experiments/Azure.Experiments/ChildResourceConfig.cs

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

experiments/Azure.Experiments/Azure.Experiments/ChildResourcePolicy.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
using Microsoft.Azure.Management.Compute;
22
using Microsoft.Azure.Management.Compute.Models;
3+
using System;
4+
using System.Threading;
5+
using System.Threading.Tasks;
36

47
namespace Microsoft.Azure.Experiments.Compute
58
{
6-
public abstract class ComputePolicy<Info, Operations>
7-
: ResourcePolicy<Info, IComputeManagementClient, Operations>
8-
where Info : Resource
9-
{
10-
public sealed override string GetLocation(Info info)
11-
=> info.Location;
12-
13-
public sealed override void SetLocation(Info info, string location)
14-
=> info.Location = location;
15-
}
16-
17-
/*
189
public static class ComputePolicy
1910
{
20-
public static ResourcePolicy<Info> Create<Operations, Info>(
11+
public static ResourcePolicy<ResourceName, Config> Create<Config, Operations>(
2112
Func<IComputeManagementClient, Operations> getOperations,
22-
Func<Operations, ResourceName, Task<Info>> getAsync,
23-
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync)
24-
where Info : Management.Compute.Models.Resource
25-
=> OperationsPolicy
26-
.Create(getAsync, createOrUpdateAsync)
27-
.Transform(getOperations)
28-
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location);
13+
Func<Operations, ResourceName, CancellationToken, Task<Config>> getAsync,
14+
Func<Operations, ResourceName, Config, CancellationToken, Task<Config>> createOrUpdateAsync)
15+
where Config : Resource
16+
=> ResourcePolicy.Create(
17+
getOperations,
18+
getAsync,
19+
createOrUpdateAsync,
20+
config => config.Location,
21+
(config, location) => config.Location = location);
2922
}
30-
*/
3123
}
Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,23 @@
1-
using System.Threading.Tasks;
2-
using Microsoft.Azure.Management.Compute;
1+
using Microsoft.Azure.Management.Compute;
32
using Microsoft.Azure.Management.Compute.Models;
3+
using Microsoft.Azure.Management.ResourceManager.Models;
44

55
namespace Microsoft.Azure.Experiments.Compute
66
{
7-
public sealed class VirtualMachinePolicy
8-
: ComputePolicy<VirtualMachine, IVirtualMachinesOperations>
9-
{
10-
public override Task<VirtualMachine> CreateOrUpdateAsync(CreateParams p)
11-
=> p.Operations.CreateOrUpdateAsync(
12-
p.ResourceGroupName, p.Name, p.Info, p.CancellationToken);
13-
14-
public override Task<VirtualMachine> GetAsync(GetParams p)
15-
=> p.Operations.GetAsync(
16-
p.ResourceGroupName, p.Name, cancellationToken: p.CancellationToken);
17-
18-
public override IVirtualMachinesOperations GetOperations(IComputeManagementClient client)
19-
=> client.VirtualMachines;
20-
}
21-
22-
/*
237
public static class VirtualMachinePolicy
248
{
25-
public static ResourcePolicy<VirtualMachine> Policy { get; }
9+
public static ResourcePolicy<ResourceName, VirtualMachine> Policy { get; }
2610
= ComputePolicy.Create(
2711
client => client.VirtualMachines,
28-
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
29-
(operations, name, info)
30-
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));
12+
(operations, name, cancellationTokent)
13+
=> operations.GetAsync(
14+
name.ResourceGroupName, name.Name, cancellationToken: cancellationTokent),
15+
(operations, name, config, cancellationTokent)
16+
=> operations.CreateOrUpdateAsync(
17+
name.ResourceGroupName, name.Name, config, cancellationTokent));
3118

32-
public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
33-
this ResourceName name,
34-
ResourceConfig<NetworkInterface> networkInterface)
35-
=> Policy.CreateConfig(
36-
name,
37-
state => new VirtualMachine
38-
{
39-
NetworkProfile = new NetworkProfile
40-
{
41-
NetworkInterfaces = new []
42-
{
43-
new NetworkInterfaceReference
44-
{
45-
Id = state.Get(networkInterface).Id
46-
}
47-
}
48-
}
49-
},
50-
new[] { networkInterface });
19+
public static ResourceConfig<ResourceName, VirtualMachine> CreateVirtualMachineConfig(
20+
this ResourceConfig<string, ResourceGroup> resourceGroup, string name)
21+
=> Policy.CreateConfig(resourceGroup, name);
5122
}
52-
*/
5323
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Threading;
2+
3+
namespace Microsoft.Azure.Experiments
4+
{
5+
public sealed class CreateOrUpdateAsyncParams<TOperations, TConfig>
6+
{
7+
public TOperations Operations { get; }
8+
9+
public string ResourceGroupName { get; }
10+
11+
public string Name { get; }
12+
13+
public CancellationToken CancellationToken { get; }
14+
15+
public TConfig Config { get; }
16+
17+
public CreateOrUpdateAsyncParams(
18+
TOperations operations,
19+
ResourceName name,
20+
TConfig config,
21+
CancellationToken cancellationToken)
22+
{
23+
Operations = operations;
24+
ResourceGroupName = name.ResourceGroupName;
25+
Name = name.Name;
26+
Config = config;
27+
CancellationToken = cancellationToken;
28+
}
29+
}
30+
}

experiments/Azure.Experiments/Azure.Experiments/CreateTask.cs

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

experiments/Azure.Experiments/Azure.Experiments/EnumerableEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace Microsoft.Azure.Experiments
66
public static class EnumerableEx
77
{
88
public static IEnumerable<T> EmptyIfNull<T>(this IEnumerable<T> value)
9-
=> value == null ? Enumerable.Empty<T>() : value;
9+
=> value ?? Enumerable.Empty<T>();
1010
}
1111
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Threading;
2+
3+
namespace Microsoft.Azure.Experiments
4+
{
5+
public sealed class GetAsyncParams<TOperations>
6+
{
7+
public TOperations Operations { get; }
8+
9+
public string ResourceGroupName { get; }
10+
11+
public string Name { get; }
12+
13+
public CancellationToken CancellationToken { get; }
14+
15+
public GetAsyncParams(
16+
TOperations operations, ResourceName name, CancellationToken cancellationToken)
17+
{
18+
Operations = operations;
19+
ResourceGroupName = name.ResourceGroupName;
20+
Name = name.Name;
21+
CancellationToken = cancellationToken;
22+
}
23+
}
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Microsoft.Azure.Experiments
2+
{
3+
public interface IResourceConfig
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Microsoft.Azure.Experiments
2+
{
3+
public interface IResourcePolicy
4+
{
5+
}
6+
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
using Microsoft.Azure.Management.ResourceManager.Models;
2-
3-
namespace Microsoft.Azure.Experiments
1+
namespace Microsoft.Azure.Experiments
42
{
53
public interface IState
64
{
7-
ResourceGroup GetResourceGroup(string name);
8-
9-
T Get<T>(ResourceConfig<T> resourceConfig)
10-
where T : class;
11-
12-
T Get<T, P>(ChildResourceConfig<T, P> childResourceConfig)
13-
where T : class
14-
where P : class;
155
}
166
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace Microsoft.Azure.Experiments
4+
{
5+
public sealed class NestedResourcePolicy<Config, ParentConfig> : IResourcePolicy
6+
{
7+
public Func<ParentConfig, Config> Get { get; }
8+
9+
public Action<ParentConfig, Config> Set { get; }
10+
11+
public NestedResourcePolicy(
12+
Func<ParentConfig, Config> get, Action<ParentConfig, Config> set)
13+
{
14+
Get = get;
15+
Set = set;
16+
}
17+
}
18+
}

experiments/Azure.Experiments/Azure.Experiments/Network/NetworkInterfacePolicy.cs

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

0 commit comments

Comments
 (0)