Browse Source

人工智能-高保真优化,帮助类优化

liyijie 1 year ago
parent
commit
d2563a5978

+ 13 - 1
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -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";
             }
 

+ 11 - 5
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -11,6 +11,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Threading.Tasks;
 
 namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 {
@@ -36,7 +37,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             set
             {
                 SetProperty(ref fromlanguageIndex, value);
-                fromlanguage=ChatGTPAIHelper.UpdateLanguagebType(value);
+                fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(value);
             }
         }
 
@@ -47,7 +48,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             set
             {
                 SetProperty(ref tolanguageIndex, value);
-                tolanguage = ChatGTPAIHelper.UpdateLanguagebType(value+1);
+                tolanguage = ChatGTPAIHelper.UpdateLanguagebType(value + 1);
             }
         }
 
@@ -90,12 +91,17 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
         }
         public async void translate()
         {
-           string newfile= await ChatGTPAIHelper.fileTranslate(pdfViewer.Document.FilePath, fromlanguage, tolanguage);
+            string newfile = "";
+                await Task.Run(async delegate
+                {
+                    newfile = await ChatGTPAIHelper.fileTranslate(pdfViewer.Document.FilePath, fromlanguage, tolanguage);
+                });
             if (!string.IsNullOrEmpty(newfile))
             {
                 if (File.Exists(newfile))
                 {
-                    if (viewContentViewModel != null) {
+                    if (viewContentViewModel != null)
+                    {
                         viewContentViewModel.OpenFile(new string[] { newfile });
                     }
                 }
@@ -121,7 +127,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 
             parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
             parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
-            
+
             if (pdfViewer != null)
             {
                 if (!regionManager.Regions[ViewerRegionName].Views.Contains(pdfViewer))

+ 7 - 2
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/SelectedTranslationDialogViewModel.cs

@@ -10,6 +10,8 @@ using System.Linq;
 using static System.Resources.ResXFileRef;
 using static System.Net.Mime.MediaTypeNames;
 using System.Windows.Forms;
+using Microsoft.Office.Core;
+using System.Threading.Tasks;
 
 namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 {
@@ -95,10 +97,13 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             GetTolanguageOrigin();
         }
 
-        public void translate()
+        public async void translate()
         {
             string translatetext = "";
-            ChatGTPAIHelper.textTranslate(SelectedText, fromlanguage, tolanguage, ref translatetext);
+            await Task.Run( delegate
+            {
+                ChatGTPAIHelper.textTranslate(SelectedText, fromlanguage, tolanguage, ref translatetext);
+            });
             TranslateText = translatetext;
         }
         public void copy()

+ 6 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContentViewModel.cs

@@ -4,6 +4,7 @@ using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
@@ -54,7 +55,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         public async void errorCorrection()
         {
-            ErrorCorrectionText = await ChatGTPAIHelper.Correction(InputText);
+
+            await Task.Run(async delegate
+            {
+                ErrorCorrectionText = await ChatGTPAIHelper.Correction(InputText);
+            });
         }
     }
 }

+ 5 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIRewritingContentViewModel.cs

@@ -4,6 +4,7 @@ using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
@@ -52,7 +53,10 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
         }
 
         public async void rewrite() {
-            RewriteText= await ChatGTPAIHelper.Rewrite(InputText);
+            await Task.Run(async delegate
+            {
+                RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
+            });
         }
     }
 }

+ 9 - 2
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs

@@ -1,4 +1,5 @@
-using Microsoft.Win32;
+using Microsoft.Office.Core;
+using Microsoft.Win32;
 using PDF_Master.Helper;
 using PDF_Master.Model;
 using Prism.Commands;
@@ -8,6 +9,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Threading.Tasks;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
@@ -80,7 +82,12 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
            $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
