Exemplo n.º 1
0
        private IAzureSubscription MergeSubscriptionProperties(IAzureSubscription subscription1, IAzureSubscription subscription2)
        {
            if (subscription1 == null || subscription2 == null)
            {
                throw new ArgumentNullException("subscription1");
            }
            if (subscription1.Id != subscription2.Id)
            {
                throw new ArgumentException("Subscription Ids do not match.");
            }
            AzureSubscription mergedSubscription = new AzureSubscription
            {
                Id    = subscription1.Id,
                Name  = subscription1.Name,
                State = (subscription1.State != null &&
                         subscription1.State.Equals(subscription2.State, StringComparison.OrdinalIgnoreCase)) ?
                        subscription1.State : null,
            };

            foreach (var property in subscription1.ExtendedProperties.Keys.Union(subscription2.ExtendedProperties.Keys))
            {
                mergedSubscription.SetProperty(property, subscription1.IsPropertySet(property) ?
                                               subscription1.GetProperty(property) : subscription2.GetProperty(property));
            }

            // Merge RegisteredResourceProviders
            var registeredProviders = subscription1.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders)
                                      .Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders), StringComparer.CurrentCultureIgnoreCase);

            mergedSubscription.SetProperty(AzureSubscription.Property.RegisteredResourceProviders, registeredProviders.ToArray());

            // Merge Tenants
            var tenants = subscription1.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                          .Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.Tenants), StringComparer.CurrentCultureIgnoreCase);

            mergedSubscription.SetProperty(AzureSubscription.Property.Tenants, tenants.ToArray());

            return(mergedSubscription);
        }
 /// <summary>
 /// Get the tenants associated with this subscription
 /// </summary>
 /// <param name="subscription">The subscription to check</param>
 /// <returns>The list of tenants</returns>
 public static string[] GetManagedByTenants(this IAzureSubscription subscription)
 {
     return(subscription.GetPropertyAsArray(AzureSubscription.Property.ManagedByTenants));
 }