forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34a94ee
commit bd12545
Showing
8 changed files
with
193 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 11 additions & 12 deletions
23
experiments/Azure.Experiments/Azure.Experiments/Network/NetworkPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.Network; | ||
|
||
namespace Microsoft.Azure.Experiments.Network | ||
{ | ||
public static class NetworkPolicy | ||
public abstract class NetworkPolicy<Info, Operations> | ||
: ResourcePolicy<Info, INetworkManagementClient, Operations> | ||
where Info : Resource | ||
{ | ||
public static ResourcePolicy<Info> Create<Operations, Info>( | ||
Func<INetworkManagementClient, Operations> getOperations, | ||
Func<Operations, ResourceName, Task<Info>> getAsync, | ||
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync) | ||
where Info : Management.Network.Models.Resource | ||
=> OperationsPolicy | ||
.Create(getAsync, createOrUpdateAsync) | ||
.Transform(getOperations) | ||
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location); | ||
public sealed override string GetLocation(Info info) | ||
=> info.Location; | ||
|
||
public sealed override void SetLocation(Info info, string location) | ||
=> info.Location = location; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 72 additions & 22 deletions
94
experiments/Azure.Experiments/Azure.Experiments/ResourcePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,88 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public static class ResourcePolicy | ||
public abstract class ResourcePolicy<Name, Info> | ||
where Info : class | ||
{ | ||
public static ResourcePolicy<Info> CreateResourcePolicy<Client, Info>( | ||
this OperationsPolicy<Client, Info> operationsPolicy, | ||
Func<Info, string> getLocation, | ||
Action<Info, string> setLocation) | ||
where Client : class, IDisposable | ||
where Info : class | ||
=> new ResourcePolicy<Info>( | ||
operationsPolicy.Transform<IClient>(c => c.GetClient<Client>()), | ||
getLocation, | ||
setLocation); | ||
public abstract Task<Info> GetAsync( | ||
IClient client, Name name, CancellationToken cancellationToken); | ||
|
||
public abstract Task<Info> CreateOrUpdatesAsync( | ||
IClient client, Name name, Info info, CancellationToken cancellationToken); | ||
|
||
public abstract string GetLocation(Info info); | ||
|
||
public abstract void SetLocation(Info info, string location); | ||
} | ||
|
||
public sealed class ResourcePolicy<Info> | ||
public abstract class ResourcePolicy<Info, RMClient, Operations> : ResourcePolicy<ResourceName, Info> | ||
where Info : class | ||
where RMClient : class, IDisposable | ||
{ | ||
public OperationsPolicy<IClient, Info> Operations { get; } | ||
public sealed class GetParams | ||
{ | ||
public Operations Operations { get; } | ||
|
||
public Func<Info, string> GetLocation { get; } | ||
public string ResourceGroupName { get; } | ||
|
||
public Action<Info, string> SetLocation { get; } | ||
public string Name { get; } | ||
|
||
public ResourcePolicy( | ||
OperationsPolicy<IClient, Info> operations, | ||
Func<Info, string> getLocation, | ||
Action<Info, string> setLocation) | ||
public CancellationToken CancellationToken { get; } | ||
|
||
public GetParams( | ||
Operations operations, ResourceName name, CancellationToken cancellationToken) | ||
{ | ||
Operations = operations; | ||
ResourceGroupName = name.ResourceGroupName; | ||
Name = name.Name; | ||
CancellationToken = cancellationToken; | ||
} | ||
} | ||
|
||
public sealed class CreateParams | ||
{ | ||
Operations = operations; | ||
GetLocation = getLocation; | ||
SetLocation = setLocation; | ||
public Operations Operations { get; } | ||
|
||
public string ResourceGroupName { get; } | ||
|
||
public string Name { get; } | ||
|
||
public Info Info { get; } | ||
|
||
public CancellationToken CancellationToken { get; } | ||
|
||
public CreateParams( | ||
Operations operations, | ||
ResourceName name, | ||
Info info, | ||
CancellationToken cancellationToken) | ||
{ | ||
Operations = operations; | ||
ResourceGroupName = name.ResourceGroupName; | ||
Name = name.Name; | ||
Info = info; | ||
CancellationToken = cancellationToken; | ||
} | ||
} | ||
|
||
public abstract Operations GetOperations(RMClient client); | ||
|
||
public abstract Task<Info> GetAsync(GetParams p); | ||
|
||
public abstract Task<Info> CreateOrUpdateAsync(CreateParams p); | ||
|
||
public sealed override Task<Info> GetAsync( | ||
IClient client, ResourceName name, CancellationToken cancellationToken) | ||
=> GetAsync(new GetParams(GetOperations(client), name, cancellationToken)); | ||
|
||
public sealed override Task<Info> CreateOrUpdatesAsync( | ||
IClient client, ResourceName name, Info info, CancellationToken cancellationToken) | ||
=> CreateOrUpdateAsync(new CreateParams(GetOperations(client), name, info, cancellationToken)); | ||
|
||
Operations GetOperations(IClient client) | ||
=> GetOperations(client.GetClient<RMClient>()); | ||
} | ||
} |