/// <summary>Snippet for ListCompanies</summary>
        public void ListCompanies_RequestObject()
        {
            // Snippet: ListCompanies(ListCompaniesRequest,CallSettings)
            // Create client
            CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
            // Initialize request argument(s)
            ListCompaniesRequest request = new ListCompaniesRequest
            {
                ParentAsTenantOrProjectNameOneof = TenantOrProjectNameOneof.From(new TenantName("[PROJECT]", "[TENANT]")),
            };
            // Make the request
            PagedEnumerable <ListCompaniesResponse, Company> response =
                companyServiceClient.ListCompanies(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (Company 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 (ListCompaniesResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Company 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 <Company> 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 (Company item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Example #2
0
        private static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Error.WriteLine("Specify the project ID as the only command line argument");
                return(1);
            }
            string projectId     = args[0];
            var    companyClient = CompanyServiceClient.Create();
            var    jobClient     = JobServiceClient.Create();
            var    parentName    = TenantOrProjectName.FromProject(projectId);

            var testCompanies = companyClient.ListCompanies(parentName)
                                .Where(cn => cn.ExternalId.StartsWith("test-"))
                                .Select(c => c.CompanyName)
                                .ToList();

            Console.WriteLine($"Companies to delete: {testCompanies.Count}");

            foreach (var companyName in testCompanies)
            {
                var jobs = jobClient.ListJobs(parentName, $"companyName=\"{companyName}\"").ToList();
                Console.WriteLine($"Jobs for company {companyName}: {jobs.Count}");
                foreach (var job in jobs)
                {
                    try
                    {
                        jobClient.DeleteJob(job.JobName);
                    }
                    catch (RpcException e)
                    {
                        Console.WriteLine($"Failed to delete job {job.Name}: {e.Message}");
                    }
                }

                try
                {
                    companyClient.DeleteCompany(companyName);
                }
                catch (RpcException e)
                {
                    Console.WriteLine($"Failed to delete company {companyName}: {e.Message}");
                }
            }
            return(0);
        }
 // [START job_search_create_company_core]
 /// <summary>
 /// Create Company
 /// </summary>
 /// <param name="projectId">Your Google Cloud Project ID</param>
 public static void SampleCreateCompany(string projectId, string displayName, string externalId)
 {
     CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
     // string projectId = "Your Google Cloud Project ID"
     // string displayName = "My Company Name"
     // string externalId = "Identifier of this company in my system"
     CreateCompanyRequest request = new CreateCompanyRequest
     {
         ParentAsTenantOrProjectNameOneof = TenantOrProjectNameOneof.From(new ProjectName(projectId)),
         Company = new Company
         {
             DisplayName = "My Company Name",
             ExternalId  = "Identifier of this company in my system",
         },
     };
     Company response = companyServiceClient.CreateCompany(request);
     // FIXME: inspect the results
 }
Example #4
0
        // [START job_search_list_companies_beta]
        public static object ListCompanies(string projectId, string tenantId)
        {
            CompanyServiceClient companyServiceClient = CompanyServiceClient.Create();
            TenantName           tenantName           = TenantName.FromProjectTenant(projectId, tenantId);

            ListCompaniesRequest request = new ListCompaniesRequest
            {
                ParentAsTenantName = tenantName
            };
            var companies = companyServiceClient.ListCompanies(request);

            foreach (var company in companies)
            {
                Console.WriteLine($"Company Name: {company.Name}");
                Console.WriteLine($"Display Name: {company.DisplayName}");
                Console.WriteLine($"External ID: {company.ExternalId}");
            }
            return(0);
        }