Добавлено логирование необходимых действий пользователя

This commit is contained in:
Никита Потапов 2023-11-20 20:42:25 +04:00
parent 6d3098d62b
commit 911543fd43
2 changed files with 12 additions and 4 deletions

View File

@ -99,6 +99,7 @@ namespace ProjectStormtrooper
_logger.LogInformation($"Удален набор: {name}"); _logger.LogInformation($"Удален набор: {name}");
ReloadObjects(); ReloadObjects();
} }
_logger.LogWarning("Отмена удаления набора");
} }
/// <summary> /// <summary>
/// Добавление объекта в набор /// Добавление объекта в набор
@ -129,6 +130,7 @@ namespace ProjectStormtrooper
if (obj + plane > -1) if (obj + plane > -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
_logger.LogInformation($"Добавлен объект {plane}");
pictureBoxCollection.Image = obj.ShowPlanes(); pictureBoxCollection.Image = obj.ShowPlanes();
} }
else else
@ -165,9 +167,11 @@ namespace ProjectStormtrooper
int pos = Convert.ToInt32(maskedTextBoxNumber.Text); int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
try try
{ {
if (obj - pos != null) var removedObj = obj - pos;
if (removedObj != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
_logger.LogInformation($"Удален объект {removedObj} с позиции {pos}");
pictureBoxCollection.Image = obj.ShowPlanes(); pictureBoxCollection.Image = obj.ShowPlanes();
} }
else else
@ -211,10 +215,12 @@ namespace ProjectStormtrooper
{ {
_storage.SaveData(saveFileDialog.FileName); _storage.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Данные сохранены в файл {saveFileDialog.FileName}");
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}");
} }
} }
} }
@ -229,10 +235,12 @@ namespace ProjectStormtrooper
ReloadObjects(); ReloadObjects();
RefreshCollection(); RefreshCollection();
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}");
} }
} }
} }

View File

@ -117,18 +117,18 @@ namespace ProjectStormtrooper
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
throw new Exception("Ошибка открытия файла"); throw new FileNotFoundException("Ошибка открытия файла");
} }
using (StreamReader sr = new StreamReader(filename)) using (StreamReader sr = new StreamReader(filename))
{ {
string? currentLine = sr.ReadLine(); string? currentLine = sr.ReadLine();
if (currentLine == null) if (currentLine == null)
{ {
throw new Exception("Нет данных для загрузки"); throw new IOException("Нет данных для загрузки");
} }
if (!currentLine.Contains("PlaneStorage")) if (!currentLine.Contains("PlaneStorage"))
{ {
throw new Exception("Неверный формат данных"); throw new FileFormatException("Неверный формат данных");
} }
_planeStorages.Clear(); _planeStorages.Clear();
currentLine = sr.ReadLine(); currentLine = sr.ReadLine();