123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using ClickOnceSetup.Common;
- using ClickOnceSetup.MiniServer.Server;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- namespace ClickOnceSetup
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : Application
- {
- ServerBase server = new ServerBase();
- protected override void OnStartup(StartupEventArgs e)
- {
- base.OnStartup(e);
- SettingJsonGet _jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\SystemConfig.json");
- var language = _jObjectSystemConfig.GetJsonRoot().GetJPropertyString("$.Language");
- if (string.IsNullOrWhiteSpace(language))
- {
- InitializeLanguage("English");
- }
- else
- {
- InitializeLanguage(language);
- }
- server.StartListen(9999);
- }
- protected override void OnExit(ExitEventArgs e)
- {
- server.StopListen();
- base.OnExit(e);
- }
- public void InitializeLanguage(string currentLanguage)
- {
- var assemblyName = GetType().Assembly.GetName().Name;
- foreach (var supportedLanguage in TranslateHelper.SupportedLanguages)
- {
- var resourceName = $"{assemblyName}.Common.Languages.{supportedLanguage}.json";
- using (var languageStream = GetType().Assembly.GetManifestResourceStream(resourceName))
- {
- if (languageStream != null)
- {
- var reader = new StreamReader(languageStream);
- var content = reader.ReadToEnd();
- TranslateHelper.AddLanguageResource(supportedLanguage, content);
- }
- }
- }
- if (TranslateHelper.SupportedLanguages.FirstOrDefault(v => v == currentLanguage) != null)
- {
- TranslateHelper.CurrentLanguage = currentLanguage;
- }
- else
- {
- TranslateHelper.CurrentLanguage = TranslateHelper.SupportedLanguages.FirstOrDefault();
- }
- }
- }
- }
|