From 62a9296290b20eb92aa1e8352e77ef1c37229bb8 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 20:09:04 +0400
Subject: [PATCH 01/15] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?=
=?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?=
=?UTF-8?q?=D0=BD=D0=B8=D0=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Boats/Boats/BoatNotFoundException.cs | 19 +++++++++++++
Boats/Boats/FormMapWithSetBoats.cs | 37 +++++++++++++++++--------
Boats/Boats/MapWithSetBoatsGeneric.cs | 3 +-
Boats/Boats/MapsCollection.cs | 10 +++----
Boats/Boats/SetBoatsGeneric.cs | 9 ++++--
Boats/Boats/StorageOverflowException.cs | 19 +++++++++++++
6 files changed, 75 insertions(+), 22 deletions(-)
create mode 100644 Boats/Boats/BoatNotFoundException.cs
create mode 100644 Boats/Boats/StorageOverflowException.cs
diff --git a/Boats/Boats/BoatNotFoundException.cs b/Boats/Boats/BoatNotFoundException.cs
new file mode 100644
index 0000000..5465af8
--- /dev/null
+++ b/Boats/Boats/BoatNotFoundException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Boats
+{
+ [Serializable]
+ internal class BoatNotFoundException : ApplicationException
+ {
+ public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
+ public BoatNotFoundException() : base() { }
+ public BoatNotFoundException(string message) : base(message) { }
+ public BoatNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected BoatNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 908f95c..5c4fb06 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -124,16 +124,27 @@ namespace Boats
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- pos -= 1;
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
}
- else
+ catch (BoatNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
+ }
+
}
///
/// Вывод набора
@@ -270,13 +281,14 @@ namespace Boats
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_mapsCollection.SaveData(saveFileDialog.FileName))
+ try
{
+ _mapsCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@@ -289,15 +301,16 @@ namespace Boats
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_mapsCollection.LoadData(openFileDialog.FileName))
+ try
{
+ _mapsCollection.LoadData(openFileDialog.FileName);
ReloadMaps();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
diff --git a/Boats/Boats/MapWithSetBoatsGeneric.cs b/Boats/Boats/MapWithSetBoatsGeneric.cs
index 9c989cd..9d7e474 100644
--- a/Boats/Boats/MapWithSetBoatsGeneric.cs
+++ b/Boats/Boats/MapWithSetBoatsGeneric.cs
@@ -91,6 +91,7 @@ namespace Boats
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics g = Graphics.FromImage(bmp);
DrawBackground(g);
+ Shaking();
DrawBoats(g);
return bmp;
}
@@ -135,8 +136,8 @@ namespace Boats
var boat = _setBoats[j];
if (boat != null)
{
+ boat = _setBoats.Remove(j);
_setBoats.Insert(boat, i);
- _setBoats.Remove(j);
break;
}
}
diff --git a/Boats/Boats/MapsCollection.cs b/Boats/Boats/MapsCollection.cs
index d818b99..b9c40b4 100644
--- a/Boats/Boats/MapsCollection.cs
+++ b/Boats/Boats/MapsCollection.cs
@@ -93,7 +93,7 @@ namespace Boats
///
/// Путь и имя файла
///
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (File.Exists(filename))
{
@@ -107,18 +107,17 @@ namespace Boats
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
}
}
- return true;
}
///
/// Загрузка нформации по лодкам в гавани из файла
///
///
///
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new Exception("Файл не найден");
}
using (StreamReader sr = File.OpenText(filename))
{
@@ -126,7 +125,7 @@ namespace Boats
if (currentLine == null || !currentLine.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
- return false;
+ throw new Exception("Формат данных в файле не правильный");
}
//очищаем записи
_mapStorages.Clear();
@@ -156,7 +155,6 @@ namespace Boats
currentLine = sr.ReadLine();
}
}
- return true;
}
}
}
diff --git a/Boats/Boats/SetBoatsGeneric.cs b/Boats/Boats/SetBoatsGeneric.cs
index 4097ce3..c1d5002 100644
--- a/Boats/Boats/SetBoatsGeneric.cs
+++ b/Boats/Boats/SetBoatsGeneric.cs
@@ -42,8 +42,9 @@ namespace Boats
public int Insert(T boat)
{
// Проверка на _maxCount
+ // Если достигли максимального значения - выбрасываем исключение
if (Count == _maxCount)
- return -1;
+ throw new StorageOverflowException(_maxCount);
// Вставка в начало набора
return Insert(boat, 0);
}
@@ -69,9 +70,11 @@ namespace Boats
public T Remove(int position)
{
// Проверка позиции
- if (Count == 0 || position < 0 || position >= _maxCount)
- return null;
+ // Если позиция уже пустая выбрасываем исключение
+ if (Count == 0 || position < 0 || position >= _maxCount || _places[position] == null)
+ throw new BoatNotFoundException(position);
T boat = _places[position];
+
_places[position] = null;
return boat;
}
diff --git a/Boats/Boats/StorageOverflowException.cs b/Boats/Boats/StorageOverflowException.cs
new file mode 100644
index 0000000..0eac646
--- /dev/null
+++ b/Boats/Boats/StorageOverflowException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Boats
+{
+ [Serializable]
+ internal class StorageOverflowException : ApplicationException
+ {
+ public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
+ public StorageOverflowException() : base() { }
+ public StorageOverflowException(string message) : base(message) { }
+ public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
+ protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}
--
2.25.1
From 3a6d87df272b7b2583dc586c103bbe6f2b056dc0 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 20:57:51 +0400
Subject: [PATCH 02/15] fixed bug with Remove
---
Boats/Boats/MapWithSetBoatsGeneric.cs | 3 +--
Boats/Boats/SetBoatsGeneric.cs | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/Boats/Boats/MapWithSetBoatsGeneric.cs b/Boats/Boats/MapWithSetBoatsGeneric.cs
index 9d7e474..9c989cd 100644
--- a/Boats/Boats/MapWithSetBoatsGeneric.cs
+++ b/Boats/Boats/MapWithSetBoatsGeneric.cs
@@ -91,7 +91,6 @@ namespace Boats
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics g = Graphics.FromImage(bmp);
DrawBackground(g);
- Shaking();
DrawBoats(g);
return bmp;
}
@@ -136,8 +135,8 @@ namespace Boats
var boat = _setBoats[j];
if (boat != null)
{
- boat = _setBoats.Remove(j);
_setBoats.Insert(boat, i);
+ _setBoats.Remove(j);
break;
}
}
diff --git a/Boats/Boats/SetBoatsGeneric.cs b/Boats/Boats/SetBoatsGeneric.cs
index c1d5002..5f92cb4 100644
--- a/Boats/Boats/SetBoatsGeneric.cs
+++ b/Boats/Boats/SetBoatsGeneric.cs
@@ -74,8 +74,7 @@ namespace Boats
if (Count == 0 || position < 0 || position >= _maxCount || _places[position] == null)
throw new BoatNotFoundException(position);
T boat = _places[position];
-
- _places[position] = null;
+ _places.RemoveAt(position);
return boat;
}
public T this[int position]
--
2.25.1
From 38732f72cf3baafdceac96a866628289ce608cba Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 22:27:34 +0400
Subject: [PATCH 03/15] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8=D1=80?=
=?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20nlog?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Boats/Boats/Boats.csproj | 18 ++++++++++++++++++
Boats/Boats/FormMapWithSetBoats.cs | 8 ++++++--
Boats/Boats/Program.cs | 20 +++++++++++++++++++-
Boats/Boats/nlog.config | 13 +++++++++++++
4 files changed, 56 insertions(+), 3 deletions(-)
create mode 100644 Boats/Boats/nlog.config
diff --git a/Boats/Boats/Boats.csproj b/Boats/Boats/Boats.csproj
index 13ee123..3eb1f1d 100644
--- a/Boats/Boats/Boats.csproj
+++ b/Boats/Boats/Boats.csproj
@@ -8,6 +8,24 @@
enable
+
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
+
True
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 5c4fb06..5a9cf3c 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Extensions.Logging;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -25,6 +26,7 @@ namespace Boats
/// Объект от коллекции карт
///
private readonly MapsCollection _mapsCollection;
+ private readonly ILogger _logger;
///
/// Объект от класса карты с набором объектов
///
@@ -32,9 +34,10 @@ namespace Boats
///
/// Конструктор
///
- public FormMapWithSetBoats()
+ public FormMapWithSetBoats(ILogger logger)
{
InitializeComponent();
+ _logger = logger;
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
ComboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
@@ -223,6 +226,7 @@ namespace Boats
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[ComboBoxSelectorMap.Text]);
ReloadMaps();
+ _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
}
///
/// Удаление карты
diff --git a/Boats/Boats/Program.cs b/Boats/Boats/Program.cs
index 91dda50..d6eed69 100644
--- a/Boats/Boats/Program.cs
+++ b/Boats/Boats/Program.cs
@@ -1,3 +1,7 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace Boats
{
internal static class Program
@@ -11,7 +15,21 @@ namespace Boats
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMapWithSetBoats());
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ using (ServiceProvider serviceProvider = services.BuildServiceProvider())
+ {
+ Application.Run(serviceProvider.GetRequiredService());
+ }
+ }
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddSingleton()
+ .AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
}
}
}
\ No newline at end of file
diff --git a/Boats/Boats/nlog.config b/Boats/Boats/nlog.config
new file mode 100644
index 0000000..9338255
--- /dev/null
+++ b/Boats/Boats/nlog.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
2.25.1
From 3d397d9854533afce1c2c9a61a77d78f9a700c24 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 22:38:07 +0400
Subject: [PATCH 04/15] =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B5?=
=?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20=D0=BE?=
=?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B2=20=D0=BC=D0=B5=D1=82?=
=?UTF-8?q?=D0=BE=D0=B4=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?=
=?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Boats/Boats/MapsCollection.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Boats/Boats/MapsCollection.cs b/Boats/Boats/MapsCollection.cs
index b9c40b4..3516a03 100644
--- a/Boats/Boats/MapsCollection.cs
+++ b/Boats/Boats/MapsCollection.cs
@@ -117,7 +117,7 @@ namespace Boats
{
if (!File.Exists(filename))
{
- throw new Exception("Файл не найден");
+ throw new FileNotFoundException("Файл не найден");
}
using (StreamReader sr = File.OpenText(filename))
{
@@ -125,7 +125,7 @@ namespace Boats
if (currentLine == null || !currentLine.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
- throw new Exception("Формат данных в файле не правильный");
+ throw new FileFormatException("Формат данных в файле не правильный");
}
//очищаем записи
_mapStorages.Clear();
--
2.25.1
From 697a62d101bb0a36f6916f2e6abc9fa9bdc6b891 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 22:56:53 +0400
Subject: [PATCH 05/15] AddBoat logging
---
Boats/Boats/FormMapWithSetBoats.cs | 31 ++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 5a9cf3c..7469531 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -261,19 +261,30 @@ namespace Boats
///
private void AddBoatListener(DrawingBoat drawingBoat)
{
- if (listBoxMaps.SelectedIndex == -1)
+ try
{
- return;
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
+ DrawingObjectBoat boat = new(drawingBoat);
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ _logger.LogInformation($"Добавлен объект {drawingBoat.GetType().Name}");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ _logger.LogInformation("Не удалось добавить объект");
+ }
}
- DrawingObjectBoat boat = new(drawingBoat);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
+ catch (StorageOverflowException ex)
{
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
+ _logger.LogWarning($"Ошибка переполнения хранилища: {ex.Message}");
+ MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}",
+ "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
///
--
2.25.1
From c7c82416051cb4c6c6e7aea73355e8aec702b9fc Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 22:59:39 +0400
Subject: [PATCH 06/15] SaveToolStripMenuItem_Click logging
---
Boats/Boats/FormMapWithSetBoats.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 7469531..8d2c566 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -299,11 +299,13 @@ namespace Boats
try
{
_mapsCollection.SaveData(saveFileDialog.FileName);
+ _logger.LogInformation($"Сохранение прошло успешно. Файл: {saveFileDialog.FileName}");
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogWarning($"Не удалось сохранить файл '{saveFileDialog.FileName}'. Ошибка: {ex.Message}");
}
}
}
--
2.25.1
From fd8617cbf0f18ced042e10174d91b819e731bec7 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:01:25 +0400
Subject: [PATCH 07/15] LoadToolStripMenuItem_Click logging
---
Boats/Boats/FormMapWithSetBoats.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 8d2c566..805dbed 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -324,10 +324,12 @@ namespace Boats
ReloadMaps();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _logger.LogInformation($"Открытие файла '{openFileDialog.FileName}' прошло успешно");
}
catch (Exception ex)
{
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogWarning($"Не удалось открыть файл {openFileDialog.FileName}. Ошибка: {ex.Message}");
}
}
}
--
2.25.1
From 271840c48e47c8c02fc6de08a6b1668fd9238182 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:04:33 +0400
Subject: [PATCH 08/15] ButtonDeleteMap_Click logging
---
Boats/Boats/FormMapWithSetBoats.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 805dbed..27b40ca 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -147,7 +147,6 @@ namespace Boats
{
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
}
-
}
///
/// Вывод набора
@@ -243,6 +242,7 @@ namespace Boats
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
+ _logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString() ?? ""}");
ReloadMaps();
}
}
--
2.25.1
From 8659337eb5f2447c69323ae1bd1167d849b45613 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:05:56 +0400
Subject: [PATCH 09/15] listBoxMaps_SelectedIndexChanged logging
---
Boats/Boats/FormMapWithSetBoats.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 27b40ca..072b2fe 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -254,6 +254,7 @@ namespace Boats
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ _logger.LogInformation($"Переход на карту: {listBoxMaps.SelectedItem?.ToString() ?? ""}");
}
///
/// Listener для добавления новой лодки из формы
--
2.25.1
From 57dab5fc828488e9c7d709e903fc252ba8281ff8 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:13:28 +0400
Subject: [PATCH 10/15] ButtonRemoveBoat_Click logging
---
Boats/Boats/FormMapWithSetBoats.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index 072b2fe..edd0c3e 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -129,13 +129,16 @@ namespace Boats
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try
{
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ var deletedBoat = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
+ if (deletedBoat != null)
{
MessageBox.Show("Объект удален");
+ _logger.LogInformation($"Удален объект {deletedBoat.GetType().Name}");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
+ _logger.LogInformation($"Не удалось удалить объект по позиции {pos}: объект равен null");
MessageBox.Show("Не удалось удалить объект");
}
}
--
2.25.1
From aaf1b043b7f3864dee1b398df7a80c709d63bcd2 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:44:01 +0400
Subject: [PATCH 11/15] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?=
=?UTF-8?q?=D0=BB=D0=B0=D0=BB=20=D0=BD=D0=B0=20Serilog?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Boats/Boats/Boats.csproj | 11 +++++++++--
Boats/Boats/Program.cs | 23 +++++++++++++++++------
Boats/Boats/appSettings.json | 20 ++++++++++++++++++++
Boats/Boats/nlog.config | 13 -------------
4 files changed, 46 insertions(+), 21 deletions(-)
create mode 100644 Boats/Boats/appSettings.json
delete mode 100644 Boats/Boats/nlog.config
diff --git a/Boats/Boats/Boats.csproj b/Boats/Boats/Boats.csproj
index 3eb1f1d..d95bdec 100644
--- a/Boats/Boats/Boats.csproj
+++ b/Boats/Boats/Boats.csproj
@@ -9,21 +9,26 @@
-
+
-
+
Always
+
+
+
+
+
@@ -41,4 +46,6 @@
+
+
\ No newline at end of file
diff --git a/Boats/Boats/Program.cs b/Boats/Boats/Program.cs
index d6eed69..e0412dc 100644
--- a/Boats/Boats/Program.cs
+++ b/Boats/Boats/Program.cs
@@ -1,6 +1,8 @@
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using Serilog;
+using Serilog.Extensions.Logging;
namespace Boats
{
@@ -25,11 +27,20 @@ namespace Boats
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: "appSettings.json", 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/Boats/Boats/appSettings.json b/Boats/Boats/appSettings.json
new file mode 100644
index 0000000..d4831c9
--- /dev/null
+++ b/Boats/Boats/appSettings.json
@@ -0,0 +1,20 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Information",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "log_.log",
+ "rollingInterval": "Day",
+ "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
+ }
+ }
+ ],
+ "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
+ "Properties": {
+ "Application": "Boats"
+ }
+ }
+}
\ No newline at end of file
diff --git a/Boats/Boats/nlog.config b/Boats/Boats/nlog.config
deleted file mode 100644
index 9338255..0000000
--- a/Boats/Boats/nlog.config
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
2.25.1
From f41bd15744499300b3c606c2db02617e53444ca3 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Sun, 27 Nov 2022 21:41:07 +0400
Subject: [PATCH 12/15] fixed Remove at SetBoatsGeneric
---
Boats/Boats/SetBoatsGeneric.cs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Boats/Boats/SetBoatsGeneric.cs b/Boats/Boats/SetBoatsGeneric.cs
index 5f92cb4..5def12b 100644
--- a/Boats/Boats/SetBoatsGeneric.cs
+++ b/Boats/Boats/SetBoatsGeneric.cs
@@ -70,8 +70,9 @@ namespace Boats
public T Remove(int position)
{
// Проверка позиции
- // Если позиция уже пустая выбрасываем исключение
- if (Count == 0 || position < 0 || position >= _maxCount || _places[position] == null)
+ // Если позиция неверная (пустой быть не может, потому что у нас список),
+ // то выбрасываем исключение
+ if (position < 0 || position >= Count)
throw new BoatNotFoundException(position);
T boat = _places[position];
_places.RemoveAt(position);
--
2.25.1
From 6ddf4f9380e68d208d9ba1360138d1aac78bfb49 Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Tue, 29 Nov 2022 08:56:13 +0400
Subject: [PATCH 13/15] fixed varname in MapWithSetBoatsGeneric.GetData
---
Boats/Boats/MapWithSetBoatsGeneric.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Boats/Boats/MapWithSetBoatsGeneric.cs b/Boats/Boats/MapWithSetBoatsGeneric.cs
index 9c989cd..7e330a4 100644
--- a/Boats/Boats/MapWithSetBoatsGeneric.cs
+++ b/Boats/Boats/MapWithSetBoatsGeneric.cs
@@ -247,9 +247,9 @@ namespace Boats
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
- foreach (var car in _setBoats.GetBoats())
+ foreach (var boat in _setBoats.GetBoats())
{
- data += $"{car.GetInfo()}{separatorData}";
+ data += $"{boat.GetInfo()}{separatorData}";
}
return data;
}
--
2.25.1
From 7d27bcd94f6f0ae502f5aafe44ce67fb1444e4bd Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Tue, 29 Nov 2022 09:32:03 +0400
Subject: [PATCH 14/15] added warn log with remove empty pos error
---
Boats/Boats/FormMapWithSetBoats.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Boats/Boats/FormMapWithSetBoats.cs b/Boats/Boats/FormMapWithSetBoats.cs
index edd0c3e..213d5f8 100644
--- a/Boats/Boats/FormMapWithSetBoats.cs
+++ b/Boats/Boats/FormMapWithSetBoats.cs
@@ -144,6 +144,7 @@ namespace Boats
}
catch (BoatNotFoundException ex)
{
+ _logger.LogWarning($"Ошибка удаления объекта: {ex.Message}");
MessageBox.Show($"Ошибка удаления: {ex.Message}");
}
catch (Exception ex)
--
2.25.1
From 681b60f6a6beefa8a5be3177a40847e1003ae45c Mon Sep 17 00:00:00 2001
From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com>
Date: Wed, 30 Nov 2022 08:37:17 +0400
Subject: [PATCH 15/15] fixed varname in ExtentionBoat.GetDataForSave
---
Boats/Boats/ExtentionBoat.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Boats/Boats/ExtentionBoat.cs b/Boats/Boats/ExtentionBoat.cs
index 091d411..08d009c 100644
--- a/Boats/Boats/ExtentionBoat.cs
+++ b/Boats/Boats/ExtentionBoat.cs
@@ -51,9 +51,9 @@ namespace Boats
///
public static string GetDataForSave(this DrawingBoat drawingBoat)
{
- var car = drawingBoat.Boat;
- var str = $"{car.Speed}{_separatorForObject}{car.Weight}{_separatorForObject}{car.BodyColor.Name}";
- if (car is not EntityCatamaran catamaran)
+ var boat = drawingBoat.Boat;
+ var str = $"{boat.Speed}{_separatorForObject}{boat.Weight}{_separatorForObject}{boat.BodyColor.Name}";
+ if (boat is not EntityCatamaran catamaran)
{
return str;
}
--
2.25.1