Немного валидации настроек, например, при появлении новой RountToMinutes, делили на 0 и крэш

This commit is contained in:
rutriff
2019-03-18 11:34:09 +03:00
parent 0fcce1bf1c
commit e8213d940f
4 changed files with 107 additions and 17 deletions
-1
View File
@@ -67,7 +67,6 @@
//
// tmrStart
//
this.tmrStart.Enabled = true;
this.tmrStart.Interval = 1500;
this.tmrStart.Tick += new System.EventHandler(this.tmrStart_Tick);
//
+17 -5
View File
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Configuration;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -25,6 +25,8 @@ namespace JiraTimeBotForm.UI
private readonly ITrayMenu _trayIcon;
private CancellationTokenSource _tokenSource;
private Settings _settings;
private readonly Action _settingsWindowShow;
private readonly Action<string> _settingsErrorReporter;
private CancellationTokenSource GetTokenSource()
{
@@ -46,13 +48,19 @@ namespace JiraTimeBotForm.UI
_trayIcon = _container.Resolve<ITrayMenu>();
_trayIcon.Create(this);
_settings = Settings.Load();
_job = _container.Resolve<Job>();
_log = _container.Resolve<ILog>();
_tasksProcessors = _container.Resolve<IAllTasksProcessors>();
_controls = new Control[] { txtDummyMode, btnStart, btnMeeting, btnSettings };
_settingsWindowShow = () =>
{
var frmSettings = new frmSettings();
frmSettings.ShowDialog(this);
};
_settingsErrorReporter = msg => MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);;
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
@@ -62,7 +70,7 @@ namespace JiraTimeBotForm.UI
public Settings ReadSettingsAndLock()
{
_settings = Settings.Load();
_settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter);
LockUnlock(false);
@@ -79,9 +87,13 @@ namespace JiraTimeBotForm.UI
btnCancel.Enabled = !enabled;
tmrStart.Enabled = enabled;
}
private void Form1_Load(object sender, EventArgs e)
{
_settings = Settings.Load();
_settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter);
tmrStart.Enabled = true;
_log.Info($"Загружен бот для {_settings.JiraUserName}, работаем в {_settings.RepositoryPath}");
}
private async void btnStart_Click(object sender, EventArgs e)
+7 -8
View File
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JiraTimeBotForm.Configuration;
@@ -21,7 +14,10 @@ namespace JiraTimeBotForm.UI
private void frmSettings_Load(object sender, EventArgs e)
{
var settings = Settings.Load();
SetSettings(settings);
if (settings != null)
{
SetSettings(settings);
}
}
private void SetSettings(Settings settings)
@@ -64,7 +60,10 @@ namespace JiraTimeBotForm.UI
{
var settings = ReadSettingsAndLock();
settings.Save();
MessageBox.Show("Настройки сохранены.");
DialogResult = DialogResult.OK;
this.Close();
}