Beispiel #1
0
        /// <summary>
        /// Library method to wait for an SQL operation to finish.
        /// </summary>
        /// <param name="op">
        /// The SQL operation we want to wait for.
        /// </param>
        /// <returns>
        /// The finished operation resource.
        /// </returns>
        public Operation WaitForSqlOperation(Operation op)
        {
            int delay;

            switch (op.OperationType)
            {
            case "CREATE":
            case "FAILOVER":
            case "RECREATE_REPLICA":
            case "RESTORE_VOLUME":
            case "CREATE_REPLICA":
            {
                delay = 30000;
                break;
            }

            case "UPDATE":
            case "DELETE":
            case "IMPORT":
            case "EXPORT":
            {
                delay = 5000;
                break;
            }

            default:
            {
                delay = 150;
                break;
            }
            }
            Random         rnd      = new Random();
            int            randProc = rnd.Next();
            ProgressRecord progress =
                new ProgressRecord(randProc, $"Waiting for operation '{op.OperationType}' to finish.", "Waiting");

            progress.PercentComplete = 0;
            WriteProgress(progress);
            int percentComplete = 1;

            while (op.Status != "DONE")
            {
                if (op.Error != null)
                {
                    WriteWarning(op.Error.ToString());
                    return(op);
                }
                Thread.Sleep(delay);
                progress.PercentComplete = percentComplete;
                WriteProgress(progress);
                percentComplete = (percentComplete + 1) % 100;
                OperationsResource.GetRequest request = Service.Operations.Get(op.TargetProject, op.Name);
                op = request.Execute();
            }
            progress.RecordType      = ProgressRecordType.Completed;
            progress.PercentComplete = 100;
            WriteProgress(progress);
            return(op);
        }
 /// <summary>
 /// Gets the Cloud SQL operations.
 /// </summary>
 /// <param name="id">The unique operation id.</param>
 /// <returns>The Cloud SQL operation.</returns>
 public async Task <Operation> GetOperationAsync(string id)
 {
     try
     {
         OperationsResource.GetRequest request = Service.Operations.Get(ProjectId, id);
         return(await request.ExecuteAsync());
     }
     catch (GoogleApiException ex)
     {
         Debug.WriteLine($"Failed to get the operation: {ex.Message}");
         throw new DataSourceException(ex.Message, ex);
     }
 }
Beispiel #3
0
 protected override void ProcessRecord()
 {
     if (Name != null)
     {
         OperationsResource.GetRequest request = Service.Operations.Get(Project, Name);
         Operation result = request.Execute();
         WriteObject(result);
     }
     else
     {
         IEnumerable <Operation> results = GetAllOperations();
         WriteObject(results, true);
     }
 }