/// <summary>Snippet for UpdateRealmAsync</summary>
        public async Task UpdateRealmAsync()
        {
            // Snippet: UpdateRealmAsync(Realm, FieldMask, CallSettings)
            // Additional: UpdateRealmAsync(Realm, FieldMask, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            Realm     realm      = new Realm();
            FieldMask updateMask = new FieldMask();
            // Make the request
            Operation <Realm, OperationMetadata> response = await realmsServiceClient.UpdateRealmAsync(realm, updateMask);

            // Poll until the returned long-running operation is complete
            Operation <Realm, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Realm 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 <Realm, OperationMetadata> retrievedResponse = await realmsServiceClient.PollOnceUpdateRealmAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Realm retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
        /// <summary>Snippet for DeleteRealmAsync</summary>
        public async Task DeleteRealmResourceNamesAsync()
        {
            // Snippet: DeleteRealmAsync(RealmName, CallSettings)
            // Additional: DeleteRealmAsync(RealmName, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            RealmName name = RealmName.FromProjectLocationRealm("[PROJECT]", "[LOCATION]", "[REALM]");
            // Make the request
            Operation <Empty, OperationMetadata> response = await realmsServiceClient.DeleteRealmAsync(name);

            // Poll until the returned long-running operation is complete
            Operation <Empty, OperationMetadata> 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, OperationMetadata> retrievedResponse = await realmsServiceClient.PollOnceDeleteRealmAsync(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 CreateRealmAsync</summary>
        public async Task CreateRealmAsync()
        {
            // Snippet: CreateRealmAsync(string, Realm, string, CallSettings)
            // Additional: CreateRealmAsync(string, Realm, string, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string parent  = "projects/[PROJECT]/locations/[LOCATION]";
            Realm  realm   = new Realm();
            string realmId = "";
            // Make the request
            Operation <Realm, OperationMetadata> response = await realmsServiceClient.CreateRealmAsync(parent, realm, realmId);

            // Poll until the returned long-running operation is complete
            Operation <Realm, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Realm 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 <Realm, OperationMetadata> retrievedResponse = await realmsServiceClient.PollOnceCreateRealmAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Realm retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
    public async Task <Realm> UpdateRealmAsync(
        string projectId, string regionId, string realmId)
    {
        // Create the client.
        RealmsServiceClient client = await RealmsServiceClient.CreateAsync();

        Realm realm = new Realm
        {
            RealmName = RealmName.FromProjectLocationRealm(projectId, regionId, realmId),
        };

        realm.Labels.Add("label-key-1", "label-value-1");
        realm.Labels.Add("label-key-2", "label-value-2");

        UpdateRealmRequest request = new UpdateRealmRequest
        {
            Realm      = realm,
            UpdateMask = new FieldMask {
                Paths = { "labels" }
            }
        };

        // Make the request.
        Operation <Realm, OperationMetadata> response = await client.UpdateRealmAsync(request);

        Operation <Realm, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result. This result will NOT contain the updated labels.
        // If you want to get the updated resource, use a GET request on the resource.
        return(completedResponse.Result);
    }
Пример #5
0
    public async Task <Realm> CreateRealmAsync(
        string projectId, string regionId, string realmId)
    {
        // Create the client.
        RealmsServiceClient client = await RealmsServiceClient.CreateAsync();

        Realm realm = new Realm
        {
            RealmName = RealmName.FromProjectLocationRealm(projectId, regionId, realmId),
            TimeZone  = "America/Los_Angeles"
        };

        CreateRealmRequest request = new CreateRealmRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, regionId),
            RealmId = realmId,
            Realm   = realm
        };

        // Make the request.
        Operation <Realm, OperationMetadata> response = await client.CreateRealmAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation <Realm, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
        /// <summary>Snippet for ListRealms</summary>
        public async Task ListRealmsRequestObjectAsync()
        {
            // Snippet: ListRealmsAsync(ListRealmsRequest, CallSettings)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListRealmsRequest request = new ListRealmsRequest
            {
                ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
                Filter  = "",
                OrderBy = "",
            };
            // Make the request
            PagedAsyncEnumerable <ListRealmsResponse, Realm> response = realmsServiceClient.ListRealmsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Realm 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((ListRealmsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Realm 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 <Realm> 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 (Realm 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 GetRealmAsync</summary>
        public async Task GetRealmResourceNamesAsync()
        {
            // Snippet: GetRealmAsync(RealmName, CallSettings)
            // Additional: GetRealmAsync(RealmName, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            RealmName name = RealmName.FromProjectLocationRealm("[PROJECT]", "[LOCATION]", "[REALM]");
            // Make the request
            Realm response = await realmsServiceClient.GetRealmAsync(name);

            // End snippet
        }
        /// <summary>Snippet for GetRealmAsync</summary>
        public async Task GetRealmAsync()
        {
            // Snippet: GetRealmAsync(string, CallSettings)
            // Additional: GetRealmAsync(string, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string name = "projects/[PROJECT]/locations/[LOCATION]/realms/[REALM]";
            // Make the request
            Realm response = await realmsServiceClient.GetRealmAsync(name);

            // End snippet
        }
        /// <summary>Snippet for PreviewRealmUpdateAsync</summary>
        public async Task PreviewRealmUpdateRequestObjectAsync()
        {
            // Snippet: PreviewRealmUpdateAsync(PreviewRealmUpdateRequest, CallSettings)
            // Additional: PreviewRealmUpdateAsync(PreviewRealmUpdateRequest, CancellationToken)
            // Create client
            RealmsServiceClient realmsServiceClient = await RealmsServiceClient.CreateAsync();

            // Initialize request argument(s)
            PreviewRealmUpdateRequest request = new PreviewRealmUpdateRequest
            {
                Realm       = new Realm(),
                UpdateMask  = new FieldMask(),
                PreviewTime = new Timestamp(),
            };
            // Make the request
            PreviewRealmUpdateResponse response = await realmsServiceClient.PreviewRealmUpdateAsync(request);

            // End snippet
        }