public void Run()
        {
            string name = "testpage5.html.zip";   // storage file name
            string folder = "HtmlTemp"; // storage folder name

            string filePath = Path.Combine(CommonSettings.DataFolder, name);
            if (File.Exists(filePath))
            {
                SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder);
            }
            else
                throw new Exception(string.Format("Error: file {0} not found.", filePath));

            IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            // call SDK method that gets a zip archive with all HTML document images
            Stream stream = docApi.GetDocumentImages(name, null, folder);
            if (stream != null && typeof(FileStream) == stream.GetType())
            {
                string outFile = $"{Path.GetFileNameWithoutExtension(name)}_images.zip";
                string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.Position = 0;
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                }
            }

        }
Ejemplo n.º 2
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_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 Run()
        {
            string name   = "testpage5.html.zip"; // storage file name
            string folder = "HtmlTemp";           // storage folder name

            string     filePath    = Path.Combine(CommonSettings.DataFolder, name);
            StorageApi storageApi  = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            string     storagePath = string.IsNullOrEmpty(folder) ? name : string.Format("{0}/{1}", folder, name);

            if (File.Exists(filePath))
            {
                // upload source file to the cloud storage (default is AmazonS3)
                //filePath = string.Format("file:///{0}", filePath.Replace('\\', '/'));
                storageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(filePath));
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", filePath));
            }

            IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            // call SDK method that gets a zip archive with all HTML document images
            Stream stream = docApi.GetDocumentImages(name, null, folder);

            if (stream != null && typeof(FileStream) == stream.GetType())
            {
                string outFile = $"{Path.GetFileNameWithoutExtension(name)}_images.zip";
                string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.Position = 0;
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                }
            }
        }