|
|
|
|
@ -4,15 +4,26 @@ using Prism.Mvvm;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using Txgy.EWS.Client.Common;
|
|
|
|
|
using Txgy.EWS.Client.Common.MessageEvents;
|
|
|
|
|
using Txgy.EWS.Client.Entity;
|
|
|
|
|
|
|
|
|
|
namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class SystemSettingsViewModel : BindableBase
|
|
|
|
|
{
|
|
|
|
|
private const string AdvancedSettingsTargetView = "SystemSettingsAdvanced";
|
|
|
|
|
private static readonly string[] AdvancedSettingsFallbackTargetViews =
|
|
|
|
|
{
|
|
|
|
|
"MenuManagementView",
|
|
|
|
|
"RoleManagementView",
|
|
|
|
|
"UserManagementView"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
|
private string _statusMessage;
|
|
|
|
|
private Brush _statusBrush = Brushes.Gray;
|
|
|
|
|
@ -20,6 +31,7 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
public SystemSettingsViewModel(IEventAggregator eventAggregator)
|
|
|
|
|
{
|
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
|
CanEditAdvancedSettings = HasAdvancedSettingsPermission();
|
|
|
|
|
ReloadFromConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -37,6 +49,9 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
set => SetProperty(ref _statusBrush, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanEditAdvancedSettings { get; }
|
|
|
|
|
public Visibility AdvancedSettingsVisibility => CanEditAdvancedSettings ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
|
|
|
|
public string ApiDomain { get; set; }
|
|
|
|
|
public string AlarmSetting { get; set; }
|
|
|
|
|
public string AlarmLevelConfig { get; set; }
|
|
|
|
|
@ -56,7 +71,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
public string DataLookbackHours { get; set; }
|
|
|
|
|
public string DataCacheTimeLenMins { get; set; }
|
|
|
|
|
public string TencentMySql { get; set; }
|
|
|
|
|
public string NasMySql { get; set; }
|
|
|
|
|
public string RealtimeResultTable { get; set; }
|
|
|
|
|
public string RealtimeWaveDataTable { get; set; }
|
|
|
|
|
public string RealtimeFocalmechanismTable { get; set; }
|
|
|
|
|
@ -96,7 +110,7 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var previousConfig = BusinessConfigManager.Current;
|
|
|
|
|
var config = BuildConfig();
|
|
|
|
|
var config = BuildConfig(previousConfig);
|
|
|
|
|
var savedConfig = BusinessConfigManager.Save(config);
|
|
|
|
|
var shouldReloadWarningData = ShouldReloadWarningData(previousConfig, savedConfig);
|
|
|
|
|
GlobalConfig.ApplyBusinessConfig(savedConfig);
|
|
|
|
|
@ -145,7 +159,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
DataLookbackHours = config.Runtime.DataLookbackHours.ToString("0.##", CultureInfo.InvariantCulture);
|
|
|
|
|
DataCacheTimeLenMins = config.Runtime.DataCacheTimeLenMins.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
TencentMySql = GetConnection(config, "TencetnMySQL");
|
|
|
|
|
NasMySql = GetConnection(config, "NasMySQL");
|
|
|
|
|
RealtimeResultTable = config.Database.Tables.RealtimeResultTable;
|
|
|
|
|
RealtimeWaveDataTable = config.Database.Tables.RealtimeWaveDataTable;
|
|
|
|
|
RealtimeFocalmechanismTable = config.Database.Tables.RealtimeFocalmechanismTable;
|
|
|
|
|
@ -166,19 +179,18 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
RaiseAllSettingPropertiesChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BusinessConfig BuildConfig()
|
|
|
|
|
private BusinessConfig BuildConfig(BusinessConfig currentConfig)
|
|
|
|
|
{
|
|
|
|
|
DateTime.Parse(Require(DailyReportStartTime, "日报起始时间"));
|
|
|
|
|
|
|
|
|
|
var dataLookbackHours = ParseDouble(DataLookbackHours, "数据回看时长");
|
|
|
|
|
DataCacheTimeLenMins = ((int)Math.Round(dataLookbackHours * 60.0)).ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
var endpointSettings = BuildEndpointSettings(currentConfig);
|
|
|
|
|
var databaseSettings = BuildDatabaseSettings(currentConfig);
|
|
|
|
|
|
|
|
|
|
return new BusinessConfig
|
|
|
|
|
{
|
|
|
|
|
Endpoints = new EndpointSettings
|
|
|
|
|
{
|
|
|
|
|
ApiDomain = Require(ApiDomain, "API 域名")
|
|
|
|
|
},
|
|
|
|
|
Endpoints = endpointSettings,
|
|
|
|
|
Paths = new PathSettings
|
|
|
|
|
{
|
|
|
|
|
AlarmSetting = Require(AlarmSetting, "报警配置"),
|
|
|
|
|
@ -190,35 +202,19 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
DwgJsonSetting = Require(DwgJsonSetting, "DWG 图层配置"),
|
|
|
|
|
WavesMseedFilePath = Require(WavesMseedFilePath, "Mseed 缓存目录"),
|
|
|
|
|
WavesTxtFilePath = Require(WavesTxtFilePath, "Txt 缓存目录"),
|
|
|
|
|
LocalSqLiteDb = Require(LocalSqLiteDb, "本地 SQLite"),
|
|
|
|
|
LocalSqLiteDb = CanEditAdvancedSettings ? Require(LocalSqLiteDb, "本地 SQLite") : currentConfig.Paths.LocalSqLiteDb,
|
|
|
|
|
DwgSettings = EmptyToNull(DwgSettings),
|
|
|
|
|
CadSettingsFileName = EmptyToNull(CadSettingsFileName)
|
|
|
|
|
},
|
|
|
|
|
Runtime = new RuntimeSettings
|
|
|
|
|
{
|
|
|
|
|
IsDesign = IsDesign,
|
|
|
|
|
IsRealtime = IsRealtime,
|
|
|
|
|
IsDesign = CanEditAdvancedSettings ? IsDesign : currentConfig.Runtime.IsDesign,
|
|
|
|
|
IsRealtime = CanEditAdvancedSettings ? IsRealtime : currentConfig.Runtime.IsRealtime,
|
|
|
|
|
RefreshInterval = ParseInt(RefreshInterval, "刷新间隔"),
|
|
|
|
|
DataLookbackHours = dataLookbackHours,
|
|
|
|
|
DataCacheTimeLenMins = ParseInt(DataCacheTimeLenMins, "数据缓存时长")
|
|
|
|
|
},
|
|
|
|
|
Database = new DatabaseSettings
|
|
|
|
|
{
|
|
|
|
|
Connections = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "TencetnMySQL", Require(TencentMySql, "腾讯 MySQL") },
|
|
|
|
|
{ "NasMySQL", Require(NasMySql, "NAS MySQL") }
|
|
|
|
|
},
|
|
|
|
|
Tables = new TableSettings
|
|
|
|
|
{
|
|
|
|
|
RealtimeResultTable = Require(RealtimeResultTable, "实时结果表"),
|
|
|
|
|
RealtimeWaveDataTable = Require(RealtimeWaveDataTable, "实时波形表"),
|
|
|
|
|
RealtimeFocalmechanismTable = Require(RealtimeFocalmechanismTable, "实时震源机制表"),
|
|
|
|
|
PostResultTable = Require(PostResultTable, "后处理结果表"),
|
|
|
|
|
PostWaveDataTable = Require(PostWaveDataTable, "后处理波形表"),
|
|
|
|
|
PostFocalmechanismTable = Require(PostFocalmechanismTable, "后处理震源机制表")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Database = databaseSettings,
|
|
|
|
|
Branding = new BrandingSettings
|
|
|
|
|
{
|
|
|
|
|
CommpanyName = Require(CommpanyName, "公司名称"),
|
|
|
|
|
@ -242,6 +238,59 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EndpointSettings BuildEndpointSettings(BusinessConfig currentConfig)
|
|
|
|
|
{
|
|
|
|
|
return new EndpointSettings
|
|
|
|
|
{
|
|
|
|
|
ApiDomain = CanEditAdvancedSettings ? Require(ApiDomain, "API 域名") : currentConfig.Endpoints.ApiDomain
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DatabaseSettings BuildDatabaseSettings(BusinessConfig currentConfig)
|
|
|
|
|
{
|
|
|
|
|
if (!CanEditAdvancedSettings)
|
|
|
|
|
{
|
|
|
|
|
return new DatabaseSettings
|
|
|
|
|
{
|
|
|
|
|
Connections = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "TencetnMySQL", GetConnection(currentConfig, "TencetnMySQL") }
|
|
|
|
|
},
|
|
|
|
|
Tables = CopyTableSettings(currentConfig.Database.Tables)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DatabaseSettings
|
|
|
|
|
{
|
|
|
|
|
Connections = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "TencetnMySQL", Require(TencentMySql, "腾讯 MySQL") }
|
|
|
|
|
},
|
|
|
|
|
Tables = new TableSettings
|
|
|
|
|
{
|
|
|
|
|
RealtimeResultTable = Require(RealtimeResultTable, "实时结果表"),
|
|
|
|
|
RealtimeWaveDataTable = Require(RealtimeWaveDataTable, "实时波形表"),
|
|
|
|
|
RealtimeFocalmechanismTable = Require(RealtimeFocalmechanismTable, "实时震源机制表"),
|
|
|
|
|
PostResultTable = Require(PostResultTable, "后处理结果表"),
|
|
|
|
|
PostWaveDataTable = Require(PostWaveDataTable, "后处理波形表"),
|
|
|
|
|
PostFocalmechanismTable = Require(PostFocalmechanismTable, "后处理震源机制表")
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TableSettings CopyTableSettings(TableSettings source)
|
|
|
|
|
{
|
|
|
|
|
return new TableSettings
|
|
|
|
|
{
|
|
|
|
|
RealtimeResultTable = source.RealtimeResultTable,
|
|
|
|
|
RealtimeWaveDataTable = source.RealtimeWaveDataTable,
|
|
|
|
|
RealtimeFocalmechanismTable = source.RealtimeFocalmechanismTable,
|
|
|
|
|
PostResultTable = source.PostResultTable,
|
|
|
|
|
PostWaveDataTable = source.PostWaveDataTable,
|
|
|
|
|
PostFocalmechanismTable = source.PostFocalmechanismTable
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetConnection(BusinessConfig config, string name)
|
|
|
|
|
{
|
|
|
|
|
if (config.Database.Connections != null && config.Database.Connections.TryGetValue(name, out var value))
|
|
|
|
|
@ -252,6 +301,23 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool HasAdvancedSettingsPermission()
|
|
|
|
|
{
|
|
|
|
|
var menus = GlobalData.CurrentUserInfo?.Menus;
|
|
|
|
|
if (menus == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ContainsTargetView(menus, AdvancedSettingsTargetView) ||
|
|
|
|
|
AdvancedSettingsFallbackTargetViews.Any(targetView => ContainsTargetView(menus, targetView));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ContainsTargetView(IEnumerable<MenuEntity> menus, string targetView)
|
|
|
|
|
{
|
|
|
|
|
return menus.Any(menu => string.Equals(menu.TargetView, targetView, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string Require(string value, string name)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
|
|
@ -314,7 +380,6 @@ namespace Txgy.EWS.Client.SysModule.ViewModels
|
|
|
|
|
RaisePropertyChanged(nameof(DataLookbackHours));
|
|
|
|
|
RaisePropertyChanged(nameof(DataCacheTimeLenMins));
|
|
|
|
|
RaisePropertyChanged(nameof(TencentMySql));
|
|
|
|
|
RaisePropertyChanged(nameof(NasMySql));
|
|
|
|
|
RaisePropertyChanged(nameof(RealtimeResultTable));
|
|
|
|
|
RaisePropertyChanged(nameof(RealtimeWaveDataTable));
|
|
|
|
|
RaisePropertyChanged(nameof(RealtimeFocalmechanismTable));
|
|
|
|
|
|