From a74bda99cf144610d414f277d5386273c02ec2fb Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 20 Nov 2022 12:36:36 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=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 --- .../AntiAircraftGunNotFoundException.cs | 19 ++++++++++ .../FormMapWithSetAntiAircraftGuns.cs | 35 +++++++++++++------ .../AntiAircraftGun/MapsCollection.cs | 10 +++--- .../SetAntiAircraftGunsGeneric.cs | 2 ++ .../StorageOverflowException.cs | 19 ++++++++++ 5 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs new file mode 100644 index 0000000..5e75f45 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + [Serializable] + internal class AntiAircraftGunNotFoundException : ApplicationException + { + public AntiAircraftGunNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + public AntiAircraftGunNotFoundException() : base() { } + public AntiAircraftGunNotFoundException(string message) : base(message) { } + public AntiAircraftGunNotFoundException(string message, Exception exception) : base(message, exception) { } + protected AntiAircraftGunNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs index f8af888..428b465 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs @@ -150,14 +150,25 @@ namespace AntiAircraftGun return; } 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 (AntiAircraftGunNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления {ex.Message}"); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка {ex.Message}"); } } /// @@ -226,13 +237,14 @@ namespace AntiAircraftGun { 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("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не сохранилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -245,14 +257,15 @@ namespace AntiAircraftGun { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + try { + _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); } - else + catch(Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не загрузилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs index 02de5e8..8d88567 100644 --- a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs +++ b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs @@ -78,7 +78,7 @@ namespace AntiAircraftGun /// /// Путь и имя файла /// - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { @@ -92,18 +92,17 @@ namespace AntiAircraftGun sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"); } } - 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 StreamReader(filename)) { @@ -112,7 +111,7 @@ namespace AntiAircraftGun str = sr.ReadLine(); if (!str.Contains("MapsCollection")) { - return false; + throw new Exception("Формат данных в файле неправильный"); } while ((str = sr.ReadLine()) != null) { @@ -130,7 +129,6 @@ namespace AntiAircraftGun _mapStorages.Add(elem[0], new MapWithSetAntiAircraftGunsGeneric(_pictureWidth, _pictureHeight, map)); _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } - return true; } } } diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs index 9807595..e512797 100644 --- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -56,6 +56,7 @@ namespace AntiAircraftGun /// public int Insert(T antiAircraftGun, int position) { + //TODO проверка на _maxCount if (position < 0 || position >= _places.Count) return -1; _places.Insert(position, antiAircraftGun); return position; @@ -67,6 +68,7 @@ namespace AntiAircraftGun /// public T Remove(int position) { + //TODO исключение if (position < 0 || position >= _places.Count) return null; if (_places[position] == null) return null; T removed = _places[position]; diff --git a/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs b/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs new file mode 100644 index 0000000..ebeb2d7 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun +{ + [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 ff6ce298cd7da8ecc460aa0463060f8b5bde909b Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 20 Nov 2022 13:05:02 +0400 Subject: [PATCH 2/5] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntiAircraftGun/AntiAircraftGun.csproj | 18 +++++++++++++++++ .../FormMapWithSetAntiAircraftGuns.cs | 11 ++++++++-- AntiAircraftGun/AntiAircraftGun/Program.cs | 20 ++++++++++++++++++- AntiAircraftGun/AntiAircraftGun/nlog.config | 13 ++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/nlog.config diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj index 13ee123..3eb1f1d 100644 --- a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj +++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj @@ -8,6 +8,24 @@ enable + + + + + + + Always + + + + + + + + + + + True diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs index 428b465..417275c 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -24,11 +25,16 @@ namespace AntiAircraftGun /// Объект от коллекции карт /// private readonly MapsCollection _mapsCollection; + /// + /// Логер + /// + private readonly ILogger _logger; /// Конструктор /// - public FormMapWithSetAntiAircraftGuns() + public FormMapWithSetAntiAircraftGuns(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -75,6 +81,7 @@ namespace AntiAircraftGun } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Выбор карты diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index ce76065..f03c116 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace AntiAircraftGun { internal static class Program @@ -11,7 +15,21 @@ namespace AntiAircraftGun // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetAntiAircraftGuns()); + 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/AntiAircraftGun/AntiAircraftGun/nlog.config b/AntiAircraftGun/AntiAircraftGun/nlog.config new file mode 100644 index 0000000..6d5e25e --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From f809f7eb78bea7cb495637681dc584e5d040e1e6 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sun, 20 Nov 2022 17:20:56 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetAntiAircraftGuns.cs | 52 +++++++++++++++---- .../AntiAircraftGun/MapsCollection.cs | 4 +- .../SetAntiAircraftGunsGeneric.cs | 23 +++----- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs index 417275c..dfd7d50 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs @@ -1,10 +1,12 @@ using Microsoft.Extensions.Logging; +using Serilog.Filters; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -72,11 +74,13 @@ namespace AntiAircraftGun if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "не была выбрана карта" : "не была названа карта"); return; } if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) { MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogInformation($"Попытка добавить несуществующую карту: {textBoxNewMapName.Text}"); return; } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); @@ -91,6 +95,7 @@ namespace AntiAircraftGun private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Переход на карту: {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}"); } /// /// Удаление карты @@ -101,12 +106,14 @@ namespace AntiAircraftGun { if (listBoxMaps.SelectedIndex == -1) { + _logger.LogInformation($"Попытка удалить несуществующую карту: {textBoxNewMapName.Text}"); return; } if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); + _logger.LogInformation($"Удалена карта: {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}"); } } /// @@ -122,19 +129,36 @@ namespace AntiAircraftGun } private void AddAntiAircraftGun(DrawingAntiAircraftGun drawingAntiAircraftGuns) { - if (listBoxMaps.SelectedIndex == -1) + try { - return; + if (listBoxMaps.SelectedIndex == -1) + { + _logger.LogInformation($"Попытка добавления объекта на невыбранную карту"); + return; + } + if (drawingAntiAircraftGuns == null) + { + MessageBox.Show("Нужно выбрать объект перед добавлением"); + _logger.LogInformation($"Не выбран объект для добавления на карту"); + return; + } + DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Добавлен объект {drawingAntiAircraftGuns} на карту "); + } + else + { + MessageBox.Show("Не получилось добавить объект"); + _logger.LogInformation($"Не получилось добавить объект {drawingAntiAircraftGuns} на карту "); + } } - DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1) + catch (StorageOverflowException ex) { - MessageBox.Show("Object added"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Cant add object"); + _logger.LogWarning($"Ошибка переполнения хранилища: {ex.Message}"); + MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } /// @@ -163,18 +187,22 @@ namespace AntiAircraftGun { MessageBox.Show("Объект удален"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation($"Удален объект {pos}"); } else { MessageBox.Show("Не удалось удалить объект"); + _logger.LogInformation($"Не удалось удалить объект {pos}"); } } catch (AntiAircraftGunNotFoundException ex) { + _logger.LogWarning($"Ошибка удаления: {ex.Message}"); MessageBox.Show($"Ошибка удаления {ex.Message}"); } catch (Exception ex) { + _logger.LogWarning($"Неизвестная ошибка: {ex.Message}"); MessageBox.Show($"Неизвестная ошибка {ex.Message}"); } } @@ -248,10 +276,12 @@ namespace AntiAircraftGun { _mapsCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Успешно сохранено в файл: {saveFileDialog.FileName}"); } catch(Exception ex) { MessageBox.Show($"Не сохранилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Ошибка сохранения в файл: {saveFileDialog.FileName}"); } } } @@ -269,10 +299,12 @@ namespace AntiAircraftGun _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); + _logger.LogInformation($"Успешная загрузка из файла: {openFileDialog.FileName}"); } catch(Exception ex) { MessageBox.Show($"Не загрузилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Ошибка загрузки из файла: {openFileDialog.FileName}"); } } } diff --git a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs index 8d88567..7db9e5c 100644 --- a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs +++ b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs @@ -102,7 +102,7 @@ namespace AntiAircraftGun { if (!File.Exists(filename)) { - throw new Exception("Файл не найден"); + throw new FileNotFoundException("Файл не найден"); } using (StreamReader sr = new StreamReader(filename)) { @@ -111,7 +111,7 @@ namespace AntiAircraftGun str = sr.ReadLine(); if (!str.Contains("MapsCollection")) { - throw new Exception("Формат данных в файле неправильный"); + throw new FileFormatException($"Неправильный формат данных в файле {filename}"); } while ((str = sr.ReadLine()) != null) { diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs index e512797..29b3012 100644 --- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -1,6 +1,8 @@ -using System; +using Serilog.Filters; +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; @@ -38,15 +40,8 @@ namespace AntiAircraftGun /// public int Insert(T antiAircraftGun) { - if (_places.Count < _maxCount) - { - _places.Add(antiAircraftGun); - for (int i = 0; i < _places.Count; i++) - { - if (_places[i] == antiAircraftGun) return i; - } - } - return -1; + if (_places.Count < _maxCount) return Insert(antiAircraftGun, 0); + else throw new StorageOverflowException(_maxCount); } /// /// Добавление объекта в набор на конкретную позицию @@ -56,8 +51,7 @@ namespace AntiAircraftGun /// public int Insert(T antiAircraftGun, int position) { - //TODO проверка на _maxCount - if (position < 0 || position >= _places.Count) return -1; + if (position >= _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(position, antiAircraftGun); return position; } @@ -68,9 +62,8 @@ namespace AntiAircraftGun /// public T Remove(int position) { - //TODO исключение - if (position < 0 || position >= _places.Count) return null; - if (_places[position] == null) return null; + if (position < 0 || position >= _places.Count) throw new AntiAircraftGunNotFoundException(position); ; + if (_places[position] == null) throw new AntiAircraftGunNotFoundException(position); T removed = _places[position]; _places.RemoveAt(position); return removed; -- 2.25.1 From cf5bb6bee12a337446aedeb69cfd25e233dca158 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 21 Nov 2022 09:27:37 +0400 Subject: [PATCH 4/5] Serilog --- .../AntiAircraftGun/AntiAircraftGun.csproj | 14 ++++---------- AntiAircraftGun/AntiAircraftGun/Program.cs | 11 ++++++++++- .../AntiAircraftGun/SetAntiAircraftGunsGeneric.cs | 2 +- AntiAircraftGun/AntiAircraftGun/nlog.config | 13 ------------- AntiAircraftGun/AntiAircraftGun/seriLog.json | 12 ++++++++++++ 5 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 AntiAircraftGun/AntiAircraftGun/nlog.config create mode 100644 AntiAircraftGun/AntiAircraftGun/seriLog.json diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj index 3eb1f1d..3483561 100644 --- a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj +++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGun.csproj @@ -8,22 +8,16 @@ enable - - - - - - - Always - - - + + + + diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index f03c116..7b43459 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -1,6 +1,8 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using Serilog; namespace AntiAircraftGun { @@ -27,8 +29,15 @@ namespace AntiAircraftGun services.AddSingleton() .AddLogging(option => { + var configuration = new ConfigurationBuilder() + .AddJsonFile("C:\\\\2 \\\\AntiAircraftGun\\AntiAircraftGun\\AntiAircraftGun\\seriLog.json") + .Build(); + + var Logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(Logger); }); } } diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs index 29b3012..b5b0f68 100644 --- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs +++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs @@ -62,7 +62,7 @@ namespace AntiAircraftGun /// public T Remove(int position) { - if (position < 0 || position >= _places.Count) throw new AntiAircraftGunNotFoundException(position); ; + if (position >= _places.Count) throw new AntiAircraftGunNotFoundException(position); if (_places[position] == null) throw new AntiAircraftGunNotFoundException(position); T removed = _places[position]; _places.RemoveAt(position); diff --git a/AntiAircraftGun/AntiAircraftGun/nlog.config b/AntiAircraftGun/AntiAircraftGun/nlog.config deleted file mode 100644 index 6d5e25e..0000000 --- a/AntiAircraftGun/AntiAircraftGun/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/seriLog.json b/AntiAircraftGun/AntiAircraftGun/seriLog.json new file mode 100644 index 0000000..15f0b39 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/seriLog.json @@ -0,0 +1,12 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "C:\\Университет\\2 курс\\РПП\\AntiAircraftGun\\AntiAircraftGun\\AntiAircraftGun\\bin\\Debug\\net6.0-windows\\Log.txt" } + } + ] + } +} -- 2.25.1 From b7c63b40a2266a66141e829cb99c6528c92d5ecf Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 21 Nov 2022 10:06:54 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20NLog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AntiAircraftGun/AntiAircraftGun/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AntiAircraftGun/AntiAircraftGun/Program.cs b/AntiAircraftGun/AntiAircraftGun/Program.cs index 7b43459..296ffa7 100644 --- a/AntiAircraftGun/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/AntiAircraftGun/Program.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; using Serilog; namespace AntiAircraftGun -- 2.25.1