protected override void ProcessRecord() { // Set up the Dataset based on parameters Dataset newData; switch (ParameterSetName) { case ParameterSetNames.ByObject: newData = Dataset; Project = Dataset.DatasetReference.ProjectId; break; case ParameterSetNames.ByValues: newData = new Dataset(); newData.DatasetReference = new DatasetReference(); newData.DatasetReference.DatasetId = DatasetId; newData.DatasetReference.ProjectId = Project; newData.FriendlyName = Name; newData.Description = Description; if (Expiration != 0) { newData.DefaultTableExpirationMs = Expiration * 1000; } break; default: throw UnknownParameterSetException; } // Add the new dataset to the project supplied. DatasetsResource.InsertRequest request = Service.Datasets.Insert(newData, Project); try { Dataset response = request.Execute(); // Send a Get request to correctly populate the ETag field. DatasetsResource.GetRequest getCorrectETag = Service.Datasets.Get(Project, response.DatasetReference.DatasetId); response = getCorrectETag.Execute(); WriteObject(response); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Conflict) { ThrowTerminatingError(new ErrorRecord(ex, $"A dataset with the name '{DatasetId}' already exists in project '{Project}'.", ErrorCategory.InvalidArgument, newData)); } }
private Dataset DoGetRequest(string project, string dataset) { DatasetsResource.GetRequest gRequest = Service.Datasets.Get(project, dataset); try { return(gRequest.Execute()); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { ThrowTerminatingError(new ErrorRecord(ex, $"Error 404: Dataset '{dataset}' not found in '{project}'.", ErrorCategory.ObjectNotFound, dataset)); return(null); } }