コード例 #1
0
        /// <summary>
        /// Copy folder
        /// </summary>
        /// <param name="request">Request. <see cref="CopyFolderRequest" /></param>
        public void CopyFolder(CopyFolderRequest request)
        {
            // verify the required parameter 'srcPath' is set
            if (request.srcPath == null)
            {
                throw new ApiException(400, "Missing required parameter 'srcPath' when calling CopyFolder");
            }

            // verify the required parameter 'destPath' is set
            if (request.destPath == null)
            {
                throw new ApiException(400, "Missing required parameter 'destPath' when calling CopyFolder");
            }

            // create path and map variables
            var resourcePath = this.configuration.GetServerUrl() + "/editor/storage/folder/copy/{srcPath}";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddPathParameter(resourcePath, "srcPath", request.srcPath);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destPath", request.destPath);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "srcStorageName", request.srcStorageName);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destStorageName", request.destStorageName);

            this.apiInvoker.InvokeApi(
                resourcePath,
                "PUT",
                null,
                null,
                null);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: skalitin/Porcupine
        private static async Task CopyFolderTest(StorageService.StorageServiceClient client)
        {
            Console.WriteLine($"\nCalling 'CopyFolder'...");

            var request = new CopyFolderRequest()
            {
                Source = @"C:\Temp\Data", Target = @"C:\Temp\Data_Temp"
            };

            var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));

            using var streamingCall = client.CopyFolder(request, cancellationToken: cancellationTokenSource.Token);

            try
            {
                await foreach (var copyItem in streamingCall.ResponseStream.ReadAllAsync(cancellationTokenSource.Token))
                {
                    Console.WriteLine($"\tFile copied: {copyItem.FileName}, created at {copyItem.CreationTimestamp.ToDateTime()}");
                }
            }
            catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
            {
                Console.WriteLine("Stream cancelled.");
            }
        }
コード例 #3
0
        public override async Task CopyFolder(CopyFolderRequest request, IServerStreamWriter <CopyFolderResponse> responseStream, ServerCallContext context)
        {
            _logger.LogDebug($"Copying folder {request.Source} to {request.Target}...");

            var directory = new DirectoryInfo(request.Source);
            var files     = directory.GetFiles();

            if (!Directory.Exists(request.Target))
            {
                Directory.CreateDirectory(request.Target);
            }

            foreach (var file in files)
            {
                var newPath = Path.Combine(request.Target, file.Name);

                _logger.LogDebug($"Copying file {file.Name} to {request.Target}...");
                file.CopyTo(newPath, true);

                // Simulate long copy operation
                await Task.Delay(TimeSpan.FromMilliseconds(500));

                if (context.CancellationToken.IsCancellationRequested)
                {
                    _logger.LogWarning($"Copy folder cancelled.");
                    break;
                }

                var creationTimestamp = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.SpecifyKind(file.CreationTime, DateTimeKind.Utc));
                await responseStream.WriteAsync(new CopyFolderResponse {
                    FileName          = file.Name,
                    CreationTimestamp = creationTimestamp
                });
            }
        }
コード例 #4
0
        /// <summary>
        /// Copy folder
        /// </summary>
        /// <param name="request">Request. <see cref="CopyFolderRequest" /></param>
        /// <returns><see cref=""/></returns>
        public void CopyFolder(CopyFolderRequest request)
        {
            // verify the required parameter 'srcPath' is set
            if (request.srcPath == null)
            {
                throw new ApiException(400, "Missing required parameter 'srcPath' when calling CopyFolder");
            }

            // verify the required parameter 'destPath' is set
            if (request.destPath == null)
            {
                throw new ApiException(400, "Missing required parameter 'destPath' when calling CopyFolder");
            }

            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/ocr/storage/folder/copy/{srcPath}";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddPathParameter(resourcePath, "srcPath", request.srcPath);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destPath", request.destPath);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "srcStorageName", request.srcStorageName);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "destStorageName", request.destStorageName);

            try
            {
                var response = this.apiInvoker.InvokeApi <string>(
                    resourcePath,
                    "PUT",
                    null,
                    null,
                    null);
                if (response != null)
                {
                    return;
                }

                return;
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 404)
                {
                    return;
                }

                throw;
            }
        }
コード例 #5
0
        public static void Run()
        {
            var apiInstance = new FolderApi(Constants.GetConfig());

            try
            {
                var request = new CopyFolderRequest("Annotationdocs", "Annotationdocs1", Constants.MyStorage, Constants.MyStorage);

                apiInstance.CopyFolder(request);
                Console.WriteLine("Expected response type is Void: 'Annotationdocs' folder copied as 'Annotationdocs1'.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling FolderApi: " + e.Message);
            }
        }
コード例 #6
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new FolderApi(configuration);

            try
            {
                var request = new CopyFolderRequest("Comparisondocs", "Comparisondocs1", Common.MyStorage, Common.MyStorage);

                apiInstance.CopyFolder(request);
                Console.WriteLine("Expected response type is Void: 'Comparisondocs' folder copied as 'Comparisondocs1'.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling FolderApi: " + e.Message);
            }
        }
コード例 #7
0
        public void TestCopyFolder()
        {
            string folderToCopy = remoteDataFolder + "/TestCopyFolder";

            this.UploadFileToStorage(
                folderToCopy + "Src/TestCopyFolderSrc.docx",
                null,
                null,
                File.ReadAllBytes(LocalTestDataFolder + localFile)
                );

            var request = new CopyFolderRequest(
                destPath: folderToCopy + "Dest",
                srcPath: folderToCopy + "Src"
                );

            this.WordsApi.CopyFolder(request);
        }
コード例 #8
0
        public void TestCopyMoveFolder()
        {
            // Create temp folder
            var cRequest = new CreateFolderRequest("temp");

            FolderApi.CreateFolder(cRequest);

            // Copy folder
            var copyRequest = new CopyFolderRequest("temp", "temp1");

            FolderApi.CopyFolder(copyRequest);

            // Check copied folder
            var eRequest  = new ObjectExistsRequest("temp1");
            var eResponse = StorageApi.ObjectExists(eRequest);

            Assert.IsTrue(eResponse.Exists);
            Assert.IsTrue(eResponse.IsFolder);

            // Copy folder
            var moveRequest = new MoveFolderRequest("temp1", "temp2");

            FolderApi.MoveFolder(moveRequest);

            // Check moved folder
            eRequest  = new ObjectExistsRequest("temp1");
            eResponse = StorageApi.ObjectExists(eRequest);
            Assert.IsFalse(eResponse.Exists);
            eRequest  = new ObjectExistsRequest("temp2");
            eResponse = StorageApi.ObjectExists(eRequest);
            Assert.IsTrue(eResponse.Exists);

            // Delete temp and temp2 folders
            var delRequest = new DeleteFolderRequest("temp", null, true);

            FolderApi.DeleteFolder(delRequest);
            delRequest = new DeleteFolderRequest("temp2", null, true);
            FolderApi.DeleteFolder(delRequest);
        }