Skip to content

Commit f11c08c

Browse files
committed
update to v1.1.0
1 parent d51a639 commit f11c08c

18 files changed

+126
-85
lines changed

CTT/setup.zip

2.13 MB
Binary file not shown.

CommentTranslateTool/ApiKeys.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Workshop.Helper
2+
{
3+
/// <summary>
4+
/// 有道云翻译的Api资源
5+
/// https://ai.youdao.com/
6+
/// </summary>
7+
public static class ApiKeys
8+
{
9+
//请申请您自己的有道云翻译服务Api
10+
//https://ai.youdao.com/DOCSIRMA/html/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E7%BF%BB%E8%AF%91/API%E6%96%87%E6%A1%A3/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1-API%E6%96%87%E6%A1%A3.html
11+
public const string _appKey = "767601e0cfb1456a";
12+
public const string _appSecret = "uxDHX1dGXBcF7xy8AKV2FGq6dF4JwvQ9";
13+
}
14+
}

CommentTranslateTool/App.xaml.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
using System.Data;
66
using System.Windows;
77
using System.Windows.Threading;
8-
using GalaSoft.MvvmLight.Messaging;
98
using Workshop.Common;
109
using Workshop.Helper;
11-
10+
using CommunityToolkit.Mvvm.DependencyInjection;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Workshop.ViewModel;
13+
using CommunityToolkit.Mvvm.Messaging;
1214

