コード例 #1
0
        public void Test_PutHtmlTranslateByURL_en_de_1()
        {
            string sourceUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_02.htm";
            string folder    = "TempHtml";

            var response = TranslationApi.PutTranslateDocumentByUrl(sourceUrl, "en", "de", folder);

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

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

            Assert.IsTrue(stResp.FileExist.IsExist);
        }
        public void Run()
        {
            string srcUrl = @"http://www.htmlhelp.com/reference/css/stylesheets-now.html";
            //string srcUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_01.htm";
            string folder  = null; // default folder is root
            string storage = null; // default storage is AmazonS3

            TranslationApi     transApi = new TranslationApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            NativeRestResponse resp     = transApi.PutTranslateDocumentByUrl(srcUrl, SrcLang, ResLang, folder, storage);

            if (resp.ContentType == NativeRestResponse.RespContentType.FileName &&
                resp.ContentName != null)
            {
                StorageApi storageApi  = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
                var        storagePath = !string.IsNullOrEmpty(folder)
                    ? string.Format("{0}/{1}", folder, resp.ContentName) : resp.ContentName;
                var stResp = storageApi.GetIsExist(storagePath, null, storage);
                if (stResp.FileExist.IsExist)
                {
                    Console.WriteLine(string.Format("\nFile '{0}' created in the cloud storage: folder = '{1}', storage = '{2}' ",
                                                    resp.ContentName, folder ?? "", storage ?? "<default>"));

                    ResponseMessage resp2 = storageApi.GetDownload(storagePath, null, storage);
                    using (MemoryStream resStream = new MemoryStream(resp2.ResponseStream))
                    {
                        var outPath = Path.Combine(CommonSettings.OutDirectory, resp.ContentName);
                        using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                        {
                            resStream.Position = 0;
                            resStream.CopyTo(fstr);
                            fstr.Flush();
                            Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                        }
                    }
                }
            }
        }