public IEnumerable <Google.Cloud.Datastore.Admin.V1.Index> ListIndexes(string projectId = "your-project-id") { // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) ListIndexesRequest listIndexesRequest = new ListIndexesRequest { ProjectId = projectId }; var response = datastoreAdminClient.ListIndexes(listIndexesRequest); foreach (var index in response) { Console.WriteLine($"Index Id: {index.IndexId}"); Console.WriteLine($"Kind: {index.Kind}"); Console.WriteLine("Properties:"); foreach (var property in index.Properties) { Console.WriteLine($"Property: {property.Name}"); Console.WriteLine($"Direction: {property.Direction}"); } } return(response); }
/// <summary>Snippet for DeleteIndexAsync</summary> public async Task DeleteIndexRequestObjectAsync() { // Snippet: DeleteIndexAsync(DeleteIndexRequest, CallSettings) // Additional: DeleteIndexAsync(DeleteIndexRequest, CancellationToken) // Create client DatastoreAdminClient datastoreAdminClient = await DatastoreAdminClient.CreateAsync(); // Initialize request argument(s) DeleteIndexRequest request = new DeleteIndexRequest { ProjectId = "", IndexId = "", }; // Make the request Operation <gcdav::Index, IndexOperationMetadata> response = await datastoreAdminClient.DeleteIndexAsync(request); // Poll until the returned long-running operation is complete Operation <gcdav::Index, IndexOperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result gcdav::Index result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <gcdav::Index, IndexOperationMetadata> retrievedResponse = await datastoreAdminClient.PollOnceDeleteIndexAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result gcdav::Index retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for ExportEntities</summary> public void ExportEntitiesRequestObject() { // Snippet: ExportEntities(ExportEntitiesRequest, CallSettings) // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) ExportEntitiesRequest request = new ExportEntitiesRequest { ProjectId = "", Labels = { { "", "" }, }, EntityFilter = new EntityFilter(), OutputUrlPrefix = "", }; // Make the request Operation <ExportEntitiesResponse, ExportEntitiesMetadata> response = datastoreAdminClient.ExportEntities(request); // Poll until the returned long-running operation is complete Operation <ExportEntitiesResponse, ExportEntitiesMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result ExportEntitiesResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <ExportEntitiesResponse, ExportEntitiesMetadata> retrievedResponse = datastoreAdminClient.PollOnceExportEntities(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result ExportEntitiesResponse retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for CreateIndex</summary> public void CreateIndexRequestObject() { // Snippet: CreateIndex(CreateIndexRequest, CallSettings) // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) CreateIndexRequest request = new CreateIndexRequest { ProjectId = "", Index = new gcdav::Index(), }; // Make the request Operation <gcdav::Index, IndexOperationMetadata> response = datastoreAdminClient.CreateIndex(request); // Poll until the returned long-running operation is complete Operation <gcdav::Index, IndexOperationMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result gcdav::Index result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <gcdav::Index, IndexOperationMetadata> retrievedResponse = datastoreAdminClient.PollOnceCreateIndex(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result gcdav::Index retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for ImportEntities</summary> public void ImportEntities() { // Snippet: ImportEntities(string, IDictionary<string,string>, string, EntityFilter, CallSettings) // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) string projectId = ""; IDictionary <string, string> labels = new Dictionary <string, string> { { "", "" }, }; string inputUrl = ""; EntityFilter entityFilter = new EntityFilter(); // Make the request Operation <Empty, ImportEntitiesMetadata> response = datastoreAdminClient.ImportEntities(projectId, labels, inputUrl, entityFilter); // Poll until the returned long-running operation is complete Operation <Empty, ImportEntitiesMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result Empty result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Empty, ImportEntitiesMetadata> retrievedResponse = datastoreAdminClient.PollOnceImportEntities(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Empty retrievedResult = retrievedResponse.Result; } // End snippet }
public Index GetIndex( string projectId = "your-project-id", string indexId = "your-index-id") { // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) GetIndexRequest getIndexRequest = new GetIndexRequest { ProjectId = projectId, IndexId = indexId }; Index index = datastoreAdminClient.GetIndex(getIndexRequest); Console.WriteLine($"Index Id: {index.IndexId}"); Console.WriteLine($"Kind: {index.Kind}"); Console.WriteLine("Properties:"); foreach (var property in index.Properties) { Console.WriteLine($"Property: {property.Name}"); Console.WriteLine($"Direction: {property.Direction}"); } return(index); }
public bool ImportEntities( string projectId = "your-project-id", string inputUrl = "gs://datastore-admin-bucket/data_to_import", string kind = "Task", string namespaceId = "default") { // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); IDictionary <string, string> labels = new Dictionary <string, string> { { "cloud_datastore_samples", "true" }, }; EntityFilter entityFilter = new EntityFilter() { Kinds = { kind }, NamespaceIds = { namespaceId } }; Operation <Empty, ImportEntitiesMetadata> response = datastoreAdminClient.ImportEntities(projectId, labels, inputUrl, entityFilter); // Poll until the returned long-running operation is complete Operation <Empty, ImportEntitiesMetadata> completedResponse = response.PollUntilCompleted(); if (completedResponse.IsFaulted) { Console.WriteLine($"Error while Importing Entities: {completedResponse.Exception}"); throw completedResponse.Exception; } Console.WriteLine($"Entities imported successfully."); return(completedResponse.IsCompleted); }
/// <summary>Snippet for ListIndexesAsync</summary> public async Task ListIndexesRequestObjectAsync() { // Snippet: ListIndexesAsync(ListIndexesRequest, CallSettings) // Create client DatastoreAdminClient datastoreAdminClient = await DatastoreAdminClient.CreateAsync(); // Initialize request argument(s) ListIndexesRequest request = new ListIndexesRequest { ProjectId = "", Filter = "", }; // Make the request PagedAsyncEnumerable <ListIndexesResponse, gcdav::Index> response = datastoreAdminClient.ListIndexesAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((gcdav::Index item) => { // Do something with each item Console.WriteLine(item); }); // Or iterate over pages (of server-defined size), performing one RPC per page await response.AsRawResponses().ForEachAsync((ListIndexesResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (gcdav::Index item in page) { // Do something with each item 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 <gcdav::Index> singlePage = await response.ReadPageAsync(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (gcdav::Index item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for GetIndex</summary> public void GetIndexRequestObject() { // Snippet: GetIndex(GetIndexRequest, CallSettings) // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // Initialize request argument(s) GetIndexRequest request = new GetIndexRequest { ProjectId = "", IndexId = "", }; // Make the request gcdav::Index response = datastoreAdminClient.GetIndex(request); // End snippet }
/// <summary>Snippet for GetIndexAsync</summary> public async Task GetIndexRequestObjectAsync() { // Snippet: GetIndexAsync(GetIndexRequest, CallSettings) // Additional: GetIndexAsync(GetIndexRequest, CancellationToken) // Create client DatastoreAdminClient datastoreAdminClient = await DatastoreAdminClient.CreateAsync(); // Initialize request argument(s) GetIndexRequest request = new GetIndexRequest { ProjectId = "", IndexId = "", }; // Make the request gcdav::Index response = await datastoreAdminClient.GetIndexAsync(request); // End snippet }
public string ExportEntities( string projectId = "your-project-id", string outputUrlPrefix = "gs://your-bucket-name", string kind = "Task", string namespaceId = "default") { // [START datastore_admin_client_create] // Create client DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create(); // [END datastore_admin_client_create] IDictionary <string, string> labels = new Dictionary <string, string> { { "cloud_datastore_samples", "true" }, }; EntityFilter entityFilter = new EntityFilter { Kinds = { kind }, NamespaceIds = { namespaceId } }; var response = datastoreAdminClient.ExportEntities(projectId, labels, entityFilter, outputUrlPrefix); // Poll until the returned long-running operation is complete var completedResponse = response.PollUntilCompleted(); if (completedResponse.IsFaulted) { Console.WriteLine($"Error while Exporting Entities: {completedResponse.Exception}"); throw completedResponse.Exception; } Console.WriteLine($"Entities exported successfully."); ExportEntitiesResponse result = completedResponse.Result; return(result.OutputUrl); }
/// <summary>Snippet for ImportEntitiesAsync</summary> public async Task ImportEntitiesRequestObjectAsync() { // Snippet: ImportEntitiesAsync(ImportEntitiesRequest, CallSettings) // Additional: ImportEntitiesAsync(ImportEntitiesRequest, CancellationToken) // Create client DatastoreAdminClient datastoreAdminClient = await DatastoreAdminClient.CreateAsync(); // Initialize request argument(s) ImportEntitiesRequest request = new ImportEntitiesRequest { ProjectId = "", Labels = { { "", "" }, }, InputUrl = "", EntityFilter = new EntityFilter(), }; // Make the request Operation <Empty, ImportEntitiesMetadata> response = await datastoreAdminClient.ImportEntitiesAsync(request); // Poll until the returned long-running operation is complete Operation <Empty, ImportEntitiesMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Empty result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Empty, ImportEntitiesMetadata> retrievedResponse = await datastoreAdminClient.PollOnceImportEntitiesAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Empty retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary>Snippet for ExportEntitiesAsync</summary> public async Task ExportEntitiesAsync() { // Snippet: ExportEntitiesAsync(string, IDictionary<string,string>, EntityFilter, string, CallSettings) // Additional: ExportEntitiesAsync(string, IDictionary<string,string>, EntityFilter, string, CancellationToken) // Create client DatastoreAdminClient datastoreAdminClient = await DatastoreAdminClient.CreateAsync(); // Initialize request argument(s) string projectId = ""; IDictionary <string, string> labels = new Dictionary <string, string> { { "", "" }, }; EntityFilter entityFilter = new EntityFilter(); string outputUrlPrefix = ""; // Make the request Operation <ExportEntitiesResponse, ExportEntitiesMetadata> response = await datastoreAdminClient.ExportEntitiesAsync(projectId, labels, entityFilter, outputUrlPrefix); // Poll until the returned long-running operation is complete Operation <ExportEntitiesResponse, ExportEntitiesMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result ExportEntitiesResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <ExportEntitiesResponse, ExportEntitiesMetadata> retrievedResponse = await datastoreAdminClient.PollOnceExportEntitiesAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result ExportEntitiesResponse retrievedResult = retrievedResponse.Result; } // End snippet }