From fc705e5d4e3f189f5cd42be1e3ee3b0f7b653925 Mon Sep 17 00:00:00 2001 From: "Nikolaeva_Y.A" Date: Tue, 6 Dec 2022 10:46:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=BC=D1=83=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=B4=D0=B5=D0=BA=D1=81=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 6 +++--- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 6 ++---- Airbus/Airbus/Program.cs | 24 +++++++++------------- Airbus/Airbus/SetPlanesGeneric.cs | 26 +++++++++--------------- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 5806227..a439304 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -84,8 +84,8 @@ namespace Airbus _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); - ReloadMaps(); _logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text); + ReloadMaps(); } //Выбор карты @@ -105,9 +105,8 @@ namespace Airbus if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); - - ReloadMaps(); _logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } @@ -282,6 +281,7 @@ namespace Airbus MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMaps(); } catch (Exception ex) { diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 277e013..e03cd7b 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -28,10 +28,8 @@ namespace Airbus //конструктор public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) - { - int width = picWidth / _placeSizeWidth; - int height = picHeight / _placeSizeHeight; - _setPlanes = new SetPlanesGeneric(width * height); + { + _setPlanes = new SetPlanesGeneric(18); _pictureWidth = picWidth; _pictureHeight = picHeight; _map = map; diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5ef0dde..2d39406 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -27,23 +27,19 @@ namespace Airbus Application.Run(serviceProvider.GetRequiredService()); } } - private static void ConfigureServices(ServiceCollection services) { - services.AddSingleton() - .AddLogging(option => - { - var configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(path: "C:\\Users\\Programmist73\\Desktop\\Ïðàêòèêà\\2-é êóðñ\\ÐÏÏ\\Base\\PIbd-21_Eliseev_E.E._Airbus_Base\\Airbus\\Airbus\\appsettings.json", optional: false, reloadOnChange: true) - .Build(); + services.AddSingleton(); - var logger = new LoggerConfiguration() - .ReadFrom.Configuration(configuration) - .CreateLogger(); - option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(logger); - }); + var serilogLogger = new LoggerConfiguration() + .WriteTo.RollingFile("Logs\\log.txt") + .CreateLogger(); + + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger: serilogLogger, dispose: true); + }); } } } \ No newline at end of file diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 4ef839c..3cdea1f 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -29,6 +29,11 @@ namespace Airbus //добавление объекта в набор public int Insert(T plane) { + if (Count == _maxCount) + { + throw new StorageOverflowException(_maxCount); + } + if (Count + 1 <= _maxCount) return Insert(plane, 0); else return -1; } @@ -45,11 +50,6 @@ namespace Airbus throw new ArgumentException($"Объект {plane} уже есть в наборе"); } - if (Count == _maxCount) - { - throw new StorageOverflowException(_maxCount); - } - _places.Insert(position, plane); return position; } @@ -57,21 +57,15 @@ namespace Airbus //удаление объекта из набора с конкретной позиции public T Remove(int position) { - if (position < _maxCount && position >= 0) + if (position >= Count || position < 0) { - - if (_places.ElementAt(position) != null) - { - T result = _places.ElementAt(position); - - _places.RemoveAt(position); - - return result; - } throw new PlaneNotFoundException(position); } - return null; + T result = _places[position]; + _places.RemoveAt(position); + + return result; } //получение объекта из набора по позиции