Skip to content

Commit

Permalink
Creating.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Nov 3, 2017
1 parent cc429b7 commit a26b706
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static ResourceConfig<VirtualMachine> Create(
.CreateComputeManagementClient()
.VirtualMachines
.GetAsync(resourceGroup.Name, name),
c => c.Location);
c => c.Location,
(c, location) => c
.CreateComputeManagementClient()
.VirtualMachines
.CreateOrUpdateAsync(
resourceGroup.Name, name, new VirtualMachine { Location = location }));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public static ResourceConfig<I> Create<I>(
string name,
IEnumerable<IResourceConfig> dependencies,
Func<Context, Task<I>> getAsync,
Func<I, string> getLocation)
Func<I, string> getLocation,
Func<Context, string, Task<I>> createAsync)
where I : class
=> ResourceConfig.Create(
name,
dependencies.Concat(new[] { resourceGroup }),
getAsync,
i => new Location(true, getLocation(i)),
(map, config) => map.Get(config));
(map, config) => map.Get(config),
createAsync);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static ResourceConfig<NetworkInterface> Create(
resourceGroup,
name,
new IResourceConfig[] { subnet, publicIpAddress, networkSecurityGroup },
c => c.NetworkInterfaces.GetAsync(resourceGroup.Name, name));
c => c.NetworkInterfaces.GetAsync(resourceGroup.Name, name),
(c, location) => c.NetworkInterfaces.CreateOrUpdateAsync(
resourceGroup.Name, name, new NetworkInterface { Location = location }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public static ResourceConfig<I> Create<I>(
ResourceConfig<ResourceGroup> resourceGroup,
string name,
IEnumerable<IResourceConfig> dependencies,
Func<INetworkManagementClient, Task<I>> getAsync)
Func<INetworkManagementClient, Task<I>> getAsync,
Func<INetworkManagementClient, string, Task<I>> createAsync)
where I : Management.Network.Models.Resource
=> ManagedResourceConfig.Create(
resourceGroup,
name,
dependencies,
context => getAsync(context.CreateNetworkManagementClient()),
i => i.Location);
c => getAsync(c.CreateNetworkManagementClient()),
i => i.Location,
(c, location) => createAsync(c.CreateNetworkManagementClient(), location));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static ResourceConfig<NetworkSecurityGroup> Create(
resourceGroup,
name,
new IResourceConfig[] { },
c => c.NetworkSecurityGroups.GetAsync(resourceGroup.Name, name));
c => c.NetworkSecurityGroups.GetAsync(resourceGroup.Name, name),
(c, location) => c.NetworkSecurityGroups.CreateOrUpdateAsync(
resourceGroup.Name, name, new NetworkSecurityGroup { Location = location }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static ResourceConfig<PublicIPAddress> Create(
resourceGroup,
name,
new IResourceConfig[] { },
c => c.PublicIPAddresses.GetAsync(resourceGroup.Name, name));
c => c.PublicIPAddresses.GetAsync(resourceGroup.Name, name),
(c, location) => c.PublicIPAddresses.CreateOrUpdateAsync(
resourceGroup.Name, name, new PublicIPAddress { Location = location }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static ResourceConfig<Subnet> Create(
new[] { virtualNetwork },
_ => Task.FromResult<Subnet>(null),
null,
(map, _) => map.Get(virtualNetwork)?.Subnets?.FirstOrDefault(v => v.Name == name));
(map, _) => map.Get(virtualNetwork)?.Subnets?.FirstOrDefault(v => v.Name == name),
(_0, _1) => null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static ResourceConfig<VirtualNetwork> Create(
resourceGroup,
name,
new IResourceConfig[] { },
c => c.VirtualNetworks.GetAsync(resourceGroup.Name, name));
c => c.VirtualNetworks.GetAsync(resourceGroup.Name, name),
(c, location) => c.VirtualNetworks.CreateOrUpdateAsync(
resourceGroup.Name, name, new VirtualNetwork { Location = location }));
}
}
17 changes: 14 additions & 3 deletions experiments/Azure.Experiments/Azure.Experiments/ResourceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface IResourceConfig
Location GetLocation(object i);

object GetState(IStateMap getState);

Task<object> CreateAsync(Context context, string location);
}

public static class ResourceConfig
Expand All @@ -24,8 +26,10 @@ public static ResourceConfig<I> Create<I>(
IEnumerable<IResourceConfig> dependencies,
Func<Context, Task<I>> getAsync,
Func<I, Location> getLocation,
Func<IStateMap, ResourceConfig<I>, I> getState)
=> new ResourceConfig<I>(name, dependencies, getAsync, getLocation, getState);
Func<IStateMap, ResourceConfig<I>, I> getState,
Func<Context, string, Task<I>> createAsync)
=> new ResourceConfig<I>(
name, dependencies, getAsync, getLocation, getState, createAsync);
}

public sealed class ResourceConfig<I> : IResourceConfig
Expand All @@ -39,13 +43,15 @@ public ResourceConfig(
IEnumerable<IResourceConfig> dependencies,
Func<Context, Task<I>> getAsyncFunc,
Func<I, Location> getLocationFunc,
Func<IStateMap, ResourceConfig<I>, I> getStateFunc)
Func<IStateMap, ResourceConfig<I>, I> getStateFunc,
Func<Context, string, Task<I>> createAsyncFunc)
{
Name = name;
Dependencies = dependencies;
GetAsyncFunc = getAsyncFunc;
GetLocationFunc = getLocationFunc;
GetStateFunc = getStateFunc;
CreateAsyncFunc = createAsyncFunc;
}

public async Task<object> GetAsync(Context context) => await GetAsyncFunc(context);
Expand All @@ -54,10 +60,15 @@ public ResourceConfig(

public object GetState(IStateMap stateMap) => GetStateFunc(stateMap, this);

public async Task<object> CreateAsync(Context context, string location)
=> await CreateAsyncFunc(context, location);

private Func<Context, Task<I>> GetAsyncFunc { get; }

private Func<I, Location> GetLocationFunc { get; }

public Func<IStateMap, ResourceConfig<I>, I> GetStateFunc { get; }

private Func<Context, string, Task<I>> CreateAsyncFunc { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static ResourceConfig<ResourceGroup> Create(string name)
new IResourceConfig[] { },
c => c.CreateResourceManagementClient().ResourceGroups.GetAsync(name),
i => new Location(false, i.Location),
(map, config) => map.Get(config));
(map, config) => map.Get(config),
(c, location) => c.CreateResourceManagementClient().ResourceGroups.CreateOrUpdateAsync(
name, new ResourceGroup { Location = location }));
}
}

0 comments on commit a26b706

Please sign in to comment.