From e8c588bde398ccb56a7b16fadf279d097b6ac543 Mon Sep 17 00:00:00 2001 From: zggsong Date: Mon, 4 Mar 2024 15:19:49 +0800 Subject: [PATCH] perf: Filtering empty data in the configuration --- .../ViewModels/Preference/Services/TranslatorAli.cs | 10 +++++++++- .../ViewModels/Preference/Services/TranslatorApi.cs | 10 +++++++++- .../Preference/Services/TranslatorBaidu.cs | 7 +++++++ .../Preference/Services/TranslatorCaiyun.cs | 12 ++++++++---- .../Preference/Services/TranslatorEcdict.cs | 9 +++++++++ .../Preference/Services/TranslatorGemini.cs | 7 +++++++ .../Preference/Services/TranslatorMicrosoft.cs | 7 +++++++ .../Preference/Services/TranslatorNiutrans.cs | 7 +++++++ .../Preference/Services/TranslatorOpenAI.cs | 9 +++++++++ .../Preference/Services/TranslatorSTranslate.cs | 7 +++++++ .../Preference/Services/TranslatorTencent.cs | 7 +++++++ .../Preference/Services/TranslatorVolcengine.cs | 7 +++++++ .../Preference/Services/TranslatorYoudao.cs | 7 +++++++ STranslate/ViewModels/Preference/TTS/TTSAzure.cs | 7 +++++++ STranslate/ViewModels/Preference/TTS/TTSOffline.cs | 7 +++++++ 15 files changed, 114 insertions(+), 6 deletions(-) diff --git a/STranslate/ViewModels/Preference/Services/TranslatorAli.cs b/STranslate/ViewModels/Preference/Services/TranslatorAli.cs index 09eb8b7a..1b67456c 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorAli.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorAli.cs @@ -6,6 +6,7 @@ using STranslate.Model; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -60,14 +61,20 @@ public TranslatorAli( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] @@ -120,6 +127,7 @@ private void ShowEncryptInfo(string? obj) * @return Client * @throws Exception */ + public static Client CreateClient(string accessKeyId, string accessKeySecret, string url) { if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) @@ -175,4 +183,4 @@ public Task TranslateAsync(object request, Action OnDataReceived, Cancel throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/STranslate/ViewModels/Preference/Services/TranslatorApi.cs b/STranslate/ViewModels/Preference/Services/TranslatorApi.cs index 3c199cc5..7b57a404 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorApi.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorApi.cs @@ -4,6 +4,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -57,14 +58,20 @@ public TranslatorApi( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] @@ -76,7 +83,8 @@ public TranslatorApi( public List Icons { get; private set; } = Enum.GetValues(typeof(IconType)).OfType().ToList(); [JsonIgnore] - public string Tips { get; set; } = @"请求: + public string Tips { get; set; } = + @"请求: { ""text"": ""test"", ""source_lang"": ""auto"", diff --git a/STranslate/ViewModels/Preference/Services/TranslatorBaidu.cs b/STranslate/ViewModels/Preference/Services/TranslatorBaidu.cs index 8a59122d..faecce71 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorBaidu.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorBaidu.cs @@ -5,6 +5,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -58,14 +59,20 @@ public TranslatorBaidu( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorCaiyun.cs b/STranslate/ViewModels/Preference/Services/TranslatorCaiyun.cs index 405c6a38..bd57b8f1 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorCaiyun.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorCaiyun.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,14 +60,20 @@ public TranslatorCaiyun( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] @@ -123,10 +130,7 @@ public async Task TranslateAsync(object request, Cancellation detect = true }; - var headers = new Dictionary - { - { "X-Authorization", $"token {AppKey}" }, - }; + var headers = new Dictionary { { "X-Authorization", $"token {AppKey}" }, }; string resp = await HttpUtil.PostAsync(Url, JsonConvert.SerializeObject(body), null, headers, token); if (string.IsNullOrEmpty(resp)) diff --git a/STranslate/ViewModels/Preference/Services/TranslatorEcdict.cs b/STranslate/ViewModels/Preference/Services/TranslatorEcdict.cs index 671e3cc9..ece0dec5 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorEcdict.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorEcdict.cs @@ -7,6 +7,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Net.Http; @@ -68,14 +69,20 @@ public TranslatorEcdict( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] @@ -147,6 +154,7 @@ private void ShowEncryptInfo(string? obj) private string _dbFileSize = ""; [RelayCommand] + [property: JsonIgnore] private async Task DownloadResource() { ProcessValue = 0; @@ -223,6 +231,7 @@ private void ProcessDownloadedFile() } [RelayCommand] + [property: JsonIgnore] private void DeleteResource() { try diff --git a/STranslate/ViewModels/Preference/Services/TranslatorGemini.cs b/STranslate/ViewModels/Preference/Services/TranslatorGemini.cs index 15936c24..5c2a3966 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorGemini.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorGemini.cs @@ -5,6 +5,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text.RegularExpressions; using System.Threading; @@ -59,14 +60,20 @@ public TranslatorGemini( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorMicrosoft.cs b/STranslate/ViewModels/Preference/Services/TranslatorMicrosoft.cs index bc3279e0..898d7a93 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorMicrosoft.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorMicrosoft.cs @@ -5,6 +5,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -58,14 +59,20 @@ public TranslatorMicrosoft( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorNiutrans.cs b/STranslate/ViewModels/Preference/Services/TranslatorNiutrans.cs index e71d0dcf..36d81b50 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorNiutrans.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorNiutrans.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,14 +60,20 @@ public TranslatorNiutrans( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorOpenAI.cs b/STranslate/ViewModels/Preference/Services/TranslatorOpenAI.cs index bc54a88c..bedd86b1 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorOpenAI.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorOpenAI.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,18 +60,26 @@ public TranslatorOpenAI( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] private string _model = "gpt-3.5-turbo"; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorSTranslate.cs b/STranslate/ViewModels/Preference/Services/TranslatorSTranslate.cs index 377a1f47..0fa0c508 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorSTranslate.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorSTranslate.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading; @@ -60,14 +61,20 @@ public TranslatorSTranslate( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorTencent.cs b/STranslate/ViewModels/Preference/Services/TranslatorTencent.cs index 74b689ce..833aa59e 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorTencent.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorTencent.cs @@ -4,6 +4,7 @@ using STranslate.Model; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -62,14 +63,20 @@ public TranslatorTencent( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorVolcengine.cs b/STranslate/ViewModels/Preference/Services/TranslatorVolcengine.cs index 79ea68f7..04873050 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorVolcengine.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorVolcengine.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading; @@ -60,14 +61,20 @@ public TranslatorVolcengine( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/Services/TranslatorYoudao.cs b/STranslate/ViewModels/Preference/Services/TranslatorYoudao.cs index b610606b..bd8bd7fe 100644 --- a/STranslate/ViewModels/Preference/Services/TranslatorYoudao.cs +++ b/STranslate/ViewModels/Preference/Services/TranslatorYoudao.cs @@ -6,6 +6,7 @@ using STranslate.Util; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,14 +60,20 @@ public TranslatorYoudao( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore] diff --git a/STranslate/ViewModels/Preference/TTS/TTSAzure.cs b/STranslate/ViewModels/Preference/TTS/TTSAzure.cs index ab480eb4..6c10fc8c 100644 --- a/STranslate/ViewModels/Preference/TTS/TTSAzure.cs +++ b/STranslate/ViewModels/Preference/TTS/TTSAzure.cs @@ -7,6 +7,7 @@ using STranslate.Model; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Threading; using System.Threading.Tasks; @@ -50,14 +51,20 @@ public TTSAzure(Guid guid, string url, string name = "", IconType icon = IconTyp [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; #region Show/Hide Encrypt Info diff --git a/STranslate/ViewModels/Preference/TTS/TTSOffline.cs b/STranslate/ViewModels/Preference/TTS/TTSOffline.cs index f874afc8..acdd74b5 100644 --- a/STranslate/ViewModels/Preference/TTS/TTSOffline.cs +++ b/STranslate/ViewModels/Preference/TTS/TTSOffline.cs @@ -4,6 +4,7 @@ using STranslate.Model; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Speech.Synthesis; using System.Threading; @@ -58,14 +59,20 @@ public TTSOffline( [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _url = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _AppID = string.Empty; [JsonIgnore] [ObservableProperty] + [property: DefaultValue("")] + [property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string _appKey = string.Empty; [JsonIgnore]