-                string newfile = await ChatGTPAIHelper.fileTranslate(dialog.FileName, fromlanguage, tolanguage);
+                string newfile = "";
+                await Task.Run(async delegate
+                {
+                    newfile = await ChatGTPAIHelper.fileTranslate(dialog.FileName, fromlanguage, tolanguage);
+                   
+                });
                 if (!string.IsNullOrEmpty(newfile))
                 {
                     if (File.Exists(newfile))

+ 4 - 4
PDF Office/Views/Dialog/ChatGPTAIDialogs/SelectedTranslationDialog.xaml

@@ -70,15 +70,15 @@
                 <StackPanel Orientation="Horizontal" Margin="0,16,0,0">
                     <StackPanel>
                         <Grid Width="250" Height="180" Margin="16,0,0,0">
-                            <TextBox Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}" >
-                            </TextBox>
+                            <cus:TextBoxEx x:Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}" FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                            </cus:TextBoxEx>
                             <TextBlock x:Name="SizeTextBlock" Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}"/>
                         </Grid>
                         <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Translate" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Margin="0,8,0,0" Command="{Binding TranslateCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
                     </StackPanel>
                     <StackPanel>
-                        <TextBox  Width="250" Height="180" Margin="16,0,0,0" Text="{Binding TranslateText}">
-                        </TextBox>
+                        <cus:TextBoxEx  Width="250" Height="180" Margin="16,0,0,0" Text="{Binding TranslateText}" FontFamily="Segoe UI" ShowClose="False" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8" IsReadOnly="True">
+                        </cus:TextBoxEx>
                         <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Copy" VerticalAlignment="Bottom"  Margin="0,8,0,0" Command="{Binding CopyCommand}"></Button>
                     </StackPanel>
                 </StackPanel>

+ 5 - 4
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContent.xaml

@@ -1,6 +1,7 @@
 <UserControl x:Class="PDF_Master.Views.HomePanel.ChatGPTAI.ChatGPTAIErrorCorrectionContent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:convert="clr-namespace:PDF_Master.DataConvert"
+             xmlns:cus="clr-namespace:PDF_Master.CustomControl"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
@@ -43,8 +44,8 @@
                 <Button HorizontalAlignment="Right" Width="104" Height="32" Content="ErrorCorrection" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding ErrorCorrectionCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
             </Grid>
             <Grid Height="260" Margin="0,12,0,0">
-                <TextBox Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}">
-                </TextBox>
+                <cus:TextBoxEx x:Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}" FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                </cus:TextBoxEx>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}"/>
             </Grid>
         </StackPanel>
@@ -56,9 +57,9 @@
             Foreground="{StaticResource color.sys.text.neutral.lv1}" Height="28" HorizontalAlignment="Left"></TextBlock>
                 <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White" Command="{Binding CopyCommand}"></Button>
             </Grid>
-            <TextBox  Height="260" Margin="0,12,0,0" Text="{Binding ErrorCorrectionText}">
+            <cus:TextBoxEx Height="260" Margin="0,12,0,0" Text="{Binding ErrorCorrectionText}" FontFamily="Segoe UI" ShowClose="False" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8" IsReadOnly="True">
 
-            </TextBox>
+            </cus:TextBoxEx>
         </StackPanel>
     </Grid>
 </UserControl>

+ 5 - 4
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIRewritingContent.xaml

@@ -1,6 +1,7 @@
 <UserControl x:Class="PDF_Master.Views.HomePanel.ChatGPTAI.ChatGPTAIRewritingContent"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:convert="clr-namespace:PDF_Master.DataConvert"
+             xmlns:cus="clr-namespace:PDF_Master.CustomControl"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
@@ -43,8 +44,8 @@
                 <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding RewriteCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
             </Grid>
             <Grid  Height="260" Margin="0,12,0,0">
-                <TextBox Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}" >
-                </TextBox>
+                <cus:TextBoxEx x:Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}"  FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                </cus:TextBoxEx>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right"  VerticalAlignment="Bottom" Margin="0,0,12,8"/>
             </Grid>
         </StackPanel>
@@ -56,9 +57,9 @@
             Foreground="{StaticResource color.sys.text.neutral.lv1}" Height="28" HorizontalAlignment="Left"></TextBlock>
                 <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Copy" Background="White" Command="{Binding CopyCommand}" ></Button>
             </Grid>
-            <TextBox  Height="260" Margin="0,12,0,0" Text="{Binding RewriteText}">
+            <cus:TextBoxEx  Height="260" Margin="0,12,0,0" Text="{Binding RewriteText}" FontFamily="Segoe UI" ShowClose="False" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8" IsReadOnly="True">
 
-            </TextBox>
+            </cus:TextBoxEx>
         </StackPanel>
     </Grid>
 </UserControl>

+ 6 - 2
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml.cs

@@ -9,10 +9,10 @@ using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
 using PDF_Master.ViewModels.HomePanel.ChatGPTAI;
 using Microsoft.Office.Core;
 using PDF_Master.ViewModels;
-using Microsoft.Office.Interop.Word;
 using System.IO;
 using Point = System.Windows.Point;
 using Window = System.Windows.Window;
+using System.Threading.Tasks;
 
 namespace PDF_Master.Views.HomePanel.ChatGPTAI
 {
@@ -51,7 +51,11 @@ namespace PDF_Master.Views.HomePanel.ChatGPTAI
                     dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); 
                     if (dropFile.ToLower().EndsWith("pdf")|| dropFile.ToLower().EndsWith(".doc") || dropFile.ToLower().EndsWith(".docx")|| dropFile.ToLower().EndsWith(".docm")|| dropFile.ToLower().EndsWith(".dot")|| dropFile.ToLower().EndsWith(".dotx") || dropFile.ToLower().EndsWith(".dotm")) 
                     {
-                        string newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
+                        string newfile = "";
+                        await Task.Run(async delegate
+                        {
+                            newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
+                        });
                         if (!string.IsNullOrEmpty(newfile))
                         {
                             if (File.Exists(newfile))