Skip to content

Commit

Permalink
GetDependencyLocation()
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Oct 24, 2017
1 parent 94b26c2 commit 43bd4c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,32 @@ public abstract class AzureObject

public int Priority { get; }

public abstract string GetInfoLocation();

/// <summary>
/// The function should be called only after GetInfo is called for the
/// object and its dependencies.
/// </summary>
/// <returns></returns>
public DependencyLocation GetDependencyLocation()
{
var location = GetInfoLocation();
return location != null
? new DependencyLocation(location, Priority)
: Dependencies
.Select(d => GetDependencyLocation())
.Aggregate(
DependencyLocation.None,
(a, b) => a.Priority > b.Priority ? a : b);
}

protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
{
Name = name;
Dependencies = dependencies;
Priority = dependencies.Any() ? dependencies.Max(d => d.Priority) + 1 : 0;
Priority = dependencies.Any()
? dependencies.Max(d => d.Priority) + 1
: 1;
}
}

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

public override string GetInfoLocation()
=> Info == null ? null : new P().GetLocation(Info);

public async Task<T> GetOrNullAsync()
{
if (!IsGetCalled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{
public sealed class DependencyLocation
{
public static DependencyLocation None { get; }
= new DependencyLocation(null, 0);

public string Location { get; }

public int Priority { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Azure.Experiments.Network
public abstract class NetworkObject<T> : ResourceObject<T, NetworkPolicy<T>>
where T : Resource
{
protected NetworkObject(string name, ResourceGroupObject rg) : base(name, rg)
protected NetworkObject(string name, ResourceGroupObject rg)
: base(name, rg)
{
}

Expand Down

0 comments on commit 43bd4c0

Please sign in to comment.