Example #1
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));
        }
        public void Run()
        {
            string name    = "testpage1.html";
            string folder  = null;
            string storage = null;

            string srcPath = Path.Combine(CommonSettings.DataFolder, name);

            if (File.Exists(srcPath))
            {
                var storagePath = !string.IsNullOrEmpty(folder)
                    ? string.Format("{0}/{1}", folder, name) : name;

                StorageApi storageApi = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
                storageApi.PutCreate(storagePath, null, storage, File.ReadAllBytes(srcPath));
                var response = storageApi.GetIsExist(storagePath, null, storage);
                if (response.FileExist.IsExist)
                {
                    TranslationApi transApi = new TranslationApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
                    Stream         stream   = transApi.GetTranslateDocument(name, SrcLang, ResLang, folder, storage);

                    if (stream != null && stream.GetType() == typeof(FileStream))
                    {
                        string outName = ((FileStream)stream).Name;
                        string outPath = Path.Combine(CommonSettings.OutDirectory, Path.GetFileName(outName));
                        using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                        {
                            stream.CopyTo(fstr);
                            fstr.Flush();
                            Console.WriteLine(string.Format("File '{0}' downloaded to: {1}", Path.GetFileName(outName), outPath));
                        }
                    }
                    stream.Close();
                    stream.Dispose();
                }
            }
            else
            {
                throw new FileNotFoundException("File not found in the Data folder", name);
            }
        }
        public void Test_GetHtmlTranslate_en_fr_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);
            }

            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));
        }