Required by GoogleCloudStorageProvider.GetContentWriter, which is used by the cmdlet Set-Content.
Inheritance: IContentWriter
Esempio n. 1
0
        /// <summary>
        /// Gets a writer used to upload data to a Google Cloud Storage object. Used by Set-Content.
        /// </summary>
        /// <param name="path">The path of the object to upload to.</param>
        /// <returns>The writer.</returns>
        public IContentWriter GetContentWriter(string path)
        {
            var    gcsPath = GcsPath.Parse(path);
            Object body    = new Object
            {
                Name   = gcsPath.ObjectPath,
                Bucket = gcsPath.Bucket
            };
            var inputStream  = new AnonymousPipeServerStream(PipeDirection.Out);
            var outputStream = new AnonymousPipeClientStream(PipeDirection.In, inputStream.ClientSafePipeHandle);
            var contentType  = ((GcsGetContentWriterDynamicParameters)DynamicParameters).ContentType ?? GcsCmdlet.UTF8TextMimeType;

            ObjectsResource.InsertMediaUpload request =
                Service.Objects.Insert(body, gcsPath.Bucket, outputStream, contentType);
            request.UploadAsync();
            IContentWriter contentWriter = new GcsContentWriter(inputStream);

            // Force the bucket models to refresh with the potentially new object.
            BucketModels.Clear();
            TelemetryReporter.ReportSuccess(nameof(GoogleCloudStorageProvider), nameof(GetContentWriter));
            return(contentWriter);
        }
 /// <summary>
 /// Gets a writer used to upload data to a Google Cloud Storage object. Used by Set-Content.
 /// </summary>
 /// <param name="path">The path of the object to upload to.</param>
 /// <returns>The writer.</returns>
 public IContentWriter GetContentWriter(string path)
 {
     var gcsPath = GcsPath.Parse(path);
     Object body = new Object
     {
         Name = gcsPath.ObjectPath,
         Bucket = gcsPath.Bucket
     };
     var inputStream = new AnonymousPipeServerStream(PipeDirection.Out);
     var outputStream = new AnonymousPipeClientStream(PipeDirection.In, inputStream.ClientSafePipeHandle);
     var contentType = ((GcsGetContentWriterDynamicParameters)DynamicParameters).ContentType ?? GcsCmdlet.UTF8TextMimeType;
     ObjectsResource.InsertMediaUpload request =
         Service.Objects.Insert(body, gcsPath.Bucket, outputStream, contentType);
     request.UploadAsync();
     IContentWriter contentWriter = new GcsContentWriter(inputStream);
     // Force the bucket models to refresh with the potentially new object.
     BucketModels.Clear();
     TelemetryReporter.ReportSuccess(nameof(GoogleCloudStorageProvider), nameof(GetContentWriter));
     return contentWriter;
 }