Fixed issue settings not refreshing until restart
This commit is contained in:
parent
3dd5a8bfd1
commit
0f2cb35fc7
|
@ -15,15 +15,23 @@ namespace Core.Main
|
||||||
private GeneralSettings _generalSettings = null;
|
private GeneralSettings _generalSettings = null;
|
||||||
private AnalyzerSettings _analyzerSettings = null;
|
private AnalyzerSettings _analyzerSettings = null;
|
||||||
private SecureSettings _secureSettings = null;
|
private SecureSettings _secureSettings = null;
|
||||||
|
private string _basePath;
|
||||||
|
|
||||||
public PTMagicConfiguration()
|
public PTMagicConfiguration()
|
||||||
{
|
{
|
||||||
LoadSettings(Directory.GetCurrentDirectory());
|
_basePath = Directory.GetCurrentDirectory();
|
||||||
|
LoadSettings(_basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PTMagicConfiguration(string basePath)
|
public PTMagicConfiguration(string basePath)
|
||||||
{
|
{
|
||||||
LoadSettings(basePath);
|
_basePath = basePath;
|
||||||
|
LoadSettings(_basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshSettings()
|
||||||
|
{
|
||||||
|
LoadSettings(_basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSettings(string basePath)
|
private void LoadSettings(string basePath)
|
||||||
|
@ -100,17 +108,17 @@ namespace Core.Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteGeneralSettings(string basePath)
|
public void WriteGeneralSettings()
|
||||||
{
|
{
|
||||||
GeneralSettingsWrapper gsWrapper = new GeneralSettingsWrapper();
|
GeneralSettingsWrapper gsWrapper = new GeneralSettingsWrapper();
|
||||||
gsWrapper.GeneralSettings = this.GeneralSettings;
|
gsWrapper.GeneralSettings = this.GeneralSettings;
|
||||||
|
|
||||||
FileHelper.CreateBackup(basePath + "settings.general.json", basePath, "settings.general.json.backup");
|
FileHelper.CreateBackup(_basePath + "settings.general.json", _basePath, "settings.general.json.backup");
|
||||||
|
|
||||||
FileHelper.WriteTextToFile(basePath, "settings.general.json", JsonConvert.SerializeObject(gsWrapper, Formatting.Indented));
|
FileHelper.WriteTextToFile(_basePath, "settings.general.json", JsonConvert.SerializeObject(gsWrapper, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteAnalyzerSettings(string basePath)
|
public void WriteAnalyzerSettings()
|
||||||
{
|
{
|
||||||
AnalyzerSettingsWrapper asWrapper = new AnalyzerSettingsWrapper();
|
AnalyzerSettingsWrapper asWrapper = new AnalyzerSettingsWrapper();
|
||||||
asWrapper.AnalyzerSettings = this.AnalyzerSettings;
|
asWrapper.AnalyzerSettings = this.AnalyzerSettings;
|
||||||
|
@ -119,12 +127,12 @@ namespace Core.Main
|
||||||
settings.NullValueHandling = NullValueHandling.Ignore;
|
settings.NullValueHandling = NullValueHandling.Ignore;
|
||||||
settings.DefaultValueHandling = DefaultValueHandling.Ignore;
|
settings.DefaultValueHandling = DefaultValueHandling.Ignore;
|
||||||
|
|
||||||
FileHelper.CreateBackup(basePath + "settings.analyzer.json", basePath, "settings.analyzer.json.backup");
|
FileHelper.CreateBackup(_basePath + "settings.analyzer.json", _basePath, "settings.analyzer.json.backup");
|
||||||
|
|
||||||
FileHelper.WriteTextToFile(basePath, "settings.analyzer.json", JsonConvert.SerializeObject(asWrapper, Formatting.Indented, settings));
|
FileHelper.WriteTextToFile(_basePath, "settings.analyzer.json", JsonConvert.SerializeObject(asWrapper, Formatting.Indented, settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteSecureSettings(string password, string basePath)
|
public void WriteSecureSettings(string password)
|
||||||
{
|
{
|
||||||
string passwordEncrypted = EncryptionHelper.Encrypt(password);
|
string passwordEncrypted = EncryptionHelper.Encrypt(password);
|
||||||
|
|
||||||
|
@ -133,7 +141,7 @@ namespace Core.Main
|
||||||
SecureSettingsWrapper ssWrapper = new SecureSettingsWrapper();
|
SecureSettingsWrapper ssWrapper = new SecureSettingsWrapper();
|
||||||
ssWrapper.SecureSettings = this.SecureSettings;
|
ssWrapper.SecureSettings = this.SecureSettings;
|
||||||
|
|
||||||
FileHelper.WriteTextToFile(basePath, "settings.secure.json", JsonConvert.SerializeObject(ssWrapper, Formatting.Indented));
|
FileHelper.WriteTextToFile(_basePath, "settings.secure.json", JsonConvert.SerializeObject(ssWrapper, Formatting.Indented));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace Monitor.Pages
|
||||||
SaveGlobalSettings(formKeys);
|
SaveGlobalSettings(formKeys);
|
||||||
SaveSingleMarketSettings(formKeys);
|
SaveSingleMarketSettings(formKeys);
|
||||||
|
|
||||||
PTMagicConfiguration.WriteAnalyzerSettings(PTMagicBasePath);
|
PTMagicConfiguration.WriteAnalyzerSettings();
|
||||||
|
PTMagicConfiguration.RefreshSettings();
|
||||||
|
|
||||||
NotifyHeadline = "Settings saved!";
|
NotifyHeadline = "Settings saved!";
|
||||||
NotifyMessage = "Settings saved successfully to settings.analyzer.json.";
|
NotifyMessage = "Settings saved successfully to settings.analyzer.json.";
|
||||||
|
|
|
@ -65,6 +65,7 @@ namespace Monitor.Pages
|
||||||
{
|
{
|
||||||
base.Init();
|
base.Init();
|
||||||
|
|
||||||
|
// Read the new settings
|
||||||
PTMagicConfiguration.GeneralSettings.Application.IsEnabled = HttpContext.Request.Form["Application_IsEnabled"].Equals("on");
|
PTMagicConfiguration.GeneralSettings.Application.IsEnabled = HttpContext.Request.Form["Application_IsEnabled"].Equals("on");
|
||||||
PTMagicConfiguration.GeneralSettings.Application.TestMode = HttpContext.Request.Form["Application_TestMode"].Equals("on");
|
PTMagicConfiguration.GeneralSettings.Application.TestMode = HttpContext.Request.Form["Application_TestMode"].Equals("on");
|
||||||
PTMagicConfiguration.GeneralSettings.Application.StartBalance = SystemHelper.TextToDouble(HttpContext.Request.Form["Application_StartBalance"], PTMagicConfiguration.GeneralSettings.Application.StartBalance, "en-US");
|
PTMagicConfiguration.GeneralSettings.Application.StartBalance = SystemHelper.TextToDouble(HttpContext.Request.Form["Application_StartBalance"], PTMagicConfiguration.GeneralSettings.Application.StartBalance, "en-US");
|
||||||
|
@ -79,7 +80,7 @@ namespace Monitor.Pages
|
||||||
PTMagicConfiguration.GeneralSettings.Application.InstanceName = HttpContext.Request.Form["Application_InstanceName"];
|
PTMagicConfiguration.GeneralSettings.Application.InstanceName = HttpContext.Request.Form["Application_InstanceName"];
|
||||||
PTMagicConfiguration.GeneralSettings.Application.CoinMarketCapAPIKey = HttpContext.Request.Form["Application_CoinMarketCapAPIKey"];
|
PTMagicConfiguration.GeneralSettings.Application.CoinMarketCapAPIKey = HttpContext.Request.Form["Application_CoinMarketCapAPIKey"];
|
||||||
PTMagicConfiguration.GeneralSettings.Application.FreeCurrencyConverterAPIKey = HttpContext.Request.Form["Application_FreeCurrencyConverterAPIKey"];
|
PTMagicConfiguration.GeneralSettings.Application.FreeCurrencyConverterAPIKey = HttpContext.Request.Form["Application_FreeCurrencyConverterAPIKey"];
|
||||||
//
|
|
||||||
PTMagicConfiguration.GeneralSettings.Monitor.IsPasswordProtected = HttpContext.Request.Form["Monitor_IsPasswordProtected"].Equals("on");
|
PTMagicConfiguration.GeneralSettings.Monitor.IsPasswordProtected = HttpContext.Request.Form["Monitor_IsPasswordProtected"].Equals("on");
|
||||||
PTMagicConfiguration.GeneralSettings.Monitor.OpenBrowserOnStart = HttpContext.Request.Form["Monitor_OpenBrowserOnStart"].Equals("on");
|
PTMagicConfiguration.GeneralSettings.Monitor.OpenBrowserOnStart = HttpContext.Request.Form["Monitor_OpenBrowserOnStart"].Equals("on");
|
||||||
PTMagicConfiguration.GeneralSettings.Monitor.DefaultDCAMode = HttpContext.Request.Form["Monitor_AnalyzerChart"];
|
PTMagicConfiguration.GeneralSettings.Monitor.DefaultDCAMode = HttpContext.Request.Form["Monitor_AnalyzerChart"];
|
||||||
|
@ -105,8 +106,11 @@ namespace Monitor.Pages
|
||||||
PTMagicConfiguration.GeneralSettings.Telegram.ChatId = SystemHelper.TextToInteger64(HttpContext.Request.Form["Telegram_ChatId"], PTMagicConfiguration.GeneralSettings.Telegram.ChatId);
|
PTMagicConfiguration.GeneralSettings.Telegram.ChatId = SystemHelper.TextToInteger64(HttpContext.Request.Form["Telegram_ChatId"], PTMagicConfiguration.GeneralSettings.Telegram.ChatId);
|
||||||
PTMagicConfiguration.GeneralSettings.Telegram.SilentMode = HttpContext.Request.Form["Telegram_SilentMode"].Equals("on");
|
PTMagicConfiguration.GeneralSettings.Telegram.SilentMode = HttpContext.Request.Form["Telegram_SilentMode"].Equals("on");
|
||||||
|
|
||||||
PTMagicConfiguration.WriteGeneralSettings(PTMagicBasePath);
|
// Save and reload the settings
|
||||||
|
PTMagicConfiguration.WriteGeneralSettings();
|
||||||
|
PTMagicConfiguration.RefreshSettings();
|
||||||
|
|
||||||
|
// Notify
|
||||||
NotifyHeadline = "Settings saved!";
|
NotifyHeadline = "Settings saved!";
|
||||||
NotifyMessage = "Settings saved successfully to settings.general.json.";
|
NotifyMessage = "Settings saved successfully to settings.general.json.";
|
||||||
NotifyType = "success";
|
NotifyType = "success";
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Monitor.Pages
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
base.PreInit();
|
base.PreInit();
|
||||||
PTMagicConfiguration.WriteSecureSettings(password, PTMagicBasePath);
|
PTMagicConfiguration.WriteSecureSettings(password);
|
||||||
|
|
||||||
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "Login");
|
Response.Redirect(PTMagicConfiguration.GeneralSettings.Monitor.RootUrl + "Login");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue