public void ListTopics()
        {
            // Snippet: ListTopics(string,string,int?,CallSettings)
            // Create client
            PublisherClient publisherClient = PublisherClient.Create();
            // Initialize request argument(s)
            string formattedProject = PublisherClient.FormatProjectName("[PROJECT]");
            // Make the request
            IPagedEnumerable <ListTopicsResponse, Topic> response =
                publisherClient.ListTopics(formattedProject);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (Topic item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over fixed-sized pages, lazily performing RPCs as required
            int pageSize = 10;

            foreach (FixedSizePage <Topic> page in response.AsPages().WithFixedSize(pageSize))
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Topic item in page)
                {
                    Console.WriteLine(item);
                }
            }
            // End snippet
        }
Exemple #2
0
        public void WithFixedSize()
        {
            string projectId            = _fixture.ProjectId;
            string pageTokenFromRequest = "";

            // Sample: WithFixedSize
            PublisherClient client      = PublisherClient.Create();
            string          projectName = PublisherClient.FormatProjectName(projectId);
            IPagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageTokenFromRequest);

            IEnumerable <FixedSizePage <Topic> > fixedSizePages = topics.AsPages().WithFixedSize(3);
            // With fixed size pages, if there are no more resources, there are no more pages.
            FixedSizePage <Topic> nextPage = fixedSizePages.FirstOrDefault();

            if (nextPage != null)
            {
                // In a web application, this would be a matter of including the topics in the web page.
                foreach (Topic topic in nextPage)
                {
                    Console.WriteLine(topic.Name);
                }
                // ... and embedding the next page token into a "next page" link.
                Console.WriteLine($"Next page token: {nextPage.NextPageToken}");
            }
            // End sample
        }
Exemple #3
0
        public IEnumerable <Topic> ListProjectTopics(PublisherClient publisher)
        {
            // [START list_topics]
            string projectName         = PublisherClient.FormatProjectName(_projectId);
            IEnumerable <Topic> topics = publisher.ListTopics(projectName);

            // [END list_topics]
            return(topics);
        }
Exemple #4
0
        public IEnumerable <Subscription> ListSubscriptions(SubscriberClient
                                                            subscriber)
        {
            // [START list_subscriptions]
            string projectName = PublisherClient.FormatProjectName(_projectId);
            IEnumerable <Subscription> subscriptions =
                subscriber.ListSubscriptions(projectName);

            // [END list_subscriptions]
            return(subscriptions);
        }
Exemple #5
0
        public void AllResources()
        {
            string projectId = _fixture.ProjectId;
            // Sample: AllResources
            PublisherClient client      = PublisherClient.Create();
            string          projectName = PublisherClient.FormatProjectName(projectId);
            IPagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageSize: 3);

            foreach (Topic topic in topics)
            {
                Console.WriteLine(topic.Name);
            }
            // End sample
        }
        public void ListTopics()
        {
            string projectId = _fixture.ProjectId;

            // Snippet: ListTopics
            PublisherClient client = PublisherClient.Create();

            // Alternative: use a known project resource name:
            // "projects/{PROJECT_ID}"
            string projectName = PublisherClient.FormatProjectName(projectId);

            foreach (Topic topic in client.ListTopics(projectName))
            {
                Console.WriteLine(topic.Name);
            }
            // End snippet
        }
        public async Task ListTopicsAsync()
        {
            string projectId = _fixture.ProjectId;

            // Snippet: ListTopicsAsync
            PublisherClient client = PublisherClient.Create();

            // Alternative: use a known project resource name:
            // "projects/{PROJECT_ID}"
            string projectName = PublisherClient.FormatProjectName(projectId);
            IAsyncEnumerable <Topic> topics = client.ListTopicsAsync(projectName);
            await topics.ForEachAsync(topic =>
            {
                Console.WriteLine(topic.Name);
            });

            // End snippet
        }
        public void Dispose()
        {
            var subscriber    = SubscriberClient.Create();
            var subscriptions = subscriber.ListSubscriptions(SubscriberClient.FormatProjectName(ProjectId))
                                .Where(sub => SubscriberClient.SubscriptionTemplate.ParseName(sub.Name)[1].StartsWith(TopicPrefix))
                                .ToList();

            foreach (var sub in subscriptions)
            {
                subscriber.DeleteSubscription(sub.Name);
            }

            var publisher = PublisherClient.Create();
            var topics    = publisher.ListTopics(PublisherClient.FormatProjectName(ProjectId))
                            .Where(topic => PublisherClient.TopicTemplate.ParseName(topic.Name)[1].StartsWith(TopicPrefix))
                            .ToList();

            foreach (var topic in topics)
            {
                publisher.DeleteTopic(topic.Name);
            }
        }
Exemple #9
0
        public void SingleResponse()
        {
            string projectId = _fixture.ProjectId;
            // Sample: SingleResponse
            PublisherClient client      = PublisherClient.Create();
            string          projectName = PublisherClient.FormatProjectName(projectId);
            IPagedEnumerable <ListTopicsResponse, Topic>    topics     = client.ListTopics(projectName, pageSize: 3);
            IResponseEnumerable <ListTopicsResponse, Topic> topicPages = topics.AsPages();
            // This is just the regular LINQ First() method. The sequence of pages will never be empty,
            // but the page may have no resources.
            ListTopicsResponse firstPage = topicPages.First();

            Console.WriteLine("Topics in response:");
            foreach (Topic topic in firstPage.Topics)
            {
                Console.WriteLine($"  {topic.Name}");
            }
            // If you were processing items in batches, you might wish to store this
            // in order to recover from failures. The page token can be passed into the ListTopics method.
            Console.WriteLine($"Next page token: {firstPage.NextPageToken}");
            // End sample
        }
Exemple #10
0
        public void Responses()
        {
            string projectId = _fixture.ProjectId;
            // Sample: Responses
            PublisherClient client      = PublisherClient.Create();
            string          projectName = PublisherClient.FormatProjectName(projectId);
            IPagedEnumerable <ListTopicsResponse, Topic>    topics     = client.ListTopics(projectName, pageSize: 3);
            IResponseEnumerable <ListTopicsResponse, Topic> topicPages = topics.AsPages();

            foreach (ListTopicsResponse page in topicPages)
            {
                Console.WriteLine("Topics in response:");
                foreach (Topic topic in page.Topics)
                {
                    Console.WriteLine($"  {topic.Name}");
                }
                // If you were processing items in batches, you might wish to store this
                // in order to recover from failures. The page token can be passed into the ListTopics method.
                Console.WriteLine($"Next page token: {page.NextPageToken}");
            }
            // End sample
        }