From 73aa9c2f1c5b8b70d463e44882fa83dc277cddba Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Sun, 5 May 2024 20:39:16 +0400
Subject: [PATCH 1/6] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=207=20=D1=81=20?=
=?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=B0=D0=BC=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ListGenericObjects.cs | 39 +++---
.../MassiveGenericObjects.cs | 62 ++++++----
.../StorageCollection.cs | 32 ++---
.../Exceptions/CollectionOverflowException.cs | 20 +++
.../Exceptions/ObjectNotFoundException.cs | 20 +++
.../PositionOutOfCollectionException.cs | 21 ++++
laba 0/laba 0/FormBoatCollection.cs | 116 +++++++++++-------
laba 0/laba 0/MotorBoat.csproj | 5 +
laba 0/laba 0/Program.cs | 29 ++++-
laba 0/laba 0/nlog.config | 14 +++
10 files changed, 245 insertions(+), 113 deletions(-)
create mode 100644 laba 0/laba 0/Exceptions/CollectionOverflowException.cs
create mode 100644 laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
create mode 100644 laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
create mode 100644 laba 0/laba 0/nlog.config
diff --git a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
index f7f7dee..c853c63 100644
--- a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,4 +1,6 @@
-namespace MotorBoat.CollectionGenericObjects;
+using MotorBoat.Exceptions;
+
+namespace MotorBoat.CollectionGenericObjects;
///
/// Параметризованный набор объекта
@@ -46,45 +48,34 @@ public class ListGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- // TODO проверка позиции
- if (position >= 0 && position < Count)
- {
- return _collection[position];
- }
- else
- {
- return null;
- }
+ //TODO выброс ошибки если выход за границу
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ return _collection[position];
}
public int Insert(T obj)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO вставка в конец набора
- if (Count == _maxCount) { return -1; }
+ // TODO выброс ошибки если переполнение
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO проверка позиции
- // TODO вставка по позиции
- if (position < 0 || position >= Count || Count == _maxCount)
- {
- return -1;
- }
+ // TODO выброс ошибки если переполнение
+ // TODO выброс ошибки если за границу
+ if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
- // TODO проверка позиции
- // TODO удаление объекта из списка
- if (position >= Count || position < 0) return null;
- T? obj = _collection[position];
+ // TODO если выброс за границу
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
index ca75819..eed0d0c 100644
--- a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using MotorBoat.Exceptions;
namespace MotorBoat.CollectionGenericObjects;
@@ -50,62 +51,71 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- if (position < 0 || position >= _collection.Length) return null;
+ // TODO выброс ошибки если выход за границу
+ // TODO выброс ошибки если объект пустой
+ if (position < 0 || position >= _collection.Length)
+ throw new PositionOutOfCollectionException(position);
+ if (_collection[position] == null)
+ throw new ObjectNotFoundException(position);
return _collection[position];
}
public int Insert(T obj)
{
- for (int i = 0; i < Count; i++)
+ // TODO выброс ошибки если переполнение
+ int index = 0;
+ while (index < _collection.Length)
{
- if (_collection[i] == null)
+ if (_collection[index] == null)
{
- _collection[i] = obj;
- return i;
+ _collection[index] = obj;
+ return index;
}
+ ++index;
}
- return -1;
+ throw new CollectionOverflowException(Count);
}
public int Insert(T obj, int position)
{
- if (position < 0 || position >= Count)
- {
- return -1;
- }
+ // TODO выброс ошибки если переполнение
+ // TODO выброс ошибки если выход за границу
+ if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
-
- for (int i = position + 1; i < Count; i++)
+ int index = position + 1;
+ while (index < _collection.Length)
{
- if (_collection[i] == null)
+ if (_collection[index] == null)
{
- _collection[i] = obj;
- return i;
+ _collection[index] = obj;
+ return index;
}
+ ++index;
}
- for (int i = position - 1; i >= 0; i--)
+ index = position - 1;
+ while (index >= 0)
{
- if (_collection[i] == null)
+ if (_collection[index] == null)
{
- _collection[i] = obj;
- return i;
+ _collection[index] = obj;
+ return index;
}
+ --index;
}
-
- return -1;
+ throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
{
- if (position < 0 || position >= Count)
- {
- return null;
- }
- T? obj = _collection[position];
+ // TODO выброс ошибки если выход за границу
+ // TODO выброс ошибки если объект пустой
+ if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
+ if (_collection[position] == null) throw new ObjectNotFoundException(position);
+ T obj = _collection[position];
_collection[position] = null;
return obj;
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
index 9dde66f..8c48225 100644
--- a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
@@ -1,4 +1,5 @@
using MotorBoat.Drawning;
+using MotorBoat.Exceptions;
namespace MotorBoat.CollectionGenericObjects;
@@ -100,12 +101,11 @@ public class StorageCollection
/// Сохранение информации по катеру в хранилище в файл
///
/// Путь и имя файла
- /// true - сохранение прошло успешно, false - ошибка при сохранении данных
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (_storages.Count == 0)
{
- return false;
+ throw new Exception("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@@ -145,31 +145,29 @@ public class StorageCollection
}
}
}
- return true;
}
///
/// Загрузка информации по автомобилям в хранилище из файла
///
/// Путь и имя файла
- /// true - загрузка прошла успешно, false - ошибка при загрузке данных
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new Exception("Файл не существует");
}
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
- return false;
+ throw new Exception("В файле нет данных");
}
if (!str.StartsWith(_collectionKey))
{
- return false;
+ throw new Exception("В файле неверные данные");
}
_storages.Clear();
@@ -186,25 +184,31 @@ public class StorageCollection
ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
if (collection == null)
{
- return false;
+ throw new Exception("Не удалось создать коллекцию");
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
- if (elem?.CreateDrawningB() is T ship)
+ if (elem?.CreateDrawningB() is T B)
{
- if (collection.Insert(ship) == -1)
+ try
{
- return false;
+ if (collection.Insert(B) == -1)
+ {
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ }
+ }
+ catch (CollectionOverflowException ex)
+ {
+ throw new Exception("Коллекция переполнена", ex);
}
}
}
_storages.Add(record[0], collection);
}
- return true;
}
}
diff --git a/laba 0/laba 0/Exceptions/CollectionOverflowException.cs b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
new file mode 100644
index 0000000..af09235
--- /dev/null
+++ b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
@@ -0,0 +1,20 @@
+using System.Runtime.Serialization;
+
+namespace MotorBoat.Exceptions;
+
+///
+/// Класс, описывающий ошибку переполнения коллекции
+///
+[Serializable]
+internal class CollectionOverflowException : ApplicationException
+{
+ public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + 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/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs b/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
new file mode 100644
index 0000000..505502a
--- /dev/null
+++ b/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
@@ -0,0 +1,20 @@
+using System.Runtime.Serialization;
+
+namespace MotorBoat.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/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
new file mode 100644
index 0000000..17d9ba8
--- /dev/null
+++ b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
@@ -0,0 +1,21 @@
+using System.Runtime.Serialization;
+
+namespace MotorBoat.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/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs
index 293a423..e8b0615 100644
--- a/laba 0/laba 0/FormBoatCollection.cs
+++ b/laba 0/laba 0/FormBoatCollection.cs
@@ -7,8 +7,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using Microsoft.Extensions.Logging;
using MotorBoat.CollectionGenericObjects;
using MotorBoat.Drawning;
+using MotorBoat.Exceptions;
namespace MotorBoat;
@@ -27,13 +29,19 @@ public partial class FormBoatCollection : Form
///
private AbstractCompany? _company = null;
+ ///
+ /// Логер
+ ///
+ private readonly ILogger _logger;
+
///
/// Конструктор
///
- public FormBoatCollection()
+ public FormBoatCollection(ILogger logger)
{
InitializeComponent();
_storageCollection = new();
+ _logger = logger;
}
///
@@ -60,37 +68,51 @@ public partial class FormBoatCollection : Form
///
private void SetBoat(DrawningB? b)
{
- if (_company == null || b == null)
+ try
{
- return;
+ if (_company == null || b == null)
+ {
+ return;
+ }
+ if (_company + b != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ _logger.LogInformation("Добавлен объект: " + b.GetDataForSave());
+ }
}
-
- if (_company + b != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
- }
- else
+ catch (ObjectNotFoundException) { }
+ catch (CollectionOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
{
- if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) return;
-
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
-
- int pos = Convert.ToInt32(maskedTextBox.Text);
- if (_company - pos != null)
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
- MessageBox.Show("Объект удалён");
- pictureBox.Image = _company.Show();
+ return;
}
- else
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBox.Text);
+ try
+ {
+ if (_company - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ _logger.LogInformation("Удален объект по позиции " + pos);
+ }
+ }
+ catch (Exception ex)
{
MessageBox.Show("Не удалось удалить объект");
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
}
@@ -100,29 +122,29 @@ public partial class FormBoatCollection : Form
{
return;
}
-
DrawningB? B = null;
int counter = 100;
- while (B == null)
+ try
{
- B = _company.GetRandomObject();
- counter--;
- if (counter <= 0)
+ while (B == null)
{
- break;
+ B = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
}
+ FormBoat form = new()
+ {
+ SetB = B
+ };
+ form.ShowDialog();
}
-
- if (B == null)
+ catch (Exception ex)
{
- return;
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
-
- FormBoat form = new()
- {
- SetB = B
- };
- form.ShowDialog();
}
private void buttonRefresh_Click(object sender, EventArgs e)
@@ -235,15 +257,16 @@ public partial class FormBoatCollection : Form
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storageCollection.SaveData(saveFileDialog.FileName))
+ try
{
- MessageBox.Show("Сохранение прошло успешно",
- "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _storageCollection.SaveData(saveFileDialog.FileName);
+ MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
@@ -258,16 +281,17 @@ public partial class FormBoatCollection : Form
//TODO продумать логику
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storageCollection.LoadData(openFileDialog.FileName))
+ try
{
- MessageBox.Show("Загрузка прошла успешно",
- "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _storageCollection.LoadData(openFileDialog.FileName);
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RefreshListBoxItems();
+ _logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
diff --git a/laba 0/laba 0/MotorBoat.csproj b/laba 0/laba 0/MotorBoat.csproj
index 1a83870..77e4dc7 100644
--- a/laba 0/laba 0/MotorBoat.csproj
+++ b/laba 0/laba 0/MotorBoat.csproj
@@ -9,6 +9,11 @@
enable
+
+
+
+
+
True
diff --git a/laba 0/laba 0/Program.cs b/laba 0/laba 0/Program.cs
index 8145421..06caaff 100644
--- a/laba 0/laba 0/Program.cs
+++ b/laba 0/laba 0/Program.cs
@@ -1,9 +1,14 @@
+using System.Drawing;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace MotorBoat
{
internal static class Program
{
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -11,7 +16,25 @@ namespace MotorBoat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormBoatCollection());
+
+ ServiceCollection services = new();
+ ConfigureServices(services);
+ using ServiceProvider serviceProvider = services.BuildServiceProvider();
+ Application.Run(serviceProvider.GetRequiredService());
+ }
+
+ ///
+ /// DI
+ ///
+ ///
+ 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/laba 0/laba 0/nlog.config b/laba 0/laba 0/nlog.config
new file mode 100644
index 0000000..63b7d65
--- /dev/null
+++ b/laba 0/laba 0/nlog.config
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
2.25.1
From de20ec28284a397be349d29fccdbe9edfd6a4bea Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Mon, 6 May 2024 15:43:43 +0400
Subject: [PATCH 2/6] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=207=20=D0=B2=D1=81?=
=?UTF-8?q?=D0=B5=20=D0=B5=D1=89=D0=B5=20=D1=81=20=D0=B1=D0=B0=D0=B3=D0=B0?=
=?UTF-8?q?=D0=BC=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
laba 0/laba 0/MotorBoat.csproj | 6 +++++
laba 0/laba 0/Program.cs | 41 +++++++++++++++++++---------------
laba 0/laba 0/appSetting.json | 20 +++++++++++++++++
laba 0/laba 0/nlog.config | 14 ------------
4 files changed, 49 insertions(+), 32 deletions(-)
create mode 100644 laba 0/laba 0/appSetting.json
delete mode 100644 laba 0/laba 0/nlog.config
diff --git a/laba 0/laba 0/MotorBoat.csproj b/laba 0/laba 0/MotorBoat.csproj
index 77e4dc7..6a01d56 100644
--- a/laba 0/laba 0/MotorBoat.csproj
+++ b/laba 0/laba 0/MotorBoat.csproj
@@ -10,8 +10,14 @@
+
+
+
+
+
+
diff --git a/laba 0/laba 0/Program.cs b/laba 0/laba 0/Program.cs
index 06caaff..8c2ce41 100644
--- a/laba 0/laba 0/Program.cs
+++ b/laba 0/laba 0/Program.cs
@@ -1,14 +1,14 @@
-using System.Drawing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using Microsoft.Extensions.Configuration;
+using Serilog;
namespace MotorBoat
{
internal static class Program
{
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -16,25 +16,30 @@ namespace MotorBoat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
-
- ServiceCollection services = new();
+ var services = new ServiceCollection();
ConfigureServices(services);
- using ServiceProvider serviceProvider = services.BuildServiceProvider();
- Application.Run(serviceProvider.GetRequiredService());
+ using (ServiceProvider serviceProvider = services.BuildServiceProvider())
+ {
+ Application.Run(serviceProvider.GetRequiredService());
+ }
}
-
- ///
- /// DI
- ///
- ///
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton()
- .AddLogging(option =>
- {
- option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
- });
+ .AddLogging(option =>
+ {
+ var configuration = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile(path: "C:\\Users\\\\Desktop\\ .txt", optional: false, reloadOnChange: true)
+ .Build();
+
+ var logger = new LoggerConfiguration()
+ .ReadFrom.Configuration(configuration)
+ .CreateLogger();
+
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddSerilog(logger);
+ });
}
}
-}
+}
\ No newline at end of file
diff --git a/laba 0/laba 0/appSetting.json b/laba 0/laba 0/appSetting.json
new file mode 100644
index 0000000..bc1bff2
--- /dev/null
+++ b/laba 0/laba 0/appSetting.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": "Battleship"
+ }
+ }
+}
diff --git a/laba 0/laba 0/nlog.config b/laba 0/laba 0/nlog.config
deleted file mode 100644
index 63b7d65..0000000
--- a/laba 0/laba 0/nlog.config
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
2.25.1
From 2b59f7093753b3323512af36f57f1fda17a670cf Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Wed, 15 May 2024 00:26:03 +0400
Subject: [PATCH 3/6] 7
---
.../ICollectionGenericObjects.cs | 14 +-
.../ListGenericObjects.cs | 14 +-
.../MassiveGenericObjects.cs | 65 +++----
.../StorageCollection.cs | 106 +++++------
.../Exceptions/CollectionOverflowException.cs | 6 +-
.../Exceptions/ObjectNotFoundException.cs | 6 +-
.../PositionOutOfCollectionException.cs | 5 -
laba 0/laba 0/FormBoatCollection.cs | 167 +++++++++++-------
laba 0/laba 0/MotorBoat.csproj | 15 +-
laba 0/laba 0/Program.cs | 37 ++--
laba 0/laba 0/appSetting.json | 20 ---
laba 0/laba 0/serilog.json | 15 ++
12 files changed, 239 insertions(+), 231 deletions(-)
delete mode 100644 laba 0/laba 0/appSetting.json
create mode 100644 laba 0/laba 0/serilog.json
diff --git a/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
index d675b62..9ef4425 100644
--- a/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace MotorBoat.CollectionGenericObjects;
+namespace MotorBoat.CollectionGenericObjects;
///
/// Интерфейс описания действий для набора хранимых объектов
@@ -27,7 +21,7 @@ public interface ICollectionGenericObjects
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
- /// true - вставка прошла удачно, false - вставка неудалась
+ /// true - вставка прошла удачно, false - вставка не удалась
int Insert(T obj);
///
@@ -35,7 +29,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// Позиция
- /// true - вставка прошла удачно, false - вставка неудалась
+ /// true - вставка прошла удачно, false - вставка не удалась
int Insert(T obj, int position);
///
@@ -43,7 +37,7 @@ public interface ICollectionGenericObjects
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- T Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
diff --git a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
index c853c63..2bac180 100644
--- a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
@@ -48,14 +48,12 @@ public class ListGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- //TODO выброс ошибки если выход за границу
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return _collection[position];
}
public int Insert(T obj)
{
- // TODO выброс ошибки если переполнение
if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
@@ -63,17 +61,17 @@ public class ListGenericObjects : ICollectionGenericObjects
public int Insert(T obj, int position)
{
- // TODO выброс ошибки если переполнение
- // TODO выброс ошибки если за границу
- if (Count == _maxCount) throw new CollectionOverflowException(Count);
- if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ if (position < 0 || position >= Count)
+ throw new PositionOutOfCollectionException(position);
+
+ if (Count == _maxCount)
+ throw new CollectionOverflowException(Count);
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
- // TODO если выброс за границу
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position];
_collection.RemoveAt(position);
@@ -82,7 +80,7 @@ public class ListGenericObjects : ICollectionGenericObjects
public IEnumerable GetItems()
{
- for (int i = 0; i < Count; ++i)
+ for (int i = 0; i < _collection.Count; ++i)
{
yield return _collection[i];
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
index eed0d0c..a8c2032 100644
--- a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,12 +1,12 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+
using MotorBoat.Exceptions;
namespace MotorBoat.CollectionGenericObjects;
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
public class MassiveGenericObjects : ICollectionGenericObjects
where T : class
{
@@ -51,69 +51,62 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- // TODO выброс ошибки если выход за границу
- // TODO выброс ошибки если объект пустой
- if (position < 0 || position >= _collection.Length)
- throw new PositionOutOfCollectionException(position);
- if (_collection[position] == null)
- throw new ObjectNotFoundException(position);
+ if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
+ if (_collection[position] == null) throw new ObjectNotFoundException(position);
return _collection[position];
}
public int Insert(T obj)
{
- // TODO выброс ошибки если переполнение
- int index = 0;
- while (index < _collection.Length)
+ for (int i = 0; i < Count; i++)
{
- if (_collection[index] == null)
+ if (_collection[i] == null)
{
- _collection[index] = obj;
- return index;
+ _collection[i] = obj;
+ return i;
}
- ++index;
}
throw new CollectionOverflowException(Count);
}
public int Insert(T obj, int position)
{
- // TODO выброс ошибки если переполнение
- // TODO выброс ошибки если выход за границу
- if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
+ if (position < 0 || position >= Count)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
- int index = position + 1;
- while (index < _collection.Length)
+
+ for (int i = position + 1; i < Count; i++)
{
- if (_collection[index] == null)
+ if (_collection[i] == null)
{
- _collection[index] = obj;
- return index;
+ _collection[i] = obj;
+ return i;
}
- ++index;
}
- index = position - 1;
- while (index >= 0)
+ for (int i = position - 1; i >= 0; i--)
{
- if (_collection[index] == null)
+ if (_collection[i] == null)
{
- _collection[index] = obj;
- return index;
+ _collection[i] = obj;
+ return i;
}
- --index;
}
+
throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
{
- // TODO выброс ошибки если выход за границу
- // TODO выброс ошибки если объект пустой
- if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
+ if (position < 0 || position >= Count)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
if (_collection[position] == null) throw new ObjectNotFoundException(position);
T obj = _collection[position];
_collection[position] = null;
diff --git a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
index 8c48225..87655b0 100644
--- a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
@@ -1,5 +1,6 @@
using MotorBoat.Drawning;
using MotorBoat.Exceptions;
+using System.Text;
namespace MotorBoat.CollectionGenericObjects;
@@ -20,6 +21,21 @@ public class StorageCollection
///
public List Keys => _storages.Keys.ToList();
+ ///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+
///
/// Конструктор
///
@@ -35,8 +51,6 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
- // TODO Прописать логику для добавления
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
{
return;
@@ -60,7 +74,6 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- // TODO Прописать логику для удаления коллекции
if (_storages.ContainsKey(name))
{
_storages.Remove(name);
@@ -76,7 +89,6 @@ public class StorageCollection
{
get
{
- // TODO Продумать логику получения объекта
if (_storages.ContainsKey(name))
{
return _storages[name];
@@ -85,18 +97,6 @@ public class StorageCollection
}
}
- ///
- /// Ключевое слово, с которого должен начинаться файл
- ///
- private readonly string _collectionKey = "CollectionsStorage";
- ///
- /// Разделитель для записи ключа и значения элемента словаря
- ///
- private readonly string _separatorForKeyValue = "|";
- ///
- /// Разделитель для записей коллекции данных в файл
- ///
- private readonly string _separatorItems = ";";
///
/// Сохранение информации по катеру в хранилище в файл
///
@@ -113,36 +113,32 @@ public class StorageCollection
File.Delete(filename);
}
- using (StreamWriter writer = new StreamWriter(filename))
+ StringBuilder sb = new();
+
+ using (StreamWriter sw = new StreamWriter(filename))
{
- writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ sw.WriteLine(_collectionKey.ToString());
+ foreach (KeyValuePair> kvpair in _storages)
{
- writer.Write(Environment.NewLine);
// не сохраняем пустые коллекции
- if (value.Value.Count == 0)
- {
+ if (kvpair.Value.Count == 0)
continue;
- }
-
- writer.Write(value.Key);
- writer.Write(_separatorForKeyValue);
- writer.Write(value.Value.GetCollectionType);
- writer.Write(_separatorForKeyValue);
- writer.Write(value.Value.MaxCount);
- writer.Write(_separatorForKeyValue);
-
- foreach (T? item in value.Value.GetItems())
+ sb.Append(kvpair.Key);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(kvpair.Value.GetCollectionType);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(kvpair.Value.MaxCount);
+ sb.Append(_separatorForKeyValue);
+ foreach (T? item in kvpair.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data))
- {
continue;
- }
-
- writer.Write(data);
- writer.Write(_separatorItems);
+ sb.Append(data);
+ sb.Append(_separatorItems);
}
+ sw.WriteLine(sb.ToString());
+ sb.Clear();
}
}
}
@@ -151,35 +147,29 @@ public class StorageCollection
/// Загрузка информации по автомобилям в хранилище из файла
///
/// Путь и имя файла
- public void LoadData(string filename)
+ public void LoadData(string filename)
{
- if (!File.Exists(filename))
+ if (!File.Exists(filename))
{
throw new Exception("Файл не существует");
}
- using (StreamReader fs = File.OpenText(filename))
- {
- string str = fs.ReadLine();
- if (str == null || str.Length == 0)
- {
- throw new Exception("В файле нет данных");
- }
- if (!str.StartsWith(_collectionKey))
- {
+ using (StreamReader sr = new StreamReader(filename))
+ {
+ string? str;
+ str = sr.ReadLine();
+ if (str == null || str.Length == 0)
+ throw new Exception("В файле нет данных");
+ if (str != _collectionKey.ToString())
throw new Exception("В файле неверные данные");
- }
-
_storages.Clear();
- string strs = "";
- while ((strs = fs.ReadLine()) != null)
+ while ((str = sr.ReadLine()) != null)
{
- string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ string[] record = str.Split(_separatorForKeyValue);
if (record.Length != 4)
{
continue;
}
-
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
if (collection == null)
@@ -188,17 +178,16 @@ public class StorageCollection
}
collection.MaxCount = Convert.ToInt32(record[2]);
+
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
- if (elem?.CreateDrawningB() is T B)
+ if (elem?.CreateDrawningB() is T boat)
{
try
{
- if (collection.Insert(B) == -1)
- {
+ if (collection.Insert(boat) == -1)
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
- }
}
catch (CollectionOverflowException ex)
{
@@ -206,7 +195,6 @@ public class StorageCollection
}
}
}
-
_storages.Add(record[0], collection);
}
}
diff --git a/laba 0/laba 0/Exceptions/CollectionOverflowException.cs b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
index af09235..519b255 100644
--- a/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
+++ b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
@@ -9,12 +9,8 @@ namespace MotorBoat.Exceptions;
internal class CollectionOverflowException : ApplicationException
{
public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
-
public CollectionOverflowException() : base() { }
-
public CollectionOverflowException(string message) : base(message) { }
-
- public CollectionOverflowException(string message, Exception exception) : base(message, exception){ }
-
+ public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
diff --git a/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs b/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
index 505502a..7f10ea1 100644
--- a/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
+++ b/laba 0/laba 0/Exceptions/ObjectNotFoundException.cs
@@ -9,12 +9,8 @@ namespace MotorBoat.Exceptions;
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) { }
-}
+}
\ No newline at end of file
diff --git a/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
index 17d9ba8..25ef92b 100644
--- a/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
+++ b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
@@ -9,13 +9,8 @@ namespace MotorBoat.Exceptions;
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/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs
index e8b0615..15ce982 100644
--- a/laba 0/laba 0/FormBoatCollection.cs
+++ b/laba 0/laba 0/FormBoatCollection.cs
@@ -1,13 +1,4 @@
-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 Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging;
using MotorBoat.CollectionGenericObjects;
using MotorBoat.Drawning;
using MotorBoat.Exceptions;
@@ -30,30 +21,36 @@ public partial class FormBoatCollection : Form
private AbstractCompany? _company = null;
///
- /// Логер
+ /// Логгер
///
private readonly ILogger _logger;
///
- /// Конструктор
- ///
+ /// Конструктор
+ ///
public FormBoatCollection(ILogger logger)
{
InitializeComponent();
_storageCollection = new();
_logger = logger;
+ _logger.LogInformation("Форма загрузилась");
}
///
- /// Выбор компании
- ///
- ///
- ///
+ /// Выбор компании
+ ///
+ ///
+ ///
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
panelCompanyTools.Enabled = false;
}
+ ///
+ /// Добавление лодки
+ ///
+ ///
+ ///
private void buttonAddBoat_Click(object sender, EventArgs e)
{
FormBoatConfig form = new();
@@ -62,11 +59,11 @@ public partial class FormBoatCollection : Form
form.AddEvent(SetBoat);
}
- ///
- /// Добавление катера в коллекцию
- ///
- ///
- private void SetBoat(DrawningB? b)
+ ///
+ /// Добавление лодки в коллекцию
+ ///
+ ///
+ private void SetBoat(DrawningB? b)
{
try
{
@@ -74,6 +71,7 @@ public partial class FormBoatCollection : Form
{
return;
}
+
if (_company + b != -1)
{
MessageBox.Show("Объект добавлен");
@@ -84,44 +82,58 @@ public partial class FormBoatCollection : Form
catch (ObjectNotFoundException) { }
catch (CollectionOverflowException ex)
{
- MessageBox.Show("Не удалось добавить объект");
+ MessageBox.Show("В коллекции превышено допустимое количество элементов");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
- private void buttonRemoveBoat_Click(object sender, EventArgs e)
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
- {
- return;
- }
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
int pos = Convert.ToInt32(maskedTextBox.Text);
try
{
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ {
+ throw new Exception("Входные данные отсутствуют");
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
- _logger.LogInformation("Удален объект по позиции " + pos);
+ _logger.LogInformation("Объект удален");
}
}
catch (Exception ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show("Не найден объект по позиции " + pos);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
- private void buttonGoToCheck_Click(object sender, EventArgs e)
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
+
DrawningB? B = null;
int counter = 100;
try
@@ -135,21 +147,34 @@ public partial class FormBoatCollection : Form
break;
}
}
- FormBoat form = new()
+
+ if (B == null)
{
- SetB = B
- };
+ return;
+ }
+
+ FormBoat form = new FormBoat();
+ form.SetB = B;
form.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
+
}
- private void buttonRefresh_Click(object sender, EventArgs e)
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
{
- if (_company == null) return;
+ if (_company == null)
+ {
+ return;
+ }
pictureBox.Image = _company.Show();
}
@@ -163,28 +188,37 @@ public partial class FormBoatCollection : Form
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{
- MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не все данный заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
- CollectionType collectionType = CollectionType.None;
- if (radioButtonMassive.Checked)
+ try
{
- collectionType = CollectionType.Massive;
+ CollectionType collectionType = CollectionType.None;
+ if (radioButtonMassive.Checked)
+ {
+ collectionType = CollectionType.Massive;
+ }
+ else if (radioButtonList.Checked)
+ {
+ collectionType = CollectionType.List;
+ }
+
+ _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ RefreshListBoxItems();
+ _logger.LogInformation("Добавлена коллекция:", textBoxCollectionName.Text);
}
- else if (radioButtonList.Checked)
+ catch (Exception ex)
{
- collectionType = CollectionType.List;
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
- _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
- RefreshListBoxItems();
}
///
- /// Обновление списка в listBoxCollection
- ///
- private void RefreshListBoxItems()
+ /// Обновление списка в listBoxCollection
+ ///
+ private void RefreshListBoxItems()
{
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
@@ -195,6 +229,7 @@ public partial class FormBoatCollection : Form
listBoxCollection.Items.Add(colName);
}
}
+
}
///
@@ -209,12 +244,21 @@ public partial class FormBoatCollection : Form
MessageBox.Show("Коллекция не выбрана");
return;
}
- if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+
+ try
{
- return;
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RefreshListBoxItems();
+ _logger.LogInformation("Удалена коллекция: ", listBoxCollection.SelectedItem.ToString());
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
- _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
- RefreshListBoxItems();
}
///
@@ -222,7 +266,7 @@ public partial class FormBoatCollection : Form
///
///
///
- private void buttonCreateCompany_Click(object sender, EventArgs e)
+ private void buttonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
@@ -253,7 +297,7 @@ public partial class FormBoatCollection : Form
///
///
///
- private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
+ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
@@ -268,17 +312,18 @@ public partial class FormBoatCollection : Form
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
+
+
}
}
///
- /// Обработка нажатия "Загрузка"
+ /// Обработка кнопки загрузки
///
///
///
- private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
- //TODO продумать логику
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
@@ -290,7 +335,7 @@ public partial class FormBoatCollection : Form
}
catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
diff --git a/laba 0/laba 0/MotorBoat.csproj b/laba 0/laba 0/MotorBoat.csproj
index 6a01d56..4dd00b4 100644
--- a/laba 0/laba 0/MotorBoat.csproj
+++ b/laba 0/laba 0/MotorBoat.csproj
@@ -10,14 +10,13 @@
-
-
+
-
-
-
+
+
+
@@ -35,4 +34,10 @@
+
+
+ Always
+
+
+
\ No newline at end of file
diff --git a/laba 0/laba 0/Program.cs b/laba 0/laba 0/Program.cs
index 8c2ce41..4eb1bd0 100644
--- a/laba 0/laba 0/Program.cs
+++ b/laba 0/laba 0/Program.cs
@@ -1,9 +1,10 @@
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Configuration;
+using MotorBoat;
using Serilog;
-namespace MotorBoat
+namespace ProjectCatamaran
{
internal static class Program
{
@@ -16,29 +17,31 @@ namespace MotorBoat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- var services = new ServiceCollection();
+ ServiceCollection services = new();
ConfigureServices(services);
- using (ServiceProvider serviceProvider = services.BuildServiceProvider())
- {
- Application.Run(serviceProvider.GetRequiredService());
- }
+ using ServiceProvider serviceProvider = services.BuildServiceProvider();
+ Application.Run(serviceProvider.GetRequiredService());
}
+
+ ///
+ /// DI
+ ///
+ ///
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 =>
{
- var configuration = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile(path: "C:\\Users\\\\Desktop\\ .txt", optional: false, reloadOnChange: true)
- .Build();
-
- var logger = new LoggerConfiguration()
- .ReadFrom.Configuration(configuration)
- .CreateLogger();
-
option.SetMinimumLevel(LogLevel.Information);
- option.AddSerilog(logger);
+ option.AddSerilog(new LoggerConfiguration().ReadFrom.Configuration(new ConfigurationBuilder().
+ AddJsonFile($"{pathNeed}serilog.json").Build()).CreateLogger());
});
}
}
diff --git a/laba 0/laba 0/appSetting.json b/laba 0/laba 0/appSetting.json
deleted file mode 100644
index bc1bff2..0000000
--- a/laba 0/laba 0/appSetting.json
+++ /dev/null
@@ -1,20 +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" ],
- "Properties": {
- "Application": "Battleship"
- }
- }
-}
diff --git a/laba 0/laba 0/serilog.json b/laba 0/laba 0/serilog.json
new file mode 100644
index 0000000..fdf9719
--- /dev/null
+++ b/laba 0/laba 0/serilog.json
@@ -0,0 +1,15 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": { "path": "log.log" }
+ }
+ ],
+ "Properties": {
+ "Applicatoin": "Sample"
+ }
+ }
+}
\ No newline at end of file
--
2.25.1
From 888038edd46cd51d726f868a938411cf4c05ea40 Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Wed, 15 May 2024 02:28:35 +0400
Subject: [PATCH 4/6] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2?=
=?UTF-8?q?=D1=81=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ListGenericObjects.cs | 38 ++--
.../MassiveGenericObjects.cs | 32 ++--
.../StorageCollection.cs | 106 ++++++-----
.../Exceptions/CollectionOverflowException.cs | 2 +-
.../PositionOutOfCollectionException.cs | 4 +-
laba 0/laba 0/FormBoatCollection.Designer.cs | 14 +-
laba 0/laba 0/FormBoatCollection.cs | 166 ++++++++----------
laba 0/laba 0/MotorBoat.csproj | 7 +-
laba 0/laba 0/Program.cs | 8 +-
laba 0/laba 0/serilog.json | 2 +-
10 files changed, 193 insertions(+), 186 deletions(-)
diff --git a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
index 2bac180..d5e775c 100644
--- a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
@@ -14,8 +14,6 @@ public class ListGenericObjects : ICollectionGenericObjects
///
private readonly List _collection;
- public CollectionType GetCollectionType => CollectionType.List;
-
///
/// Максимально допустимое число объектов в списке
///
@@ -29,6 +27,7 @@ public class ListGenericObjects : ICollectionGenericObjects
{
return Count;
}
+
set
{
if (value > 0)
@@ -38,6 +37,8 @@ public class ListGenericObjects : ICollectionGenericObjects
}
}
+ public CollectionType GetCollectionType => CollectionType.List;
+
///
/// Конструктор
///
@@ -48,39 +49,56 @@ public class ListGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+ // Проверка позиции
+ if (position >= Count || position < 0)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
return _collection[position];
}
public int Insert(T obj)
{
- if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ // Проверка, что не превышено максимальное количество элементов
+ if (Count == _maxCount)
+ {
+ throw new CollectionOverflowException(Count);
+ }
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
- if (position < 0 || position >= Count)
- throw new PositionOutOfCollectionException(position);
-
+ // Проверка, что не превышено максимальное количество элементов
if (Count == _maxCount)
+ {
throw new CollectionOverflowException(Count);
+ }
+ // Проверка позиции
+ if (position >= Count || position < 0)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
- if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
- T obj = _collection[position];
+ // Проверка позиции
+ if (position >= Count || position < 0)
+ {
+ throw new PositionOutOfCollectionException(position);
+ }
+ T? obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
public IEnumerable GetItems()
{
- for (int i = 0; i < _collection.Count; ++i)
+ for (int i = 0; i < Count; ++i)
{
yield return _collection[i];
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
index a8c2032..dd6bed4 100644
--- a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -23,6 +23,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
{
return _collection.Length;
}
+
set
{
if (value > 0)
@@ -51,36 +52,32 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
- if (_collection[position] == null) throw new ObjectNotFoundException(position);
+ // Проверка позиции
+ if (position >= _collection.Length || position < 0)
+ { return null; }
return _collection[position];
}
public int Insert(T obj)
{
- for (int i = 0; i < Count; i++)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return i;
- }
- }
- throw new CollectionOverflowException(Count);
+ // Вставка в свободное место набора
+ return Insert(obj, 0);
}
public int Insert(T obj, int position)
{
+ // Проверка позиции
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
}
+ // Проверка, что элемент массива по этой позиции пустой
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
-
+ //Свободное место после этой позиции
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
@@ -89,6 +86,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return i;
}
}
+ //Свободное место до этой позиции
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
@@ -97,18 +95,22 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return i;
}
}
-
throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
{
+ // Проверка позиции и наличия объекта
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
}
- if (_collection[position] == null) throw new ObjectNotFoundException(position);
- T obj = _collection[position];
+ if (_collection[position] == null)
+ {
+ throw new ObjectNotFoundException(position);
+ }
+ // Удаление объекта из массива
+ T? obj = _collection[position];
_collection[position] = null;
return obj;
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
index 87655b0..90922c6 100644
--- a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
@@ -51,20 +51,18 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
+ // Проверка, что name не пустой и нет в словаре записи с таким ключом
+ if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name) || collectionType == CollectionType.None)
{
return;
}
- switch (collectionType)
+ if (collectionType == CollectionType.Massive)
{
- case CollectionType.Massive:
- _storages[name] = new MassiveGenericObjects();
- break;
- case CollectionType.List:
- _storages[name] = new ListGenericObjects();
- break;
- default:
- return;
+ _storages[name] = new MassiveGenericObjects();
+ }
+ if (collectionType == CollectionType.List)
+ {
+ _storages[name] = new ListGenericObjects();
}
}
@@ -93,7 +91,10 @@ public class StorageCollection
{
return _storages[name];
}
- return null;
+ else
+ {
+ return null;
+ }
}
}
@@ -105,7 +106,7 @@ public class StorageCollection
{
if (_storages.Count == 0)
{
- throw new Exception("В хранилище отсутствуют коллекции для сохранения");
+ throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@@ -113,32 +114,33 @@ public class StorageCollection
File.Delete(filename);
}
- StringBuilder sb = new();
-
- using (StreamWriter sw = new StreamWriter(filename))
+ using (StreamWriter writer = new StreamWriter(filename))
{
- sw.WriteLine(_collectionKey.ToString());
- foreach (KeyValuePair> kvpair in _storages)
+ writer.Write(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
{
+ writer.Write(Environment.NewLine);
// не сохраняем пустые коллекции
- if (kvpair.Value.Count == 0)
+ if (value.Value.Count == 0)
+ {
continue;
- sb.Append(kvpair.Key);
- sb.Append(_separatorForKeyValue);
- sb.Append(kvpair.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
- sb.Append(kvpair.Value.MaxCount);
- sb.Append(_separatorForKeyValue);
- foreach (T? item in kvpair.Value.GetItems())
+ }
+ writer.Write(value.Key);
+ writer.Write(_separatorForKeyValue);
+ writer.Write(value.Value.GetCollectionType);
+ writer.Write(_separatorForKeyValue);
+ writer.Write(value.Value.MaxCount);
+ writer.Write(_separatorForKeyValue);
+ foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data))
+ {
continue;
- sb.Append(data);
- sb.Append(_separatorItems);
+ }
+ writer.Write(data);
+ writer.Write(_separatorItems);
}
- sw.WriteLine(sb.ToString());
- sb.Clear();
}
}
}
@@ -147,34 +149,42 @@ public class StorageCollection
/// Загрузка информации по автомобилям в хранилище из файла
///
/// Путь и имя файла
- public void LoadData(string filename)
+ public void LoadData(string filename)
{
- if (!File.Exists(filename))
+ if (!File.Exists(filename))
{
- throw new Exception("Файл не существует");
+ throw new FileNotFoundException("Файл не существует");
}
- using (StreamReader sr = new StreamReader(filename))
+ using (StreamReader read = File.OpenText(filename))
{
- string? str;
- str = sr.ReadLine();
- if (str == null || str.Length == 0)
- throw new Exception("В файле нет данных");
- if (str != _collectionKey.ToString())
- throw new Exception("В файле неверные данные");
- _storages.Clear();
- while ((str = sr.ReadLine()) != null)
+ string str = read.ReadLine();
+
+ if (str == null || str.Length == 0)
{
- string[] record = str.Split(_separatorForKeyValue);
+ throw new FormatException("В файле нет данных");
+ }
+
+ if (!str.StartsWith(_collectionKey))
+ {
+ throw new FormatException("В файле неверные данные");
+ }
+
+ _storages.Clear();
+ string strs = "";
+ while ((strs = read.ReadLine()) != null)
+ {
+ string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
{
continue;
}
+
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
if (collection == null)
{
- throw new Exception("Не удалось создать коллекцию");
+ throw new InvalidOperationException("Не удалось создать коллекцию");
}
collection.MaxCount = Convert.ToInt32(record[2]);
@@ -182,16 +192,18 @@ public class StorageCollection
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
- if (elem?.CreateDrawningB() is T boat)
+ if (elem?.CreateDrawningB() is T B)
{
try
{
- if (collection.Insert(boat) == -1)
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ if (collection.Insert(B) == -1)
+ {
+ throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
+ }
}
catch (CollectionOverflowException ex)
{
- throw new Exception("Коллекция переполнена", ex);
+ throw new CollectionOverflowException("Коллекция переполнена", ex);
}
}
}
diff --git a/laba 0/laba 0/Exceptions/CollectionOverflowException.cs b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
index 519b255..91c6417 100644
--- a/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
+++ b/laba 0/laba 0/Exceptions/CollectionOverflowException.cs
@@ -13,4 +13,4 @@ internal class CollectionOverflowException : ApplicationException
public CollectionOverflowException(string message) : base(message) { }
public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
-}
+}
\ No newline at end of file
diff --git a/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
index 25ef92b..0b83b2d 100644
--- a/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
+++ b/laba 0/laba 0/Exceptions/PositionOutOfCollectionException.cs
@@ -8,9 +8,9 @@ namespace MotorBoat.Exceptions;
[Serializable]
internal class PositionOutOfCollectionException : ApplicationException
{
- public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции.Позиция " + i) { }
+ 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) { }
-}
+}
\ No newline at end of file
diff --git a/laba 0/laba 0/FormBoatCollection.Designer.cs b/laba 0/laba 0/FormBoatCollection.Designer.cs
index 385e959..ff53c9e 100644
--- a/laba 0/laba 0/FormBoatCollection.Designer.cs
+++ b/laba 0/laba 0/FormBoatCollection.Designer.cs
@@ -116,7 +116,7 @@
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить ";
buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += buttonRefresh_Click;
+ buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonRemoveBoat
//
@@ -127,7 +127,7 @@
buttonRemoveBoat.TabIndex = 4;
buttonRemoveBoat.Text = "Удалить катер\r\n ";
buttonRemoveBoat.UseVisualStyleBackColor = true;
- buttonRemoveBoat.Click += buttonRemoveBoat_Click;
+ buttonRemoveBoat.Click += ButtonRemoveBoat_Click;
//
// buttonGoToCheck
//
@@ -138,7 +138,7 @@
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты ";
buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += buttonGoToCheck_Click;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonCreateCompany
//
@@ -148,7 +148,7 @@
buttonCreateCompany.TabIndex = 8;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
- buttonCreateCompany.Click += buttonCreateCompany_Click;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// panelStorage
//
@@ -173,7 +173,7 @@
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
- buttonCollectionDel.Click += buttonCollectionDel_Click;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
// listBoxCollection
//
@@ -192,7 +192,7 @@
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
- buttonCollectionAdd.Click += buttonCollectionAdd_Click;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
@@ -242,7 +242,7 @@
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 23);
comboBoxSelectorCompany.TabIndex = 0;
- comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
diff --git a/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs
index 15ce982..ad06912 100644
--- a/laba 0/laba 0/FormBoatCollection.cs
+++ b/laba 0/laba 0/FormBoatCollection.cs
@@ -26,14 +26,13 @@ public partial class FormBoatCollection : Form
private readonly ILogger _logger;
///
- /// Конструктор
- ///
+ /// Конструктор
+ ///
public FormBoatCollection(ILogger logger)
{
InitializeComponent();
_storageCollection = new();
_logger = logger;
- _logger.LogInformation("Форма загрузилась");
}
///
@@ -41,7 +40,7 @@ public partial class FormBoatCollection : Form
///
///
///
- private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
panelCompanyTools.Enabled = false;
}
@@ -54,24 +53,22 @@ public partial class FormBoatCollection : Form
private void buttonAddBoat_Click(object sender, EventArgs e)
{
FormBoatConfig form = new();
- // TODO передать метод
form.Show();
form.AddEvent(SetBoat);
}
- ///
- /// Добавление лодки в коллекцию
- ///
- ///
- private void SetBoat(DrawningB? b)
+ ///
+ /// Добавление лодки в коллекцию
+ ///
+ ///
+ private void SetBoat(DrawningB b)
{
- try
+ try
{
if (_company == null || b == null)
{
return;
}
-
if (_company + b != -1)
{
MessageBox.Show("Объект добавлен");
@@ -79,10 +76,9 @@ public partial class FormBoatCollection : Form
_logger.LogInformation("Добавлен объект: " + b.GetDataForSave());
}
}
- catch (ObjectNotFoundException) { }
catch (CollectionOverflowException ex)
{
- MessageBox.Show("В коллекции превышено допустимое количество элементов");
+ MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
@@ -94,30 +90,39 @@ public partial class FormBoatCollection : Form
///
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
- int pos = Convert.ToInt32(maskedTextBox.Text);
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
try
{
- if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
- {
- throw new Exception("Входные данные отсутствуют");
- }
-
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- {
- return;
- }
-
-
+ int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
- _logger.LogInformation("Объект удален");
+ _logger.LogInformation("Удаление объекта по индексу " + pos);
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ _logger.LogInformation("Не удалось удалить объект из коллекции по индексу " + pos);
}
}
- catch (Exception ex)
+ catch (ObjectNotFoundException ex)
{
- MessageBox.Show("Не найден объект по позиции " + pos);
+ MessageBox.Show(ex.Message);
+ _logger.LogError("Ошибка: {Message}", ex.Message);
+ }
+ catch (PositionOutOfCollectionException ex)
+ {
+ MessageBox.Show(ex.Message);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
@@ -133,35 +138,26 @@ public partial class FormBoatCollection : Form
{
return;
}
-
DrawningB? B = null;
int counter = 100;
- try
+ while (B == null)
{
- while (B == null)
+ B = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
{
- B = _company.GetRandomObject();
- counter--;
- if (counter <= 0)
- {
- break;
- }
+ break;
}
-
- if (B == null)
- {
- return;
- }
-
- FormBoat form = new FormBoat();
- form.SetB = B;
- form.ShowDialog();
}
- catch (Exception ex)
+ if (B == null)
{
- MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
}
-
+ FormBoat form = new()
+ {
+ SetB = B
+ };
+ form.ShowDialog();
}
///
@@ -175,7 +171,6 @@ public partial class FormBoatCollection : Form
{
return;
}
-
pictureBox.Image = _company.Show();
}
@@ -184,35 +179,27 @@ public partial class FormBoatCollection : 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);
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogInformation("Не удалось добавить коллекцию: не все данные заполнены");
return;
}
-
- try
+ CollectionType collectionType = CollectionType.None;
+ if (radioButtonMassive.Checked)
{
- CollectionType collectionType = CollectionType.None;
- if (radioButtonMassive.Checked)
- {
- collectionType = CollectionType.Massive;
- }
- else if (radioButtonList.Checked)
- {
- collectionType = CollectionType.List;
- }
-
- _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
- RefreshListBoxItems();
- _logger.LogInformation("Добавлена коллекция:", textBoxCollectionName.Text);
+ collectionType = CollectionType.Massive;
}
- catch (Exception ex)
+ else if (radioButtonList.Checked)
{
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ collectionType = CollectionType.List;
}
-
+ _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ RefreshListBoxItems();
+ _logger.LogInformation("Добавлена коллекция типа " + collectionType + " с названием "
+ + textBoxCollectionName.Text);
}
///
@@ -229,7 +216,6 @@ public partial class FormBoatCollection : Form
listBoxCollection.Items.Add(colName);
}
}
-
}
///
@@ -237,28 +223,20 @@ public partial class FormBoatCollection : Form
///
///
///
- private void buttonCollectionDel_Click(object sender, EventArgs e)
+ private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
- if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItems == null)
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
-
- try
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
- if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
- {
- return;
- }
- _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
- RefreshListBoxItems();
- _logger.LogInformation("Удалена коллекция: ", listBoxCollection.SelectedItem.ToString());
- }
- catch (Exception ex)
- {
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ return;
}
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ _logger.LogInformation("Удаление коллекции с названием {name}", listBoxCollection.SelectedItem.ToString());
+ RefreshListBoxItems();
}
///
@@ -266,28 +244,25 @@ public partial class FormBoatCollection : Form
///
///
///
- private void buttonCreateCompany_Click(object sender, EventArgs e)
+ private void ButtonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
-
ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
-
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new BoatHarbor(pictureBox.Width, pictureBox.Height, collection);
break;
}
-
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
@@ -297,7 +272,7 @@ public partial class FormBoatCollection : Form
///
///
///
- private void saveToolStripMenuItem_Click(object sender, EventArgs e)
+ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
@@ -306,14 +281,13 @@ public partial class FormBoatCollection : Form
_storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
+
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
-
-
}
}
@@ -322,7 +296,7 @@ public partial class FormBoatCollection : Form
///
///
///
- private void loadToolStripMenuItem_Click(object sender, EventArgs e)
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
@@ -335,7 +309,7 @@ public partial class FormBoatCollection : Form
}
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/laba 0/laba 0/MotorBoat.csproj b/laba 0/laba 0/MotorBoat.csproj
index 4dd00b4..6ad1d74 100644
--- a/laba 0/laba 0/MotorBoat.csproj
+++ b/laba 0/laba 0/MotorBoat.csproj
@@ -10,12 +10,11 @@
-
+
-
-
+
-
+
diff --git a/laba 0/laba 0/Program.cs b/laba 0/laba 0/Program.cs
index 4eb1bd0..9a0c6c5 100644
--- a/laba 0/laba 0/Program.cs
+++ b/laba 0/laba 0/Program.cs
@@ -35,13 +35,15 @@ namespace ProjectCatamaran
{
pathNeed += path[i] + "\\";
}
-
services.AddSingleton()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
- option.AddSerilog(new LoggerConfiguration().ReadFrom.Configuration(new ConfigurationBuilder().
- AddJsonFile($"{pathNeed}serilog.json").Build()).CreateLogger());
+ option.AddSerilog(new LoggerConfiguration()
+ .ReadFrom.Configuration(new ConfigurationBuilder()
+ .AddJsonFile($"{pathNeed}serilog.json")
+ .Build())
+ .CreateLogger());
});
}
}
diff --git a/laba 0/laba 0/serilog.json b/laba 0/laba 0/serilog.json
index fdf9719..0036428 100644
--- a/laba 0/laba 0/serilog.json
+++ b/laba 0/laba 0/serilog.json
@@ -9,7 +9,7 @@
}
],
"Properties": {
- "Applicatoin": "Sample"
+ "Application": "Sample"
}
}
}
\ No newline at end of file
--
2.25.1
From 512c6f4f03462c2acc86079f2e0986fbf47a3329 Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Wed, 15 May 2024 12:15:59 +0400
Subject: [PATCH 5/6] =?UTF-8?q?7=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D0=BF=D0=BE?=
=?UTF-8?q?=D0=BB=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 2 +-
.../CollectionGenericObjects/BoatHarbor.cs | 2 +-
laba 0/laba 0/FormBoatCollection.Designer.cs | 41 ++++++++++---------
laba 0/laba 0/FormBoatCollection.cs | 19 +++++----
laba 0/laba 0/FormBoatCollection.resx | 3 ++
5 files changed, 38 insertions(+), 29 deletions(-)
diff --git a/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
index d045b1d..fc69662 100644
--- a/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
@@ -40,7 +40,7 @@ public abstract class AbstractCompany
///
/// Вычисление максимального количества элементов, который можно разместить в окне
///
- private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+ private int GetMaxCount => (_pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight)) - 5;
///
/// Конструктор
diff --git a/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs b/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs
index 8d38026..7908088 100644
--- a/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs
@@ -38,7 +38,7 @@ public class BoatHarbor : AbstractCompany
if (_collection.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
- _collection?.Get(i)?.SetPosition(posX * _placeSizeWidth +200, posY * _placeSizeHeight + 15);
+ _collection?.Get(i)?.SetPosition(posX * _placeSizeWidth +200, posY * _placeSizeHeight + 30);
}
posX++;
diff --git a/laba 0/laba 0/FormBoatCollection.Designer.cs b/laba 0/laba 0/FormBoatCollection.Designer.cs
index ff53c9e..3a6fe36 100644
--- a/laba 0/laba 0/FormBoatCollection.Designer.cs
+++ b/laba 0/laba 0/FormBoatCollection.Designer.cs
@@ -68,7 +68,7 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(489, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(194, 497);
+ groupBoxTools.Size = new Size(194, 440);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -82,15 +82,15 @@
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(3, 278);
+ panelCompanyTools.Location = new Point(3, 265);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(188, 216);
+ panelCompanyTools.Size = new Size(188, 172);
panelCompanyTools.TabIndex = 9;
//
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBoat.Location = new Point(6, 3);
+ buttonAddBoat.Location = new Point(3, 3);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(179, 38);
buttonAddBoat.TabIndex = 1;
@@ -100,7 +100,7 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(6, 91);
+ maskedTextBox.Location = new Point(3, 47);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(173, 23);
@@ -110,7 +110,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(6, 186);
+ buttonRefresh.Location = new Point(6, 142);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(179, 27);
buttonRefresh.TabIndex = 6;
@@ -121,7 +121,7 @@
// buttonRemoveBoat
//
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveBoat.Location = new Point(6, 120);
+ buttonRemoveBoat.Location = new Point(3, 76);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(179, 27);
buttonRemoveBoat.TabIndex = 4;
@@ -132,7 +132,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(6, 153);
+ buttonGoToCheck.Location = new Point(3, 109);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(179, 27);
buttonGoToCheck.TabIndex = 5;
@@ -142,7 +142,7 @@
//
// buttonCreateCompany
//
- buttonCreateCompany.Location = new Point(3, 252);
+ buttonCreateCompany.Location = new Point(3, 242);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(188, 23);
buttonCreateCompany.TabIndex = 8;
@@ -162,12 +162,12 @@
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 19);
panelStorage.Name = "panelStorage";
- panelStorage.Size = new Size(188, 206);
+ panelStorage.Size = new Size(188, 190);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
- buttonCollectionDel.Location = new Point(3, 180);
+ buttonCollectionDel.Location = new Point(3, 165);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(182, 23);
buttonCollectionDel.TabIndex = 6;
@@ -179,14 +179,14 @@
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 15;
- listBoxCollection.Location = new Point(3, 110);
+ listBoxCollection.Location = new Point(3, 96);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(182, 64);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
- buttonCollectionAdd.Location = new Point(3, 81);
+ buttonCollectionAdd.Location = new Point(3, 70);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(182, 23);
buttonCollectionAdd.TabIndex = 4;
@@ -197,7 +197,7 @@
// radioButtonList
//
radioButtonList.AutoSize = true;
- radioButtonList.Location = new Point(97, 56);
+ radioButtonList.Location = new Point(97, 50);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(67, 19);
radioButtonList.TabIndex = 3;
@@ -208,7 +208,7 @@
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
- radioButtonMassive.Location = new Point(17, 56);
+ radioButtonMassive.Location = new Point(13, 49);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(69, 19);
radioButtonMassive.TabIndex = 2;
@@ -218,7 +218,7 @@
//
// textBoxCollectionName
//
- textBoxCollectionName.Location = new Point(3, 27);
+ textBoxCollectionName.Location = new Point(3, 22);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(182, 23);
textBoxCollectionName.TabIndex = 1;
@@ -226,11 +226,12 @@
// labelCollectionName
//
labelCollectionName.AutoSize = true;
- labelCollectionName.Location = new Point(29, 9);
+ labelCollectionName.Location = new Point(29, 5);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(135, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
+ labelCollectionName.Click += labelCollectionName_Click;
//
// comboBoxSelectorCompany
//
@@ -238,7 +239,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(3, 228);
+ comboBoxSelectorCompany.Location = new Point(3, 214);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -249,7 +250,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(489, 497);
+ pictureBox.Size = new Size(489, 440);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -298,7 +299,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(683, 521);
+ ClientSize = new Size(683, 464);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
diff --git a/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs
index ad06912..cf0adcb 100644
--- a/laba 0/laba 0/FormBoatCollection.cs
+++ b/laba 0/laba 0/FormBoatCollection.cs
@@ -63,7 +63,7 @@ public partial class FormBoatCollection : Form
///
private void SetBoat(DrawningB b)
{
- try
+ try
{
if (_company == null || b == null)
{
@@ -83,12 +83,12 @@ public partial class FormBoatCollection : Form
}
}
- ///
- /// Удаление объекта
- ///
- ///
- ///
- private void ButtonRemoveBoat_Click(object sender, EventArgs e)
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
@@ -314,4 +314,9 @@ public partial class FormBoatCollection : Form
}
}
}
+
+ private void labelCollectionName_Click(object sender, EventArgs e)
+ {
+
+ }
}
diff --git a/laba 0/laba 0/FormBoatCollection.resx b/laba 0/laba 0/FormBoatCollection.resx
index 151c7f3..b44b220 100644
--- a/laba 0/laba 0/FormBoatCollection.resx
+++ b/laba 0/laba 0/FormBoatCollection.resx
@@ -126,4 +126,7 @@
270, 17
+
+ 25
+
\ No newline at end of file
--
2.25.1
From 984640d7e2ef215e11585ad1cc89963dec4bdf51 Mon Sep 17 00:00:00 2001
From: Petek1234 <149153720+Petek1234@users.noreply.github.com>
Date: Wed, 12 Jun 2024 15:18:48 +0400
Subject: [PATCH 6/6] 777
---
laba 0/laba 0/serilog.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/laba 0/laba 0/serilog.json b/laba 0/laba 0/serilog.json
index 0036428..a68507b 100644
--- a/laba 0/laba 0/serilog.json
+++ b/laba 0/laba 0/serilog.json
@@ -4,10 +4,11 @@
"MinimumLevel": "Debug",
"WriteTo": [
{
- "Name": "File",
+ "Name": "File",
"Args": { "path": "log.log" }
}
],
+
"Properties": {
"Application": "Sample"
}
--
2.25.1