App.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using ClickOnceSetup.Common;
  2. using ClickOnceSetup.MiniServer.Server;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. namespace ClickOnceSetup
  12. {
  13. /// <summary>
  14. /// App.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class App : Application
  17. {
  18. ServerBase server = new ServerBase();
  19. protected override void OnStartup(StartupEventArgs e)
  20. {
  21. base.OnStartup(e);
  22. SettingJsonGet _jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\SystemConfig.json");
  23. var language = _jObjectSystemConfig.GetJsonRoot().GetJPropertyString("$.Language");
  24. if (string.IsNullOrWhiteSpace(language))
  25. {
  26. InitializeLanguage("English");
  27. }
  28. else
  29. {
  30. InitializeLanguage(language);
  31. }
  32. server.StartListen(9999);
  33. }
  34. protected override void OnExit(ExitEventArgs e)
  35. {
  36. server.StopListen();
  37. base.OnExit(e);
  38. }
  39. public void InitializeLanguage(string currentLanguage)
  40. {
  41. var assemblyName = GetType().Assembly.GetName().Name;
  42. foreach (var supportedLanguage in TranslateHelper.SupportedLanguages)
  43. {
  44. var resourceName = $"{assemblyName}.Common.Languages.{supportedLanguage}.json";
  45. using (var languageStream = GetType().Assembly.GetManifestResourceStream(resourceName))
  46. {
  47. if (languageStream != null)
  48. {
  49. var reader = new StreamReader(languageStream);
  50. var content = reader.ReadToEnd();
  51. TranslateHelper.AddLanguageResource(supportedLanguage, content);
  52. }
  53. }
  54. }
  55. if (TranslateHelper.SupportedLanguages.FirstOrDefault(v => v == currentLanguage) != null)
  56. {
  57. TranslateHelper.CurrentLanguage = currentLanguage;
  58. }
  59. else
  60. {
  61. TranslateHelper.CurrentLanguage = TranslateHelper.SupportedLanguages.FirstOrDefault();
  62. }
  63. }
  64. }
  65. }