Beispiel #1
0
        /// <summary>
        /// Creates a copy of the specified file.
        /// Documentation https://developers.google.com/drive/v2/reference/files/copy
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Drive service.</param>
        /// <param name="fileId">The ID of the file to copy.</param>
        /// <param name="body">A valid Drive v2 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>FileResponse</returns>
        public static File Copy(DriveService service, string fileId, File body, FilesCopyOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (fileId == null)
                {
                    throw new ArgumentNullException(fileId);
                }

                // Building the initial request.
                var request = service.Files.Copy(body, fileId);

                // Applying optional parameters to the request.
                request = (FilesResource.CopyRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Files.Copy failed.", ex);
            }
        }
        /// <summary>
        /// Creates a copy of a file and applies any requested updates with patch semantics.
        /// Documentation https://developers.google.com/drive/v3/reference/files/copy
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Drive service.</param>
        /// <param name="fileId">The ID of the file.</param>
        /// <param name="body">A valid Drive v3 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>FileResponse</returns>
        public async Task <File> Copy(string fileId, File body, FilesCopyOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (_service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (fileId == null)
                {
                    throw new ArgumentNullException(fileId);
                }

                // Building the initial request.
                var request = _service.Files.Copy(body, fileId);

                // Applying optional parameters to the request.
                request = (FilesResource.CopyRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(await request.ExecuteAsync());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Files.Copy failed.", ex);
            }
        }