Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            // Form and send request.
            DatasetsResource.DeleteRequest request;
            switch (ParameterSetName)
            {
            case ParameterSetNames.ByObject:
                Project   = Dataset.ProjectId;
                DatasetId = Dataset.DatasetId;
                request   = Service.Datasets.Delete(Project, DatasetId);
                break;

            case ParameterSetNames.ByValues:
                request = Service.Datasets.Delete(Project, DatasetId);
                break;

            default:
                throw UnknownParameterSetException;
            }
            String response = "Dataset Removal Stopped.";

            if (ShouldProcess(DatasetId))
            {
                try
                {
                    if (Force == true)
                    {
                        request.DeleteContents = true;
                        response = request.Execute();
                    }
                    else
                    {
                        TablesResource.ListRequest checkTables =
                            new TablesResource.ListRequest(Service, Project, DatasetId);
                        var tableResponse = checkTables.Execute();
                        if (tableResponse.TotalItems == 0)
                        {
                            response = request.Execute();
                        }
                        else if (ShouldContinue(
                                     GetConfirmationMessage(DatasetId, tableResponse.TotalItems),
                                     "Confirm Deletion"))
                        {
                            request.DeleteContents = true;
                            response = request.Execute();
                        }
                    }
                    WriteObject(response);
                }
                catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Forbidden)
                {
                    ThrowTerminatingError(new ErrorRecord(ex,
                                                          $"You do not have permission to delete '{DatasetId}'.",
                                                          ErrorCategory.PermissionDenied,
                                                          DatasetId));
                }
            }
        }
Ejemplo n.º 2
0
 public void DoListRequest(TablesResource.ListRequest request)
 {
     do
     {
         TableList response = request.Execute();
         if (response == null)
         {
             ThrowTerminatingError(new ErrorRecord(
                                       new Exception("The List query returned null instead of a well formed list."),
                                       "Null List Returned", ErrorCategory.ReadError, Dataset));
         }
         if (response.Tables != null)
         {
             WriteObject(response.Tables, true);
         }
         request.PageToken = response.NextPageToken;
     }while (!Stopping && request.PageToken != null);
 }