Exemplo n.º 1
0
 /// <summary>
 /// Gets all of the subscriptions of a current project.
 /// </summary>
 public async Task <IList <Subscription> > GetSubscriptionListAsync()
 {
     ProjectsResource.SubscriptionsResource.ListRequest request =
         Service.Projects.Subscriptions.List(ProjectResourceName);
     return(await LoadPagedListAsync(
                token =>
     {
         request.PageToken = token;
         return request.ExecuteAsync();
     },
                response => response.Subscriptions,
                response => response.NextPageToken));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets all of the subscriptions of a current project.
 /// </summary>
 public async Task <IList <Subscription> > GetSubscriptionListAsync()
 {
     try
     {
         ProjectsResource.SubscriptionsResource.ListRequest request =
             Service.Projects.Subscriptions.List(ProjectResourceName);
         return(await LoadPagedListAsync(
                    token =>
         {
             request.PageToken = token;
             return request.ExecuteAsync();
         },
                    response => response.Subscriptions,
                    response => response.NextPageToken));
     }
     catch (GoogleApiException e)
     {
         throw new DataSourceException(e.Message, e);
     }
 }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            if (Subscription != null)
            {
                Subscription = Subscription.Select(item => GetProjectPrefixForSubscription(item, Project)).ToArray();
            }

            // Handles the case where user wants to list all subscriptions in a particular topic.
            // In this case, we will have to make a call to get the name of all the subscriptions in that topic
            // before calling get request on each subscription.
            if (Topic != null)
            {
                Topic = GetProjectPrefixForTopic(Topic, Project);
                ProjectsResource.TopicsResource.SubscriptionsResource.ListRequest listRequest =
                    Service.Projects.Topics.Subscriptions.List(Topic);
                do
                {
                    ListTopicSubscriptionsResponse response = null;
                    try
                    {
                        response = listRequest.Execute();
                    }
                    catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
                    {
                        WriteResourceMissingError(
                            exceptionMessage: $"Topic '{Topic}' does not exist in project '{Project}'.",
                            errorId: "TopicNotFound",
                            targetObject: Topic);
                    }

                    if (response?.Subscriptions != null)
                    {
                        // If user gives us a list of subscriptions to search for, we have to make sure that
                        // those subscriptions belong to the topic.
                        if (Subscription != null)
                        {
                            IEnumerable <string> selectedSubscriptions = response.Subscriptions
                                                                         .Where(sub => Subscription.Contains(sub, System.StringComparer.OrdinalIgnoreCase));
                            GetSubscriptions(selectedSubscriptions);
                        }
                        else
                        {
                            GetSubscriptions(response.Subscriptions);
                        }
                    }
                    listRequest.PageToken = response.NextPageToken;
                }while (!Stopping && listRequest.PageToken != null);
                return;
            }

            // If no topic is given, then we are left with 2 cases:
            // 1. User gives us a list of subscriptions: we just find those subscriptions and returned.
            // 2. User does not give us any subscriptions: we just return all subscriptions in the project.
            if (Subscription != null && Subscription.Length > 0)
            {
                GetSubscriptions(Subscription.Select(item => GetProjectPrefixForSubscription(item, Project)));
            }
            else
            {
                ProjectsResource.SubscriptionsResource.ListRequest listRequest =
                    Service.Projects.Subscriptions.List($"projects/{Project}");
                do
                {
                    ListSubscriptionsResponse response = listRequest.Execute();

                    if (response.Subscriptions != null)
                    {
                        WriteObject(response.Subscriptions, true);
                    }
                    listRequest.PageToken = response.NextPageToken;
                }while (!Stopping && listRequest.PageToken != null);
            }
        }