示例#1
0
        /// <summary>
        /// Upload logo images used during template generation in separate folder on cloud storage
        /// </summary>
        /// <param name="dataDirPath">Path to directory containing logo images</param>
        protected void UploadDemoFiles(string dataDirPath)
        {
            // check if folder already exists on storage
            FileExistResponse response = this.StorageApi.GetIsExist(new GetIsExistRequest(this.LogosFolderName));

            if (response.FileExist.IsExist == false)
            {
                this.StorageApi.PutCreateFolder(new PutCreateFolderRequest(this.LogosFolderName));
            }

            // upload logo images
            foreach (string logo in this.templateLogosImagesNames)
            {
                string destLogoPath = $"{this.LogosFolderName}/{logo}";
                response = this.StorageApi.GetIsExist(new GetIsExistRequest(destLogoPath));
                if (response.FileExist.IsExist == false)
                {
                    this.UploadFile(Path.Combine(dataDirPath, logo), destLogoPath);
                }
                else
                {
                    Console.WriteLine($"File {destLogoPath} already exists");
                }
            }
        }
        /// <summary>
        /// Remove files from cloud storage
        /// </summary>
        /// <param name="files">List of file names to remove</param>
        public static void StorageCleanUp(List <string> files)
        {
            StorageApi storageApi = new StorageApi(AppKey, AppSid, Basepath);

            foreach (string file in files)
            {
                BusyIndicatorManager.UpdateText("Storage clean up...\n Deleting file: " + file);

                FileExistResponse existsResponse = storageApi.GetIsExist(file, "", "");
                if (existsResponse.FileExist.IsExist)
                {
                    RemoveFileResponse deleteResponse = storageApi.DeleteFile(file, "", "");
                }
            }
        }
        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);

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            var result = OcrApi.GetRecognizeAndTranslateToHtml(name, "en", "de", folder);

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

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

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            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_GetHtmlConvert_Jpeg_StorageToStream()
        {
            string name   = "testpage1.html";
            string folder = "TempHtml";

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

            this.StorageApi.PutCreate(path, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = this.StorageApi.GetIsExist(path, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            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));
        }
示例#6
0
        public void Test_GetHtmlTranslate_en_fr_1()
        {
            string name        = "testpage1.html";
            string folder      = "HtmlTestTranslate";
            string storagePath = $"{folder}/{name}";

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

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            Stream stream = TranslationApi.GetTranslateDocument(
                name, "en", "fr", folder, null);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
示例#7
0
        /// <summary>
        /// Remove files from cloud storage
        /// </summary>
        /// <param name="files">List of file names to remove</param>
        public static void StorageCleanUp(List <string> files)
        {
            string        baseHost             = new Uri(Basepath).GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped).ToString();
            Configuration storageConfiguration = new Configuration();

            storageConfiguration.AppKey     = AppKey;
            storageConfiguration.AppSid     = AppSid;
            storageConfiguration.ApiBaseUrl = baseHost;
            StorageApi storageApi = new StorageApi(storageConfiguration);

            foreach (string file in files)
            {
                BusyIndicatorManager.UpdateText("Storage clean up...\n Deleting file: " + file);

                FileExistResponse existsResponse = storageApi.GetIsExist(new GetIsExistRequest(file));
                if (existsResponse.FileExist.IsExist == true)
                {
                    RemoveFileResponse deleteResponse = storageApi.DeleteFile(new DeleteFileRequest(file));
                }
            }
        }
        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));
        }
示例#11
0
        public void Test_PutHtmlTranslate_en_ru_1()
        {
            string name        = "testpage1.html";
            string folder      = "HtmlTestTranslate";
            string storagePath = $"{folder}/{name}";

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

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            var response = TranslationApi.PutTranslateDocument(name, "en", "ru", folder);

            Assert.AreEqual("storage", (string)response.Content);
            Assert.IsTrue(response.ContentName != null);

            storagePath = string.Format("{0}/{1}", folder, response.ContentName);
            var stResp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(stResp.FileExist.IsExist);
        }
        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 Storage_File_Tests()
        {
            try
            {
                FileExistResponse fileExistResponse = storageService.File.CheckFileExistance(Utils.CloudStorage_Input_Folder + "/cells-sample.xlsx");
                storageService.File.DownloadFile(Utils.CloudStorage_Input_Folder + "/cells-sample.xlsx", Utils.Local_Output_Path + "test-cells-doc-downloaded.xlsx", 0, string.Empty);

                storageService.File.UploadFile(Utils.Local_Input_Path + "bmp-sample.bmp", Utils.CloudStorage_Output_Folder + "/test-bitmap-copied-from-local.bmp");
                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/bmp-sample.bmp", Utils.CloudStorage_Output_Folder + "/test-bitmap-copied.bmp");

                storageService.File.MoveFile(Utils.CloudStorage_Output_Folder + "/test-bitmap-copied-from-local.bmp", Utils.CloudStorage_Output_Folder + "/test-bitmap-moved.bmp");

                storageService.File.RemoveFile(Utils.CloudStorage_Output_Folder + "/test-bitmap-moved.bmp");
                storageService.File.RemoveFile(Utils.CloudStorage_Output_Folder + "/test-bitmap-copied-from-local.bmp");

                storageService.File.CheckDiskUsageOfCurrentAccount(string.Empty);

                FileVersionResponse fileVersionResponse = storageService.File.GetFileVersionsList(Utils.CloudStorage_Input_Folder + "/cells-sample.xlsx", string.Empty);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void Run()
        {
            string name = "testpage4_embcss.html";
            string path = Path.Combine(CommonSettings.DataFolder, name);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("File not found in the Data folder", name);
            }

            string folder  = null;
            string storage = null;

            int width        = 800;
            int height       = 1200;
            int leftMargin   = 15;
            int rightMargin  = 15;
            int topMargin    = 15;
            int bottomMargin = 15;
            int xResolution  = 96;
            int yResolution  = 96;

            string ext     = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format);
            string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}";

            using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                IConversionApi     convApi  = new ConversionApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
                NativeRestResponse response = null;
                // call SDK methods that convert HTML document to supported out format
                switch (Format)
                {
                case "pdf":
                    outFile += ".pdf";
                    response = convApi.PutConvertDocumentToPdf(
                        srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage);
                    break;

                case "xps":
                    response = convApi.PutConvertDocumentToXps(
                        srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage);
                    break;

                case "jpeg":
                case "bmp":
                case "png":
                case "tiff":
                    response = convApi.PutConvertDocumentToImage(
                        srcStream, Format, outFile, width, height,
                        leftMargin, rightMargin, topMargin, bottomMargin,
                        xResolution, yResolution, storage);
                    break;

                default:
                    throw new ArgumentException($"Unsupported output format: {Format}");
                }

                if (response != null &&
                    (string)response.Content == "storage" &&
                    response.ContentType == NativeRestResponse.RespContentType.FileName)
                {
                    // get the result file name from response object
                    string            outFileName = response.ContentName;
                    StorageApi        storageApi  = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
                    FileExistResponse resp2       = storageApi.GetIsExist(outFileName, null, null);
                    if (resp2.FileExist.IsExist)
                    {
                        // if result file exists in the storage, try to downloa it to the local file system
                        var resp3 = storageApi.GetDownload(outFileName, null, null);
                        if (resp3.ResponseStream != null)
                        {
                            string outPath = Path.Combine(CommonSettings.OutDirectory, outFileName);
                            using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                            {
                                fstr.Write(resp3.ResponseStream, 0, resp3.ResponseStream.Length);
                                fstr.Flush();
                                Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error: result file wasn't saved to storage.");
                    }
                }
            }
        }