Пример #1
0
 private void UploadTestFiles()
 {
     foreach (var testFile in TestFiles.TestFilesList)
     {
         var existRequest  = new ObjectExistsRequest(testFile.FullName);
         var existResponse = StorageApi.ObjectExists(existRequest);
         if (existResponse.Exists == true)
         {
             continue;
         }
         var request = new UploadFileRequest(testFile.FullName, GetTestFileStream(testFile));
         FileApi.UploadFile(request);
     }
 }
        public void TestObjectExists()
        {
            // Arrange
            var testFile = TestFiles.FourPagesDocx;
            var request  = new ObjectExistsRequest {
                path = testFile.FullName
            };

            // Act & Assert
            var response = StorageApi.ObjectExists(request);

            Assert.NotNull(response);
            Assert.IsTrue(response.Exists);
            Assert.IsFalse(response.IsFolder);
        }
Пример #3
0
        public void StorageIfObjectExists()
        {
            // Arrange
            var testFile = TestFiles.SpreadsheetStorage[0];
            var request  = new ObjectExistsRequest {
                path = testFile.Path
            };

            // Act & Assert
            var response = StorageApi.ObjectExists(request);

            Assert.NotNull(response);
            Assert.IsTrue(response.Exists);
            Assert.IsFalse(response.IsFolder);
        }
        public static void Run()
        {
            var apiInstance = new StorageApi(Constants.GetConfig());

            try
            {
                var request = new ObjectExistsRequest("one-page.docx", Constants.MyStorage);

                var response = apiInstance.ObjectExists(request);
                Console.WriteLine("Expected response type is ObjectExist: " + response.Exists);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling StorageApi: " + e.Message);
            }
        }
        public void TestDeleteFile()
        {
            // Arrange
            var testFile = TestFiles.Docx;
            var deleteRequest = new DeleteFileRequest {path = testFile.FullName};
            var existsRequest = new ObjectExistsRequest { path = testFile.FullName };
            var uploadRequest = new UploadFileRequest(testFile.FullName, GetTestFileStream(testFile));

            // Act & Assert
            FileApi.DeleteFile(deleteRequest);
            var response = StorageApi.ObjectExists(existsRequest);
            Assert.IsFalse(response.Exists);
            FileApi.UploadFile(uploadRequest);
            response = StorageApi.ObjectExists(existsRequest);
            Assert.IsTrue(response.Exists);
        }
Пример #6
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new StorageApi(configuration);

            try
            {
                var request = new ObjectExistsRequest("Annotationdocs/one-page.docx", Common.MyStorage);

                var response = apiInstance.ObjectExists(request);
                Console.WriteLine("Expected response type is ObjectExist: " + response.Exists.Value.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling StorageApi: " + e.Message);
            }
        }
Пример #7
0
        /// <summary>
        /// Check if file or folder exists
        /// </summary>
        /// <param name="request">Request. <see cref="ObjectExistsRequest" /></param>
        /// <returns><see cref="ObjectExist"/></returns>
        public ObjectExist ObjectExists(ObjectExistsRequest request)
        {
            // verify the required parameter 'path' is set
            if (request.path == null)
            {
                throw new ApiException(400, "Missing required parameter 'path' when calling ObjectExists");
            }

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

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.path);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.storageName);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.versionId);

            try
            {
                var response = this.apiInvoker.InvokeApi(
                    resourcePath,
                    "GET",
                    null,
                    null,
                    null);
                if (response != null)
                {
                    return((ObjectExist)SerializationHelper.Deserialize(response, typeof(ObjectExist)));
                }

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

                throw;
            }
        }
        public void StorageDeleteFile()
        {
            // Arrange
            var testFile      = TestFiles.PdfStorage.FirstOrDefault(x => x.Name.Equals("01_pages.pdf"));
            var deleteRequest = new DeleteFileRequest {
                path = testFile.Path
            };
            var existsRequest = new ObjectExistsRequest {
                path = testFile.Path
            };
            var uploadRequest = new UploadFileRequest(testFile.Path, GetTestFileStream(testFile));

            // Act & Assert
            FileApi.DeleteFile(deleteRequest);
            var response = StorageApi.ObjectExists(existsRequest);

            Assert.IsFalse(response.Exists);
            FileApi.UploadFile(uploadRequest);
            response = StorageApi.ObjectExists(existsRequest);
            Assert.IsTrue(response.Exists);
        }
Пример #9
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);
        }
        public void TestCopyMoveFile()
        {
            var testFile = TestFiles.FourPagesDocx;

            // Create temp folder
            var cRequest = new CreateFolderRequest("temp");

            FolderApi.CreateFolder(cRequest);

            // Copy file
            var destPath = $"temp/{testFile.FileName}";
            var request  = new CopyFileRequest(testFile.FullName, destPath);

            FileApi.CopyFile(request);

            // Check copied file
            var eRequest  = new ObjectExistsRequest(destPath);
            var eResponse = StorageApi.ObjectExists(eRequest);

            Assert.IsTrue(eResponse.Exists);

            // Move file
            var newDestPath = $"temp/{testFile.FileName.Replace(".", "_1.")}";
            var mRequest    = new MoveFileRequest(destPath, newDestPath);

            FileApi.MoveFile(mRequest);

            // Check moved file
            eRequest  = new ObjectExistsRequest(newDestPath);
            eResponse = StorageApi.ObjectExists(eRequest);
            Assert.IsTrue(eResponse.Exists);

            // Delete temp folder
            var delRequest = new DeleteFolderRequest("temp", null, true);

            FolderApi.DeleteFolder(delRequest);
        }
        public void StorageCopyMoveFile()
        {
            var testFile = TestFiles.PdfStorage.FirstOrDefault(x => x.Name.Equals("01_pages.pdf"));

            // Create temp folder
            var cRequest = new CreateFolderRequest("temp");

            FolderApi.CreateFolder(cRequest);

            // Copy file
            var destPath = $"temp/{testFile.Name}";
            var request  = new CopyFileRequest(testFile.Path, destPath);

            FileApi.CopyFile(request);

            // Check copied file
            var eRequest  = new ObjectExistsRequest(destPath);
            var eResponse = StorageApi.ObjectExists(eRequest);

            Assert.IsTrue(eResponse.Exists);

            // Move file
            var newDestPath = $"temp/{testFile.Path.Replace(".", "_1.")}";
            var mRequest    = new MoveFileRequest(destPath, newDestPath);

            FileApi.MoveFile(mRequest);

            // Check moved file
            eRequest  = new ObjectExistsRequest(newDestPath);
            eResponse = StorageApi.ObjectExists(eRequest);
            Assert.IsTrue(eResponse.Exists);

            // Delete temp folder
            var delRequest = new DeleteFolderRequest("temp", null, true);

            FolderApi.DeleteFolder(delRequest);
        }