diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj
index 8c229c9..a5bf5b2 100644
--- a/Airbus/Airbus/Airbus.csproj
+++ b/Airbus/Airbus/Airbus.csproj
@@ -8,16 +8,6 @@
enable
-
-
-
-
-
-
- Always
-
-
-
True
@@ -36,6 +26,7 @@
+
diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs
index a2ac496..74ab113 100644
--- a/Airbus/Airbus/FormMapWithSetPlanes.cs
+++ b/Airbus/Airbus/FormMapWithSetPlanes.cs
@@ -69,6 +69,7 @@ namespace Airbus
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
return;
}
@@ -76,6 +77,7 @@ namespace Airbus
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogInformation("Отсутствует карта с названием {0}", textBoxNewMapName.Text);
return;
}
@@ -83,13 +85,14 @@ namespace Airbus
_mapsCollection.AddMap(textBoxNewMapName.Text,
_mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
- _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
+ _logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
}
//Выбор карты
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ _logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
}
// Удаление карты
@@ -104,24 +107,40 @@ namespace Airbus
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
+ _logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
}
}
//отрисовка добавленного объекта в хранилище
private void AddPlane(DrawningAirbus plane)
{
- if (listBoxMaps.SelectedIndex == -1)
+ try
{
- return;
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectPlane(plane) != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ _logger.LogInformation("Добавлен объект {@Airbus}", plane);
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ _logger.LogInformation("Не удалось добавить объект");
+ }
}
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectPlane(plane) != -1)
+ catch(StorageOverflowException ex)
{
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ _logger.LogWarning("Ошибка, переполнение хранилища: {0}", ex.Message);
+ MessageBox.Show($"Ошибка, хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
- else
+ catch(ArgumentException ex)
{
- MessageBox.Show("Не удалось добавить объект");
+ _logger.LogWarning("Ошибка добавления: {0}. Объект: {@Airbus}", ex.Message, plane);
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@@ -137,7 +156,7 @@ namespace Airbus
//удаление объекта
private void ButtonRemovePlane_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
@@ -152,22 +171,28 @@ namespace Airbus
try
{
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null)
+ var deletedPlane = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
+
+ if (deletedPlane != null)
{
MessageBox.Show("Объект удалён");
+ _logger.LogInformation("Из текущей карты удалён объект {@Airbus}", deletedPlane);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
}
else
{
+ _logger.LogInformation("Не удалось удалить объект по позиции {0}. Объект равен null", pos);
MessageBox.Show("Не удалось удалить объект");
}
}
catch (PlaneNotFoundException ex)
{
+ _logger.LogWarning("Ошибка удаления: {0}", ex.Message);
MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
catch (Exception ex)
{
+ _logger.LogWarning("Неизвестная ошибка удаления: {0}", ex.Message);
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
}
}
@@ -233,7 +258,7 @@ namespace Airbus
try
{
_mapsCollection.SaveData(saveFileDialog.FileName);
-
+ _logger.LogInformation("Сохранение прошло успешно. Расположение файла: {0}", saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@@ -241,6 +266,7 @@ namespace Airbus
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogInformation("Не удалось сохранить файл '{0}'. Текст ошибки: {1}", saveFileDialog.FileName, ex.Message);
}
}
}
@@ -253,7 +279,7 @@ namespace Airbus
try
{
_mapsCollection.LoadData(openFileDialog.FileName);
-
+ _logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName);
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@@ -261,6 +287,7 @@ namespace Airbus
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogInformation("Не удалось загрузить файл '{0}'. Текст ошибки: {1}", openFileDialog.FileName, ex.Message);
}
}
}
diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs
index bdeb554..ec1063b 100644
--- a/Airbus/Airbus/SetPlanesGeneric.cs
+++ b/Airbus/Airbus/SetPlanesGeneric.cs
@@ -61,12 +61,9 @@ namespace Airbus
return result;
}
- return null;
+ throw new PlaneNotFoundException(position);
}
- //TODO проверка позиции???
- //что-то типа throw new PlaneNotFoundException(position);
-
return null;
}