1315
namespace Workshop
1416
{
@@ -17,9 +19,26 @@ namespace Workshop
1719
/// </summary>
1820
public partial class App : Application
1921
{
22+
private bool _initialized;
23+
2024
public static string Session;
2125
public App()
2226
{
27+
// Register services
28+
if (!_initialized)
29+
{
30+
_initialized = true;
31+
Ioc.Default.ConfigureServices(
32+
new ServiceCollection()
33+
//ViewModels
34+
.AddSingleton<MainViewModel>()
35+
.AddSingleton<IndexPageViewModel>()
36+
.AddSingleton<SettingPageViewModel>()
37+
.AddSingleton<BatchProcessViewModel>()
38+
.BuildServiceProvider());
39+
}
40+
41+
2342
App.Current.Startup += Current_Startup;
2443
App.Current.Exit += Current_Exit;
2544

@@ -40,7 +59,7 @@ private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandl
4059
{
4160
try
4261
{
43-
Messenger.Default.Send("", MessengerToken.CLOSEPROGRESS);
62+
WeakReferenceMessenger.Default.Send(MessengerToken.CLOSEPROGRESS);
4463

4564
LogHelper.LogError("UI线程全局异常" + e.Exception);
4665
MessageBox.Show("An unhandled exception just occurred: " + e.Exception.Message, "UI线程全局异常", MessageBoxButton.OK, MessageBoxImage.Error);
@@ -62,7 +81,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
6281
{
6382
try
6483
{
65-
Messenger.Default.Send("", MessengerToken.CLOSEPROGRESS);
84+
WeakReferenceMessenger.Default.Send(MessengerToken.CLOSEPROGRESS);
6685

6786
var exception = e.ExceptionObject as Exception;
6887
if (exception != null)

CommentTranslateTool/CommentTranslateTool.csproj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net5.0-windows</TargetFramework>
5+
<TargetFramework>net6.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
77
<RootNamespace>Workshop</RootNamespace>
88
<AssemblyName>CommentTranslateTool</AssemblyName>
@@ -23,16 +23,15 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="AvalonEdit" Version="6.1.2.30" />
27-
<PackageReference Include="CommonServiceLocator" Version="2.0.6" />
28-
<PackageReference Include="MahApps.Metro" Version="2.4.4" />
29-
<PackageReference Include="MahApps.Metro.IconPacks.Material" Version="4.8.0" />
30-
<PackageReference Include="MahApps.Metro.IconPacks.Modern" Version="4.8.0" />
31-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
32-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.9.0" />
33-
<PackageReference Include="MvvmLight" Version="5.4.1.1" />
34-
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
35-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
26+
<PackageReference Include="AvalonEdit" Version="6.1.3.50" />
27+
<PackageReference Include="CommunityToolkit.Mvvm" Version="7.1.2" />
28+
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
29+
<PackageReference Include="MahApps.Metro.IconPacks.Material" Version="4.11.0" />
30+
<PackageReference Include="MahApps.Metro.IconPacks.Modern" Version="4.11.0" />
31+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
32+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
33+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
34+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
3635
</ItemGroup>
3736

3837
<ItemGroup>

CommentTranslateTool/Control/ProgressWindow.xaml.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GalaSoft.MvvmLight.Messaging;
1+
using CommunityToolkit.Mvvm.Messaging;
22
using MahApps.Metro.Controls;
33
using System;
44
using System.Collections.Generic;
@@ -50,9 +50,10 @@ public static void StaticUnShowDialog()
5050
public ProgressWindow()
5151
{
5252
InitializeComponent();
53-
Messenger.Default.Register<string>(this, MessengerToken.UPDATEPROGRESS, HandleMessage);
54-
Messenger.Default.Register<string>(this, MessengerToken.CLOSEPROGRESS, HandleClose);
55-
this.Unloaded += (sender, e) => Messenger.Default.Unregister(this);
53+
WeakReferenceMessenger.Default.Register<string>( MessengerToken.UPDATEPROGRESS, HandleMessage);
54+
WeakReferenceMessenger.Default.Register<string>( MessengerToken.CLOSEPROGRESS, HandleClose);
55+
this.Unloaded += (sender, e) => WeakReferenceMessenger.Default.UnregisterAll(MessengerToken.UPDATEPROGRESS);
56+
this.Unloaded += (sender, e) => WeakReferenceMessenger.Default.UnregisterAll(MessengerToken.CLOSEPROGRESS);
5657

5758
}
5859

@@ -69,13 +70,13 @@ public void ShowDialog(string title)
6970
base.ShowDialog();
7071
}
7172

72-
private void HandleClose(string obj)
73+
private void HandleClose(object recipient, string obj)
7374
{
7475
Debug.WriteLine("ProgressWindow close by" +obj);
7576
this.Close();
7677
}
7778

78-
private void HandleMessage(string obj)
79+
private void HandleMessage(object recipient, string obj)
7980
{
8081
this.MainProgress.IsIndeterminate = false;
8182
this.CancelButton.Visibility = Visibility.Visible;

CommentTranslateTool/Helper/WebHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Text;
88
using System.Threading;
99
using System.Windows;
10-
using GalaSoft.MvvmLight.Messaging;
1110
using Workshop.Common;
1211

1312
namespace Workshop.Helper

CommentTranslateTool/Helper/YouDaoApiHelper.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ namespace Workshop.Helper
1313
{
1414
public class YouDaoApiHelper
1515
{
16-
const string _appKey = "75766d8fc97f34a3";
17-
const string _appSecret = "rFkTqsDws1bCoETcxSL7afG33emwJdr5";
18-
19-
20-
2116
public YouDaoApiHelper()
2217
{
2318
}
@@ -87,13 +82,13 @@ private static string GetRequestUrl(string queryText)
8782
string salt = DateTime.Now.Millisecond.ToString();
8883

8984
MD5 md5 = new MD5CryptoServiceProvider();
90-
string md5Str = _appKey + queryText + salt + _appSecret;
85+
string md5Str = ApiKeys._appKey + queryText + salt + ApiKeys._appSecret;
9186
byte[] output = md5.ComputeHash(Encoding.UTF8.GetBytes(md5Str));
9287
string sign = BitConverter.ToString(output).Replace("-", "");
9388

9489
var requestUrl = string.Format(
9590
"http://openapi.youdao.com/api?appKey={0}&q={1}&from={2}&to={3}&sign={4}&salt={5}",
96-
_appKey,
91+
ApiKeys._appKey,
9792
queryText,
9893
_from, _to, sign, salt);
9994

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Workshop.Helper
2+
{
3+
internal static class YouDaoApiHelperHelpers
4+
{
5+
const string _appKey = "75766d8fc97f34a3";
6+
const string _appSecret = "rFkTqsDws1bCoETcxSL7afG33emwJdr5";
7+
}
8+
}

CommentTranslateTool/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
99
mc:Ignorable="d"
1010
WindowState="Maximized"
11-
Title="Comment Translate Tool 版本0.1" Height="720" Width="1080">
11+
Title="Comment Translate Tool 版本1.1.0" Height="720" Width="1080">
1212
<mah:MetroWindow.RightWindowCommands>
1313
<mah:WindowCommands>
1414
<Button Content="关于" Click="ButtonBase_OnClick"></Button>

CommentTranslateTool/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows;
66
using System.Windows.Controls;
77
using System.Windows.Navigation;
8-
using GalaSoft.MvvmLight.Messaging;
98
using GeneralServiceHost.View;
109
using Workshop.Common;
1110
using Workshop.Control;

0 commit comments

Comments
 (0)