From 43b355e7ddac050265288c52553aedd844ee45e1 Mon Sep 17 00:00:00 2001 From: artur-kalimullin <144933634+artur-kalimullin@users.noreply.github.com> Date: Fri, 24 May 2024 22:01:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 7 ++- .../CollectionGenericObjects/AirCraftAngar.cs | 6 +- .../StorageCollection.cs | 12 ++-- .../FormAirCraftCollection.cs | 60 ++++++++++--------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs index 88c0438..0965886 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -102,10 +102,11 @@ public abstract class AbstractCompany DrawningAirCraft? obj = _collection?.Get(i); obj?.DrawTransport(graphics); } - catch (ObjectNotFoundException e){} - catch (PositionOutOfCollectionException e){} - } + catch (ObjectNotFoundException) + { + } + } return bitmap; } diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs index 3cbac34..e4f599a 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs @@ -58,8 +58,10 @@ public class AirCraftAngar : AbstractCompany _collection.Get(currentIndex)?.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); } } - catch (ObjectNotFoundException e){} - catch (PositionOutOfCollectionException e){} + catch (ObjectNotFoundException) + { + + } currentIndex++; } } diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs index 3b065ea..1937879 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -1,5 +1,6 @@ using ProjectAirFighter.Drawnings; using ProjectAirFighter.Exceptions; +using System.Data; using System.Text; namespace ProjectAirFighter.CollectionGenericObjects; @@ -93,7 +94,7 @@ public class StorageCollection { if (_storages.Count == 0) { - throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения"); + throw new InvalidDataException("В хранилище отсутствуют коллекции для сохранения"); } if (File.Exists(filename)) @@ -133,7 +134,6 @@ public class StorageCollection } writer.Write(sb); } - } } @@ -145,7 +145,7 @@ public class StorageCollection { if (!File.Exists(filename)) { - throw new FileNotFoundException("Файл не существует"); + throw new FileNotFoundException($"{filename} не существует"); } using (StreamReader fs = File.OpenText(filename)) @@ -153,11 +153,11 @@ public class StorageCollection string str = fs.ReadLine(); if (str == null || str.Length == 0) { - throw new ArgumentException("В файле нет данных"); + throw new FileFormatException("Файл не подходит"); } if (!str.StartsWith(_collectionKey)) { - throw new InvalidDataException("В файле неверные данные"); + throw new IOException("В файле неверные данные"); } _storages.Clear(); string strs = ""; @@ -189,7 +189,7 @@ public class StorageCollection } catch (CollectionOverflowException ex) { - throw new CollectionOverflowException("Коллекция переполнена", ex); + throw new DataException("Коллекция переполнена", ex); } } } diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs index ee8dab7..1923cbf 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs @@ -78,7 +78,7 @@ public partial class FormAirCraftCollection : Form catch (CollectionOverflowException ex) { MessageBox.Show("Не удалось добавить объект"); - _logger.LogWarning($"Не удалось добавить объект: {ex.Message}"); + _logger.LogError($"Не удалось добавить объект: {ex.Message}"); } } @@ -91,7 +91,7 @@ public partial class FormAirCraftCollection : Form { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) { - _logger.LogWarning("Удаление объекта из несуществующей коллекции"); + _logger.LogError("Удаление объекта из несуществующей коллекции"); return; } @@ -105,18 +105,18 @@ public partial class FormAirCraftCollection : Form { object decrementObject = _company - pos; MessageBox.Show("Объект удален"); - _logger.LogInformation($"Удален по позиции {pos}"); + _logger.LogInformation($"Удален объект по позиции {pos}"); pictureBox.Image = _company.Show(); } - catch (ObjectNotFoundException ex) + catch (ObjectNotFoundException) { MessageBox.Show("Объект не найден"); - _logger.LogWarning($"Удаление не найденного объекта в позиции {pos} "); + _logger.LogError($"Удаление не найденного объекта в позиции {pos} "); } - catch (PositionOutOfCollectionException ex) + catch (PositionOutOfCollectionException) { MessageBox.Show("Удаление вне рамках коллекции"); - _logger.LogWarning($"Удаление объекта за пределами коллекции {pos} "); + _logger.LogError($"Удаление объекта за пределами коллекции {pos} "); } } @@ -131,29 +131,33 @@ public partial class FormAirCraftCollection : Form { return; } - - DrawningAirCraft? aircraft = null; - int counter = 100; - while (aircraft == null) + try { - aircraft = _company.GetRandomObject(); - counter--; - if (counter <= 0) + DrawningAirCraft? aircraft = null; + int counter = 100; + while (aircraft == null) { - break; + aircraft = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } } + if (aircraft == null) + { + return; + } + FormAirFighter form = new() + { + SetAirCraft = aircraft + }; + form.ShowDialog(); } - - if (aircraft == null) + catch (ObjectNotFoundException) { - return; + _logger.LogError("Ошибка при передаче объекта на FormAirFighter"); } - - FormAirFighter form = new() - { - SetAirCraft = aircraft - }; - form.ShowDialog(); } /// @@ -181,7 +185,7 @@ public partial class FormAirCraftCollection : Form if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogWarning("Не заполненная коллекция"); + _logger.LogError("Не заполненная коллекция"); return; } @@ -210,7 +214,7 @@ public partial class FormAirCraftCollection : Form if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) { MessageBox.Show("Коллекция не выбрана"); - _logger.LogWarning("Удаление невыбранной коллекции"); + _logger.LogError("Удаление невыбранной коллекции"); return; } string name = listBoxCollection.SelectedItem.ToString() ?? string.Empty; @@ -248,7 +252,7 @@ public partial class FormAirCraftCollection : Form if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) { MessageBox.Show("Коллекция не выбрана"); - _logger.LogWarning("Создание компании невыбранной коллекции"); + _logger.LogError("Создание компании невыбранной коллекции"); return; } @@ -256,7 +260,7 @@ public partial class FormAirCraftCollection : Form if (collection == null) { MessageBox.Show("Коллекция не проинициализирована"); - _logger.LogWarning("Не удалось инициализировать коллекцию"); + _logger.LogError("Не удалось инициализировать коллекцию"); return; }