示例#1
0
    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 DeleteIndex</summary>
        public void DeleteIndexRequestObject()
        {
            // Snippet: DeleteIndex(DeleteIndexRequest, CallSettings)
            // Create client
            DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();
            // Initialize request argument(s)
            DeleteIndexRequest request = new DeleteIndexRequest
            {
                ProjectId = "",
                IndexId   = "",
            };
            // Make the request
            Operation <gcdav::Index, IndexOperationMetadata> response = datastoreAdminClient.DeleteIndex(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.PollOnceDeleteIndex(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 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
        }
示例#5
0
    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);
    }
示例#6
0
    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 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 ListIndexes</summary>
        public void ListIndexesRequestObject()
        {
            // Snippet: ListIndexes(ListIndexesRequest, CallSettings)
            // Create client
            DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();
            // Initialize request argument(s)
            ListIndexesRequest request = new ListIndexesRequest
            {
                ProjectId = "",
                Filter    = "",
            };
            // Make the request
            PagedEnumerable <ListIndexesResponse, gcdav::Index> response = datastoreAdminClient.ListIndexes(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (gcdav::Index 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 (ListIndexesResponse page in response.AsRawResponses())
            {
                // 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 = response.ReadPage(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
        }
    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);
    }