From 1bde953853bd6e05c5e645265438a4e80cf4677c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 16 Nov 2022 23:43:56 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 42 ++++++++++++++++------- Airbus/Airbus/MapsCollection.cs | 12 +++---- Airbus/Airbus/PlaneNotFoundException.cs | 25 ++++++++++++++ Airbus/Airbus/SetPlanesGeneric.cs | 3 ++ Airbus/Airbus/StorageOverflowException.cs | 25 ++++++++++++++ 5 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 Airbus/Airbus/PlaneNotFoundException.cs create mode 100644 Airbus/Airbus/StorageOverflowException.cs diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 14d8c07..b8e7bed 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -123,6 +123,8 @@ namespace Airbus //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { + //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ + var formPlaneConfig = new FormPlaneConfig(); formPlaneConfig.AddEvent(AddPlane); @@ -132,6 +134,8 @@ namespace Airbus //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { + //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ УДАЛЕНИЯ + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -145,14 +149,25 @@ namespace Airbus int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null) + try { - MessageBox.Show("Объект удалён"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null) + { + MessageBox.Show("Объект удалён"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } } - else + catch (PlaneNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } @@ -214,14 +229,16 @@ namespace Airbus { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) + try { + _mapsCollection.SaveData(saveFileDialog.FileName); + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch(Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", + MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -232,15 +249,16 @@ namespace Airbus { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + try { - ReloadMaps(); + _mapsCollection.LoadData(openFileDialog.FileName); + MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch(Exception ex) { - MessageBox.Show("Ошибка загрузки данных", "Результат", + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index a47df27..0455f09 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -54,7 +54,7 @@ namespace Airbus } //сохранение информации по самолётам в ангарах в файл - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { @@ -72,16 +72,14 @@ namespace Airbus $"{Environment.NewLine}"); } } - - return true; } //загрузка нформации по по самолётам в ангарах из файла - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не найден"); } using (StreamReader sr = new(filename)) @@ -91,7 +89,7 @@ namespace Airbus //если не содержит такую запись или пустой файл if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) { - return false; + throw new Exception("Формат данных в файле неправильный"); } _mapStorage.Clear(); @@ -120,8 +118,6 @@ namespace Airbus _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } } - - return true; } diff --git a/Airbus/Airbus/PlaneNotFoundException.cs b/Airbus/Airbus/PlaneNotFoundException.cs new file mode 100644 index 0000000..69a851a --- /dev/null +++ b/Airbus/Airbus/PlaneNotFoundException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + [Serializable] + + //класс собственных исключений + internal class PlaneNotFoundException : ApplicationException + { + public PlaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + + public PlaneNotFoundException() : base() { } + + public PlaneNotFoundException(string message) : base(message) { } + + public PlaneNotFoundException(string message, Exception exception) : base(message, exception) { } + + protected PlaneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index aa457ec..bdeb554 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -64,6 +64,9 @@ namespace Airbus return null; } + //TODO проверка позиции??? + //что-то типа throw new PlaneNotFoundException(position); + return null; } diff --git a/Airbus/Airbus/StorageOverflowException.cs b/Airbus/Airbus/StorageOverflowException.cs new file mode 100644 index 0000000..3a95d3c --- /dev/null +++ b/Airbus/Airbus/StorageOverflowException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + [Serializable] + + //класс собственных исключений + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { } + + public StorageOverflowException() : base() { } + + public StorageOverflowException(string message) : base(message) { } + + public StorageOverflowException(string message, Exception exception) : base(message, exception) { } + + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} -- 2.25.1 From c846489b7cda9d08184fdb606abca03e03de44f0 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 12:54:49 +0400 Subject: [PATCH 02/10] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 18 ++++++++++++++++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 15 ++++++++------- Airbus/Airbus/Program.cs | 23 ++++++++++++++++++++++- Airbus/Airbus/nlog.config | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 Airbus/Airbus/nlog.config diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 3ec74d3..c22bcea 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -8,6 +8,16 @@ enable + + + + + + + Always + + + True @@ -28,4 +38,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index b8e7bed..a2ac496 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -24,10 +25,14 @@ namespace Airbus //объект от коллекции карт private readonly MapsCollection _mapsCollection; + //логер + private readonly ILogger _logger; + //конструктор - public FormMapWithSetPlanes() + public FormMapWithSetPlanes(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var element in _mapsDict) @@ -78,6 +83,7 @@ namespace Airbus _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } //Выбор карты @@ -117,14 +123,11 @@ namespace Airbus { MessageBox.Show("Не удалось добавить объект"); } - } //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { - //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ - var formPlaneConfig = new FormPlaneConfig(); formPlaneConfig.AddEvent(AddPlane); @@ -134,8 +137,6 @@ namespace Airbus //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { - //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ УДАЛЕНИЯ - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5166800..5dc32b1 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Airbus { internal static class Program @@ -11,7 +15,24 @@ namespace Airbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetPlanes()); + + var services = new ServiceCollection(); + 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); + option.AddNLog("nlog.config"); + }); } } } \ No newline at end of file diff --git a/Airbus/Airbus/nlog.config b/Airbus/Airbus/nlog.config new file mode 100644 index 0000000..02f005b --- /dev/null +++ b/Airbus/Airbus/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 12f0622d683a55cba1eebd57efbd2e33921bf46d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 15:11:22 +0400 Subject: [PATCH 03/10] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20Serilog.=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20json.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 7 +++++ Airbus/Airbus/Program.cs | 16 ++++++++++-- Airbus/Airbus/appsettings.json | 48 ++++++++++++++++++++++++++++++++++ Airbus/Airbus/nlog.config | 15 ----------- 4 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 Airbus/Airbus/appsettings.json delete mode 100644 Airbus/Airbus/nlog.config diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index c22bcea..8c229c9 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -39,11 +39,18 @@ + + + + + + + \ No newline at end of file diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 5dc32b1..16904b8 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -1,6 +1,9 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Serilog; +using Serilog.Extensions.Logging; +using System; namespace Airbus { @@ -30,8 +33,17 @@ namespace Airbus 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(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(logger); }); } } diff --git a/Airbus/Airbus/appsettings.json b/Airbus/Airbus/appsettings.json new file mode 100644 index 0000000..bb6390d --- /dev/null +++ b/Airbus/Airbus/appsettings.json @@ -0,0 +1,48 @@ +{ + "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" ], + "Destructure": [ + { + "Name": "ByTransforming", + "Args": { + "returnType": "Plane.EntityAirbus", + "transformation": "r => new { BodyColor = r.BodyColor.Name, r.Speed, r.Weight }" + } + }, + { + "Name": "ByTransforming", + "Args": { + "returnType": "Plane.EntitySuperAirbus", + "transformation": "r => new { BodyColor = r.BodyColor.Name, DopColor = r.DopColor.Name, r.HasСompartment, r.HasEngine, r.Speed, r.Weight }" + } + }, + { + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 4 } + }, + { + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 100 } + }, + { + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 10 } + } + ], + "Properties": { + "Application": "Airbus" + } + } +} \ No newline at end of file diff --git a/Airbus/Airbus/nlog.config b/Airbus/Airbus/nlog.config deleted file mode 100644 index 02f005b..0000000 --- a/Airbus/Airbus/nlog.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file -- 2.25.1 From 06f9ceb75db652ff6e0f19ed4368a138e2b79331 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 18:20:03 +0400 Subject: [PATCH 04/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E?= =?UTF-8?q?=20=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8E.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 11 +----- Airbus/Airbus/FormMapWithSetPlanes.cs | 51 ++++++++++++++++++++------- Airbus/Airbus/SetPlanesGeneric.cs | 5 +-- 3 files changed, 41 insertions(+), 26 deletions(-) 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; } -- 2.25.1 From ea0d683eb1ffe01098638498ea40f98517cf4f73 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 18:35:42 +0400 Subject: [PATCH 05/10] =?UTF-8?q?=D0=92=D1=8B=D0=B7=D0=BE=D0=B2=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Exception.=20?= =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=87=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 1 - Airbus/Airbus/MapsCollection.cs | 4 ++-- Airbus/Airbus/SetPlanesGeneric.cs | 12 +++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index a5bf5b2..6a62cf2 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -26,7 +26,6 @@ - diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 0455f09..fca15ee 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -79,7 +79,7 @@ namespace Airbus { if (!File.Exists(filename)) { - throw new Exception("Файл не найден"); + throw new FileNotFoundException("Файл не найден"); } using (StreamReader sr = new(filename)) @@ -89,7 +89,7 @@ namespace Airbus //если не содержит такую запись или пустой файл if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) { - throw new Exception("Формат данных в файле неправильный"); + throw new FileFormatException("Формат данных в файле неправильный"); } _mapStorage.Clear(); diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index ec1063b..bdebdd9 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -36,11 +36,21 @@ namespace Airbus //добавление объекта в набор на конкретную позицию public int Insert(T plane, int position) { - if (position >= _maxCount && position < 0) + if (position > _maxCount && position < 0) { return -1; } + if (_places.Contains(plane)) + { + throw new ArgumentException($"Объект {plane} уже есть в наборе"); + } + + if(Count == _maxCount) + { + throw new StorageOverflowException(_maxCount); + } + _places.Insert(position, plane); return position; -- 2.25.1 From fd417fc6b6d9a4cdb7d3bde6b030da2dd8f05f8c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 17 Nov 2022 18:51:36 +0400 Subject: [PATCH 06/10] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 1 + Airbus/Airbus/MapsCollection.cs | 2 +- Airbus/Airbus/SaveData.txt | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 74ab113..9083cd7 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -282,6 +282,7 @@ namespace Airbus _logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName); MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMaps(); } catch(Exception ex) { diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index fca15ee..7d87b34 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -113,7 +113,7 @@ namespace Airbus } _mapStorage.Add(element[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, - map)); + map)); _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } diff --git a/Airbus/Airbus/SaveData.txt b/Airbus/Airbus/SaveData.txt index 8b13789..ee94049 100644 --- a/Airbus/Airbus/SaveData.txt +++ b/Airbus/Airbus/SaveData.txt @@ -1 +1,4 @@ - +MapsCollection +123|DesertStormMap|1000:750:Blue; +6543|StarWarsMap|1000:750:Red:Red:True:True; +9876|SimpleMap|1000:750:Lime; -- 2.25.1 From 15553c9fddc3a76fdf3f484cb0811a8bcea6ef7a Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 18 Nov 2022 12:42:27 +0400 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D0=BD=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=BC=D1=83=20=D0=B8?= =?UTF-8?q?=D0=BD=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/SetPlanesGeneric.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index bdebdd9..744e88e 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -59,22 +59,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; } //получение объекта из набора по позиции -- 2.25.1 From 46569d56d32aa36299435c84a4e1b0bde69082e5 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 18 Nov 2022 13:10:45 +0400 Subject: [PATCH 08/10] =?UTF-8?q?=D0=9D=D0=B0=D0=BB=D0=B0=D0=B6=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/Airbus.csproj | 1 + Airbus/Airbus/Program.cs | 23 +++++++--------- Airbus/Airbus/appsettings.json | 48 ---------------------------------- 3 files changed, 11 insertions(+), 61 deletions(-) delete mode 100644 Airbus/Airbus/appsettings.json diff --git a/Airbus/Airbus/Airbus.csproj b/Airbus/Airbus/Airbus.csproj index 6a62cf2..8ea4f98 100644 --- a/Airbus/Airbus/Airbus.csproj +++ b/Airbus/Airbus/Airbus.csproj @@ -41,6 +41,7 @@ + \ No newline at end of file diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 16904b8..960b56d 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -30,21 +30,18 @@ namespace Airbus 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(); + var serilogLogger = new LoggerConfiguration() + .WriteTo.RollingFile("Logs\\log.txt") + .CreateLogger(); + + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger: serilogLogger, dispose: true); + }); - option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(logger); - }); } } } \ No newline at end of file diff --git a/Airbus/Airbus/appsettings.json b/Airbus/Airbus/appsettings.json deleted file mode 100644 index bb6390d..0000000 --- a/Airbus/Airbus/appsettings.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "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" ], - "Destructure": [ - { - "Name": "ByTransforming", - "Args": { - "returnType": "Plane.EntityAirbus", - "transformation": "r => new { BodyColor = r.BodyColor.Name, r.Speed, r.Weight }" - } - }, - { - "Name": "ByTransforming", - "Args": { - "returnType": "Plane.EntitySuperAirbus", - "transformation": "r => new { BodyColor = r.BodyColor.Name, DopColor = r.DopColor.Name, r.HasСompartment, r.HasEngine, r.Speed, r.Weight }" - } - }, - { - "Name": "ToMaximumDepth", - "Args": { "maximumDestructuringDepth": 4 } - }, - { - "Name": "ToMaximumStringLength", - "Args": { "maximumStringLength": 100 } - }, - { - "Name": "ToMaximumCollectionCount", - "Args": { "maximumCollectionCount": 10 } - } - ], - "Properties": { - "Application": "Airbus" - } - } -} \ No newline at end of file -- 2.25.1 From f148e15e633ad34899f3e8fb43f807dede2610ea Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 22 Nov 2022 09:43:35 +0400 Subject: [PATCH 09/10] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D1=87=D0=B0=207-=D0=B9?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 4 +--- Airbus/Airbus/SaveData.txt | 4 +--- Airbus/Airbus/SetPlanesGeneric.cs | 11 ++++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 485747c..4917a05 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -34,9 +34,7 @@ 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/SaveData.txt b/Airbus/Airbus/SaveData.txt index ee94049..f236e33 100644 --- a/Airbus/Airbus/SaveData.txt +++ b/Airbus/Airbus/SaveData.txt @@ -1,4 +1,2 @@ MapsCollection -123|DesertStormMap|1000:750:Blue; -6543|StarWarsMap|1000:750:Red:Red:True:True; -9876|SimpleMap|1000:750:Lime; +123|DesertStormMap|1000:750:Blue;1000:750:Yellow;1000:750:Red;1000:750:Lime;1000:750:Red;1000:750:Yellow;1000:750:Black;1000:750:Red;1000:750:DeepPink;1000:750:Black;1000:750:Yellow;1000:750:White;1000:750:Red;1000:750:Gray;1000:750:Lime;1000:750:Black;1000:750:Blue;1000:750:DeepPink; diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 744e88e..70d5559 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -29,7 +29,13 @@ 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; } @@ -46,11 +52,6 @@ namespace Airbus throw new ArgumentException($"Объект {plane} уже есть в наборе"); } - if(Count == _maxCount) - { - throw new StorageOverflowException(_maxCount); - } - _places.Insert(position, plane); return position; -- 2.25.1 From c915bfbae18c424fed4e10b09e3bcccc5318f9cd Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 24 Nov 2022 23:05:26 +0400 Subject: [PATCH 10/10] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BE?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E.=20?= =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D1=91=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=207-=D1=8F=20=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.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 4 ++-- Airbus/Airbus/MapsCollection.cs | 4 +--- Airbus/Airbus/SaveData.txt | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 9083cd7..18f4ffd 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(); } //Выбор карты @@ -106,8 +106,8 @@ namespace Airbus { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); - ReloadMaps(); _logger.LogInformation("Удалена карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 7d87b34..9cc94ff 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -67,7 +67,6 @@ namespace Airbus foreach (var storage in _mapStorage) { - sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + $"{Environment.NewLine}"); } @@ -113,14 +112,13 @@ namespace Airbus } _mapStorage.Add(element[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, - map)); + map)); _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } } } - //доступ к аэродрому public MapWithSetPlanesGeneric this[string ind] { diff --git a/Airbus/Airbus/SaveData.txt b/Airbus/Airbus/SaveData.txt index f236e33..c96b589 100644 --- a/Airbus/Airbus/SaveData.txt +++ b/Airbus/Airbus/SaveData.txt @@ -1,2 +1,2 @@ MapsCollection -123|DesertStormMap|1000:750:Blue;1000:750:Yellow;1000:750:Red;1000:750:Lime;1000:750:Red;1000:750:Yellow;1000:750:Black;1000:750:Red;1000:750:DeepPink;1000:750:Black;1000:750:Yellow;1000:750:White;1000:750:Red;1000:750:Gray;1000:750:Lime;1000:750:Black;1000:750:Blue;1000:750:DeepPink; +123|StarWarsMap|1000:750:Red;1000:750:DeepPink:Control:False:False; -- 2.25.1