Skip to content

Commit

Permalink
IClient.GetClient()
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Nov 9, 2017
1 parent b643730 commit 6d8b26f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Experiments.Compute
{
public static class ComputePolicy
{
public static ResourcePolicy<IComputeManagementClient, ResourceName, Info> Create<Operations, Info>(
public static ResourcePolicy<ResourceName, Info> Create<Operations, Info>(
Func<IComputeManagementClient, Operations> getOperations,
Func<Operations, ResourceName, Task<Info>> getAsync,
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync)
Expand All @@ -17,7 +17,7 @@ public static ResourcePolicy<IComputeManagementClient, ResourceName, Info> Creat
.Transform(getOperations)
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location);

public static ResourcePolicy<IComputeManagementClient, ResourceName, VirtualMachine> VirtualMachine
public static ResourcePolicy<ResourceName, VirtualMachine> VirtualMachine
{ get; }
= Create(
client => client.VirtualMachines,
Expand Down
7 changes: 5 additions & 2 deletions experiments/Azure.Experiments/Azure.Experiments/IClient.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Microsoft.Azure.Experiments
using System;

namespace Microsoft.Azure.Experiments
{
public interface IClient
{
Context Context { get; }

T GetClient<T>();
T GetClient<T>()
where T : class, IDisposable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Experiments.Network
{
public static class NetworkPolicy
{
public static ResourcePolicy<INetworkManagementClient, ResourceName, Info> Create<Operations, Info>(
public static ResourcePolicy<ResourceName, Info> Create<Operations, Info>(
Func<INetworkManagementClient, Operations> getOperations,
Func<Operations, ResourceName, Task<Info>> getAsync,
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync)
Expand All @@ -17,32 +17,28 @@ public static ResourcePolicy<INetworkManagementClient, ResourceName, Info> Creat
.Transform(getOperations)
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location);

public static ResourcePolicy<INetworkManagementClient, ResourceName, NetworkInterface> NetworkInterface
{ get; }
public static ResourcePolicy<ResourceName, NetworkInterface> NetworkInterface { get; }
= Create(
client => client.NetworkInterfaces,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
(operations, name, info)
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));

public static ResourcePolicy<INetworkManagementClient, ResourceName, NetworkSecurityGroup> NetworkSecurityGroup
{ get; }
public static ResourcePolicy<ResourceName, NetworkSecurityGroup> NetworkSecurityGroup { get; }
= Create(
client => client.NetworkSecurityGroups,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
(operations, name, info)
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));

public static ResourcePolicy<INetworkManagementClient, ResourceName, PublicIPAddress> PublicIPAddresss
{ get; }
public static ResourcePolicy<ResourceName, PublicIPAddress> PublicIPAddresss { get; }
= Create(
client => client.PublicIPAddresses,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
(operations, name, info)
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));

public static ResourcePolicy<INetworkManagementClient, ResourceName, VirtualNetwork> VirtualNetwork
{ get; }
public static ResourcePolicy<ResourceName, VirtualNetwork> VirtualNetwork { get; }
= Create(
client => client.VirtualNetworks,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public interface IResourceConfig

public static class ResourceConfig
{
public static ResourceConfig<Client, Name, Info> CreateResourceConfig<Client, Name, Info>(
this ResourcePolicy<Client, Name, Info> policy,
public static ResourceConfig<Name, Info> CreateResourceConfig<Name, Info>(
this ResourcePolicy<Name, Info> policy,
Name name,
Info info,
IEnumerable<IResourceConfig> dependencies)
where Info : class
=> new ResourceConfig<Client, Name, Info>(policy, name, info, dependencies);
=> new ResourceConfig<Name, Info>(policy, name, info, dependencies);
}

public sealed class ResourceConfig<Client, TName, TInfo>
public sealed class ResourceConfig<TName, TInfo>
where TInfo : class
{
public ResourcePolicy<Client, TName, TInfo> Policy { get; }
public ResourcePolicy<TName, TInfo> Policy { get; }

public TName Name { get; }

Expand All @@ -29,7 +29,7 @@ public sealed class ResourceConfig<Client, TName, TInfo>
public IEnumerable<IResourceConfig> Dependencies { get; }

public ResourceConfig(
ResourcePolicy<Client, TName, TInfo> policy,
ResourcePolicy<TName, TInfo> policy,
TName name,
TInfo info,
IEnumerable<IResourceConfig> dependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace Microsoft.Azure.Experiments.ResourceManager
{
public static class ResourceManagerPolicy
{
public static ResourcePolicy<IResourceManagementClient, string, ResourceGroup> ResourceGroup
{ get; }
public static ResourcePolicy<string, ResourceGroup> ResourceGroup { get; }
= OperationsPolicy
.Create<IResourceGroupsOperations, string, ResourceGroup>(
(operations, name) => operations.GetAsync(name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ namespace Microsoft.Azure.Experiments
{
public static class ResourcePolicy
{
public static ResourcePolicy<Client, Name, Info> CreateResourcePolicy<Client, Name, Info>(
public static ResourcePolicy<Name, Info> CreateResourcePolicy<Client, Name, Info>(
this OperationsPolicy<Client, Name, Info> operationsPolicy,
Func<Info, string> getLocation,
Action<Info, string> setLocation)
where Client : class, IDisposable
where Info : class
=> new ResourcePolicy<Client, Name, Info>(operationsPolicy, getLocation, setLocation);
=> new ResourcePolicy<Name, Info>(
operationsPolicy.Transform<IClient>(c => c.GetClient<Client>()),
getLocation,
setLocation);
}

public sealed class ResourcePolicy<Client, Name, Info>
public sealed class ResourcePolicy<Name, Info>
where Info : class
{
public OperationsPolicy<Client, Name, Info> OperationsPolicy { get; }
public OperationsPolicy<IClient, Name, Info> OperationsPolicy { get; }

public Func<Info, string> GetLocation { get; }

public Action<Info, string> SetLocation { get; }

public ResourcePolicy(
OperationsPolicy<Client, Name, Info> operationsPolicy,
OperationsPolicy<IClient, Name, Info> operationsPolicy,
Func<Info, string> getLocation,
Action<Info, string> setLocation)
{
Expand Down

0 comments on commit 6d8b26f

Please sign in to comment.