diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs
index ae11658..4fbb3ae 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs
@@ -59,8 +59,8 @@
// maskedTextBoxNumber
//
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBoxNumber.Location = new Point(38, 532);
- maskedTextBoxNumber.Mask = "0";
+ maskedTextBoxNumber.Location = new Point(38, 342);
+ maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(156, 27);
maskedTextBoxNumber.TabIndex = 4;
@@ -69,9 +69,9 @@
//
ButtonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonRefreshCollection.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point);
- ButtonRefreshCollection.Location = new Point(45, 663);
+ ButtonRefreshCollection.Location = new Point(38, 412);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
- ButtonRefreshCollection.Size = new Size(150, 41);
+ ButtonRefreshCollection.Size = new Size(150, 29);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = "Обновить все";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
@@ -80,9 +80,9 @@
//
ButtonRemoveLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonRemoveLocomotive.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point);
- ButtonRemoveLocomotive.Location = new Point(45, 590);
+ ButtonRemoveLocomotive.Location = new Point(37, 375);
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
- ButtonRemoveLocomotive.Size = new Size(150, 44);
+ ButtonRemoveLocomotive.Size = new Size(150, 31);
ButtonRemoveLocomotive.TabIndex = 1;
ButtonRemoveLocomotive.Text = "Удалить локо";
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
@@ -92,9 +92,9 @@
//
ButtonAddLocomotive.Anchor = AnchorStyles.Top;
ButtonAddLocomotive.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point);
- ButtonAddLocomotive.Location = new Point(42, 461);
+ ButtonAddLocomotive.Location = new Point(38, 306);
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
- ButtonAddLocomotive.Size = new Size(150, 39);
+ ButtonAddLocomotive.Size = new Size(150, 30);
ButtonAddLocomotive.TabIndex = 0;
ButtonAddLocomotive.Text = "Добавить локо";
ButtonAddLocomotive.UseVisualStyleBackColor = true;
@@ -103,15 +103,15 @@
// pictureBoxCollections
//
pictureBoxCollections.Anchor = AnchorStyles.Left;
- pictureBoxCollections.Location = new Point(-1, 27);
+ pictureBoxCollections.Location = new Point(-1, 31);
pictureBoxCollections.Name = "pictureBoxCollections";
- pictureBoxCollections.Size = new Size(1104, 692);
+ pictureBoxCollections.Size = new Size(303, 409);
pictureBoxCollections.TabIndex = 1;
pictureBoxCollections.TabStop = false;
//
// textBoxStorageName
//
- textBoxStorageName.Location = new Point(31, 43);
+ textBoxStorageName.Location = new Point(31, 28);
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
textBoxStorageName.Name = "textBoxStorageName";
textBoxStorageName.Size = new Size(149, 27);
@@ -119,6 +119,7 @@
//
// groupBox1
//
+ groupBox1.Anchor = AnchorStyles.None;
groupBox1.Controls.Add(listBoxStorage);
groupBox1.Controls.Add(ButtonAddObject);
groupBox1.Controls.Add(ButtonRemoveObject);
@@ -127,7 +128,7 @@
groupBox1.Margin = new Padding(3, 4, 3, 4);
groupBox1.Name = "groupBox1";
groupBox1.Padding = new Padding(3, 4, 3, 4);
- groupBox1.Size = new Size(216, 395);
+ groupBox1.Size = new Size(216, 270);
groupBox1.TabIndex = 5;
groupBox1.TabStop = false;
groupBox1.Text = "Наборы";
@@ -136,7 +137,7 @@
//
listBoxStorage.FormattingEnabled = true;
listBoxStorage.ItemHeight = 20;
- listBoxStorage.Location = new Point(31, 163);
+ listBoxStorage.Location = new Point(31, 97);
listBoxStorage.Margin = new Padding(3, 4, 3, 4);
listBoxStorage.Name = "listBoxStorage";
listBoxStorage.Size = new Size(149, 124);
@@ -147,9 +148,9 @@
//
ButtonAddObject.Anchor = AnchorStyles.Top;
ButtonAddObject.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point);
- ButtonAddObject.Location = new Point(31, 96);
+ ButtonAddObject.Location = new Point(31, 62);
ButtonAddObject.Name = "ButtonAddObject";
- ButtonAddObject.Size = new Size(150, 39);
+ ButtonAddObject.Size = new Size(149, 28);
ButtonAddObject.TabIndex = 7;
ButtonAddObject.Text = "Добавить набор";
ButtonAddObject.UseVisualStyleBackColor = true;
@@ -159,9 +160,9 @@
//
ButtonRemoveObject.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
ButtonRemoveObject.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point);
- ButtonRemoveObject.Location = new Point(31, 325);
+ ButtonRemoveObject.Location = new Point(31, 228);
ButtonRemoveObject.Name = "ButtonRemoveObject";
- ButtonRemoveObject.Size = new Size(150, 44);
+ ButtonRemoveObject.Size = new Size(149, 31);
ButtonRemoveObject.TabIndex = 8;
ButtonRemoveObject.Text = "Удалить набор";
ButtonRemoveObject.UseVisualStyleBackColor = true;
@@ -175,11 +176,11 @@
Instruments.Controls.Add(maskedTextBoxNumber);
Instruments.Controls.Add(ButtonAddLocomotive);
Instruments.Controls.Add(ButtonRemoveLocomotive);
- Instruments.Location = new Point(1102, 0);
+ Instruments.Location = new Point(302, -1);
Instruments.Margin = new Padding(3, 4, 3, 4);
Instruments.Name = "Instruments";
Instruments.Padding = new Padding(3, 4, 3, 4);
- Instruments.Size = new Size(236, 719);
+ Instruments.Size = new Size(236, 448);
Instruments.TabIndex = 6;
Instruments.TabStop = false;
Instruments.Text = "Инструменты";
@@ -190,7 +191,7 @@
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
- menuStrip1.Size = new Size(1338, 28);
+ menuStrip1.Size = new Size(538, 28);
menuStrip1.TabIndex = 7;
menuStrip1.Text = "menuStrip1";
//
@@ -228,7 +229,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1338, 724);
+ ClientSize = new Size(538, 443);
Controls.Add(Instruments);
Controls.Add(pictureBoxCollections);
Controls.Add(menuStrip1);
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs
index d2a4f71..1332dc1 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs
@@ -1,7 +1,9 @@
-using ElectricLocomotive;
+using Microsoft.Extensions.Logging;
+//using ElectricLocomotive;
using ProjectElectricLocomotive.DrawingObjects;
+using ProjectElectricLocomotive.Exceptions;
using ProjectElectricLocomotive.Generics;
-using ProjectElectricLocomotive.MovementStrategy;
+/*using ProjectElectricLocomotive.MovementStrategy;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -9,7 +11,7 @@ using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+using System.Threading.Tasks;*/
using System.Windows.Forms;
@@ -18,10 +20,15 @@ namespace ProjectElectricLocomotive
public partial class FormLocomotiveCollections : Form
{
private readonly LocomotiveGenericStorage _storage;
- public FormLocomotiveCollections()
+ ///
+ /// Логер
+ ///
+ private readonly ILogger _logger;
+ public FormLocomotiveCollections(ILogger logger)
{
InitializeComponent();
_storage = new LocomotiveGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
+ _logger = logger;
}
///
@@ -51,10 +58,13 @@ namespace ProjectElectricLocomotive
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ _logger.LogWarning("Неудачная попытка. Коллекция не добавлена, не все данные заполнены");
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
+
+ _logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
}
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
@@ -68,12 +78,15 @@ namespace ProjectElectricLocomotive
{
return;
}
+ string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
- _storage.DelSet(listBoxStorage.SelectedItem.ToString() ?? string.Empty);
+ _storage.DelSet(name);
ReloadObjects();
+ _logger.LogInformation($"Набор '{name}' удален");
}
+ _logger.LogWarning("Отмена удаления набора");
}
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
@@ -95,17 +108,25 @@ namespace ProjectElectricLocomotive
{
return;
}
-
+ try
+ {
+ if (obj + loco > -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollections.Image = obj.ShowLocomotives();
+ _logger.LogInformation($"Добавлен объект {obj}");
+; }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ catch (StorageOverflowException ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
//проверяем, удалось ли нам загрузить объект
- if (obj + loco > -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBoxCollections.Image = obj.ShowLocomotives();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
+
}
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
@@ -119,17 +140,28 @@ namespace ProjectElectricLocomotive
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
+ _logger.LogWarning("Отмена удаления объекта");
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
- if (obj - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBoxCollections.Image = obj.ShowLocomotives();
+ var removeObj = obj - pos;
+ if (removeObj != null)
+ {
+ MessageBox.Show("Объект удален");
+ _logger.LogInformation($"Удален объект с позиции{pos}");
+ pictureBoxCollections.Image = obj.ShowLocomotives();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
}
- else
+ catch (LocoNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show(ex.Message);
+ _logger.LogWarning($"Не найден объект по позиции: {obj}");
}
}
@@ -152,15 +184,15 @@ namespace ProjectElectricLocomotive
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storage.SaveData(saveFileDialog.FileName))
+ try
{
- MessageBox.Show("Сохранение прошло успешно",
- "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _storage.SaveData(saveFileDialog.FileName);
+ _logger.LogInformation($"Данные загружены в файл {saveFileDialog.FileName}");
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Не сохранилось", "Результат",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}");
}
}
}
@@ -172,17 +204,18 @@ namespace ProjectElectricLocomotive
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
// TODO продумать логику
- if(openFileDialog.ShowDialog() == DialogResult.OK)
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
{
- if (_storage.LoadData(openFileDialog.FileName))
+ try
{
- MessageBox.Show("Load is done!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _storage.LoadData(openFileDialog.FileName);
+ _logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
ReloadObjects();
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("Load is fail!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
-
+ MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ _logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}");
}
}
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx
index f2c8442..3d78e27 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx
@@ -133,6 +133,6 @@
615, 17
- 84
+ 25
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoNotFoundException.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoNotFoundException.cs
new file mode 100644
index 0000000..b2a0ec9
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoNotFoundException.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.Exceptions
+{
+ [Serializable]
+
+ internal class LocoNotFoundException : ApplicationException
+ {
+ public LocoNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
+ public LocoNotFoundException() : base() { }
+ public LocoNotFoundException(string message) : base(message) { }
+ public LocoNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected LocoNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs
index fcbb498..70aea37 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs
@@ -51,10 +51,7 @@ namespace ProjectElectricLocomotive.Generics
public static T? operator -(LocomotiveGenericCollection collect, int pos)
{
T? obj = collect._collection[pos];
- if (obj != null)
- {
- collect._collection.Remove(pos);
- }
+ collect._collection.Remove(pos);
return obj;
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs
index 100df98..e137d59 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs
@@ -10,6 +10,8 @@ namespace ProjectElectricLocomotive.Generics
{
internal class LocomotiveGenericStorage
{
+
+ //create lab 7
///
/// Словарь (хранилище)
///
@@ -97,7 +99,7 @@ namespace ProjectElectricLocomotive.Generics
///
/// Путь и имя файла
/// true - сохранение прошло успешно, false - ошибка при сохранении данных
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (File.Exists(filename))
{
@@ -115,25 +117,25 @@ namespace ProjectElectricLocomotive.Generics
}
if (data.Length == 0)
{
- return false;
+ throw new Exception("Нет данных для записи, ошибка");
}
using StreamWriter fs = new StreamWriter(filename);
{
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
fs.WriteLine(data);
}
- return true;
+ return;
}
///
/// Загрузка информации по автомобилям в хранилище из файла
///
/// Путь и имя файла
/// true - загрузка прошла успешно, false - ошибка при загрузке данных
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new FileNotFoundException("Файл не найден");
}
using (StreamReader fs = File.OpenText(filename))
@@ -143,13 +145,13 @@ namespace ProjectElectricLocomotive.Generics
if (str == null || str.Length == 0)
{
- return false;
+ throw new IOException("Нет данных для загрузки");
}
if (!str.StartsWith("LocomotiveStorage"))
{
//если нет такой записи, то это не те данные
- return false;
+ throw new FileFormatException("Неверный формат данных");
}
_locomotivesStorage.Clear();
@@ -161,7 +163,7 @@ namespace ProjectElectricLocomotive.Generics
if (strs == null)
{
- return false;
+ throw new FileNotFoundException("Нет данных для загрузки");
}
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
@@ -178,13 +180,13 @@ namespace ProjectElectricLocomotive.Generics
{
if ((collection + loco) == -1) // for my realization it's -1, for eegov's realization it's boolean
{
- return false;
+ throw new Exception("Ошибка добавления ");
}
}
}
_locomotivesStorage.Add(record[0], collection);
}
- return true;
+ return;
}
}
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
index 0dccc49..fa42fd5 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/Program.cs
@@ -1,11 +1,14 @@
-using ProjectElectricLocomotive;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Serilog;
-namespace ElectricLocomotive
+namespace ProjectElectricLocomotive
{
internal static class Program
{
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
@@ -13,7 +16,30 @@ namespace ElectricLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormLocomotiveCollections());
+ 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 =>
+ {
+ var configuration = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile(path: "C:\\Users\\katri\\OneDrive\\ \\ \\\\PIbd-21_Bakalskaya_E.D._ElectricLocomotive._BASE\\ProjectElectricLocomotive\\ProjectElectricLocomotive\\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/ProjectElectricLocomotive/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj b/ProjectElectricLocomotive/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj
index 13ee123..2a73900 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj
@@ -8,6 +8,29 @@
enable
+
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
True
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs
index 026eba2..ef88ca7 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs
@@ -1,4 +1,5 @@
-using System;
+using ProjectElectricLocomotive.Exceptions;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,8 +10,8 @@ namespace ProjectElectricLocomotive.Generics
internal class SetGeneric where T : class
{
- private readonly List _places;
-
+ private readonly List _places;
+
public int Count => _places.Count;
/// Максимальное количество объектов в списке
@@ -29,17 +30,26 @@ namespace ProjectElectricLocomotive.Generics
public int Insert(T loco, int position)
{
- if (position < 0 || position >= _maxCount) return -1;
+ if(_places.Count >= _maxCount)
+ throw new StorageOverflowException(_maxCount);
+
+ if (position < 0 || position >= _maxCount)
+ {
+ return -1;
+ }
+
_places.Insert(position, loco);
return position;
}
public T? Remove(int position)
{
- if (position >= Count || position < 0)
+ if (position >= Count || position < 0)
return null;
T? tmp = _places[position];
+ if (tmp == null)
+ throw new LocoNotFoundException(position);
_places[position] = null;
return tmp;
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/StorageOverflowException.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/StorageOverflowException.cs
new file mode 100644
index 0000000..98ccf57
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/StorageOverflowException.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive
+{
+ [Serializable]
+ internal class StorageOverflowException : ApplicationException
+ {
+ public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
+ public StorageOverflowException() : base() { }
+ public StorageOverflowException(string message) : base(message) { }
+ public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
+ protected StorageOverflowException(SerializationInfo info,
+ StreamingContext contex) : base(info, contex) { }
+ }
+}
+
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/appSettings.json b/ProjectElectricLocomotive/ProjectElectricLocomotive/appSettings.json
new file mode 100644
index 0000000..f98af6a
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/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": "Locomotives"
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/nlog.config b/ProjectElectricLocomotive/ProjectElectricLocomotive/nlog.config
new file mode 100644
index 0000000..cca6f0f
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/nlog.config
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+