/// <inheritdoc/>
        public Task DeleteGroupAsync(ScalingGroupId groupId, bool?force, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}?force={force}");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }
            };

            if (force ?? false)
            {
                parameters.Add("force", force.ToString().ToLowerInvariant());
            }

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.DELETE, template, parameters);

            Func <Task <HttpWebRequest>, Task <string> > requestResource =
                GetResponseAsyncFunc(cancellationToken);

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource));
        }
        /// <inheritdoc/>
        public Task <ReadOnlyCollectionPage <ScalingGroup> > ListScalingGroupsAsync(ScalingGroupId marker, int?limit, CancellationToken cancellationToken)
        {
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException("limit");
            }

            UriTemplate template   = new UriTemplate("/groups/?marker={marker}&limit={limit}");
            var         parameters = new Dictionary <string, string>();

            if (marker != null)
            {
                parameters.Add("marker", marker.Value);
            }
            if (limit != null)
            {
                parameters.Add("limit", limit.ToString());
            }

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters);

            Func <Task <HttpWebRequest>, Task <JObject> > requestResource =
                GetResponseAsyncFunc <JObject>(cancellationToken);

            Func <Task <JObject>, ReadOnlyCollectionPage <ScalingGroup> > resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valuesToken = result["groups"];
                if (valuesToken == null)
                {
                    return(null);
                }

                JToken linksToken = result["groups_links"];
                Link[] links      = linksToken != null?linksToken.ToObject <Link[]>() : null;

                ScalingGroup[] values = valuesToken.ToObject <ScalingGroup[]>();

                ScalingGroupId nextMarker = values.Any() && (links == null || links.Any(i => string.Equals(i.Rel, "next", StringComparison.OrdinalIgnoreCase))) ? values.Last().Id : null;
                Func <CancellationToken, Task <ReadOnlyCollectionPage <ScalingGroup> > > getNextPageAsync = null;
                if (nextMarker != null)
                {
                    getNextPageAsync = nextCancellationToken => ListScalingGroupsAsync(nextMarker, limit, cancellationToken);
                }

                return(new BasicReadOnlyCollectionPage <ScalingGroup>(values, getNextPageAsync));
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        /// <inheritdoc/>
        public Task SetPolicyAsync(ScalingGroupId groupId, PolicyId policyId, PolicyConfiguration configuration, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/policies/{policyId}");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.PUT, template, parameters, configuration);

            Func <Task <HttpWebRequest>, Task <string> > requestResource =
                GetResponseAsyncFunc(cancellationToken);

            return(AuthenticateServiceAsync(cancellationToken)
                   .Then(prepareRequest)
                   .Then(requestResource));
        }
        /// <inheritdoc/>
        public Task DeleteWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (webhookId == null)
            {
                throw new ArgumentNullException("webhookId");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/{webhookId}");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }, { "webhookId", webhookId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.DELETE, template, parameters);

            Func <Task <HttpWebRequest>, Task <string> > requestResource =
                GetResponseAsyncFunc(cancellationToken);

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource));
        }
        /// <inheritdoc/>
        public Task <ReadOnlyCollection <Webhook> > CreateWebhookRangeAsync(ScalingGroupId groupId, PolicyId policyId, IEnumerable <NewWebhookConfiguration> configurations, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (configurations == null)
            {
                throw new ArgumentNullException("configurations");
            }

            NewWebhookConfiguration[] configurationsArray = configurations.ToArray();
            if (configurationsArray.Contains(null))
            {
                throw new ArgumentException("configurations cannot contain any null values", "configurations");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.POST, template, parameters, configurations);

            Func <Task <HttpWebRequest>, Task <JObject> > requestResource =
                GetResponseAsyncFunc <JObject>(cancellationToken);

            Func <Task <JObject>, ReadOnlyCollection <Webhook> > resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valueToken = result["webhooks"];
                if (valueToken == null)
                {
                    return(null);
                }

                ReadOnlyCollection <Webhook> webhooks = valueToken.ToObject <ReadOnlyCollection <Webhook> >();
                return(webhooks);
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Then(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        /// <inheritdoc/>
        public Task <Webhook> CreateWebhookAsync(ScalingGroupId groupId, PolicyId policyId, NewWebhookConfiguration configuration, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, Task <HttpWebRequest> > prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.POST, template, parameters, new[] { configuration });

            Func <Task <HttpWebRequest>, Task <JObject> > requestResource =
                GetResponseAsyncFunc <JObject>(cancellationToken);

            Func <Task <JObject>, Webhook> resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valueToken = result["webhooks"];
                if (valueToken == null)
                {
                    return(null);
                }

                Webhook[] webhooks = valueToken.ToObject <Webhook[]>();
                return(webhooks[0]);
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Then(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        /// <inheritdoc/>
        public Task <Webhook> GetWebhookAsync(ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }
            if (policyId == null)
            {
                throw new ArgumentNullException("policyId");
            }
            if (webhookId == null)
            {
                throw new ArgumentNullException("webhookId");
            }

            UriTemplate.UriTemplate template = new UriTemplate.UriTemplate("/groups/{groupId}/policies/{policyId}/webhooks/{webhookId}");
            var parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }, { "policyId", policyId.Value }, { "webhookId", webhookId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters);

            Func <Task <HttpWebRequest>, Task <JObject> > requestResource =
                GetResponseAsyncFunc <JObject>(cancellationToken);

            Func <Task <JObject>, Webhook> resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JToken valueToken = result["webhook"];
                if (valueToken == null)
                {
                    return(null);
                }

                return(valueToken.ToObject <Webhook>());
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        public static ReadOnlyCollectionPage<ScalingGroup> ListScalingGroups(this IAutoScaleService service, ScalingGroupId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListScalingGroupsAsync(marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <inheritdoc/>
        public Task <LaunchConfiguration> GetLaunchConfigurationAsync(ScalingGroupId groupId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/launch");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters);

            Func <Task <HttpWebRequest>, Task <JObject> > requestResource =
                GetResponseAsyncFunc <JObject>(cancellationToken);

            Func <Task <JObject>, LaunchConfiguration> resultSelector =
                task =>
            {
                JObject result = task.Result;
                if (result == null)
                {
                    return(null);
                }

                JObject valueToken = result["launchConfiguration"] as JObject;
                if (valueToken == null)
                {
                    return(null);
                }

                return(LaunchConfiguration.FromJObject(valueToken));
            };

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource)
                   .Select(resultSelector));
        }
        /// <inheritdoc/>
        public Task ResumeGroupAsync(ScalingGroupId groupId, CancellationToken cancellationToken)
        {
            if (groupId == null)
            {
                throw new ArgumentNullException("groupId");
            }

            UriTemplate template   = new UriTemplate("/groups/{groupId}/resume");
            var         parameters = new Dictionary <string, string> {
                { "groupId", groupId.Value }
            };

            Func <Task <Tuple <IdentityToken, Uri> >, HttpWebRequest> prepareRequest =
                PrepareRequestAsyncFunc(HttpMethod.POST, template, parameters);

            Func <Task <HttpWebRequest>, Task <string> > requestResource =
                GetResponseAsyncFunc(cancellationToken);

            return(AuthenticateServiceAsync(cancellationToken)
                   .Select(prepareRequest)
                   .Then(requestResource));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get detailed information about a scaling group.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <returns>A <see cref="ScalingGroup"/> object describing the scaling group.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="groupId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_showGroupManifest_v1.0__tenantId__groups__groupId__autoscale-groups.html">Show scaling group details (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static ScalingGroup GetGroup(this IAutoScaleService service, ScalingGroupId groupId)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                return(service.GetGroupAsync(groupId, CancellationToken.None).Result);
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Remove and delete a webhook associated with a scaling policy.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param>
        /// <param name="webhookId">The ID of the webhook. This is obtained from <see cref="Webhook.Id">Webhook.Id</see>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="groupId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="webhookId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__autoscale-webhooks.html">Delete webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                service.DeleteWebhookAsync(groupId, policyId, webhookId, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create a webhook capable of anonymously executing a scaling policy.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param>
        /// <param name="configuration">A <see cref="NewWebhookConfiguration"/> object describing the webhook configuration.</param>
        /// <returns>A <see cref="Webhook"/> object describing the newly created webhook.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="groupId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="configuration"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks_autoscale-webhooks.html">Create a webhook (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static Webhook CreateWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, NewWebhookConfiguration configuration)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                return(service.CreateWebhookAsync(groupId, policyId, configuration, CancellationToken.None).Result);
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Set the launch configuration for a scaling group.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <param name="configuration">The new launch configuration for the scaling group.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="groupId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="configuration"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putLaunchConfig_v1.0__tenantId__groups__groupId__launch_Configurations.html">Update launch configuration (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static void SetLaunchConfiguration(this IAutoScaleService service, ScalingGroupId groupId, LaunchConfiguration configuration)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                service.SetLaunchConfigurationAsync(groupId, configuration, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
        public static void DeleteWebhook(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId webhookId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.DeleteWebhookAsync(groupId, policyId, webhookId, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        public static void SetLaunchConfiguration(this IAutoScaleService service, ScalingGroupId groupId, LaunchConfiguration configuration)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.SetLaunchConfigurationAsync(groupId, configuration, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets a collection of webhooks which trigger the execution of a particular
        /// scaling policy.
        /// </summary>
        /// <param name="service">The Auto Scale service instance.</param>
        /// <param name="groupId">The ID of the scaling group. This is obtained from <see cref="ScalingGroup.Id">ScalingGroup.Id</see>.</param>
        /// <param name="policyId">The ID of the scaling policy. This is obtained from <see cref="Policy.Id">Policy.Id</see>.</param>
        /// <param name="marker">The <see cref="Webhook.Id"/> of the last item in the previous list. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">Indicates the maximum number of items to return. Used for <see href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>A collection of <see cref="Webhook"/> objects describing the webhooks for the scaling policy.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="groupId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="policyId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getWebhooks_v1.0__tenantId__groups__groupId__policies__policyId__webhooks_autoscale-webhooks.html">List webhooks for the policy (Rackspace Auto Scale Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage <Webhook> ListWebhooks(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, WebhookId marker, int?limit)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            try
            {
                return(service.ListWebhooksAsync(groupId, policyId, marker, limit, CancellationToken.None).Result);
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection <Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                {
                    throw innerExceptions[0];
                }

                throw;
            }
        }
        public static ReadOnlyCollection<Webhook> CreateWebhookRange(this IAutoScaleService service, ScalingGroupId groupId, PolicyId policyId, IEnumerable<NewWebhookConfiguration> configurations)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.CreateWebhookRangeAsync(groupId, policyId, configurations, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        public static ScalingGroup GetGroup(this IAutoScaleService service, ScalingGroupId groupId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetGroupAsync(groupId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }