From 22f080fa4f74b6035f1b8b3d58d91cab30b5bc9a Mon Sep 17 00:00:00 2001 From: Daria Date: Tue, 21 May 2024 15:18:19 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Excavator/.editorconfig | 4 + Excavator/Excavator.sln | 2 +- .../AbstractCompany.cs | 14 +++- .../CollectionGenericObjects/Garage.cs | 34 ++++++-- .../ListGenericObjects.cs | 46 +++++++--- .../MassiveGenericObjects.cs | 78 +++++++++++------ .../StorageCollection.cs | 35 ++++---- Excavator/Excavator/Excavator.csproj | 29 +++++++ .../Exceptions/CollectionOverflowException.cs | 20 +++++ .../Exceptions/ObjectNotFoundException.cs | 20 +++++ .../PositionOutOfCollectionException.cs | 15 ++++ .../Excavator/FormTrackedVehicleCollection.cs | 83 ++++++++++++------- Excavator/Excavator/Program.cs | 29 ++++++- Excavator/Excavator/serilogConfig.json | 20 +++++ 14 files changed, 330 insertions(+), 99 deletions(-) create mode 100644 Excavator/.editorconfig create mode 100644 Excavator/Excavator/Exceptions/CollectionOverflowException.cs create mode 100644 Excavator/Excavator/Exceptions/ObjectNotFoundException.cs create mode 100644 Excavator/Excavator/Exceptions/PositionOutOfCollectionException.cs create mode 100644 Excavator/Excavator/serilogConfig.json diff --git a/Excavator/.editorconfig b/Excavator/.editorconfig new file mode 100644 index 0000000..91c8707 --- /dev/null +++ b/Excavator/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0058: Значение выражения никогда не используется +csharp_style_unused_value_expression_statement_preference = discard_variable diff --git a/Excavator/Excavator.sln b/Excavator/Excavator.sln index 328269f..f6d32b9 100644 --- a/Excavator/Excavator.sln +++ b/Excavator/Excavator.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excavator", "Excavator\Excavator.csproj", "{DD2A9FE6-2F74-4387-9318-59AE715EBA73}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excavator", "Excavator\Excavator.csproj", "{DD2A9FE6-2F74-4387-9318-59AE715EBA73}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs index 9991527..ce941c9 100644 --- a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs +++ b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs @@ -1,4 +1,5 @@ using Excavator.Drawnings; +using Excavator.Exceptions; namespace Excavator.CollectionGenericObjects; @@ -95,14 +96,19 @@ public abstract class AbstractCompany Bitmap bitmap = new(_pictureWidth, _pictureHeight); Graphics graphics = Graphics.FromImage(bitmap); DrawBackgound(graphics); - SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - DrawningTrackedVehicle? obj = _collection?.Get(i); - obj?.DrawTransport(graphics); + try + { + DrawningTrackedVehicle? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + catch (ObjectNotFoundException) + { + continue; + } } - return bitmap; } diff --git a/Excavator/Excavator/CollectionGenericObjects/Garage.cs b/Excavator/Excavator/CollectionGenericObjects/Garage.cs index e3f6f2f..f1c84a5 100644 --- a/Excavator/Excavator/CollectionGenericObjects/Garage.cs +++ b/Excavator/Excavator/CollectionGenericObjects/Garage.cs @@ -1,4 +1,5 @@ using Excavator.Drawnings; +using Excavator.Exceptions; namespace Excavator.CollectionGenericObjects; @@ -36,16 +37,31 @@ public class Garage(int picWidth, int picHeight, ICollectionGenericObjects 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + + if (curHeight >= height) + { + return; + } } } } diff --git a/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs index 1c4dadc..dfdfc12 100644 --- a/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs +++ b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,6 @@ - +using Excavator.Exceptions; + + namespace Excavator.CollectionGenericObjects; /// /// Параметризованный набор объектов @@ -33,31 +35,51 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position >= Count || position < 0) return null; + if (position < 0 || position >= Count) + { + throw new PositionOutOfCollectionException(position); + } + return _collection[position]; } public int Insert(T obj) { - if (Count + 1 > _maxCount) return -1; + if (Count == _maxCount) + { + throw new CollectionOverflowException(Count); + } + _collection.Add(obj); - return Count; + return _collection.Count; } public int Insert(T obj, int position) { - if (Count + 1 > _maxCount) return -1; - if (position < 0 || position > Count) return -1; - _collection.Insert(position, obj); - return 1; - } + + if (position < 0 || position > Count) + { + throw new PositionOutOfCollectionException(position); + } + if (Count == _maxCount) + { + throw new CollectionOverflowException(Count); + } + _collection.Insert(position, obj); + return position; + } public T? Remove(int position) { - if (position < 0 || position > Count) return null; - T? pos = _collection[position]; + + if (position < 0 || position > Count) + { + throw new PositionOutOfCollectionException(position); + } + + T? obj = _collection[position]; _collection.RemoveAt(position); - return pos; + return obj; } public IEnumerable GetItems() diff --git a/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs index cfb5a8b..ce1751d 100644 --- a/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Excavator/Excavator/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,4 +1,6 @@  +using Excavator.Exceptions; + namespace Excavator.CollectionGenericObjects; /// @@ -49,53 +51,79 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position < 0 || position > Count) + if (position >= _collection.Length || position < 0) { - return null; + throw new PositionOutOfCollectionException(position); + } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(position); } return _collection[position]; } public int Insert(T excavator) { - return Insert(excavator, 0); - } - public int Insert(T excavator, int position) - { - int nullIndex = -1, i; - if (!(position >= 0 && position < Count)) - return -1; - for (i = position; i < Count; i++) + for (int i = 0; i < Count; i++) { if (_collection[i] == null) { - nullIndex = i; - break; + _collection[i] = excavator; + return i; } } - if (nullIndex < 0) + + throw new CollectionOverflowException(Count); + } + public int Insert(T obj, int position) + { + + if (position < 0 || position >= Count) { - return -1; + throw new PositionOutOfCollectionException(position); } - for (i = nullIndex; i > position; i--) + + if (_collection[position] == null) { - _collection[i] = _collection[i - 1]; + _collection[position] = obj; + return position; } - _collection[position] = excavator; - return position; + + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + throw new CollectionOverflowException(Count); } - public T Remove(int position) + public T? Remove(int position) { - if (position < 0 || position > Count) + + if (position < 0 || position >= Count) { - return null; + throw new PositionOutOfCollectionException(position); + } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(position); } - T drawningTrackedVehicle = _collection[position]; - _collection[position] = null; - - return drawningTrackedVehicle; + T? obj = _collection[position]; + _collection[position] = null; + return obj; } public IEnumerable GetItems() diff --git a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs index 62c5d10..02dbf10 100644 --- a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs +++ b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs @@ -1,5 +1,7 @@ using Excavator.Drawnings; +using Excavator.Exceptions; using System.Text; +using static System.Windows.Forms.LinkLabel; namespace Excavator.CollectionGenericObjects; /// @@ -88,12 +90,11 @@ public class StorageCollection /// Сохранение информации по автомобилям в хранилище в файл /// /// Путь и имя файла - /// true - сохранение прошло успешно, false - ошибка при сохранении данных - public bool SaveData(string filename) + public void SaveData(string filename) { if (_storages.Count == 0) { - return false; + throw new NullReferenceException("В хранилище отсутствуют коллекции для сохранения"); } if (File.Exists(filename)) @@ -134,18 +135,16 @@ public class StorageCollection } } - return true; } /// /// Загрузка информации по автомобилям в хранилище из файла /// /// Путь и имя файла - /// true - загрузка прошла успешно, false - ошибка при загрузке данных - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new FileNotFoundException("Файл не существует"); } using (StreamReader reader = File.OpenText(filename)) @@ -153,11 +152,11 @@ public class StorageCollection string? str = reader.ReadLine(); if (str == null || str.Length == 0) { - return false; + throw new FileFormatException("В файле нет данных"); } - if (!str.StartsWith(_collectionKey)) + if (!str.Equals(_collectionKey)) { - return false; + throw new FileFormatException("В файле неверные данные"); } _storages.Clear(); string? strs = ""; @@ -175,25 +174,31 @@ public class StorageCollection if (collection == null) { - return false; + throw new InvalidOperationException("Не удалось создать коллекцию"); } collection.MaxCount = Convert.ToInt32(record[2]); string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - if (elem?.CreateDrawningTrackedVehicle() is T car) + if (elem?.CreateDrawningTrackedVehicle() is T ship) { - if (collection.Insert(car) == -1) + try { - return false; + if (collection.Insert(ship) == -1) + { + throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]); + } + } + catch (CollectionOverflowException ex) + { + throw new OverflowException("Коллекция переполнена", ex); } } } _storages.Add(record[0], collection); } - return true; } } /// diff --git a/Excavator/Excavator/Excavator.csproj b/Excavator/Excavator/Excavator.csproj index af03d74..8a02074 100644 --- a/Excavator/Excavator/Excavator.csproj +++ b/Excavator/Excavator/Excavator.csproj @@ -8,6 +8,29 @@ enable + + + + + + + + + + + + + + + + + + + + + + + True @@ -23,4 +46,10 @@ + + + Always + + + \ No newline at end of file diff --git a/Excavator/Excavator/Exceptions/CollectionOverflowException.cs b/Excavator/Excavator/Exceptions/CollectionOverflowException.cs new file mode 100644 index 0000000..4d4cca8 --- /dev/null +++ b/Excavator/Excavator/Exceptions/CollectionOverflowException.cs @@ -0,0 +1,20 @@ +using System.Runtime.Serialization; + +namespace Excavator.Exceptions; + +/// +/// Класс, описывающий ошибку переполнения коллекции +/// +[Serializable] +internal class CollectionOverflowException : ApplicationException +{ + public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { } + + public CollectionOverflowException() : base() { } + + public CollectionOverflowException(string message) : base(message) { } + + public CollectionOverflowException(string message, Exception exception) : base(message, exception) { } + + protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} \ No newline at end of file diff --git a/Excavator/Excavator/Exceptions/ObjectNotFoundException.cs b/Excavator/Excavator/Exceptions/ObjectNotFoundException.cs new file mode 100644 index 0000000..39cf0d7 --- /dev/null +++ b/Excavator/Excavator/Exceptions/ObjectNotFoundException.cs @@ -0,0 +1,20 @@ +using System.Runtime.Serialization; + +namespace Excavator.Exceptions; + +/// +/// Класс, описывающий ошибку, что по указанной позиции нет элемента +/// +[Serializable] +internal class ObjectNotFoundException : ApplicationException +{ + public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { } + + public ObjectNotFoundException() : base() { } + + public ObjectNotFoundException(string message) : base(message) { } + + public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { } + + protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} \ No newline at end of file diff --git a/Excavator/Excavator/Exceptions/PositionOutOfCollectionException.cs b/Excavator/Excavator/Exceptions/PositionOutOfCollectionException.cs new file mode 100644 index 0000000..0fb60d0 --- /dev/null +++ b/Excavator/Excavator/Exceptions/PositionOutOfCollectionException.cs @@ -0,0 +1,15 @@ +using System.Runtime.Serialization; +namespace Excavator.Exceptions; + +/// +/// Класс, описывающий ошибку выхода за границы коллекции +/// +[Serializable] +internal class PositionOutOfCollectionException : ApplicationException +{ + public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции.Позиция " + i) { } + public PositionOutOfCollectionException() : base() { } + public PositionOutOfCollectionException(string message) : base(message) { } + public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { } + protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} \ No newline at end of file diff --git a/Excavator/Excavator/FormTrackedVehicleCollection.cs b/Excavator/Excavator/FormTrackedVehicleCollection.cs index 2edc8ec..d91cace 100644 --- a/Excavator/Excavator/FormTrackedVehicleCollection.cs +++ b/Excavator/Excavator/FormTrackedVehicleCollection.cs @@ -1,5 +1,7 @@ using Excavator.CollectionGenericObjects; using Excavator.Drawnings; +using Excavator.Exceptions; +using Microsoft.Extensions.Logging; namespace Excavator; @@ -17,13 +19,19 @@ public partial class FormTrackedVehicleCollection : Form /// private AbstractCompany? _company = null; + /// + /// Логер + /// + private readonly ILogger _logger; + /// /// Конструктор /// - public FormTrackedVehicleCollection() + public FormTrackedVehicleCollection(ILogger logger) { InitializeComponent(); _storageCollection = new(); + _logger = logger; } @@ -45,7 +53,6 @@ public partial class FormTrackedVehicleCollection : Form private void ButtonAddCar_Click(object sender, EventArgs e) { FormTrackedVehicleConfig form = new(); - form.Show(); form.AddEvent(SetCar); } @@ -56,19 +63,24 @@ public partial class FormTrackedVehicleCollection : Form /// private void SetCar(DrawningTrackedVehicle? car) { - if (_company == null || car == null) + try { - return; - } + if (_company == null || car == null) + { + return; + } - if (_company + car != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); + if (_company + car != -1) + { + MessageBox.Show("Объект добавлен"); + _logger.LogInformation($"Добавлен объект {car.GetDataForSave()}"); + pictureBox.Image = _company.Show(); + } } - else + catch (CollectionOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning($"Ошибка: {ex.Message}"); } } @@ -89,15 +101,25 @@ public partial class FormTrackedVehicleCollection : Form return; } - int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + _logger.LogInformation($"Удален объект по позиции {pos}"); + pictureBox.Image = _company.Show(); + } } - else + catch (ObjectNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show(ex.Message); + _logger.LogError($"Ошибка: {ex.Message}"); + } + catch (PositionOutOfCollectionException ex) + { + MessageBox.Show(ex.Message); + _logger.LogError($"Ошибка: {ex.Message}"); } } @@ -253,18 +275,18 @@ public partial class FormTrackedVehicleCollection : Form { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.SaveData(saveFileDialog.FileName)) + try { - MessageBox.Show("Сохранение прошло успешно", - "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _storageCollection.SaveData(saveFileDialog.FileName); + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } } - } /// /// Обработка нажатия "Загрузка" @@ -275,16 +297,17 @@ public partial class FormTrackedVehicleCollection : Form { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.LoadData(openFileDialog.FileName)) + try { - MessageBox.Show("Загрузка прошла успешно", - "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _storageCollection.LoadData(openFileDialog.FileName); + MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); RerfreshListBoxItems(); + _logger.LogInformation("Загрузка из фала: {filename}", openFileDialog.FileName); } - else + catch (Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } } } diff --git a/Excavator/Excavator/Program.cs b/Excavator/Excavator/Program.cs index f33af9d..fb1b1c4 100644 --- a/Excavator/Excavator/Program.cs +++ b/Excavator/Excavator/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Serilog; + namespace Excavator { internal static class Program @@ -8,10 +13,28 @@ namespace Excavator [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormTrackedVehicleCollection()); + + ServiceCollection services = new(); + ConfigureServices(services); + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + Application.Run(serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services + .AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + var config = new ConfigurationBuilder() + .AddJsonFile("serilogConfig.json", optional: false, reloadOnChange: true) + .Build(); + option.AddSerilog(Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(config) + .CreateLogger()); + }); } } } \ No newline at end of file diff --git a/Excavator/Excavator/serilogConfig.json b/Excavator/Excavator/serilogConfig.json new file mode 100644 index 0000000..50717a4 --- /dev/null +++ b/Excavator/Excavator/serilogConfig.json @@ -0,0 +1,20 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Properties": { + "Application": "Excavator" + } + } +} \ No newline at end of file -- 2.25.1 From 0ba01e0bd8bae9f9b17f4ba5aa6cdea4d716d5de Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 27 May 2024 12:09:57 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../CollectionGenericObjects/Garage.cs | 6 +++- .../FormTrackedVehicleCollection.Designer.cs | 32 +++++++++---------- .../Excavator/FormTrackedVehicleCollection.cs | 2 ++ .../FormTrackedVehicleCollection.resx | 3 ++ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs index ce941c9..7746e42 100644 --- a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs +++ b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs @@ -36,7 +36,7 @@ public abstract class AbstractCompany /// /// Вычисление максимального количества элементов, который можно разместить в окне /// - private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + private int GetMaxCount =>( _pictureWidth * _pictureHeight) / (_placeSizeWidth * _placeSizeHeight); /// /// Конструктор diff --git a/Excavator/Excavator/CollectionGenericObjects/Garage.cs b/Excavator/Excavator/CollectionGenericObjects/Garage.cs index f1c84a5..cd7d3b5 100644 --- a/Excavator/Excavator/CollectionGenericObjects/Garage.cs +++ b/Excavator/Excavator/CollectionGenericObjects/Garage.cs @@ -45,8 +45,10 @@ public class Garage(int picWidth, int picHeight, ICollectionGenericObjects 310, 17 + + 25 + \ No newline at end of file -- 2.25.1 From 28657238237a1a4fcbc91a53fb4b612dd72a9151 Mon Sep 17 00:00:00 2001 From: Daria Date: Sun, 2 Jun 2024 20:20:52 +0400 Subject: [PATCH 3/5] . --- .../Excavator/CollectionGenericObjects/AbstractCompany.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs index 7746e42..201fd1b 100644 --- a/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs +++ b/Excavator/Excavator/CollectionGenericObjects/AbstractCompany.cs @@ -11,7 +11,7 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 200; /// /// Размер места (высота) @@ -36,7 +36,7 @@ public abstract class AbstractCompany /// /// Вычисление максимального количества элементов, который можно разместить в окне /// - private int GetMaxCount =>( _pictureWidth * _pictureHeight) / (_placeSizeWidth * _placeSizeHeight); + private int GetMaxCount =>( _pictureWidth * _pictureHeight) / (2 * _placeSizeWidth * _placeSizeHeight); /// /// Конструктор -- 2.25.1 From 7ab11658549f273b2bcd3c51eadf8017cf8589d1 Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 3 Jun 2024 00:33:18 +0400 Subject: [PATCH 4/5] llllllllllllllllllllllllll --- .../StorageCollection.cs | 10 +++-- Excavator/Excavator/Excavator.csproj | 1 + .../Excavator/FormTrackedVehicleCollection.cs | 41 ++++++++++--------- Excavator/Excavator/Program.cs | 3 +- Excavator/Excavator/serilogConfig.json | 26 ++++++++---- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs index 02dbf10..dae655d 100644 --- a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs +++ b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs @@ -52,11 +52,15 @@ public class StorageCollection /// /// Удаление коллекции /// - /// Название коллекции + /// public void DelCollection(string name) { - if (_storages.ContainsKey(name)) - _storages.Remove(name); + if (name == null || !_storages.ContainsKey(name)) + { + return; + } + + _storages.Remove(name); } /// diff --git a/Excavator/Excavator/Excavator.csproj b/Excavator/Excavator/Excavator.csproj index 8a02074..c34a49f 100644 --- a/Excavator/Excavator/Excavator.csproj +++ b/Excavator/Excavator/Excavator.csproj @@ -26,6 +26,7 @@ + diff --git a/Excavator/Excavator/FormTrackedVehicleCollection.cs b/Excavator/Excavator/FormTrackedVehicleCollection.cs index 8e4bcfa..8f29df0 100644 --- a/Excavator/Excavator/FormTrackedVehicleCollection.cs +++ b/Excavator/Excavator/FormTrackedVehicleCollection.cs @@ -178,28 +178,29 @@ public partial class FormTrackedVehicleCollection : Form /// /// /// - private void buttonCollectionAdd_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + private void buttonCollectionAdd_Click(object sender, EventArgs e) { - MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: Заполнены не все данные для добавления коллекции"); + return; + } - CollectionType collectionType = CollectionType.None; - if (radioButtonMassive.Checked) - { - collectionType = CollectionType.Massive; - } - else if (radioButtonList.Checked) - { - collectionType = CollectionType.List; - } + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } - _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); - RerfreshListBoxItems(); - - } + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + _logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text} типа: {collectionType}"); + RerfreshListBoxItems(); + } /// /// Удаление коллекции /// @@ -217,6 +218,8 @@ public partial class FormTrackedVehicleCollection : Form return; } _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + _logger.LogInformation($"Удалена коллекция: {listBoxCollection.SelectedItem.ToString()}"); + RerfreshListBoxItems(); } /// diff --git a/Excavator/Excavator/Program.cs b/Excavator/Excavator/Program.cs index fb1b1c4..0924217 100644 --- a/Excavator/Excavator/Program.cs +++ b/Excavator/Excavator/Program.cs @@ -37,4 +37,5 @@ namespace Excavator }); } } -} \ No newline at end of file +} + diff --git a/Excavator/Excavator/serilogConfig.json b/Excavator/Excavator/serilogConfig.json index 50717a4..2682115 100644 --- a/Excavator/Excavator/serilogConfig.json +++ b/Excavator/Excavator/serilogConfig.json @@ -1,20 +1,28 @@ { + "AllowedHosts": "*", "Serilog": { - "Using": [ "Serilog.Sinks.File" ], - "MinimumLevel": "Information", + "Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ], "WriteTo": [ + { "Name": "Console" }, { "Name": "File", "Args": { "path": "Logs/log_.log", "rollingInterval": "Day", - "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}" } } - ], - "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], - "Properties": { - "Application": "Excavator" - } + ] } -} \ No newline at end of file +} + + + -- 2.25.1 From ed9c654fb25886b120407f361259d3ce115714b4 Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 3 Jun 2024 08:22:36 +0400 Subject: [PATCH 5/5] . --- .../Excavator/FormTrackedVehicleCollection.Designer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs b/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs index 859dc09..752cd42 100644 --- a/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs +++ b/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs @@ -68,7 +68,7 @@ groupBox1.Dock = DockStyle.Right; groupBox1.Location = new Point(843, 28); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(221, 781); + groupBox1.Size = new Size(221, 785); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; @@ -82,7 +82,7 @@ panelCompanyTools.Controls.Add(buttonDelExcavator); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 510); + panelCompanyTools.Location = new Point(3, 514); panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Size = new Size(215, 268); panelCompanyTools.TabIndex = 9; @@ -248,7 +248,7 @@ pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; pictureBox.Location = new Point(1, 28); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(842, 773); + pictureBox.Size = new Size(842, 797); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -298,7 +298,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1064, 809); + ClientSize = new Size(1064, 813); Controls.Add(pictureBox); Controls.Add(groupBox1); Controls.Add(menuStrip); -- 2.25.1