InfomationTabsWindow.xaml.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. using ClickOnceSetup.Common;
  2. using ClickOnceSetup.Common.ChainResponsibility;
  3. using ClickOnceSetup.MiniServer.Database;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Threading;
  15. using Vinno.vCloud.Protocol.Initializers;
  16. namespace ClickOnceSetup
  17. {
  18. /// <summary>
  19. /// InfomationTabs.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class InfomationTabs
  22. {
  23. private InstallProcess _installProcess;
  24. SettingJsonGet _jObject = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\InstallPackage\\SystemPackage\\Server\\Settings\\Server\\Setting.conf");
  25. SettingJsonGet _jObjectManagement = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\InstallPackage\\SystemPackage\\Management\\appsettings.json");
  26. SettingJsonGet _jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\SystemConfig.json");
  27. SettingJsonGet _jObjectVideoConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\InstallPackage\\SystemPackage\\VideoServer\\appsettings.json");
  28. List<string> _iPWhiteList = new List<string>();
  29. public InfomationTabs()
  30. {
  31. ClientTagsInitializer.Initialize();
  32. InitializeComponent();
  33. try
  34. {
  35. if (TranslateHelper.CurrentLanguage.ToUpper() == "ENGLISH")
  36. {
  37. cb_ChooseLanguage.SelectedIndex = 0;
  38. }
  39. else
  40. {
  41. cb_ChooseLanguage.SelectedIndex = 1;
  42. }
  43. FuncInOutHelper.AddDelegate(CloseWindow);
  44. FuncInOutHelper.AddDelegate(CopyFiles);
  45. FuncInOutHelper.AddDelegate(OpenHintShow);
  46. FuncInOutHelper.AddDelegate(GetInstallPath);
  47. FuncInOutHelper.AddDelegate(GetTagValue);
  48. FuncInOutHelper.AddDelegate(GetUpgradePath);
  49. FuncInOutHelper.AddDelegate(GetIsBak);
  50. FuncInOutHelper.AddDelegate(GetUseTestServer);
  51. FuncInOutHelper.AddDelegate(JumpToFinish);
  52. FuncInOutHelper.AddDelegate(GetLiveVideoTypeSelectIndex);
  53. FuncInOutHelper.AddDelegate(MessageBox);
  54. if (IsInitialized)
  55. {
  56. FirstSetting();
  57. LoadSetting(_jObject.GetJsonRoot());
  58. LoadManagementSetting(_jObjectManagement.GetJsonRoot());
  59. LoadOldSettingFile(txt_Systeminstallationpath.Text);
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. FileHelper.AppendWriteFile("InstallLog.txt", ex.Message + "|" + ex.StackTrace);
  65. }
  66. }
  67. /// <summary>
  68. /// 加载管理站配置
  69. /// </summary>
  70. /// <param name="jObjectManagement"></param>
  71. private void LoadManagementSetting(JToken jObjectManagement)
  72. {
  73. if (jObjectManagement == null || !jObjectManagement.HasValues)
  74. {
  75. return;
  76. }
  77. jObjectManagement.GetJPropertyStringAction($"$.AppSettings.ServerConfig.Host",v=> txt_ServerHost.Text = v);
  78. jObjectManagement.GetJPropertyStringAction($"$.AppSettings.ServerConfig.Port",v=> txt_ServerPort.Text = v);
  79. jObjectManagement.GetJPropertyStringAction($"$.AppSettings.GetReportApiUrl",v=> txt_GetReportApiUrl.Text = v);
  80. jObjectManagement.GetJPropertyStringAction($"$.AppSettings.ApiCacheFolder", v=> txt_ApiCacheFolder.Text = v);
  81. }
  82. private void LoadVideoServerSetting(JToken videoServerRoot)
  83. {
  84. if (videoServerRoot == null || !videoServerRoot.HasValues) { return; }
  85. videoServerRoot.GetJPropertyStringAction($"$.AppSettings.StoageVideoFolder",v=> txt_StoageVideoFolder.Text = v);
  86. videoServerRoot.GetJPropertyStringAction($"$.AppSettings.ServerUrl",v=> txt_ServerUrl.Text = v);
  87. //txt_AppKey.Text = "9c96274f5eca47f181bf24b6b737e43e";
  88. //txt_AppSecret.Text = "ac60a9a87d5f4f8c9fa1a55cfeb0826f";
  89. }
  90. /// <summary>
  91. /// 保存管理站配置
  92. /// </summary>
  93. /// <param name="jObjectManagement"></param>
  94. private void SaveManagementSettings(JToken jObjectManagement)
  95. {
  96. if (jObjectManagement == null || !jObjectManagement.HasValues) { return; }
  97. jObjectManagement.SetPropertyValue("Host", txt_ServerHost.Text, $"$.AppSettings.ServerConfig");
  98. jObjectManagement.SetPropertyValue("Port", txt_ServerPort.Text.ToInt(), $"$.AppSettings.ServerConfig");
  99. jObjectManagement.SetPropertyValue("GetReportApiUrl", txt_GetReportApiUrl.Text, $"$.AppSettings");
  100. jObjectManagement.SetPropertyValue("ApiCacheFolder", txt_ApiCacheFolder.Text, $"$.AppSettings");
  101. _jObjectManagement.SaveJson();
  102. ((JObject)_jObjectSystemConfig.GetJsonRoot()).AddChild("ManagementConfig", _jObjectManagement.GetJsonRoot());
  103. }
  104. private void FirstSetting()
  105. {
  106. if (string.IsNullOrWhiteSpace(txt_Serverdomainname.Text))
  107. {
  108. txt_Serverdomainname.Text = IpInfoGet.GetLocalIpByManagementClass().FirstOrDefault() ?? string.Empty;
  109. }
  110. var jObjectSystemConfig = _jObjectSystemConfig.GetJsonRoot();
  111. if (jObjectSystemConfig == null || !jObjectSystemConfig.HasValues) { return; }
  112. string installationPath = jObjectSystemConfig.GetJPropertyString($"$.SystemInstallationPath");
  113. if (!string.IsNullOrWhiteSpace(installationPath) && string.IsNullOrWhiteSpace(txt_Systeminstallationpath.Text))
  114. {
  115. _systeminstallationpath = installationPath;
  116. txt_Systeminstallationpath.Text = installationPath;
  117. }
  118. string serverdomainname = jObjectSystemConfig.GetJPropertyString($"$.ServerDomainName");
  119. if (!string.IsNullOrWhiteSpace(serverdomainname) && string.IsNullOrWhiteSpace(txt_Serverdomainname.Text))
  120. {
  121. txt_Serverdomainname.Text = serverdomainname;
  122. }
  123. var dependpacks = jObjectSystemConfig.GetAllChildren("$.DependpackConfig");
  124. if (dependpacks != null)
  125. {
  126. foreach (var jToken in dependpacks)
  127. {
  128. var dependpack = (JProperty) jToken;
  129. string elementName = dependpack.Name;
  130. int elementValue = dependpack.Value.Value<int>();
  131. var element = grid_dependPack.FindName(elementName);
  132. if (element != null)
  133. {
  134. ((CheckBox)element).IsChecked = elementValue == 1;
  135. }
  136. }
  137. }
  138. var managementStartPort = jObjectSystemConfig.GetJPropertyString("$.ManagementStartPort");
  139. if (!string.IsNullOrWhiteSpace(managementStartPort))
  140. {
  141. txt_ManagementStartPort.Text = managementStartPort;
  142. }
  143. int isBak = jObjectSystemConfig.GetJPropertyInt($"$.IsBak");
  144. int useTestServer = jObjectSystemConfig.GetJPropertyInt($"$.UseTestServer");
  145. cb_isBak.IsChecked = isBak == 1;
  146. cb_useTestServer.IsChecked = useTestServer == 1;
  147. var iPWhiteListData = jObjectSystemConfig.GetJPropertyCollectionsValueByPath<string>("$.IPWhiteList")?.ToList();
  148. if (iPWhiteListData !=null && iPWhiteListData.Any())
  149. {
  150. _iPWhiteList.AddRange(iPWhiteListData);
  151. dtgIpWhiteList.ItemsSource = null;
  152. dtgIpWhiteList.ItemsSource = _iPWhiteList.Select(x => new { IP = x });
  153. }
  154. }
  155. /// <summary>
  156. /// 加载配置
  157. /// </summary>
  158. /// <param name="jObject"></param>
  159. private void LoadSetting(JToken jObject)
  160. {
  161. if (jObject == null || !jObject.HasValues)
  162. {
  163. return;
  164. }
  165. #region 加载主要配置
  166. jObject.GetJPropertyStringAction($"$.LiveVideo.ChannelProvider",v=> cb_LiveVideoType.SelectedIndex = (v == "Common" ? 1 : 0)) ;
  167. jObject.GetJPropertyStringAction($"$.LiveVideo.CommonBaseUrl",v=> txt_LiveVideoAddress.Text = v);
  168. PageBags.SetData("LiveNeteaseAppKey", jObject.GetJPropertyString($"$.LiveVideo.NeteaseAppKey"));
  169. PageBags.SetData("LiveNeteaseAppSecret", jObject.GetJPropertyString($"$.LiveVideo.NeteaseAppSecret"));
  170. PageBags.SetData("LiveChannelCount", jObject.GetJPropertyInt($"$.LiveVideo.ChannelCount"));
  171. jObject.GetJPropertyStringAction($"$.Video.StorageProvider", v=> cb_StorageProvider.SelectedIndex = (v == "Netease" ? 0 : 1));
  172. if (jObject.GetJPropertyInt($"$.Video.Port") > 0)
  173. {
  174. jObject.GetJPropertyIntAction($"$.Video.Port",v=> txt_VideoPort.Text = v.ToString());
  175. }
  176. #endregion
  177. #region 加载开关
  178. serviceCheckBoxGrid.Children.Clear();
  179. var jTokenChildren = jObject.GetAllChildren("$.Service");
  180. if (jTokenChildren != null)
  181. {
  182. foreach (var jToken in jTokenChildren)
  183. {
  184. var jPropertyChild = (JProperty) jToken;
  185. string elementName = jPropertyChild.Name;
  186. int elementValue = jPropertyChild.Value.Value<int>();
  187. CheckBox ck = new CheckBox();
  188. ck.Name = elementName;
  189. ck.Content = elementName;
  190. ck.IsChecked = elementValue == 1;
  191. serviceCheckBoxGrid.Children.Add(ck);
  192. }
  193. }
  194. CheckBox enableIpLocationCk = new CheckBox();
  195. enableIpLocationCk.Name = "EnableIpLocation";
  196. enableIpLocationCk.Content = "EnableIpLocation";
  197. jObject.GetJPropertyIntAction($"$.Gateway.EnableIpLocation", v => enableIpLocationCk.IsChecked = (v == 1));
  198. serviceCheckBoxGrid.Children.Add(enableIpLocationCk);
  199. #endregion
  200. #region 加载端口
  201. jObject.GetJPropertyIntAction($"$.Statistics.Port",v=> txt_StatisticsPort.Text = v.ToString());
  202. jObject.GetJPropertyIntAction($"$.Gateway.GatewayPort",v=> txt_GatewayPort.Text = v.ToString());
  203. jObject.GetJPropertyIntAction($"$.Management.Port", v => txt_ManagementPort.Text = v.ToString());
  204. jObject.GetJPropertyIntAction($"$.Database.Port",v=> txt_DatabasePort.Text = v.ToString());
  205. jObject.GetJPropertyIntAction($"$.UnifyLog.LogDbPort",v=> txt_LogDbPort.Text = v.ToString());
  206. jObject.GetJPropertyIntAction($"$.UnifyLog.LogViewerPort",v=> txt_LogViewerPort.Text = v.ToString());
  207. if (string.IsNullOrWhiteSpace(txt_LogDbPort.Text) || txt_LogDbPort.Text == "0")
  208. {
  209. jObject.GetJPropertyIntAction($"$.Log.LogDbPort", v=> txt_LogDbPort.Text = v.ToString());
  210. }
  211. if (string.IsNullOrWhiteSpace(txt_LogViewerPort.Text) || txt_LogViewerPort.Text == "0")
  212. {
  213. jObject.GetJPropertyIntAction($"$.Log.LogViewerPort",v=> txt_LogViewerPort.Text = v.ToString());
  214. }
  215. #endregion
  216. #region 加载文件夹
  217. jObject.GetJPropertyStringAction($"$.Storage.StorageFolder",v=> txt_StorageFolder.Text = v);
  218. jObject.GetJPropertyStringAction($"$.Upgrade.UpgradeFolder",v=> txt_UpgradeFolder.Text = v);
  219. jObject.GetJPropertyStringAction($"$.Display.CacheFolder",v=> txt_CacheFolder.Text = v);
  220. jObject.GetJPropertyStringAction($"$.Report.ReportPostFolder",v=> txt_ReportPostFolder.Text = v);
  221. jObject.GetJPropertyStringAction($"$.Management.ApiCacheFolder", v => txt_MApiCacheFolder.Text = v);
  222. #endregion
  223. #region 加载服务Api
  224. jObject.GetJPropertyStringAction($"$.API.Url",v=> txt_ApiUrl.Text = v);
  225. jObject.GetJPropertyStringAction($"$.Report.ReportUrl",v=> txt_ReportUrl.Text = v);
  226. jObject.GetJPropertyStringAction($"$.Storage.Url",v=> txt_DefaultStorageServer.Text = v);
  227. jObject.GetJPropertyStringAction($"$.Upgrade.DefaultUpgradeServer",v=> txt_DefaultUpgradeServer.Text = v);
  228. jObject.GetJPropertyStringAction($"$.Remedical.DefaultDisplayServer",v=> txt_DefaultDisplayServer.Text = v);
  229. jObject.GetJPropertyStringAction($"$.LiveTalking.Url",v=> txt_LiveTalkingServer.Text = v);
  230. jObject.GetJPropertyStringAction($"$.Management.GetReportApiUrl", v => txt_MGetReportApiUrl.Text = v);
  231. jObject.GetJPropertyStringAction($"$.Management.DownloadApiUrl", v => txt_MDownloadApiUrl.Text = v);
  232. jObject.GetJPropertyStringAction($"$.OrderForm.GetUnityPayLink", v => txt_GetUnityPayLink.Text = v);
  233. #endregion
  234. #region 邮箱配置
  235. jObject.GetJPropertyStringAction($"$.RegisterAccount.MailHost",v=> txt_MailHost.Text = v);
  236. jObject.GetJPropertyStringAction($"$.RegisterAccount.EmailUserName",v=> txt_EmailUserName.Text = v);
  237. jObject.GetJPropertyStringAction($"$.RegisterAccount.EmailUserPassword",v=> txt_EmailUserPassword.Text = v);
  238. jObject.GetJPropertyIntAction($"$.RegisterAccount.SmtpPort",v=> txt_SmtpPort.Text = v.ToString());
  239. jObject.GetJPropertyStringAction($"$.RegisterAccount.UseSSL",v=> ck_isssl.IsChecked = (v.ToUpper() == "TRUE"));
  240. #endregion
  241. #region 支付配置
  242. jObject.GetJPropertyStringAction($"$.Payment.ServiceUrl",v=> txt_PayServiceUrl.Text = v);
  243. jObject.GetJPropertyStringAction($"$.Payment.ServicePort",v=> txt_PayServicePort.Text = v);
  244. jObject.GetJPropertyStringAction($"$.Payment.PaySuccessNotifyUrl",v=> txt_PaySuccessNotifyUrl.Text = v);
  245. jObject.GetJPropertyStringAction($"$.Payment.RefundSuccessNotifyUrl",v=> txt_RefundSuccessNotifyUrl.Text = v);
  246. string alipayJson = jObject.GetJPropertyString($"$.Payment.Alipay").TrimEnd(',');
  247. if (!string.IsNullOrWhiteSpace(alipayJson))
  248. {
  249. dynamic alipayJsonDynamic = JObject.Parse(alipayJson);
  250. txt_Alipay_Gatewayurl.Text = (string)alipayJsonDynamic.Gatewayurl;
  251. txt_Alipay_AppId.Text = (string)alipayJsonDynamic.AppId;
  252. txt_Alipay_CharSet.Text = (string)alipayJsonDynamic.CharSet;
  253. txt_Alipay_SignType.Text = (string)alipayJsonDynamic.SignType;
  254. txt_Alipay_PrivateKey.Text = (string)alipayJsonDynamic.PrivateKey;
  255. txt_Alipay_PublicKey.Text = (string)alipayJsonDynamic.PublicKey;
  256. }
  257. string paypalJson = jObject.GetJPropertyString($"$.Payment.Paypal").TrimEnd(',');
  258. if (!string.IsNullOrWhiteSpace(paypalJson))
  259. {
  260. dynamic paypalJsonDynamic = JObject.Parse(paypalJson);
  261. txt_Paypal_ClientId.Text = (string)paypalJsonDynamic.ClientId;
  262. txt_Paypal_ClientSecret.Text = (string)paypalJsonDynamic.ClientSecret;
  263. ck_UseSandBox.IsChecked = (string)paypalJsonDynamic.UseSandBox == "1";
  264. }
  265. string wechatJson = jObject.GetJPropertyString($"$.Payment.Wechat").TrimEnd(',');
  266. if (!string.IsNullOrWhiteSpace(wechatJson))
  267. {
  268. dynamic wechatJsonDynamic = JObject.Parse(wechatJson);
  269. txt_Wechat_AppID.Text = (string)wechatJsonDynamic.AppID;
  270. txt_Wechat_MchID.Text = (string)wechatJsonDynamic.MchID;
  271. txt_Wechat_Key.Text = (string)wechatJsonDynamic.Key;
  272. txt_Wechat_AppSecret.Text = (string)wechatJsonDynamic.AppSecret;
  273. txt_Wechat_SSlCertPassword.Text = (string)wechatJsonDynamic.SSlCertPassword;
  274. }
  275. ShowUploadState();
  276. #endregion
  277. }
  278. /// <summary>
  279. /// 保存Management配置
  280. /// </summary>
  281. private void SaveVideoServerSettings(JToken jObjectVideoServer)
  282. {
  283. if (jObjectVideoServer == null || !jObjectVideoServer.HasValues) { return; }
  284. jObjectVideoServer.SetPropertyValue("StoageVideoFolder", txt_StoageVideoFolder.Text, $"$.AppSettings");
  285. jObjectVideoServer.SetPropertyValue("ServerUrl", txt_ServerUrl.Text, $"$.AppSettings");
  286. _jObjectVideoConfig.SaveJson();
  287. ((JObject)_jObjectSystemConfig.GetJsonRoot()).AddChild("VideoServerConfig", _jObjectVideoConfig.GetJsonRoot());
  288. }
  289. /// <summary>
  290. /// 保存配置
  291. /// </summary>
  292. /// <param name="jObject"></param>
  293. private void SaveSettings(JToken jObject)
  294. {
  295. if (jObject == null || !jObject.HasValues) { return; }
  296. #region 保存主要配置
  297. jObject.SetPropertyValue("ChannelProvider", cb_LiveVideoType.SelectedIndex == 1 ? "Common" : "Netease", $"$.LiveVideo");
  298. jObject.SetPropertyValue("CommonBaseUrl", txt_LiveVideoAddress.Text, $"$.LiveVideo");
  299. jObject.SetPropertyValue("NeteaseAppKey", PageBags.GetData<string>("LiveNeteaseAppKey"), $"$.LiveVideo");
  300. jObject.SetPropertyValue("NeteaseAppSecret", PageBags.GetData<string>("LiveNeteaseAppSecret"), $"$.LiveVideo");
  301. jObject.SetPropertyValue("ChannelCount", PageBags.GetData<int>("LiveChannelCount"), $"$.LiveVideo");
  302. jObject.SetPropertyValue("StorageProvider", cb_StorageProvider.SelectedIndex == 1 ? "Common" : "Netease", $"$.Video");
  303. PageBags.SetData("VideoStorageProvider", cb_StorageProvider.SelectedIndex);
  304. if (cb_StorageProvider.SelectedIndex == 1)
  305. {
  306. jObject.SetPropertyValue("Url", txt_ServerUrl.Text, $"$.Video");
  307. }
  308. else
  309. {
  310. jObject.SetPropertyValue("Url", "https://vcloud.163.com", $"$.Video");
  311. }
  312. if (!string.IsNullOrWhiteSpace(txt_VideoPort.Text))
  313. {
  314. jObject.SetPropertyValue("Port", txt_VideoPort.Text.ToInt(), $"$.Video");
  315. }
  316. else
  317. {
  318. jObject.SetPropertyValue("Port", RegexHelper.MatchSub(txt_ServerUrl.Text, ".*:([\\d]*)").ToInt(), $"$.Video");
  319. }
  320. #endregion
  321. #region 保存开关
  322. foreach (UIElement checkBox in serviceCheckBoxGrid.Children)
  323. {
  324. if (checkBox.GetType().Name == "CheckBox")
  325. {
  326. var checkBoxElement = (CheckBox)checkBox;
  327. var checkBoxName = checkBoxElement.Name;
  328. if (checkBoxName == "EnableIpLocation")
  329. {
  330. jObject.SetPropertyValue("EnableIpLocation", checkBoxElement.IsChecked != null && checkBoxElement.IsChecked.Value ? 1 : 0, $"$.Gateway");
  331. }
  332. else
  333. {
  334. jObject.SetPropertyValue(checkBoxName, checkBoxElement.IsChecked != null && checkBoxElement.IsChecked.Value ? 1 : 0, $"$.Service");
  335. }
  336. }
  337. }
  338. #endregion
  339. #region 保存端口
  340. jObject.SetPropertyValue("Port", txt_StatisticsPort.Text.ToInt(), $"$.Statistics");
  341. jObject.SetPropertyValue("GatewayPort", txt_GatewayPort.Text.ToInt(), $"$.Gateway");
  342. jObject.SetPropertyValue("Port", txt_ManagementPort.Text.ToInt(), $"$.Management");
  343. txt_ServerPort.Text = txt_GatewayPort.Text;
  344. jObject.SetPropertyValue("Port", txt_DatabasePort.Text.ToInt(), $"$.Database");
  345. jObject.SetPropertyValue("LogDbPort", txt_LogDbPort.Text.ToInt(), $"$.UnifyLog");
  346. jObject.SetPropertyValue("LogViewerPort", txt_LogViewerPort.Text.ToInt(), $"$.UnifyLog");
  347. jObject.SetPropertyValue("LogDbPort", txt_LogDbPort.Text.ToInt(), $"$.Log");
  348. jObject.SetPropertyValue("LogViewerPort", txt_LogViewerPort.Text.ToInt(), $"$.Log");
  349. jObject.SetPropertyValue("ListenPort", txt_DefaultStorageServer.Text.SubWithToEnd(":").ToInt(), $"$.Storage");
  350. var hostMatchStr = RegexHelper.MatchSub(txt_DefaultStorageServer.Text, "(.*[//]?[\\w.]*)[:][0-9]*");
  351. if (!string.IsNullOrWhiteSpace(hostMatchStr))
  352. {
  353. var shareListenPort = jObject.GetJPropertyInt($"$.Share.ListenPort", 9103);
  354. jObject.SetPropertyValue("Url", $"http://{hostMatchStr.Replace("storage.","www.").Replace("cloud.", "www.")}:{shareListenPort}", $"$.Share");
  355. }
  356. var match = RegexHelper.MatchSub(txt_DefaultStorageServer.Text, "[//]?[\\w.]*[:]([0-9]*)");
  357. if (!string.IsNullOrWhiteSpace(match))
  358. {
  359. jObject.SetPropertyValue("InternalUrl", $"127.0.0.1:{match}", $"$.Storage");
  360. }
  361. jObject.SetPropertyValue("ListenPort", txt_DefaultUpgradeServer.Text.SubWithToEnd(":").ToInt(), $"$.Upgrade");
  362. jObject.SetPropertyValue("ListenPort", txt_DefaultDisplayServer.Text.SubWithToEnd(":").ToInt(), $"$.Display");
  363. jObject.SetPropertyValue("ListenPort", txt_LiveTalkingServer.Text.SubWithToEnd(":").ToInt(), $"$.LiveTalking");
  364. #endregion
  365. #region 保存文件夹
  366. jObject.SetPropertyValue("StorageFolder", txt_StorageFolder.Text, $"$.Storage");
  367. jObject.SetPropertyValue("UpgradeFolder", txt_UpgradeFolder.Text, $"$.Upgrade");
  368. jObject.SetPropertyValue("CacheFolder", txt_CacheFolder.Text, $"$.Display");
  369. jObject.SetPropertyValue("ReportPostFolder", txt_ReportPostFolder.Text, $"$.Report");
  370. jObject.SetPropertyValue("ApiCacheFolder", txt_MApiCacheFolder.Text, $"$.Management");
  371. #endregion
  372. #region 保存服务Api
  373. jObject.SetPropertyValue("Url", txt_ApiUrl.Text, $"$.API");
  374. jObject.SetPropertyValue("ReportUrl", txt_ReportUrl.Text, $"$.Report");
  375. jObject.SetPropertyValue("Url", txt_DefaultStorageServer.Text, $"$.Storage");
  376. jObject.SetPropertyValue("DefaultUpgradeServer", txt_DefaultUpgradeServer.Text, $"$.Upgrade");
  377. jObject.SetPropertyValue("DefaultDisplayServer", txt_DefaultDisplayServer.Text, $"$.Remedical");
  378. jObject.SetPropertyValue("Url", txt_LiveTalkingServer.Text, $"$.LiveTalking");
  379. jObject.SetPropertyValue("GetReportApiUrl", txt_MGetReportApiUrl.Text, $"$.Management");
  380. jObject.SetPropertyValue("DownloadApiUrl", txt_MDownloadApiUrl.Text, $"$.Management");
  381. jObject.SetPropertyValue("GetUnityPayLink", txt_GetUnityPayLink.Text, $"$.OrderForm");
  382. //DefaultStorageServer
  383. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Chat");
  384. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Display");
  385. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.AssignTerminal");
  386. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Remedical");
  387. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Report");
  388. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.AfterSales");
  389. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.API");
  390. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Training");
  391. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Admin");
  392. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Carotid");
  393. jObject.SetPropertyValue("DefaultStorageServer", txt_DefaultStorageServer.Text, $"$.Teaching");
  394. #endregion
  395. #region 保存配置
  396. jObject.SetPropertyValue("MailHost", txt_MailHost.Text, $"$.RegisterAccount");
  397. jObject.SetPropertyValue("EmailUserName", txt_EmailUserName.Text, $"$.RegisterAccount");
  398. jObject.SetPropertyValue("EmailUserPassword", txt_EmailUserPassword.Text, $"$.RegisterAccount");
  399. jObject.SetPropertyValue("SmtpPort", txt_SmtpPort.Text, $"$.RegisterAccount");
  400. jObject.SetPropertyValue("UseSSL", ck_isssl.IsChecked != null && ck_isssl.IsChecked.Value ? "true" : "false", $"$.RegisterAccount");
  401. #endregion
  402. #region 保存支付配置
  403. jObject.SetPropertyValue("ServiceUrl", txt_PayServiceUrl.Text, $"$.Payment");
  404. jObject.SetPropertyValue("ServicePort", txt_PayServicePort.Text, $"$.Payment");
  405. jObject.SetPropertyValue("PaySuccessNotifyUrl", txt_PaySuccessNotifyUrl.Text, $"$.Payment");
  406. jObject.SetPropertyValue("RefundSuccessNotifyUrl", txt_RefundSuccessNotifyUrl.Text, $"$.Payment");
  407. string alipayJson = JsonConvert.SerializeObject(new
  408. {
  409. AppId = txt_Alipay_AppId.Text,
  410. CharSet = txt_Alipay_CharSet.Text,
  411. SignType = txt_Alipay_SignType.Text,
  412. PrivateKey = txt_Alipay_PrivateKey.Text,
  413. PublicKey = txt_Alipay_PublicKey.Text,
  414. Gatewayurl = txt_Alipay_Gatewayurl.Text
  415. });
  416. jObject.SetPropertyValue("Alipay", alipayJson, $"$.Payment");
  417. string paypalJson = JsonConvert.SerializeObject(new
  418. {
  419. ClientId = txt_Paypal_ClientId.Text,
  420. ClientSecret = txt_Paypal_ClientSecret.Text,
  421. UseSandBox = ck_UseSandBox.IsChecked != null && ck_UseSandBox.IsChecked.Value ? "1":"0"
  422. });
  423. jObject.SetPropertyValue("Paypal", paypalJson, $"$.Payment");
  424. string wechatJson = JsonConvert.SerializeObject(new
  425. {
  426. AppID = txt_Wechat_AppID.Text,
  427. MchID = txt_Wechat_MchID.Text,
  428. Key = txt_Wechat_Key.Text,
  429. AppSecret = txt_Wechat_AppSecret.Text,
  430. SSlCertPassword = txt_Wechat_SSlCertPassword.Text
  431. });
  432. jObject.SetPropertyValue("Wechat", wechatJson, $"$.Payment");
  433. #endregion
  434. _jObject.SaveJson();
  435. ((JObject)_jObjectSystemConfig.GetJsonRoot()).AddChild("ServerConfig", _jObject.GetJsonRoot());
  436. }
  437. /// <summary>
  438. /// 系统配置
  439. /// </summary>
  440. private void SaveSystemConfig(JObject jObjectSystemConfig)
  441. {
  442. if (jObjectSystemConfig == null) { return; }
  443. jObjectSystemConfig.AddChild("ManagementStartPort", txt_ManagementStartPort.Text);
  444. PageBags.SetData("ManagementPort", txt_ManagementStartPort.Text);
  445. PageBags.SetData("VideoPort", txt_VideoPort.Text);
  446. jObjectSystemConfig.AddChild("SystemInstallationPath", txt_Systeminstallationpath.Text);
  447. PageBags.SetData("txt_Systeminstallationpath", txt_Systeminstallationpath.Text);
  448. jObjectSystemConfig.AddChild("ServerDomainName", txt_Serverdomainname.Text);
  449. jObjectSystemConfig.AddChild("IsBak", cb_isBak.IsChecked != null && cb_isBak.IsChecked.Value ? 1 : 0);
  450. PageBags.SetData("isBak", cb_isBak.IsChecked != null && cb_isBak.IsChecked.Value ? 1 : 0);
  451. jObjectSystemConfig.AddChild("UseTestServer", cb_useTestServer.IsChecked != null && cb_useTestServer.IsChecked.Value ? 1 : 0);
  452. PageBags.SetData("UseTestServer", cb_useTestServer.IsChecked != null && cb_useTestServer.IsChecked.Value ? 1 : 0);
  453. if (grid_dependPack.Children.Count > 0)
  454. {
  455. JObject childNode = JObject.Parse("{}");
  456. foreach (UIElement child in grid_dependPack.Children)
  457. {
  458. var cbChild = (CheckBox) child;
  459. var childName = cbChild.Name;
  460. var isChecked = cbChild.IsChecked;
  461. var childValue = (isChecked != null && isChecked.Value) ? 1 : 0;
  462. childNode.AddChild(childName, childValue);
  463. }
  464. jObjectSystemConfig.AddChild("DependpackConfig", childNode);
  465. }
  466. _jObjectSystemConfig.SaveJson();
  467. }
  468. #region 文件夹创建及检查
  469. private bool CreateAndCheckDir()
  470. {
  471. try
  472. {
  473. PageBags.SetData("txt_ApiCacheFolder", txt_ApiCacheFolder.Text);
  474. PageBags.SetData("txt_Systeminstallationpath", txt_Systeminstallationpath.Text);
  475. PageBags.SetData("txt_StorageFolder", txt_StorageFolder.Text);
  476. PageBags.SetData("txt_UpgradeFolder", txt_UpgradeFolder.Text);
  477. PageBags.SetData("txt_CacheFolder", txt_CacheFolder.Text);
  478. PageBags.SetData("txt_ReportPostFolder", txt_ReportPostFolder.Text);
  479. PageBags.SetData("txt_MApiCacheFolder", txt_MApiCacheFolder.Text);
  480. MakeDirHandler makeDirHandler = new MakeDirHandler();
  481. makeDirHandler.HandleRequestAsyn();
  482. return true;
  483. }
  484. catch
  485. {
  486. return false;
  487. }
  488. }
  489. #endregion
  490. private bool CheckRequiredFields()
  491. {
  492. List<bool> isRequiredFields = new List<bool>();
  493. isRequiredFields.Add(txt_Systeminstallationpath.Text.VerifyField(this, $"{lb_Systeminstallationpath.Content} is Empty!"));
  494. isRequiredFields.Add(!txt_LiveVideoAddress.IsEnabled || txt_LiveVideoAddress.Text.VerifyField(this, $"{lb_LiveVideoAddressLabel.Content} is Empty!"));
  495. isRequiredFields.Add(txt_StatisticsPort.Text.VerifyField(this, $"{lb_StatisticsPort.Content} is Empty!"));
  496. isRequiredFields.Add(txt_GatewayPort.Text.VerifyField(this, $"{lb_ManagementPort.Content} is Empty!"));
  497. isRequiredFields.Add(txt_ManagementPort.Text.VerifyField(this, $"{lb_LiveVideoAddressLabel.Content} is Empty!"));
  498. isRequiredFields.Add(txt_DatabasePort.Text.VerifyField(this, $"{lb_DatabasePort.Content} is Empty!"));
  499. isRequiredFields.Add(txt_LogDbPort.Text.VerifyField(this, $"{lb_LogDbPort.Content} is Empty!"));
  500. isRequiredFields.Add(txt_LogViewerPort.Text.VerifyField(this, $"{lb_LogViewerPort.Content} is Empty!"));
  501. isRequiredFields.Add(txt_StorageFolder.Text.VerifyField(this, $"{lb_StorageFolder.Content} is Empty!"));
  502. isRequiredFields.Add(txt_CacheFolder.Text.VerifyField(this, $"{lb_CacheFolder.Content} is Empty!"));
  503. isRequiredFields.Add(txt_UpgradeFolder.Text.VerifyField(this, $"{lb_UpgradeFolder.Content} is Empty!"));
  504. isRequiredFields.Add(txt_ReportPostFolder.Text.VerifyField(this, $"{lb_ReportPostFolder.Content} is Empty!"));
  505. isRequiredFields.Add(txt_MApiCacheFolder.Text.VerifyField(this, $"{lb_MApiCacheFolder.Content} is Empty!"));
  506. isRequiredFields.Add(txt_ApiUrl.Text.VerifyField(this, $"{lb_ApiUrl.Content} is Empty!"));
  507. isRequiredFields.Add(txt_ReportUrl.Text.VerifyField(this, $"{lb_ReportUrl.Content} is Empty!"));
  508. isRequiredFields.Add(txt_DefaultStorageServer.Text.VerifyField(this, $"{lb_DefaultStorageServer.Content} is Empty!"));
  509. isRequiredFields.Add(txt_DefaultUpgradeServer.Text.VerifyField(this, $"{lb_DefaultUpgradeServer.Content} is Empty!"));
  510. isRequiredFields.Add(txt_DefaultDisplayServer.Text.VerifyField(this, $"{lb_DefaultDisplayServer.Content} is Empty!"));
  511. isRequiredFields.Add(txt_LiveTalkingServer.Text.VerifyField(this, $"{lb_LiveTalkingServer.Content} is Empty!"));
  512. isRequiredFields.Add(txt_ManagementStartPort.Text.VerifyField(this, $"{lb_ManagementStartPort.Content} is Empty!"));
  513. isRequiredFields.Add(txt_ServerHost.Text.VerifyField(this, $"{lb_ServerHost.Content} is Empty!"));
  514. isRequiredFields.Add(txt_ServerPort.Text.VerifyField(this, $"{lb_ServerPort.Content} is Empty!"));
  515. isRequiredFields.Add(txt_GetReportApiUrl.Text.VerifyField(this, $"{lb_GetReportApiUrl.Content} is Empty!"));
  516. isRequiredFields.Add(txt_ApiCacheFolder.Text.VerifyField(this, $"{lb_ApiCacheFolder.Content} is Empty!"));
  517. isRequiredFields.Add(txt_MGetReportApiUrl.Text.VerifyField(this, $"{lb_MGetReportApiUrl.Content} is Empty!"));
  518. isRequiredFields.Add(txt_MApiCacheFolder.Text.VerifyField(this, $"{lb_MApiCacheFolder.Content} is Empty!"));
  519. if (isRequiredFields.Any(req => req == false))
  520. {
  521. return false;
  522. }
  523. return true;
  524. }
  525. /// <summary>
  526. /// 文件复制操作
  527. /// </summary>
  528. /// <param name="obj"></param>
  529. /// <returns></returns>
  530. private object CopyFiles(object obj = null)
  531. {
  532. string installAddress = FuncInOutHelper.RunDelegate("GetInstallPath") as string;
  533. PageBags.SetData("installAddress", installAddress);
  534. bool isBak = (string)FuncInOutHelper.RunDelegate("GetIsBak") == "1";
  535. PageBags.SetData("isBak", isBak ? 1 : 0);
  536. bool useTestServer = (string)FuncInOutHelper.RunDelegate("GetUseTestServer") == "1";
  537. PageBags.SetData("UseTestServer", useTestServer ? 1 : 0);
  538. string upgradePath = FuncInOutHelper.RunDelegate("GetUpgradePath") as string;
  539. PageBags.SetData("upgradePath", upgradePath);
  540. int liveVideoType = (int)FuncInOutHelper.RunDelegate("GetLiveVideoTypeSelectIndex");
  541. PageBags.SetData("liveVideoType", liveVideoType);
  542. CopyFileHandler copyFileHandler = new CopyFileHandler();
  543. copyFileHandler.SetSuccessor(
  544. () => //success
  545. {
  546. FuncInOutHelper.RunDelegate("JumpToFinish");
  547. },
  548. ex => //fail
  549. {
  550. FuncInOutHelper.RunDelegate("OpenHintShow");
  551. }
  552. );
  553. copyFileHandler.HandleRequestAsyn();
  554. return null;
  555. }
  556. private void SaveAllSettings()
  557. {
  558. SaveSettings(_jObject.GetJsonRoot());
  559. SaveManagementSettings(_jObjectManagement.GetJsonRoot());
  560. SaveVideoServerSettings(_jObjectVideoConfig.GetJsonRoot());
  561. SaveSystemConfig((JObject)_jObjectSystemConfig.GetJsonRoot());
  562. }
  563. /// <summary>
  564. /// 安装依赖包
  565. /// </summary>
  566. private void RunScript()
  567. {
  568. PageBags.SetData("DependNetCore",FuncInOutHelper.RunDelegate("GetTagValue", "tb_netcore") as string);
  569. PageBags.SetData("DependNodeJs", FuncInOutHelper.RunDelegate("GetTagValue", "tb_nodejs") as string);
  570. DependPackageHandler dependPackageHandler = new DependPackageHandler();
  571. dependPackageHandler.SetSuccessor(
  572. () => //success
  573. {
  574. CopyFiles();
  575. },
  576. ex => //fail
  577. {
  578. FuncInOutHelper.RunDelegate("MessageBox", ex.Message);
  579. FuncInOutHelper.RunDelegate("ApplicationExit");
  580. }
  581. );
  582. dependPackageHandler.HandleRequestAsyn();
  583. }
  584. #region 事件
  585. /// <summary>
  586. /// 选择LiveVideo
  587. /// </summary>
  588. /// <param name="sender"></param>
  589. /// <param name="e"></param>
  590. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  591. {
  592. if (IsInitialized)
  593. {
  594. if (((ComboBox)sender).SelectedIndex == 1)
  595. {
  596. txt_LiveVideoAddress.IsEnabled = true;
  597. lb_LiveVideoAddressLabel.IsEnabled = true;
  598. }
  599. else
  600. {
  601. txt_LiveVideoAddress.IsEnabled = false;
  602. lb_LiveVideoAddressLabel.IsEnabled = false;
  603. }
  604. }
  605. }
  606. private void BtnStorageFolder_Click(object sender, RoutedEventArgs e)
  607. {
  608. string folderAddress;
  609. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  610. {
  611. txt_StorageFolder.Text = folderAddress;
  612. }
  613. }
  614. private void BtnUpgradeFolder_Click(object sender, RoutedEventArgs e)
  615. {
  616. string folderAddress;
  617. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  618. {
  619. txt_UpgradeFolder.Text = folderAddress;
  620. }
  621. }
  622. private void BtnCacheFolder_Click(object sender, RoutedEventArgs e)
  623. {
  624. string folderAddress;
  625. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  626. {
  627. txt_CacheFolder.Text = folderAddress;
  628. }
  629. }
  630. private void BtnReportPostFolder_Click(object sender, RoutedEventArgs e)
  631. {
  632. string folderAddress;
  633. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  634. {
  635. txt_ReportPostFolder.Text = folderAddress;
  636. }
  637. }
  638. private void BtnMApiCacheFolder_Click(object sender, RoutedEventArgs e)
  639. {
  640. string folderAddress;
  641. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  642. {
  643. txt_MApiCacheFolder.Text = folderAddress;
  644. }
  645. }
  646. /// <summary>
  647. /// 安装操作
  648. /// </summary>
  649. /// <param name="sender"></param>
  650. /// <param name="e"></param>
  651. private void Install_Click(object sender, RoutedEventArgs e)
  652. {
  653. InstallProcess installProcess = new InstallProcess();
  654. installProcess.Show();
  655. Task.Run(() =>
  656. {
  657. try
  658. {
  659. var systemPackageName = "SystemPackage.zip";
  660. RemoteDeploymentBuilder.RunBuilder(systemPackageName, "VinnoAdmin");
  661. Dispatcher.Invoke(() =>
  662. {
  663. installProcess.Close();
  664. Finish finish = new Finish();
  665. finish.Show();
  666. });
  667. SqlExecute.ExecuteSql("insert into PublishLog(UserName,PublishTime,PublishContent) values(?,?,?)", "VinnoAdmin", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), systemPackageName);
  668. }
  669. finally {
  670. Dispatcher.Invoke(() =>
  671. {
  672. if (installProcess.IsActive)
  673. {
  674. installProcess.Close();
  675. }
  676. });
  677. }
  678. });
  679. }
  680. private void Exit_Click(object sender, RoutedEventArgs e)
  681. {
  682. Close();
  683. Application.Current.Shutdown();
  684. }
  685. private void Btn_Setdomain_Click(object sender, RoutedEventArgs e)
  686. {
  687. if (!string.IsNullOrWhiteSpace(txt_Serverdomainname.Text))
  688. {
  689. txt_ServerUrl.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  690. txt_ApiUrl.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  691. txt_ReportUrl.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  692. txt_DefaultStorageServer.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  693. txt_DefaultUpgradeServer.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  694. txt_DefaultDisplayServer.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  695. txt_LiveTalkingServer.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  696. txt_LiveVideoAddress.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  697. txt_GetReportApiUrl.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  698. txt_MGetReportApiUrl.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  699. txt_GetUnityPayLink.ReplaceTextBoxValue("[//]?([\\w.]*)[:][0-9]", txt_Serverdomainname.Text);
  700. txt_ServerHost.Text = txt_Serverdomainname.Text;
  701. }
  702. }
  703. private void Btn_Chose_Click(object sender, RoutedEventArgs e)
  704. {
  705. string folderAddress;
  706. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  707. {
  708. txt_Systeminstallationpath.Text = folderAddress;
  709. }
  710. string installDir = txt_Systeminstallationpath.Text;
  711. LoadOldSettingFile(installDir);
  712. }
  713. private void Cb_ChooseLanguage_DropDownClosed(object sender, EventArgs e)
  714. {
  715. var language = (string)((TextBlock)((ComboBox)sender).SelectedValue).Tag;
  716. InitializeLanguage(language);
  717. var systemConfig = (JObject)_jObjectSystemConfig.GetJsonRoot();
  718. systemConfig.AddChild("Language", language);
  719. _jObjectSystemConfig.SaveJson();
  720. InfomationTabs infomationTabs = new InfomationTabs();
  721. infomationTabs.Show();
  722. Close();
  723. }
  724. private string _systeminstallationpath = "D:\\Vinno\\System\\";
  725. private void Txt_Systeminstallationpath_TextChanged(object sender, TextChangedEventArgs e)
  726. {
  727. if (IsInit && _systeminstallationpath != txt_Systeminstallationpath.Text)
  728. {
  729. if (!string.IsNullOrWhiteSpace(txt_Systeminstallationpath.Text))
  730. {
  731. string installDir = txt_Systeminstallationpath.Text;
  732. LoadOldSettingFile(installDir);
  733. _systeminstallationpath = txt_Systeminstallationpath.Text;
  734. }
  735. }
  736. }
  737. private void Export_Click(object sender, RoutedEventArgs e)
  738. {
  739. try
  740. {
  741. SaveAllSettings();
  742. string folderAddress;
  743. if (!string.IsNullOrWhiteSpace(folderAddress = FolderBrowserDialogHelper.OpenFolderBrowserDialog()))
  744. {
  745. _jObject.OtherSaveJson(folderAddress + "\\Setting.conf");
  746. _jObjectSystemConfig.OtherSaveJson(folderAddress + "\\SystemConfig.json");
  747. }
  748. }
  749. catch
  750. {
  751. this.ShowMessageBox($"{TranslateHelper.Translate("SettingsError")}!");
  752. }
  753. }
  754. private void Sel_StoreDrive_SelectionChanged(object sender, SelectionChangedEventArgs e)
  755. {
  756. var drive = ((TextBlock)sel_StoreDrive.SelectedValue).Text;
  757. txt_StorageFolder.ReplaceTextBoxValue("[a-zA-Z]{1}[:]{1}\\\\", $"{drive}:\\");
  758. txt_CacheFolder.ReplaceTextBoxValue("[a-zA-Z]{1}[:]{1}\\\\", $"{drive}:\\");
  759. txt_UpgradeFolder.ReplaceTextBoxValue("[a-zA-Z]{1}[:]{1}\\\\", $"{drive}:\\");
  760. txt_ReportPostFolder.ReplaceTextBoxValue("[a-zA-Z]{1}[:]{1}\\\\", $"{drive}:\\");
  761. txt_MApiCacheFolder.ReplaceTextBoxValue("[a-zA-Z]{1}[:]{1}\\\\", $"{drive}:\\");
  762. }
  763. private void Cb_StorageProvider_SelectionChanged(object sender, SelectionChangedEventArgs e)
  764. {
  765. if (IsInitialized)
  766. {
  767. if (((ComboBox)sender).SelectedIndex == 1)
  768. {
  769. txt_StoageVideoFolder.IsEnabled = true;
  770. txt_ServerUrl.IsEnabled = true;
  771. //txt_AppKey.IsEnabled = true;
  772. //txt_AppSecret.IsEnabled = true;
  773. txt_VideoPort.IsEnabled = true;
  774. }
  775. else
  776. {
  777. txt_StoageVideoFolder.IsEnabled = false;
  778. txt_ServerUrl.IsEnabled = false;
  779. //txt_AppKey.IsEnabled = false;
  780. //txt_AppSecret.IsEnabled = false;
  781. txt_VideoPort.IsEnabled = false;
  782. }
  783. }
  784. }
  785. private void Cb_StorageProvider_Loaded(object sender, RoutedEventArgs e)
  786. {
  787. if (IsInitialized)
  788. {
  789. if (((ComboBox)sender).SelectedIndex == 1)
  790. {
  791. txt_StoageVideoFolder.IsEnabled = true;
  792. txt_ServerUrl.IsEnabled = true;
  793. //txt_AppKey.IsEnabled = true;
  794. //txt_AppSecret.IsEnabled = true;
  795. txt_VideoPort.IsEnabled = true;
  796. }
  797. else
  798. {
  799. txt_StoageVideoFolder.IsEnabled = false;
  800. txt_ServerUrl.IsEnabled = false;
  801. //txt_AppKey.IsEnabled = false;
  802. //txt_AppSecret.IsEnabled = false;
  803. txt_VideoPort.IsEnabled = false;
  804. }
  805. }
  806. }
  807. /// <summary>
  808. /// 上传证书
  809. /// </summary>
  810. /// <param name="sender"></param>
  811. /// <param name="e"></param>
  812. private void Btn_UploadCert_Click(object sender, RoutedEventArgs e)
  813. {
  814. using (var stream = FolderBrowserDialogHelper.OpenFileBrowserDialog("p12"))
  815. {
  816. if (stream != Stream.Null)
  817. {
  818. using (FileStream fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\apiclient_cert.p12", FileMode.Create))
  819. {
  820. byte[] readBytes = new byte[4096];
  821. int readCount;
  822. do
  823. {
  824. readCount = stream.Read(readBytes, 0, readBytes.Length);
  825. fileStream.Write(readBytes, 0, readCount);
  826. } while (readCount > 0);
  827. ShowUploadState();
  828. this.ShowMessageBox($"{TranslateHelper.Translate("UploadSuccess")}");
  829. }
  830. }
  831. }
  832. }
  833. private void ShowUploadState()
  834. {
  835. if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\apiclient_cert.p12"))
  836. {
  837. txt_Wechat_SSlCertData.Content = "apiclient_cert.p12";
  838. }
  839. else
  840. {
  841. txt_Wechat_SSlCertData.Content = "";
  842. }
  843. }
  844. #endregion
  845. #region ui线程调用方法
  846. private object CloseWindow(object obj = null)
  847. {
  848. Close();
  849. return null;
  850. }
  851. private string GetIsBak(object obj = null)
  852. {
  853. return cb_isBak.IsChecked != null && cb_isBak.IsChecked.Value ? "1" : "0";
  854. }
  855. private string GetUseTestServer(object obj = null)
  856. {
  857. return cb_useTestServer.IsChecked != null && cb_useTestServer.IsChecked.Value ? "1" : "0";
  858. }
  859. private object GetTagValue(object controlName)
  860. {
  861. var control = FindName((string)controlName);
  862. if (control is CheckBox)
  863. {
  864. var checkBox = (CheckBox)control;
  865. if (checkBox.IsChecked != null && checkBox.IsChecked.Value)
  866. {
  867. return (string)checkBox.Tag;
  868. }
  869. }
  870. return "";
  871. }
  872. private object OpenHintShow(object obj = null)
  873. {
  874. HintShow hint = new HintShow(CopyFiles, CloseShowInstallProcess);
  875. hint.Show();
  876. return null;
  877. }
  878. private object CloseShowInstallProcess(object obj = null)
  879. {
  880. _installProcess?.Close();
  881. return null;
  882. }
  883. private string GetUpgradePath(object obj = null)
  884. {
  885. return txt_UpgradeFolder.Text;
  886. }
  887. private string GetInstallPath(object obj = null)
  888. {
  889. return txt_Systeminstallationpath.Text.Trim('\\') + "\\";
  890. }
  891. private object JumpToFinish(object obj = null)
  892. {
  893. Finish finish = new Finish();
  894. finish.Show();
  895. _installProcess.Close();
  896. Close();
  897. return null;
  898. }
  899. private object GetLiveVideoTypeSelectIndex(object obj = null)
  900. {
  901. return cb_LiveVideoType.SelectedIndex;
  902. }
  903. private object MessageBox(object obj = null)
  904. {
  905. this.ShowMessageBox(obj as string);
  906. return null;
  907. }
  908. #endregion
  909. /// <summary>
  910. /// 初始化语言包
  911. /// </summary>
  912. /// <param name="currentLanguage"></param>
  913. private void InitializeLanguage(string currentLanguage)
  914. {
  915. var assemblyName = GetType().Assembly.GetName().Name;
  916. foreach (var supportedLanguage in TranslateHelper.SupportedLanguages)
  917. {
  918. var resourceName = $"{assemblyName}.Common.Languages.{supportedLanguage}.json";
  919. using (var languageStream = GetType().Assembly.GetManifestResourceStream(resourceName))
  920. {
  921. if (languageStream != null)
  922. {
  923. var reader = new StreamReader(languageStream);
  924. var content = reader.ReadToEnd();
  925. TranslateHelper.AddLanguageResource(supportedLanguage, content);
  926. }
  927. }
  928. }
  929. if (TranslateHelper.SupportedLanguages.FirstOrDefault(v => v == currentLanguage) != null)
  930. {
  931. TranslateHelper.CurrentLanguage = currentLanguage;
  932. }
  933. else
  934. {
  935. TranslateHelper.CurrentLanguage = TranslateHelper.SupportedLanguages.FirstOrDefault();
  936. }
  937. }
  938. /// <summary>
  939. /// 加载安装目录配置
  940. /// </summary>
  941. /// <param name="installDir"></param>
  942. private void LoadOldSettingFile(string installDir)
  943. {
  944. if (!string.IsNullOrWhiteSpace(installDir) && Directory.Exists(installDir))
  945. {
  946. txt_Systeminstallationpath.Text = installDir.Trim('\\') + "\\";
  947. SettingJsonGet oldJObject = new SettingJsonGet($"{txt_Systeminstallationpath.Text}Server\\Settings\\Server\\Setting.conf");
  948. LoadSetting(oldJObject.GetJsonRoot());
  949. SettingJsonGet oldJObjectManagement = new SettingJsonGet($"{txt_Systeminstallationpath.Text}Management\\appsettings.json");
  950. LoadManagementSetting(oldJObjectManagement.GetJsonRoot());
  951. SettingJsonGet oldJObjectVideoServer = new SettingJsonGet($"{txt_Systeminstallationpath.Text}VideoServer\\appsettings.json");
  952. LoadVideoServerSetting(oldJObjectVideoServer.GetJsonRoot());
  953. if (!_jObject.GetJsonRoot().HasValues)
  954. {
  955. _jObject.LoadJson(oldJObject.ToJson());
  956. }
  957. if (!_jObjectManagement.GetJsonRoot().HasValues)
  958. {
  959. _jObjectManagement.LoadJson(oldJObjectManagement.ToJson());
  960. }
  961. if (!_jObjectVideoConfig.GetJsonRoot().HasValues)
  962. {
  963. _jObjectVideoConfig.LoadJson(oldJObjectVideoServer.ToJson());
  964. }
  965. SaveAllSettings();
  966. }
  967. }
  968. private void Btn_Add_Click(object sender, RoutedEventArgs e)
  969. {
  970. if (!string.IsNullOrWhiteSpace(txt_IpAddress.Text) && !_iPWhiteList.Contains(txt_IpAddress.Text) && Regex.IsMatch(txt_IpAddress.Text, "^(2(5[0-5]{1}|[0-4]\\d{1})|[0-1]?\\d{1,2})(\\.(2(5[0-5]{1}|[0-4]\\d{1})|[0-1]?\\d{1,2})){3}$"))
  971. {
  972. _iPWhiteList.Add(txt_IpAddress.Text);
  973. BindIpWhiteList();
  974. }
  975. }
  976. private void DeleteIP_Click(object sender, RoutedEventArgs e)
  977. {
  978. var value = (dynamic)dtgIpWhiteList.SelectedItem;
  979. _iPWhiteList = _iPWhiteList.Where(f => f != value.IP).ToList();
  980. BindIpWhiteList();
  981. }
  982. private void BindIpWhiteList()
  983. {
  984. var systemConfig = (JObject)_jObjectSystemConfig.GetJsonRoot();
  985. systemConfig.AddChild("IPWhiteList", _iPWhiteList);
  986. _jObjectSystemConfig.SaveJson();
  987. dtgIpWhiteList.ItemsSource = null;
  988. dtgIpWhiteList.ItemsSource = _iPWhiteList.Select(x => new { IP = x });
  989. }
  990. }
  991. }