From ed278533b75b4384175deae8965482e0c1033169 Mon Sep 17 00:00:00 2001 From: nezui1 <104579567+nezui1@users.noreply.github.com> Date: Mon, 6 May 2024 22:40:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=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=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=E2=84=967?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectAirFighter/ProjectAirFighter/AdNum.cs | 16 -- .../AbstractCompany.cs | 2 +- .../ListGenericObjects.cs | 27 ++-- .../MassiveGenericObjects.cs | 27 ++-- .../StorageCollection.cs | 33 ++-- .../Exceptions/CollectionOverflowException.cs | 27 ++++ .../Exceptions/ObjectNotFoundException.cs | 28 ++++ .../PositionOutOfCollectionException.cs | 30 ++++ .../FormWarPlaneCollection.Designer.cs | 10 +- .../FormWarPlaneCollection.cs | 147 ++++++++++++------ .../FormWarPlaneConfig.Designer.cs | 2 +- .../ProjectAirFighter/Program.cs | 39 ++++- .../ProjectAirFighter.csproj | 9 ++ .../ProjectAirFighter/serilog.json | 15 ++ 14 files changed, 300 insertions(+), 112 deletions(-) delete mode 100644 ProjectAirFighter/ProjectAirFighter/AdNum.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/Exceptions/CollectionOverflowException.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/Exceptions/ObjectNotFoundException.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/Exceptions/PositionOutOfCollectionException.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/serilog.json diff --git a/ProjectAirFighter/ProjectAirFighter/AdNum.cs b/ProjectAirFighter/ProjectAirFighter/AdNum.cs deleted file mode 100644 index fb0c08c..0000000 --- a/ProjectAirFighter/ProjectAirFighter/AdNum.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ProjectAirFighter.Drawning; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Metadata.Ecma335; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectAirFighter; - -public class AdNum - where T : DrawningAirFighter -{ - public void Nothing(){ - } -} diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs index cade9e6..3994b58 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -37,7 +37,7 @@ public abstract class AbstractCompany /// /// Вычисление максимального количества элементов, которые можно разместить в окне /// - private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + private int GetMaxCount => (_pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight)) + 1; /// /// Конструктор diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs index a51ff71..9dba439 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,5 @@ using ProjectAirFighter.CollectionGenericObject; +using ProjectAirFighter.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -40,7 +41,7 @@ public class ListGenericObjects : ICollectionGenericObjects { if (value > 0) { - _maxCount = value; + _maxCount = value ; } } } @@ -57,19 +58,19 @@ public class ListGenericObjects : ICollectionGenericObjects { //проверка позиции if (position >= Count || position < 0) - { - return null; - } + throw new ObjectNotFoundException(position); + return _collection[position]; } public int Insert(T obj) { + //проверка, что не превышено максимальное количество элементов if(Count + 1 > _maxCount) - { - return -1; - } + throw new CollectionOverflowException(Count); + + //вставка в конец набора _collection.Add(obj); return Count; @@ -77,11 +78,12 @@ public class ListGenericObjects : ICollectionGenericObjects public int Insert(T obj, int position) { + if (Count + 1 > _maxCount) + throw new CollectionOverflowException(Count); //проверка позиции if (position < 0 || position >= Count) - { - return -1; - } + throw new PositionOutOfCollectionException(position); + //вставка по позиции _collection.Insert(position,obj); return 1; @@ -90,9 +92,8 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Remove(int position) { if (position < 0 || position >= Count) - { - return null; - } + throw new PositionOutOfCollectionException(position); + T? temp = _collection[position]; _collection.RemoveAt(position); return temp; diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs index 0514de2..ef0fba0 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,5 +1,6 @@ using ProjectAirFighter.CollectionGenericObject; using ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -56,11 +57,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position >= 0 && position < Count) - { - return _collection[position]; - } - return null; + if (position < 0 || position > Count) + throw new PositionOutOfCollectionException(position); + + if (position >= _collection.Length && _collection[position] == null) + throw new ObjectNotFoundException(position); + + return _collection[position]; } public int Insert(T obj) @@ -73,13 +76,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects return i; } } - return -1; + throw new CollectionOverflowException(Count); } public int Insert(T obj, int position) { - if (position < 0 || position >= Count) - return -1; + if (position < 0 || position > Count) + throw new PositionOutOfCollectionException(position); if (_collection[position] == null) { @@ -109,17 +112,17 @@ public class MassiveGenericObjects : ICollectionGenericObjects temp--; } - return -1; + throw new CollectionOverflowException(Count); } public T? Remove(int position) { - if (position < 0 || position >= Count) - return null; + if (position < 0 || position > Count) + throw new PositionOutOfCollectionException(position); if (_collection[position] == null) { - return null; + throw new ObjectNotFoundException(position); } T? temp = _collection[position]; diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs index 2035496..5d3bf48 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -1,5 +1,6 @@ using ProjectAirFighter.CollectionGenericObject; using ProjectAirFighter.Drawning; +using ProjectAirFighter.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -100,10 +101,10 @@ public class StorageCollection - public bool SaveData(string filename) + public void SaveData(string filename) { if (_storages.Count == 0) - return false; + throw new Exception("В хранилище отсутсвуют коллекции для сохранения"); if (File.Exists(filename)) File.Delete(filename); @@ -138,18 +139,18 @@ public class StorageCollection sw.Write(_separatorItems); } } - return true; + } /// /// Загрузка информации по самолетам в хранилище из файла /// /// Путь и имя файла /// true - загрузка прошла успешно, false - ошибка при загрузке данных - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не существует"); } using (FileStream fs = new(filename, FileMode.Open)) @@ -159,12 +160,12 @@ public class StorageCollection string str = sr.ReadLine(); if (str == null || str.Length == 0) { - return false; + throw new Exception("В файле нет данных"); } if (!str.Equals(_collectionKey)) { - return false; + throw new Exception("В файле неверные данные"); } _storages.Clear(); @@ -180,7 +181,7 @@ public class StorageCollection ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); if (collection == null) { - return false; + throw new Exception("Не удалось создать коллекцию"); } collection.MaxCount = Convert.ToInt32(record[2]); @@ -190,14 +191,24 @@ public class StorageCollection { if (elem?.CreateDrawningWarPlane() is T warPlane) { - if (collection.Insert(warPlane) == -1) - return false; + + try + { + if (collection.Insert(warPlane) == -1) + { + throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); + } + } + catch(CollectionOverflowException ex) + { + throw new Exception("Коллекция переполнена", ex); + } } } _storages.Add(record[0], collection); } } - return true; + } /// diff --git a/ProjectAirFighter/ProjectAirFighter/Exceptions/CollectionOverflowException.cs b/ProjectAirFighter/ProjectAirFighter/Exceptions/CollectionOverflowException.cs new file mode 100644 index 0000000..a2ae9dd --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Exceptions/CollectionOverflowException.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.Exceptions; + +/// +/// Класс, описывающий ошибку преполнения коллекции +/// +[Serializable] + +internal class CollectionOverflowException : ApplicationException +{ + public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: count " + 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) { } + +} diff --git a/ProjectAirFighter/ProjectAirFighter/Exceptions/ObjectNotFoundException.cs b/ProjectAirFighter/ProjectAirFighter/Exceptions/ObjectNotFoundException.cs new file mode 100644 index 0000000..7ccb3f6 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Exceptions/ObjectNotFoundException.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.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) { } + + +} diff --git a/ProjectAirFighter/ProjectAirFighter/Exceptions/PositionOutOfCollectionException.cs b/ProjectAirFighter/ProjectAirFighter/Exceptions/PositionOutOfCollectionException.cs new file mode 100644 index 0000000..9f0e749 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Exceptions/PositionOutOfCollectionException.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirFighter.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) { } + + +} diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs index 4e6bf16..674d827 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs @@ -143,7 +143,7 @@ buttonCreateCompany.TabIndex = 8; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; - buttonCreateCompany.Click += buttonCreateCompany_Click; + buttonCreateCompany.Click += ButtonCreateCompany_Click; // // panelStorage // @@ -168,7 +168,7 @@ buttonCollectionRemove.TabIndex = 6; buttonCollectionRemove.Text = "Удалить коллекцию"; buttonCollectionRemove.UseVisualStyleBackColor = true; - buttonCollectionRemove.Click += buttonCollectionRemove_Click; + buttonCollectionRemove.Click += ButtonCollectionRemove_Click; // // listBoxCollection // @@ -187,7 +187,7 @@ buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; - buttonCollectionAdd.Click += buttonCollectionAdd_Click; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; // // radioButtonList // @@ -270,7 +270,7 @@ saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; saveToolStripMenuItem.Size = new Size(181, 22); saveToolStripMenuItem.Text = "Сохранение"; - saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // // loadToolStripMenuItem // @@ -278,7 +278,7 @@ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; loadToolStripMenuItem.Size = new Size(181, 22); loadToolStripMenuItem.Text = "Загрузка"; - loadToolStripMenuItem.Click += loadToolStripMenuItem_Click_1; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click_1; // // saveFileDialog // diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs index 92514cb..2fc851a 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs @@ -1,15 +1,9 @@ -using ProjectAirFighter.CollectionGenericObject; +using Microsoft.Extensions.Logging; +using ProjectAirFighter.CollectionGenericObject; using ProjectAirFighter.CollectionGenericObjects; using ProjectAirFighter.Drawning; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using ProjectAirFighter.Exceptions; + namespace ProjectAirFighter; @@ -25,13 +19,19 @@ public partial class FormWarPlaneCollection : Form /// private AbstractCompany? _company; + private readonly ILogger _logger; + + + /// /// Конструктор /// - public FormWarPlaneCollection() + public FormWarPlaneCollection(ILogger logger) { InitializeComponent(); _storageCollection = new(); + _logger = logger; + _logger.LogInformation("Форма загрузилась"); } /// @@ -60,15 +60,27 @@ public partial class FormWarPlaneCollection : Form { return; } - if (_company + warPlane != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); + + try { + if (_company + warPlane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + _logger.LogInformation("Объект добавлен: " + warPlane.GetDataForSave()); + } } - else + catch (CollectionOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); + + MessageBox.Show(ex.Message); + _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (ObjectNotFoundException ex) + { + MessageBox.Show(ex.Message); + _logger.LogError("Ошибка: {Message}", ex.Message); + } + } @@ -87,15 +99,24 @@ public partial class FormWarPlaneCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); + try { + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + _logger.LogInformation("Объект удален на позиции: " + pos); + } } - else + catch(ObjectNotFoundException ex) { MessageBox.Show("Не удалось удалить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); } + catch(PositionOutOfCollectionException ex) { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } + } private void ButtonGoToCheck_Click(object sender, EventArgs e) @@ -110,12 +131,25 @@ public partial class FormWarPlaneCollection : Form int counter = 100; while (warPlane == null) { - warPlane = _company.GetRandomObject(); - counter--; - if (counter <= 0) - { - break; + try { + warPlane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } } + catch (ObjectNotFoundException ex) + { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } + catch (PositionOutOfCollectionException ex) + { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } + } if (warPlane == null) @@ -144,13 +178,15 @@ public partial class FormWarPlaneCollection : Form /// /// /// - private void buttonCollectionAdd_Click(object sender, EventArgs e) + private void ButtonCollectionAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + + try { CollectionType collectionType = CollectionType.None; if (radioButtonMassive.Checked) { @@ -162,7 +198,13 @@ public partial class FormWarPlaneCollection : Form } _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); RerfreshListBoxItems(); - } + _logger.LogInformation("Коллекция добавлена: " + textBoxCollectionName.Text); + } + catch (Exception ex) + { + _logger.LogError("Ошибка: {Massege}", ex.Message); + } + } /// /// Обновление списка в listBoxCollection /// @@ -184,27 +226,32 @@ public partial class FormWarPlaneCollection : Form /// /// /// - private void buttonCollectionRemove_Click(object sender, EventArgs e) + private void ButtonCollectionRemove_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) - { - return; + try { + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + _logger.LogInformation("Коллекция: " + listBoxCollection.SelectedItem.ToString() + " удалена"); + } + catch(Exception ex) { + _logger.LogError("Ошибка: {Message}", ex.Message); } - _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); - RerfreshListBoxItems(); - } /// /// Создать компанию /// /// /// - private void buttonCreateCompany_Click(object sender, EventArgs e) + private void ButtonCreateCompany_Click(object sender, EventArgs e) { if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) { @@ -237,18 +284,21 @@ public partial class FormWarPlaneCollection : Form /// /// /// - private void saveToolStripMenuItem_Click(object sender, EventArgs e) + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.SaveData(saveFileDialog.FileName)) + try { + _storageCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation("Сохранение в файл: {filname}", saveFileDialog.FileName); } - else - { - MessageBox.Show("Не сохраненилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + catch(Exception ex) { + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } + } } @@ -259,19 +309,24 @@ public partial class FormWarPlaneCollection : Form /// /// - private void loadToolStripMenuItem_Click_1(object sender, EventArgs e) + private void LoadToolStripMenuItem_Click_1(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.LoadData(openFileDialog.FileName)) + try { + _storageCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); RerfreshListBoxItems(); + _logger.LogInformation("Загрузка из файла: {filname}", openFileDialog.FileName); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } + + } } } diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneConfig.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneConfig.Designer.cs index 2394a96..d53d6d7 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneConfig.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneConfig.Designer.cs @@ -339,7 +339,7 @@ Controls.Add(groupBoxConfig); Margin = new Padding(3, 2, 3, 2); Name = "FormWarPlaneConfig"; - Text = "Создание объекта"; + Text = "98"; groupBoxConfig.ResumeLayout(false); groupBoxConfig.PerformLayout(); groupBoxColor.ResumeLayout(false); diff --git a/ProjectAirFighter/ProjectAirFighter/Program.cs b/ProjectAirFighter/ProjectAirFighter/Program.cs index 9361ddf..1957bec 100644 --- a/ProjectAirFighter/ProjectAirFighter/Program.cs +++ b/ProjectAirFighter/ProjectAirFighter/Program.cs @@ -1,17 +1,42 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; + + namespace ProjectAirFighter { internal static class Program { - /// - /// The main entry point for the application. - /// [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 FormWarPlaneCollection()); + ServiceCollection services = new(); + ConfigureServices(services); + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + Application.Run(serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + services.AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(pathNeed) + .AddJsonFile("serilog.json") + .Build()) + .CreateLogger()); + }); } } -} \ No newline at end of file +} diff --git a/ProjectAirFighter/ProjectAirFighter/ProjectAirFighter.csproj b/ProjectAirFighter/ProjectAirFighter/ProjectAirFighter.csproj index 629ec08..52d77c1 100644 --- a/ProjectAirFighter/ProjectAirFighter/ProjectAirFighter.csproj +++ b/ProjectAirFighter/ProjectAirFighter/ProjectAirFighter.csproj @@ -8,6 +8,15 @@ enable + + + + + + + + + True diff --git a/ProjectAirFighter/ProjectAirFighter/serilog.json b/ProjectAirFighter/ProjectAirFighter/serilog.json new file mode 100644 index 0000000..d1428e1 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +} -- 2.25.1