|
@@ -170,8 +170,13 @@ namespace PDF_Master.Helper
|
|
|
public static async Task<string> fileTranslate(string content, string fromlanguage, string tolanguage)
|
|
|
{
|
|
|
|
|
|
+ App.mainWindowViewModel.ProgressTitle = "Translating...";
|
|
|
+ App.mainWindowViewModel.MaxValue = 10;
|
|
|
+ App.mainWindowViewModel.Value = 0;
|
|
|
+ App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
|
|
|
FileInfo file = new FileInfo(content);
|
|
|
string fileKey = await fileKeyTranslate(content, file.Name);
|
|
|
+ App.mainWindowViewModel.Value = 2;
|
|
|
HttpWebResponse response = null;
|
|
|
ServicePointManager.DefaultConnectionLimit = 200;
|
|
|
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_filetranslate);
|
|
@@ -201,20 +206,23 @@ namespace PDF_Master.Helper
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
+ App.mainWindowViewModel.Value = 2;
|
|
|
string postBody = sw.ToString();
|
|
|
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
|
|
|
{
|
|
|
writer.Write(postBody);
|
|
|
writer.Close();
|
|
|
}
|
|
|
-
|
|
|
+ App.mainWindowViewModel.Value = 3;
|
|
|
response = (HttpWebResponse)request.GetResponse();
|
|
|
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
|
|
{
|
|
|
+ App.mainWindowViewModel.Value = 4;
|
|
|
string responseData = reader.ReadToEnd();
|
|
|
Console.WriteLine(responseData);
|
|
|
reader.Close();
|
|
|
JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
|
|
|
+ App.mainWindowViewModel.Value = 5;
|
|
|
if (response != null)
|
|
|
{
|
|
|
response.Close();
|
|
@@ -231,12 +239,15 @@ namespace PDF_Master.Helper
|
|
|
//return jobject["code"].ToObject<string>().ToLower();
|
|
|
using (var client = new WebClient())
|
|
|
{
|
|
|
+ App.mainWindowViewModel.Value = 6;
|
|
|
string folderPath = file.FullName.Remove(file.FullName.LastIndexOf("."), file.FullName.Length- file.FullName.LastIndexOf(".")) + "_aiTranslation.pdf"; ;
|
|
|
client.DownloadProgressChanged += (sender, e) =>
|
|
|
{
|
|
|
|
|
|
};
|
|
|
client.DownloadFile(translate, folderPath);
|
|
|
+ App.mainWindowViewModel.Value = 9;
|
|
|
+ App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
|
|
|
return folderPath;
|
|
|
}
|
|
|
//return "200";
|
|
@@ -244,6 +255,7 @@ namespace PDF_Master.Helper
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
+ App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
|
|
|
return "300";
|
|
|
}
|
|
|
|