public static bool uploadToStorage(string storagePath, string srcDir = null)
        {
            var           name        = Path.GetFileName(storagePath);
            Configuration storageConf = new Storage.Cloud.Sdk.Configuration()
            {
                ApiBaseUrl = CommonSettings.BasePath,
                AppKey     = CommonSettings.AppKey,
                AppSid     = CommonSettings.AppSID
            };
            StorageApi storageApi = new StorageApi(storageConf);
            // Upload source file to aspose cloud storage
            var srcPath = Path.Combine(srcDir ?? CommonSettings.DataFolder, name);

            if (File.Exists(srcPath))
            {
                using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
                {
                    var reqCr     = new PutCreateRequest(storagePath, fstr);
                    var respCr    = storageApi.PutCreate(reqCr);
                    var reqExist  = new GetIsExistRequest(storagePath);
                    var respExist = storageApi.GetIsExist(reqExist);

                    return(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value);
                }
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", srcPath));
            }
        }
Example #2
0
        public void StorageGetIsExistTest()
        {
            GetIsExistRequest request = new GetIsExistRequest();

            request.path      = Path.Combine(dataFolder, "folder1");
            request.storage   = storageName;
            request.versionId = null;
            var response = StorageApi.GetIsExist(request);

            Assert.AreEqual(200, response.Code);
            Assert.IsTrue(Convert.ToBoolean(response.FileExist.IsExist));
        }
        private FileExist FileExist(string storageName, string path, string versionId = null)
        {
            var request = new GetIsExistRequest();

            request.Path      = path;
            request.Storage   = storageName;
            request.VersionId = versionId;
            var response = StorageApi.GetIsExist(request);

            Assert.AreEqual(200, response.Code);

            return(response.FileExist);
        }
Example #4
0
        /// <summary>
        /// Check if a specific file or folder exists
        /// </summary>
        /// <param name="request">Request. <see cref="GetIsExistRequest" /></param>
        /// <returns><see cref="FileExistResponse"/></returns>
        public FileExistResponse GetIsExist(GetIsExistRequest request)
        {
            // verify the required parameter 'path' is set
            if (request.Path == null)
            {
                throw new ApiException(400, "Missing required parameter 'path' when calling GetIsExist");
            }

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

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "path", request.Path);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.VersionId);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.Storage);

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

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

                throw;
            }
        }
        public void Test_RecognizeAndTranslate_Get_2()
        {
            var    name        = "1168_016.3B.jpg";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";
            string srcPath     = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest  reqCr    = new PutCreateRequest(storagePath, fstr);
                UploadResponse    respUpl  = this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }
            var result = OcrApi.GetRecognizeAndTranslateToHtml(name, "en", "de", folder);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is FileStream);
            Assert.IsTrue(File.Exists(((FileStream)result).Name));
        }
        public void Test_RecognizeAndImport_Get_1()
        {
            var    name        = "ocr_test_2.png";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";
            string srcPath     = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest  reqCr    = new PutCreateRequest(storagePath, fstr);
                UploadResponse    respUpl  = this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse respEx   = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(respEx.FileExist.IsExist.HasValue && respEx.FileExist.IsExist.Value);
            }
            var result = OcrApi.GetRecognizeAndImportToHtml(name, "en", folder);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)result).Name));
        }
        public void Test_GetHtmlConvert_Jpeg_StorageToStream()
        {
            string name   = "testpage1.html";
            string folder = "TempHtml";

            string srcPath = Path.Combine(dataFolder, name);
            string path    = string.Format("{0}/{1}", folder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest reqCr = new PutCreateRequest(path, fstr);
                this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(path);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }

            var response = this.ConversionApi.GetConvertDocumentToImage(name, "jpeg", 800, 1200, null, null, null, null, null, null, folder);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)response).Name));
        }
        public void Test_GetDocumentImages()
        {
            string name        = "testpage5.html.zip";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest reqCr = new PutCreateRequest(storagePath, fstr);
                this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }

            Stream stream = DocumentApi.GetDocumentImages(name, null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
        public void Test_GetHtmlDetectKeywords_1()
        {
            string name        = "testpage1.html";
            string folder      = "HtmlTestTranslate";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest reqCr = new PutCreateRequest(storagePath, fstr);
                this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }

            var stream = SummarizationApi.GetDetectHtmlKeywords(name, folder, null);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
        public void Test_GetDocumentFragmentByXPath_2()
        {
            string name        = "testpage1.html";
            string xpath       = ".//ol/li";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                var reqCr     = new PutCreateRequest(storagePath, fstr);
                var respCr    = this.StorageApi.PutCreate(reqCr);
                var reqExist  = new GetIsExistRequest(storagePath);
                var respExist = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value);
            }

            Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }