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
        }
Ejemplo n.º 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
        }
Ejemplo n.º 3
0
        public static int Main(string[] args)
        {
            // Read projectId from args
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: Project ID must be passed as first argument.");
                Console.WriteLine();
                return(1);
            }
            string projectId = args[0];

            // Create client
            PublisherClient client = PublisherClient.Create();

            // Initialize request argument(s)
            ProjectName project = new ProjectName(projectId);

            // Call API method
            PagedEnumerable <ListTopicsResponse, Topic> pagedResponse = client.ListTopics(project);

            // Show the result
            foreach (var item in pagedResponse)
            {
                Console.WriteLine(item);
            }

            // Success
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static object ListProjectTopics(PublisherClient publisher, string projectId)
        {
            // [START list_topics]
            ProjectName         projectName = new ProjectName(projectId);
            IEnumerable <Topic> topics      = publisher.ListTopics(projectName);

            // [END list_topics]
            foreach (Topic topic in topics)
            {
                Console.WriteLine($"{topic.Name}");
            }
            return(0);
        }
Ejemplo n.º 6
0
        public void AllResources()
        {
            string projectId = _fixture.ProjectId;
            // Sample: AllResources
            PublisherClient client      = PublisherClient.Create();
            ProjectName     projectName = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageSize: 3);

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

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

            ProjectName projectName = new ProjectName(projectId);

            foreach (Topic topic in client.ListTopics(projectName))
            {
                Console.WriteLine(topic.Name);
            }
            // End snippet
        }
    public void ListTopics()
    {
        // <ListTopics>
        PublisherClient client = PublisherClient.Create();

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

        foreach (Topic topic in client.ListTopics(projectName))
        {
            Console.WriteLine(topic.Name);
        }
        // </ListTopics>
    }
Ejemplo n.º 9
0
        public void Emulator()
        {
            // Sample: Emulator
            // For example, "localhost:8615"
            string emulatorHostAndPort = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");

            Channel         channel = new Channel(emulatorHostAndPort, ChannelCredentials.Insecure);
            PublisherClient client  = PublisherClient.Create(channel);

            client.CreateTopic(new TopicName("project", "topic"));
            foreach (var topic in client.ListTopics(new ProjectName("project")))
            {
                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 void ListTopics_RequestObject()
        {
            // Snippet: ListTopics(ListTopicsRequest,CallSettings)
            // Create client
            PublisherClient publisherClient = PublisherClient.Create();
            // Initialize request argument(s)
            ListTopicsRequest request = new ListTopicsRequest
            {
                ProjectAsProjectName = new ProjectName("[PROJECT]"),
            };
            // Make the request
            PagedEnumerable <ListTopicsResponse, Topic> response =
                publisherClient.ListTopics(request);

            // 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 pages (of server-defined size), performing one RPC per page
            foreach (ListTopicsResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Topic item in page)
                {
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int          pageSize   = 10;
            Page <Topic> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Topic item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Ejemplo n.º 12
0
        public void ReadPage()
        {
            string projectId            = _fixture.ProjectId;
            string pageTokenFromRequest = "";

            // Sample: ReadPage
            PublisherClient client      = PublisherClient.Create();
            ProjectName     projectName = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageTokenFromRequest);

            Page <Topic> page = topics.ReadPage(3);

            // In a web application, this would be a matter of including the topics in the web page.
            foreach (Topic topic in page)
            {
                Console.WriteLine(topic.Name);
            }
            // ... and embedding the next page token into a "next page" link.
            Console.WriteLine($"Next page token: {page.NextPageToken}");
            // End sample
        }
Ejemplo n.º 13
0
        private async Task Run()
        {
            string CREDENTIAL_FILE_PKCS12       = "/path/to/your/cert/file.p12";
            string serviceAccountEmail          = "*****@*****.**";
            var    certificate                  = new X509Certificate2(CREDENTIAL_FILE_PKCS12, "notasecret", X509KeyStorageFlags.Exportable);
            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                //Scopes = new[] { StorageService.Scope.DevstorageReadOnly, PublisherClient.DefaultScopes },
                Scopes            = PublisherClient.DefaultScopes.Append(StorageService.Scope.DevstorageReadOnly),
                HttpClientFactory = new ProxySupportedHttpClientFactory()
            }.FromCertificate(certificate));


            //GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();
            //StorageService service = StorageClient.Create(credential);

            StorageService service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = StorageClientImpl.ApplicationName,
                HttpClientFactory     = new ProxySupportedHttpClientFactory(),
            });
            var client = new StorageClientImpl(service, null);

            foreach (var b in client.ListBuckets(projectID))
            {
                Console.WriteLine(b.Name);
            }

            ChannelCredentials channelCredentials = credential.ToChannelCredentials();
            Channel            channel            = new Channel(PublisherClient.DefaultEndpoint.ToString(), channelCredentials);
            PublisherSettings  ps        = new PublisherSettings();
            PublisherClient    publisher = PublisherClient.Create(channel, ps);

            foreach (Topic t in publisher.ListTopics(new ProjectName(projectID)))
            {
                Console.WriteLine(t.Name);
            }
        }
Ejemplo n.º 14
0
        public void SingleResponse()
        {
            string projectId = _fixture.ProjectId;
            // Sample: SingleResponse
            PublisherClient client      = PublisherClient.Create();
            ProjectName     projectName = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics         = client.ListTopics(projectName, pageSize: 3);
            IEnumerable <ListTopicsResponse>            topicResponses = topics.AsRawResponses();
            // This is just the regular LINQ First() method. The sequence of pages will never be empty,
            // but the page may have no resources.
            ListTopicsResponse firstResponse = topicResponses.First();

            Console.WriteLine("Topics in response:");
            foreach (Topic topic in firstResponse.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: {firstResponse.NextPageToken}");
            // End sample
        }
Ejemplo n.º 15
0
        public void Responses()
        {
            string projectId = _fixture.ProjectId;
            // Sample: Responses
            PublisherClient client      = PublisherClient.Create();
            ProjectName     projectName = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics         = client.ListTopics(projectName, pageSize: 3);
            IEnumerable <ListTopicsResponse>            topicResponses = topics.AsRawResponses();

            foreach (ListTopicsResponse response in topicResponses)
            {
                Console.WriteLine("Topics in response:");
                foreach (Topic topic in response.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: {response.NextPageToken}");
            }
            // End sample
        }
 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;
 }