diff --git a/Trolleybus/Trolleybus/App.config b/Trolleybus/Trolleybus/App.config
index 56efbc7..3cf0b82 100644
--- a/Trolleybus/Trolleybus/App.config
+++ b/Trolleybus/Trolleybus/App.config
@@ -1,6 +1,30 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
index a5fc4fb..8eb25ac 100644
--- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
+++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Extensions.Logging;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -18,9 +19,11 @@ namespace Trolleybus
{ "Сложная карта", new AutoStopMap() },
};
private readonly MapsCollection _mapsCollection;
- public FormMapWithSetTrolleybus()
+ private readonly ILogger _logger;
+ public FormMapWithSetTrolleybus(ILogger logger)
{
InitializeComponent();
+ _logger = logger;
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
@@ -38,11 +41,6 @@ namespace Trolleybus
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
- foreach (string map in _mapsCollection.Keys)
- {
- listBoxMaps.Items.Add(map);
- }
-
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
@@ -66,6 +64,7 @@ namespace Trolleybus
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
+ _logger.LogInformation($"Добвлена карта {textBoxNewMapName.Text}");
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -131,24 +130,6 @@ namespace Trolleybus
formTrolleybusConfig.AddEvent(AddTrolleybus);
formTrolleybusConfig.Show();
- /*if (listBoxMaps.SelectedIndex == -1)
- {
- return;
- }
- Form1 form = new();
- if (form.ShowDialog() == DialogResult.OK)
- {
- DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
- }*/
}
///
/// Удаление объекта
@@ -162,15 +143,26 @@ namespace Trolleybus
{
return;
}
- int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ 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 (TrolleybusNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show($"Ошибка удаления: {ex.Message}");
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
}
}
///
@@ -235,13 +227,14 @@ namespace Trolleybus
{
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);
}
}
}
diff --git a/Trolleybus/Trolleybus/Program.cs b/Trolleybus/Trolleybus/Program.cs
index 7ada713..c54dbda 100644
--- a/Trolleybus/Trolleybus/Program.cs
+++ b/Trolleybus/Trolleybus/Program.cs
@@ -1,4 +1,7 @@
-using System;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -16,7 +19,22 @@ namespace Trolleybus
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FormMapWithSetTrolleybus());
+ 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");
+ });
}
}
}
diff --git a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
index ff6dbdf..d4317e9 100644
--- a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
+++ b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs
@@ -29,6 +29,10 @@ namespace Trolleybus
// Добавление объекта в набор
public int Insert(T trolleybus)
{
+ if (_places.Count > _maxCount)
+ {
+ return -1;
+ }
// вставка в начало набора
return Insert(trolleybus, 0);
}
diff --git a/Trolleybus/Trolleybus/StorageOverflowException.cs b/Trolleybus/Trolleybus/StorageOverflowException.cs
new file mode 100644
index 0000000..2661901
--- /dev/null
+++ b/Trolleybus/Trolleybus/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;
+using System.Windows.Forms;
+
+namespace Trolleybus
+{
+ internal class StorageOverflowException : ApplicationException
+ {
+ public StorageOverflowException() : base() { }
+ public StorageOverflowException(int count) : base($"В наборе превышино количество: {count} элементов") { }
+ public StorageOverflowException(string message) : base(message) { }
+ public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
+ protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}
diff --git a/Trolleybus/Trolleybus/Trolleybus.csproj b/Trolleybus/Trolleybus/Trolleybus.csproj
index 9ded4bf..ac636b2 100644
--- a/Trolleybus/Trolleybus/Trolleybus.csproj
+++ b/Trolleybus/Trolleybus/Trolleybus.csproj
@@ -34,8 +34,63 @@
4
+
+ ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll
+
+
+ ..\packages\Microsoft.Extensions.Configuration.Abstractions.2.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll
+
+
+ ..\packages\Microsoft.Extensions.DependencyInjection.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll
+
+
+ ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll
+
+
+ ..\packages\Microsoft.Extensions.Logging.7.0.0\lib\net462\Microsoft.Extensions.Logging.dll
+
+
+ ..\packages\Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll
+
+
+ ..\packages\Microsoft.Extensions.Options.7.0.0\lib\net462\Microsoft.Extensions.Options.dll
+
+
+ ..\packages\Microsoft.Extensions.Primitives.7.0.0\lib\net462\Microsoft.Extensions.Primitives.dll
+
+
+ ..\packages\NLog.5.1.0\lib\net46\NLog.dll
+
+
+ ..\packages\NLog.Extensions.Logging.5.2.0\lib\net461\NLog.Extensions.Logging.dll
+
+
+ ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll
+
+
+
+
+ ..\packages\System.Diagnostics.DiagnosticSource.7.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll
+
+
+
+ ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll
+
+
+
+ ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll
+
+
+ ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll
+
+
+ ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll
+
+
+ ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
+
@@ -89,7 +144,9 @@
+
+
Form1.cs
@@ -112,6 +169,10 @@
Resources.resx
True
+
+ Always
+
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs b/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs
new file mode 100644
index 0000000..02c8b43
--- /dev/null
+++ b/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Trolleybus
+{
+ internal class TrolleybusNotFoundException : ApplicationException
+ {
+ public TrolleybusNotFoundException() : base() { }
+ public TrolleybusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
+ public TrolleybusNotFoundException(string message) : base(message) { }
+ public TrolleybusNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected TrolleybusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}
diff --git a/Trolleybus/Trolleybus/nlog.config b/Trolleybus/Trolleybus/nlog.config
new file mode 100644
index 0000000..4c50da3
--- /dev/null
+++ b/Trolleybus/Trolleybus/nlog.config
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/packages.config b/Trolleybus/Trolleybus/packages.config
new file mode 100644
index 0000000..d57f47a
--- /dev/null
+++ b/Trolleybus/Trolleybus/packages.config
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file