Skip to content

Commit 43bd4c0

Browse files
GetDependencyLocation()
1 parent 94b26c2 commit 43bd4c0

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,32 @@ public abstract class AzureObject
1818

1919
public int Priority { get; }
2020

21+
public abstract string GetInfoLocation();
22+
23+
/// <summary>
24+
/// The function should be called only after GetInfo is called for the
25+
/// object and its dependencies.
26+
/// </summary>
27+
/// <returns></returns>
28+
public DependencyLocation GetDependencyLocation()
29+
{
30+
var location = GetInfoLocation();
31+
return location != null
32+
? new DependencyLocation(location, Priority)
33+
: Dependencies
34+
.Select(d => GetDependencyLocation())
35+
.Aggregate(
36+
DependencyLocation.None,
37+
(a, b) => a.Priority > b.Priority ? a : b);
38+
}
39+
2140
protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
2241
{
2342
Name = name;
2443
Dependencies = dependencies;
25-
Priority = dependencies.Any() ? dependencies.Max(d => d.Priority) + 1 : 0;
44+
Priority = dependencies.Any()
45+
? dependencies.Max(d => d.Priority) + 1
46+
: 1;
2647
}
2748
}
2849

@@ -32,6 +53,9 @@ public abstract class AzureObject<T, P> : AzureObject
3253
{
3354
public T Info { get; private set; }
3455

56+
public override string GetInfoLocation()
57+
=> Info == null ? null : new P().GetLocation(Info);
58+
3559
public async Task<T> GetOrNullAsync()
3660
{
3761
if (!IsGetCalled)

experiments/Azure.Experiments/Azure.Experiments/DependencyLocation.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
{
33
public sealed class DependencyLocation
44
{
5+
public static DependencyLocation None { get; }
6+
= new DependencyLocation(null, 0);
7+
58
public string Location { get; }
69

710
public int Priority { get; }

experiments/Azure.Experiments/Azure.Experiments/Network/NetworkObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace Azure.Experiments.Network
66
public abstract class NetworkObject<T> : ResourceObject<T, NetworkPolicy<T>>
77
where T : Resource
88
{
9-
protected NetworkObject(string name, ResourceGroupObject rg) : base(name, rg)
9+
protected NetworkObject(string name, ResourceGroupObject rg)
10+
: base(name, rg)
1011
{
1112
}
1213

0 commit comments

Comments
 (0)