From 38c74b051e31c25c956054395972744ed5b9a8a4 Mon Sep 17 00:00:00 2001 From: chtzsch ~ Date: Wed, 29 Nov 2023 13:09:40 +0300 Subject: [PATCH 1/3] lab7 --- .../speed_Boat/BoatNotFoundException.cs | 19 ++++++++ speed_Boat/speed_Boat/BoatsGenericStorage.cs | 45 ++++++++--------- speed_Boat/speed_Boat/FormBoatCollection.cs | 48 +++++++++++++++---- speed_Boat/speed_Boat/GenericClass.cs | 18 +++++-- speed_Boat/speed_Boat/Program.cs | 43 +++++++++++++---- .../speed_Boat/StorageOverflowException.cs | 19 ++++++++ speed_Boat/speed_Boat/nlog.config | 13 +++++ speed_Boat/speed_Boat/speed_Boat.csproj | 13 ++++- 8 files changed, 170 insertions(+), 48 deletions(-) create mode 100644 speed_Boat/speed_Boat/BoatNotFoundException.cs create mode 100644 speed_Boat/speed_Boat/StorageOverflowException.cs create mode 100644 speed_Boat/speed_Boat/nlog.config diff --git a/speed_Boat/speed_Boat/BoatNotFoundException.cs b/speed_Boat/speed_Boat/BoatNotFoundException.cs new file mode 100644 index 0000000..6ab3e0f --- /dev/null +++ b/speed_Boat/speed_Boat/BoatNotFoundException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace speed_Boat.Exceptions +{ + [Serializable] + internal class BoatNotFoundException : ApplicationException + { + public BoatNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } + public BoatNotFoundException() : base() { } + public BoatNotFoundException(string message) : base(message) { } + public BoatNotFoundException(string message, Exception exception) : base(message, exception){ } + protected BoatNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/speed_Boat/speed_Boat/BoatsGenericStorage.cs b/speed_Boat/speed_Boat/BoatsGenericStorage.cs index f0d7b88..374f42e 100644 --- a/speed_Boat/speed_Boat/BoatsGenericStorage.cs +++ b/speed_Boat/speed_Boat/BoatsGenericStorage.cs @@ -1,4 +1,5 @@ -using speed_Boat.MovementStrategy; +using speed_Boat.Exceptions; +using speed_Boat.MovementStrategy; using SpeedBoatLab.Drawings; using System; using System.Collections.Generic; @@ -52,7 +53,7 @@ namespace speed_Boat.Generics { _boatStorages = new Dictionary>(); _pictureWidth = pictureWidth; - _pictureHeight = pictureHeight; + _pictureHeight = pictureHeight; } /// @@ -60,8 +61,11 @@ namespace speed_Boat.Generics /// /// Путь и имя файла /// true - сохранение прошло успешно, false - ошибка при сохранении данных - public bool SaveData(string filename) + public void SaveData(string filename) { + if (_boatStorages.Count == 0) + throw new InvalidOperationException("Невалидная операция: нет данных для сохранения"); + if (File.Exists(filename)) { File.Delete(filename); @@ -76,41 +80,33 @@ namespace speed_Boat.Generics } data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); } - if (data.Length == 0) - { - return false; - } - - using (StreamWriter sw = new (filename)) + + using (StreamWriter sw = new(filename)) { sw.WriteLine($"BoatStorage{Environment.NewLine}{data}"); } - return true; } /// /// Загрузка информации по катерам в хранилище из файла /// /// Путь и имя файла /// true - загрузка прошла успешно, false - ошибка при загрузке данных - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) - { - return false; - } + throw new FileNotFoundException("Файл не найден"); + string bufferTextFromFile = ""; using (StreamReader sr = new(filename)) { + if (sr.ReadLine() != "BoatStorage") + throw new FormatException("Неверный формат данных"); + string str = sr.ReadLine(); var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); if (strs == null || strs.Length == 0) { - return false; - } - if (!strs[0].StartsWith("BoatStorage")) - { - //если нет такой записи, то это не те данные - return false; + throw new Exception("Нет данных для загрузки"); } _boatStorages.Clear(); do @@ -132,7 +128,7 @@ namespace speed_Boat.Generics { if (!(collection + boat)) { - return false; + throw new StorageOverflowException("Ошибка добавления в коллекцию"); } } } @@ -140,7 +136,6 @@ namespace speed_Boat.Generics str = sr.ReadLine(); } while (str != null); } - return true; } @@ -176,15 +171,15 @@ namespace speed_Boat.Generics /// /// /// - public BoatsGenericCollection?this[string ind] + public BoatsGenericCollection? this[string ind] { get { BoatsGenericCollection boat; //проверка есть ли в словаре обьект с ключом ind if (_boatStorages.TryGetValue(ind, out boat)) - { - return boat; + { + return boat; } return null; } diff --git a/speed_Boat/speed_Boat/FormBoatCollection.cs b/speed_Boat/speed_Boat/FormBoatCollection.cs index 3feaea5..c547c0f 100644 --- a/speed_Boat/speed_Boat/FormBoatCollection.cs +++ b/speed_Boat/speed_Boat/FormBoatCollection.cs @@ -11,6 +11,8 @@ using SpeedBoatLab.Drawings; using speed_Boat.Generics; using speed_Boat.MovementStrategy; using speed_Boat; +using Microsoft.Extensions.Logging; + namespace SpeedBoatLab { @@ -20,13 +22,21 @@ namespace SpeedBoatLab /// Набор объектов /// private readonly BoatsGenericStorage _storage; + + /// + /// Логгер + /// + private readonly ILogger _logger; + /// /// Конструктор /// - public FormBoatCollection() + public FormBoatCollection(ILogger logger) { InitializeComponent(); _storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + _logger = logger; + } /// /// Заполнение collectionsListBox @@ -64,10 +74,13 @@ namespace SpeedBoatLab { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не все данные заполнены:{nameStorageTextBox.Name}"); return; } _storage.AddSet(nameStorageTextBox.Text); ReloadObjects(); + _logger.LogInformation($"Добавлен набор:{nameStorageTextBox.Text}"); + } /// /// Выбор набора @@ -86,11 +99,15 @@ namespace SpeedBoatLab { return; } + string name = storagesListBox.SelectedItem.ToString() ?? string.Empty; + if (MessageBox.Show($"Удалить объект {storagesListBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _storage.DelSet(storagesListBox.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); + _logger.LogInformation($"Удален набор: {name}"); + } } @@ -121,11 +138,13 @@ namespace SpeedBoatLab if (obj + boat) { MessageBox.Show("Объект добавлен"); + _logger.LogInformation($"Объект добавлен:{obj}"); pictureBoxCollection.Image = obj.ShowBoats(); } else { MessageBox.Show("Не удалось добавить объект"); + _logger.LogInformation($"Не удалось добавить объект:{obj}"); } } /// @@ -155,7 +174,10 @@ namespace SpeedBoatLab { int.TryParse(insertPosition, out pos); if (pos < 0 || pos > obj._collection.Count - 1) + { MessageBox.Show("Неверный формат позиции"); + _logger.LogWarning($"Неверный формат позиции:{pos}"); + } if (obj - pos != null) { @@ -166,10 +188,12 @@ namespace SpeedBoatLab else if (insertPosition == string.Empty) { MessageBox.Show("Неверный формат позиции"); + _logger.LogWarning($"Неверный формат позиции:{insertPosition}"); } else { MessageBox.Show("Не удалось удалить объект"); + _logger.LogWarning($"Не удалось удалить объект:{obj}"); } } /// @@ -201,16 +225,21 @@ namespace SpeedBoatLab { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.SaveData(saveFileDialog.FileName)) + try { + _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Сохранение прошло успешно:"); + } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не сохранилось: {ex.Message}", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не сохранилось:{ex.Message}"); } + } } @@ -219,16 +248,17 @@ namespace SpeedBoatLab { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.LoadData(saveFileDialog.FileName)) + try { + _storage.LoadData(saveFileDialog.FileName); ReloadObjects(); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не удалось загрузить: {ex.Message}", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/speed_Boat/speed_Boat/GenericClass.cs b/speed_Boat/speed_Boat/GenericClass.cs index 9eea6b2..683f6c6 100644 --- a/speed_Boat/speed_Boat/GenericClass.cs +++ b/speed_Boat/speed_Boat/GenericClass.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using speed_Boat.Exceptions; namespace speed_Boat.Generics { @@ -54,8 +55,11 @@ namespace speed_Boat.Generics } return true; } + else + { + throw new StorageOverflowException(); + } } - return false; } /// /// Добавление объекта в набор на конкретную позицию. @@ -87,7 +91,10 @@ namespace speed_Boat.Generics } return true; } - return false; + else + { + throw new StorageOverflowException(); + } } /// @@ -97,7 +104,12 @@ namespace speed_Boat.Generics { if (position < 0 || position >= Count) { - return false; + return false; + throw new BoatNotFoundException(); + } + if (_places[position] == null) + { + throw new BoatNotFoundException(); } _places[position] = null; return true; diff --git a/speed_Boat/speed_Boat/Program.cs b/speed_Boat/speed_Boat/Program.cs index 5c3bf4d..539f76f 100644 --- a/speed_Boat/speed_Boat/Program.cs +++ b/speed_Boat/speed_Boat/Program.cs @@ -1,23 +1,46 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; + namespace SpeedBoatLab { static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FormBoatCollection()); + ApplicationConfiguration.Initialize(); + 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 => + { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true).Build(); + var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); + } + } } diff --git a/speed_Boat/speed_Boat/StorageOverflowException.cs b/speed_Boat/speed_Boat/StorageOverflowException.cs new file mode 100644 index 0000000..f0a679b --- /dev/null +++ b/speed_Boat/speed_Boat/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 speed_Boat.Exceptions +{ + [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) { } + } +} diff --git a/speed_Boat/speed_Boat/nlog.config b/speed_Boat/speed_Boat/nlog.config new file mode 100644 index 0000000..ee75e5d --- /dev/null +++ b/speed_Boat/speed_Boat/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/speed_Boat/speed_Boat/speed_Boat.csproj b/speed_Boat/speed_Boat/speed_Boat.csproj index 2faea65..5842e93 100644 --- a/speed_Boat/speed_Boat/speed_Boat.csproj +++ b/speed_Boat/speed_Boat/speed_Boat.csproj @@ -2,10 +2,21 @@ WinExe - net5.0-windows + net7.0-windows true + + + + + + + + + + + True -- 2.25.1 From 225058cf52878a4de76b4ecc7ee74aa7789224d7 Mon Sep 17 00:00:00 2001 From: chtzsch ~ Date: Wed, 29 Nov 2023 14:42:00 +0300 Subject: [PATCH 2/3] lab7 --- .../speed_Boat/BoatNotFoundException.cs | 2 +- .../speed_Boat/BoatsGenericCollection.cs | 9 ++- speed_Boat/speed_Boat/BoatsGenericStorage.cs | 14 ++++- speed_Boat/speed_Boat/FormBoatCollection.cs | 59 +++++++++++++------ speed_Boat/speed_Boat/GenericClass.cs | 11 ++-- speed_Boat/speed_Boat/Program.cs | 3 +- speed_Boat/speed_Boat/appsettings.json | 20 +++++++ speed_Boat/speed_Boat/speed_Boat.csproj | 1 + 8 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 speed_Boat/speed_Boat/appsettings.json diff --git a/speed_Boat/speed_Boat/BoatNotFoundException.cs b/speed_Boat/speed_Boat/BoatNotFoundException.cs index 6ab3e0f..93c0228 100644 --- a/speed_Boat/speed_Boat/BoatNotFoundException.cs +++ b/speed_Boat/speed_Boat/BoatNotFoundException.cs @@ -10,7 +10,7 @@ namespace speed_Boat.Exceptions [Serializable] internal class BoatNotFoundException : ApplicationException { - public BoatNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } + public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } public BoatNotFoundException() : base() { } public BoatNotFoundException(string message) : base(message) { } public BoatNotFoundException(string message, Exception exception) : base(message, exception){ } diff --git a/speed_Boat/speed_Boat/BoatsGenericCollection.cs b/speed_Boat/speed_Boat/BoatsGenericCollection.cs index 6ad0924..e1b1730 100644 --- a/speed_Boat/speed_Boat/BoatsGenericCollection.cs +++ b/speed_Boat/speed_Boat/BoatsGenericCollection.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using SpeedBoatLab.Drawings; using speed_Boat.MovementStrategy; using System.Drawing; -using System.IO; namespace speed_Boat.Generics { @@ -53,13 +52,13 @@ namespace speed_Boat.Generics /// Перегрузка оператора сложения /// /// - public static bool operator + (BoatsGenericCollection collect, T? obj) + public static int operator + (BoatsGenericCollection collect, T? obj) { - if (obj == null) + if (obj != null) { - return false; + return collect?._collection.Insert(obj) ?? -1; } - return collect?._collection.Insert(obj) ?? false; + return 0; } /// /// Перегрузка оператора вычитания diff --git a/speed_Boat/speed_Boat/BoatsGenericStorage.cs b/speed_Boat/speed_Boat/BoatsGenericStorage.cs index 374f42e..2de35e1 100644 --- a/speed_Boat/speed_Boat/BoatsGenericStorage.cs +++ b/speed_Boat/speed_Boat/BoatsGenericStorage.cs @@ -80,7 +80,10 @@ namespace speed_Boat.Generics } data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); } - + if(data.Length == 0) + { + throw new Exception("Невалидная операция, нет данных для сохранения"); + } using (StreamWriter sw = new(filename)) { sw.WriteLine($"BoatStorage{Environment.NewLine}{data}"); @@ -126,9 +129,14 @@ namespace speed_Boat.Generics DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight); if (boat != null) { - if (!(collection + boat)) + try { _ = collection + boat; } + catch (BoatNotFoundException e) { - throw new StorageOverflowException("Ошибка добавления в коллекцию"); + throw e; + } + catch (StorageOverflowException e) + { + throw e; } } } diff --git a/speed_Boat/speed_Boat/FormBoatCollection.cs b/speed_Boat/speed_Boat/FormBoatCollection.cs index c547c0f..a00d935 100644 --- a/speed_Boat/speed_Boat/FormBoatCollection.cs +++ b/speed_Boat/speed_Boat/FormBoatCollection.cs @@ -12,7 +12,7 @@ using speed_Boat.Generics; using speed_Boat.MovementStrategy; using speed_Boat; using Microsoft.Extensions.Logging; - +using speed_Boat.Exceptions; namespace SpeedBoatLab { @@ -74,7 +74,7 @@ namespace SpeedBoatLab { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogWarning($"Не все данные заполнены:{nameStorageTextBox.Name}"); + _logger.LogWarning("Пустое название набора"); return; } _storage.AddSet(nameStorageTextBox.Text); @@ -97,6 +97,7 @@ namespace SpeedBoatLab { if (storagesListBox.SelectedIndex == -1) { + _logger.LogWarning("Набор для удаления не выбран"); return; } string name = storagesListBox.SelectedItem.ToString() ?? string.Empty; @@ -119,6 +120,11 @@ namespace SpeedBoatLab /// private void ButtonAddBoat_Click(object sender, EventArgs e) { + if (storagesListBox.SelectedIndex == -1) + { + _logger.LogWarning("Набор для добавления обьекта не выбран"); + return; + } var FormBoatConfig = new FormBoatConfig(); FormBoatConfig.AddEvent(new(AddBoat)); FormBoatConfig.Show(); @@ -128,25 +134,29 @@ namespace SpeedBoatLab { if (storagesListBox.SelectedIndex == -1) { + _logger.LogWarning("Набор для удаления не выбран"); return; } var obj = _storage[storagesListBox.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { + _logger.LogWarning("Добавление пустого обьекта"); return; } - if (obj + boat) + try { + _ = obj + boat; MessageBox.Show("Объект добавлен"); - _logger.LogInformation($"Объект добавлен:{obj}"); + _logger.LogInformation($"Добавлен объект в набор {storagesListBox.SelectedItem.ToString()}"); pictureBoxCollection.Image = obj.ShowBoats(); } - else + catch(StorageOverflowException ex) { MessageBox.Show("Не удалось добавить объект"); - _logger.LogInformation($"Не удалось добавить объект:{obj}"); + _logger.LogWarning($"{ex.Message} в наборе {storagesListBox.SelectedItem.ToString()}"); } } + /// /// Удаление объекта из набора /// @@ -156,6 +166,7 @@ namespace SpeedBoatLab { if (storagesListBox.SelectedIndex == -1) { + _logger.LogWarning("Удаление объекта из несуществующего набора"); return; } var obj = _storage[storagesListBox.SelectedItem.ToString() ?? string.Empty]; @@ -178,23 +189,31 @@ namespace SpeedBoatLab MessageBox.Show("Неверный формат позиции"); _logger.LogWarning($"Неверный формат позиции:{pos}"); } - - if (obj - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = obj.ShowBoats(); + if (obj - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = obj.ShowBoats(); + _logger.LogInformation($"Удален объект из набора {storagesListBox.SelectedItem.ToString()}"); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogInformation($"Не удалось удалить объект из набора {storagesListBox.SelectedItem.ToString()}"); + } + } + catch(BoatNotFoundException ex) + { + MessageBox.Show(ex.Message); + _logger.LogWarning($"{ex.Message} из набора {storagesListBox.SelectedItem.ToString()}"); } } - else if (insertPosition == string.Empty) + else if(insertPosition == string.Empty) { MessageBox.Show("Неверный формат позиции"); _logger.LogWarning($"Неверный формат позиции:{insertPosition}"); } - else - { - MessageBox.Show("Не удалось удалить объект"); - _logger.LogWarning($"Не удалось удалить объект:{obj}"); - } } /// /// Обновление рисунка по набору @@ -230,14 +249,14 @@ namespace SpeedBoatLab _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation($"Сохранение прошло успешно:"); + _logger.LogInformation($"Сохранение наборов в файл {saveFileDialog.FileName} прошло успешно:"); } catch (Exception ex) { MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogWarning($"Не сохранилось:{ex.Message}"); + _logger.LogWarning($"Не удалось сохранить наборы: {ex.Message}"); } } @@ -252,13 +271,15 @@ namespace SpeedBoatLab { _storage.LoadData(saveFileDialog.FileName); ReloadObjects(); - MessageBox.Show("Сохранение прошло успешно", + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Загрузились наборы из файла {openFileDialog.FileName}"); } catch (Exception ex) { MessageBox.Show($"Не удалось загрузить: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}"); } } diff --git a/speed_Boat/speed_Boat/GenericClass.cs b/speed_Boat/speed_Boat/GenericClass.cs index 683f6c6..2a71f6a 100644 --- a/speed_Boat/speed_Boat/GenericClass.cs +++ b/speed_Boat/speed_Boat/GenericClass.cs @@ -35,12 +35,12 @@ namespace speed_Boat.Generics /// /// Добавление объекта в набор /// - public bool Insert(T boat) + public int Insert(T boat) { if(_places.Count == 0) { _places.Add(boat); - return true; + return 0; } else { @@ -53,7 +53,7 @@ namespace speed_Boat.Generics _places[i] = _places[_places.Count - 1]; _places[_places.Count - 1] = temp; } - return true; + return 0; } else { @@ -103,9 +103,8 @@ namespace speed_Boat.Generics public bool Remove(int position) { if (position < 0 || position >= Count) - { - return false; - throw new BoatNotFoundException(); + { + throw new BoatNotFoundException(); } if (_places[position] == null) { diff --git a/speed_Boat/speed_Boat/Program.cs b/speed_Boat/speed_Boat/Program.cs index 539f76f..46ae747 100644 --- a/speed_Boat/speed_Boat/Program.cs +++ b/speed_Boat/speed_Boat/Program.cs @@ -14,6 +14,7 @@ namespace SpeedBoatLab [STAThread] static void Main() { + ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); @@ -40,7 +41,7 @@ namespace SpeedBoatLab option.SetMinimumLevel(LogLevel.Information); option.AddSerilog(logger); }); - } + } } } diff --git a/speed_Boat/speed_Boat/appsettings.json b/speed_Boat/speed_Boat/appsettings.json new file mode 100644 index 0000000..93ed51a --- /dev/null +++ b/speed_Boat/speed_Boat/appsettings.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": "speed_Boat" + } + } +} \ No newline at end of file diff --git a/speed_Boat/speed_Boat/speed_Boat.csproj b/speed_Boat/speed_Boat/speed_Boat.csproj index 5842e93..ca91c10 100644 --- a/speed_Boat/speed_Boat/speed_Boat.csproj +++ b/speed_Boat/speed_Boat/speed_Boat.csproj @@ -15,6 +15,7 @@ + -- 2.25.1 From 9089b795a5bef600f522ebea3485aac213ba95d8 Mon Sep 17 00:00:00 2001 From: chtzsch ~ Date: Wed, 29 Nov 2023 14:48:34 +0300 Subject: [PATCH 3/3] lab7 --- speed_Boat/speed_Boat/BoatsGenericStorage.cs | 1 - speed_Boat/speed_Boat/Program.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/speed_Boat/speed_Boat/BoatsGenericStorage.cs b/speed_Boat/speed_Boat/BoatsGenericStorage.cs index 2de35e1..0bf67c2 100644 --- a/speed_Boat/speed_Boat/BoatsGenericStorage.cs +++ b/speed_Boat/speed_Boat/BoatsGenericStorage.cs @@ -99,7 +99,6 @@ namespace speed_Boat.Generics if (!File.Exists(filename)) throw new FileNotFoundException("Файл не найден"); - string bufferTextFromFile = ""; using (StreamReader sr = new(filename)) { if (sr.ReadLine() != "BoatStorage") diff --git a/speed_Boat/speed_Boat/Program.cs b/speed_Boat/speed_Boat/Program.cs index 46ae747..bc24dd4 100644 --- a/speed_Boat/speed_Boat/Program.cs +++ b/speed_Boat/speed_Boat/Program.cs @@ -14,7 +14,6 @@ namespace SpeedBoatLab [STAThread] static void Main() { - ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); -- 2.25.1