Esempio n. 1
0
        static void Main(string[] args)
        {
            GoogleCredential credential =
                GoogleCredential.GetApplicationDefault();

            if (credential.IsCreateScopedRequired)
            {
                credential = credential.CreateScoped(new[]
                {
                    CloudResourceManagerService.Scope.CloudPlatformReadOnly
                });
            }
            var crmService = new CloudResourceManagerService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
            });
            var request = new ProjectsResource.ListRequest(crmService);

            while (true)
            {
                var result = request.Execute();
                foreach (var project in result.Projects)
                {
                    Console.WriteLine(project.ProjectId);
                }
                if (string.IsNullOrEmpty(result.NextPageToken))
                {
                    break;
                }
                request.PageToken = result.NextPageToken;
            }
        }
Esempio n. 2
0
        // [END list_datasets]

        /// <summary>
        /// Lists all Projects.
        /// </summary>
        // [START list_projects]
        public IEnumerable <ProjectList.ProjectsData> ListProjects()
        {
            BigqueryService bigquery       = CreateAuthorizedClient();
            var             projectRequest = new ProjectsResource.ListRequest(bigquery);

            // Sometimes Projects will be null instead of an empty list.
            // It's easy to forget that and dereference null.  So, catch
            // that case and return an empty list.
            return(projectRequest.Execute().Projects ??
                   new ProjectList.ProjectsData[] { });
        }
Esempio n. 3
0
        // Just loops though getting all the rows.
        private static ProjectList ProcessResults(ProjectsResource.ListRequest request)
        {
            try
            {
                ProjectList result = request.Execute();


                List <ProjectList.ProjectsData> allRows = new List <ProjectList.ProjectsData>();

                //// Loop through until we arrive at an empty page
                while (result.Projects != null)
                {
                    //Add the rows to the final list
                    allRows.AddRange(result.Projects);

                    // We will know we are on the last page when the next page token is
                    // null.
                    // If this is the case, break.
                    if (result.NextPageToken == null)
                    {
                        break;
                    }
                    // Prepare the next page of results
                    request.PageToken = result.NextPageToken;

                    // Execute and process the next page request
                    result = request.Execute();
                }
                ProjectList allData = result;
                allData.Projects = (List <ProjectList.ProjectsData>)allRows;
                return(allData);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Esempio n. 4
0
 private static IEnumerable <Project> ListAllProjects()
 {
     ProjectsResource.ListRequest request = ResourceService.Projects.List();
     do
     {
         ListProjectsResponse projects = request.Execute();
         foreach (Project project in projects.Projects ?? Enumerable.Empty <Project>())
         {
             // The Storage Service considers invactive projects to not exist.
             if (project.LifecycleState == "ACTIVE")
             {
                 yield return(project);
             }
         }
         request.PageToken = projects.NextPageToken;
     } while (request.PageToken != null);
 }
Esempio n. 5
0
        /// <summary>
        /// Returns list of projects based on the filter.
        /// </summary>
        private IEnumerable <Project> GetProjects(string filter)
        {
            ProjectsResource.ListRequest request = Service.Projects.List();
            if (!string.IsNullOrWhiteSpace(filter))
            {
                request.Filter = filter;
            }

            do
            {
                ListProjectsResponse response = request.Execute();
                if (response.Projects != null)
                {
                    foreach (Project project in response.Projects)
                    {
                        yield return(project);
                    }
                }
                request.PageToken = response.NextPageToken;
            }while (!Stopping && request.PageToken != null);
        }
Esempio n. 6
0
 // [END list_datasets]
 /// <summary>
 /// Lists all Projects.
 /// </summary>
 /// <param name="bigquery">The BigQuery object.</param>
 // [START list_projects]
 public static IEnumerable<ProjectList.ProjectsData> ListProjects(BigqueryService bigquery)
 {
     var projectRequest = new ProjectsResource.ListRequest(bigquery);
     // Sometimes Projects will be null instead of an empty list.
     // It's easy to forget that and dereference null.  So, catch
     // that case and return an empty list.
     return projectRequest.Execute().Projects ?? new ProjectList.ProjectsData[] { };
 }