|
|
@@ -6,6 +6,7 @@ using Prism.Commands;
|
|
|
using Prism.Ioc;
|
|
|
using Prism.Mvvm;
|
|
|
using System;
|
|
|
+using System.Configuration;
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
namespace LocalhostMES.ViewModels.Tabs
|
|
|
@@ -21,6 +22,10 @@ namespace LocalhostMES.ViewModels.Tabs
|
|
|
_container = container;
|
|
|
ViewLoadedCommand = new DelegateCommand(UpdateServiceStatus);
|
|
|
_isDarkTheme = ThemeManager.CurrentTheme == ThemeMode.Dark;
|
|
|
+
|
|
|
+ ApiUrl= ConfigurationManager.AppSettings[ "ApiUrl" ];
|
|
|
+ AppKey = ConfigurationManager.AppSettings[ "AppKey" ];
|
|
|
+ Token = ConfigurationManager.AppSettings[ "Token" ];
|
|
|
}
|
|
|
|
|
|
public DelegateCommand ViewLoadedCommand { get; }
|
|
|
@@ -48,7 +53,7 @@ namespace LocalhostMES.ViewModels.Tabs
|
|
|
set => SetProperty(ref _serverPort, value);
|
|
|
}
|
|
|
|
|
|
- private string _apiUrl = "http://localhost:5000";
|
|
|
+ private string _apiUrl = "http://192.168.1.26:5000";
|
|
|
public string ApiUrl
|
|
|
{
|
|
|
get => _apiUrl;
|
|
|
@@ -101,6 +106,11 @@ namespace LocalhostMES.ViewModels.Tabs
|
|
|
public DelegateCommand StartServiceCommand =>
|
|
|
_startServiceCommand ?? (_startServiceCommand = new DelegateCommand(StartService));
|
|
|
|
|
|
+
|
|
|
+ private DelegateCommand _startLocalhostServiceCommand;
|
|
|
+ public DelegateCommand StartLocalhostServiceCommand =>
|
|
|
+ _startLocalhostServiceCommand ?? ( _startLocalhostServiceCommand = new DelegateCommand(StartLocalhostService) );
|
|
|
+
|
|
|
private DelegateCommand _stopServiceCommand;
|
|
|
public DelegateCommand StopServiceCommand =>
|
|
|
_stopServiceCommand ?? (_stopServiceCommand = new DelegateCommand(StopService));
|
|
|
@@ -142,6 +152,39 @@ namespace LocalhostMES.ViewModels.Tabs
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public async void StartLocalhostService()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _workspace.Initialize();
|
|
|
+ if ( ServerPort < 1 || ServerPort > 65535 )
|
|
|
+ {
|
|
|
+ _workspace.ShowStatus("请输入有效的端口号(1-65535)", true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Management.WebApiService == null )
|
|
|
+ {
|
|
|
+ Management.WebApiService = _container.Resolve<WebApiService>();
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Management.WebApiService.IsRunning )
|
|
|
+ {
|
|
|
+ await Management.WebApiService.StopAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ Management.WebApiService.InitLocalhost(ServerPort);
|
|
|
+ await Management.WebApiService.StartAsync();
|
|
|
+
|
|
|
+ UpdateServiceStatus();
|
|
|
+ _workspace.ShowStatus($"Web API服务已启动,端口: {ServerPort}", false);
|
|
|
+ }
|
|
|
+ catch ( Exception ex )
|
|
|
+ {
|
|
|
+ _workspace.ShowStatus($"服务启动失败: {ex.Message}", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
private async void StopService()
|
|
|
{
|
|
|
try
|
|
|
@@ -173,8 +216,17 @@ namespace LocalhostMES.ViewModels.Tabs
|
|
|
_workspace.ShowStatus("请输入API地址", true);
|
|
|
return;
|
|
|
}
|
|
|
+ if(Management.ApiClient!= null) { Management.ApiClient.Dispose(); }
|
|
|
|
|
|
Management.ApiClient = new MesApiClient(apiUrl, appKey, token);
|
|
|
+
|
|
|
+ Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
+ config.AppSettings.Settings[ "ApiUrl" ].Value = ApiUrl;
|
|
|
+ config.AppSettings.Settings[ "AppKey" ].Value = AppKey;
|
|
|
+ config.AppSettings.Settings[ "Token" ].Value = Token;
|
|
|
+ config.Save(ConfigurationSaveMode.Modified);
|
|
|
+ ConfigurationManager.RefreshSection("appSettings");
|
|
|
+
|
|
|
_workspace.ShowStatus("API客户端配置已保存", false);
|
|
|
}
|
|
|
catch (Exception ex)
|