Skip to content

Commit 9821d44

Browse files
No public access to Info.
1 parent 6b5bd83 commit 9821d44

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,29 @@ public abstract class AzureObject
2424
/// object and its dependencies.
2525
/// </summary>
2626
/// <returns></returns>
27-
public abstract string GetInfoLocation();
27+
public abstract Task<string> GetInfoLocationAsync();
2828

2929
/// <summary>
3030
/// The function should be called only after GetInfo is called for the
3131
/// object and its dependencies.
3232
/// </summary>
3333
/// <returns></returns>
34-
public DependencyLocation GetDependencyLocation()
34+
public async Task<DependencyLocation> GetDependencyLocationAsync()
3535
{
36-
var location = GetInfoLocation();
37-
return location != null
38-
? new DependencyLocation(location, Priority)
39-
: Dependencies
40-
.Select(d => GetDependencyLocation())
41-
.Aggregate(
42-
DependencyLocation.None,
43-
(a, b) => a.Priority > b.Priority ? a : b);
36+
if (DependencyLocation == null)
37+
{
38+
var location = await GetInfoLocationAsync();
39+
if (location != null)
40+
{
41+
return new DependencyLocation(location, Priority);
42+
}
43+
var taskList = Dependencies.Select(d => GetDependencyLocationAsync());
44+
var dlList = await Task.WhenAll(taskList);
45+
DependencyLocation = dlList.Aggregate(
46+
DependencyLocation.None,
47+
(a, b) => a.Priority > b.Priority ? a : b);
48+
}
49+
return DependencyLocation;
4450
}
4551

4652
protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
@@ -51,16 +57,18 @@ protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
5157
? dependencies.Max(d => d.Priority) + 1
5258
: 1;
5359
}
60+
61+
private DependencyLocation DependencyLocation { get; set; }
5462
}
5563

5664
public abstract class AzureObject<T, P> : AzureObject
5765
where T: class
5866
where P: struct, IInfoPolicy<T>
5967
{
60-
public T Info { get; private set; }
68+
private T Info { get; set; }
6169

62-
public override string GetInfoLocation()
63-
=> Info == null ? null : new P().GetLocation(Info);
70+
public override async Task<string> GetInfoLocationAsync()
71+
=> await GetOrNullAsync() == null ? null : new P().GetLocation(Info);
6472

6573
public async Task<T> GetOrNullAsync()
6674
{
@@ -98,8 +106,7 @@ public async Task<T> GetOrCreateAsync(string location)
98106

99107
public async Task<T> GetOrCreateAsync()
100108
{
101-
await GetOrNullAsync();
102-
var dl = GetDependencyLocation();
109+
var dl = await GetDependencyLocationAsync();
103110
var location = dl.Location ?? "eastus";
104111
return await GetOrCreateAsync(location);
105112
}

experiments/Azure.Experiments/Azure.Experiments/Compute/VirtualMachineObject.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ public VirtualMachineObject(
2727
Ni = ni;
2828
}
2929

30-
protected override Task<VirtualMachine> CreateAsync(string location)
31-
=> Client.CreateOrUpdateAsync(
30+
protected override async Task<VirtualMachine> CreateAsync(string location)
31+
{
32+
var ni = await Ni.GetOrNullAsync();
33+
return await Client.CreateOrUpdateAsync(
3234
ResourceGroupName,
3335
Name,
3436
new VirtualMachine
3537
{
3638
Location = "eastus",
3739
OsProfile = new OSProfile
38-
{
40+
{
3941
ComputerName = Name,
4042
WindowsConfiguration = new WindowsConfiguration
41-
{
43+
{
4244
},
4345
AdminUsername = AdminUsername,
4446
AdminPassword = AdminPassword,
@@ -47,7 +49,7 @@ protected override Task<VirtualMachine> CreateAsync(string location)
4749
{
4850
NetworkInterfaces = new NetworkInterfaceReference[]
4951
{
50-
new NetworkInterfaceReference(Ni.Info.Id)
52+
new NetworkInterfaceReference(ni.Id)
5153
}
5254
},
5355
HardwareProfile = new HardwareProfile
@@ -63,8 +65,9 @@ protected override Task<VirtualMachine> CreateAsync(string location)
6365
Sku = "2016-Datacenter",
6466
Version = "latest"
6567
}
66-
},
68+
},
6769
});
70+
}
6871

6972
protected override Task<VirtualMachine> GetOrThrowAsync()
7073
=> Client.GetAsync(ResourceGroupName, Name);

experiments/Azure.Experiments/Azure.Experiments/Network/NetworkInterfaceObject.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ public NetworkInterfaceObject(
2222
}
2323

2424
protected override async Task<NetworkInterface> CreateAsync(string location)
25-
=> await Client.CreateOrUpdateAsync(
25+
{
26+
var subnet = await Subnet.GetOrNullAsync();
27+
var pia = await Pia.GetOrNullAsync();
28+
return await Client.CreateOrUpdateAsync(
2629
ResourceGroupName,
27-
Name,
30+
Name,
2831
new NetworkInterface
2932
{
3033
Location = location,
31-
IpConfigurations = new[]
34+
IpConfigurations = new[]
3235
{
3336
new NetworkInterfaceIPConfiguration
3437
{
3538
Name = Name,
36-
Subnet = Subnet.Info,
37-
PublicIPAddress = Pia.Info,
39+
Subnet = subnet,
40+
PublicIPAddress = pia,
3841
}
39-
}
42+
}
4043
});
44+
}
4145

4246
protected override Task<NetworkInterface> GetOrThrowAsync()
4347
=> Client.GetAsync(ResourceGroupName, Name);

experiments/Azure.Experiments/Azure.Experiments/Network/SubnetObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SubnetObject(
2020
protected override async Task<Subnet> CreateAsync(string location)
2121
{
2222
// The Virtual Network should be created at this point.
23-
var vn = Vn.Info;
23+
var vn = await Vn.GetOrNullAsync();
2424
vn.Subnets.Add(new Subnet { Name = Name, AddressPrefix = AddressPrefix });
2525
vn = await Vn.Client.CreateOrUpdateAsync(
2626
Vn.ResourceGroupName, Vn.Name, vn);

0 commit comments

Comments
 (0)