From 43bd4c0f654add7001b2cfa237d52b5fa949b30e Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Tue, 24 Oct 2017 16:31:25 -0700 Subject: [PATCH] GetDependencyLocation() --- .../Azure.Experiments/AzureObject.cs | 26 ++++++++++++++++++- .../Azure.Experiments/DependencyLocation.cs | 3 +++ .../Network/NetworkObject.cs | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs b/experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs index 232dc9b0a30f..15d2beddebfa 100644 --- a/experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs +++ b/experiments/Azure.Experiments/Azure.Experiments/AzureObject.cs @@ -18,11 +18,32 @@ public abstract class AzureObject public int Priority { get; } + public abstract string GetInfoLocation(); + + /// + /// The function should be called only after GetInfo is called for the + /// object and its dependencies. + /// + /// + 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 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; } } @@ -32,6 +53,9 @@ public abstract class AzureObject : AzureObject { public T Info { get; private set; } + public override string GetInfoLocation() + => Info == null ? null : new P().GetLocation(Info); + public async Task GetOrNullAsync() { if (!IsGetCalled) diff --git a/experiments/Azure.Experiments/Azure.Experiments/DependencyLocation.cs b/experiments/Azure.Experiments/Azure.Experiments/DependencyLocation.cs index 07bdb814baea..8e23210dccd8 100644 --- a/experiments/Azure.Experiments/Azure.Experiments/DependencyLocation.cs +++ b/experiments/Azure.Experiments/Azure.Experiments/DependencyLocation.cs @@ -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; } diff --git a/experiments/Azure.Experiments/Azure.Experiments/Network/NetworkObject.cs b/experiments/Azure.Experiments/Azure.Experiments/Network/NetworkObject.cs index 4c086f76e470..fd45543e726c 100644 --- a/experiments/Azure.Experiments/Azure.Experiments/Network/NetworkObject.cs +++ b/experiments/Azure.Experiments/Azure.Experiments/Network/NetworkObject.cs @@ -6,7 +6,8 @@ namespace Azure.Experiments.Network public abstract class NetworkObject : ResourceObject> where T : Resource { - protected NetworkObject(string name, ResourceGroupObject rg) : base(name, rg) + protected NetworkObject(string name, ResourceGroupObject rg) + : base(name, rg) { }