示例#1
0
        /// <summary>Snippet for UpdateIndexAsync</summary>
        public async Task UpdateIndexRequestObjectAsync()
        {
            // Snippet: UpdateIndexAsync(UpdateIndexRequest, CallSettings)
            // Additional: UpdateIndexAsync(UpdateIndexRequest, CancellationToken)
            // Create client
            IndexServiceClient indexServiceClient = await IndexServiceClient.CreateAsync();

            // Initialize request argument(s)
            UpdateIndexRequest request = new UpdateIndexRequest
            {
                Index      = new gcav::Index(),
                UpdateMask = new FieldMask(),
            };
            // Make the request
            Operation <gcav::Index, UpdateIndexOperationMetadata> response = await indexServiceClient.UpdateIndexAsync(request);

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

            // Retrieve the operation result
            gcav::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 <gcav::Index, UpdateIndexOperationMetadata> retrievedResponse = await indexServiceClient.PollOnceUpdateIndexAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                gcav::Index retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
示例#2
0
 public Task <IndexResponse> UpdateIndexAsync(string uid, UpdateIndexRequest updateRequest) =>
 rest.PutAsync <IndexResponse>(
     new RestRequest($"/indexes/{uid}").AddJsonBody(updateRequest));
        public UpdateIndexResponse UpdateIndex(UpdateIndexRequest request, bool singleUserMode)
        {
            try
            {
                var options = new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.Serializable,
                    Timeout        = new TimeSpan(0, TransactionTimeout, 0)
                };
                using (var trScope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    if (singleUserMode)
                    {
                        SetSingleMode(DatabaseName);
                    }

                    var      dependecies = new List <DroppedDependencyDbo>();
                    IndexDbo dbo         = null;
                    string   logMsg      = null;

                    switch (request.Operation)
                    {
                    case UpdateColumnOperation.Rename:
                        dbo    = RenameTheIndex(request.Table, request.OldIndexName, request.IndexName);
                        logMsg = String.Format("Table '{0}': index '{1}' was renamed to '{2}'.",
                                               request.Table, request.OldIndexName, request.IndexName);
                        break;

                    case UpdateColumnOperation.Insert:
                        dbo    = CreateTheIndex(request.Table, request.IndexDescriptor);
                        logMsg = String.Format("Table '{0}': index '{1}' was created.", request.Table, request.IndexDescriptor.Name);
                        break;

                    case UpdateColumnOperation.Delete:
                        dependecies = DeleteTheIndex(request.Table, request.IndexName, request.DisableDependencies);
                        dbo         = new IndexDbo()
                        {
                            Name = request.IndexName, IsDisabled = true
                        };
                        logMsg = String.Format("Table '{0}': index '{1}' was deleted.", request.Table, request.IndexName);
                        break;

                    case UpdateColumnOperation.Modify:
                        dependecies = UpdateTheIndex(request.Table, request.IndexDescriptor, request.DisableDependencies, out dbo);
                        logMsg      = String.Format("Table '{0}': index '{1}' was modified.", request.Table, request.IndexDescriptor.Name);
                        break;
                    }
                    int  recordCount     = CountRecords(request.Table);
                    Guid historyRecordId = LogTableOperation(request.Table, logMsg, request.CFC_DB_Major_Version,
                                                             request.CFC_DB_Minor_Version);

                    trScope.Complete();
                    return(new UpdateIndexResponse()
                    {
                        IsSuccess = true,
                        DroppedDependencies = dependecies,
                        Dbo = dbo,
                        RecordCount = recordCount
                    });
                }
            }
            catch (Exception ex)
            {
                return(new UpdateIndexResponse()
                {
                    IsSuccess = false, ErrorMessage = ParseErrorMessage(ex)
                });
            }
            finally
            {
                if (singleUserMode)
                {
                    SetMultiUserMode(DatabaseName);
                }
            }
        }