Compare commits

..

No commits in common. "31570fb993e170e8f4ef9af0790f3289c0a5148f" and "cdaae7bc7d78dbf9313c33ce1d8920515bcd9892" have entirely different histories.

7 changed files with 91 additions and 261 deletions

View File

@ -1,6 +1,4 @@
 
using ProjectAirplaneWithRadar.Exceptions;
namespace ProjectAirplaneWithRadar.CollectionGenericObjects namespace ProjectAirplaneWithRadar.CollectionGenericObjects
{ {
/// <summary> /// <summary>
@ -50,7 +48,7 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
public T? Get(int position) public T? Get(int position)
{ {
if (position >= Count || position < 0) if (position >= Count || position < 0)
throw new PositionOutOfCollectionException(position); return null;
return _collection[position]; return _collection[position];
} }
@ -58,8 +56,7 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
public int Insert(T obj) public int Insert(T obj)
{ {
if (Count + 1 > _maxCount) if (Count + 1 > _maxCount)
throw new CollectionOverflowException(Count); return -1;
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
} }
@ -67,11 +64,9 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (Count + 1 > _maxCount) if (Count + 1 > _maxCount)
throw new CollectionOverflowException(Count); return -1;
if (position < 0 || position > Count) if (position < 0 || position > Count)
throw new PositionOutOfCollectionException(position); return -1;
_collection.Insert(position, obj); _collection.Insert(position, obj);
return 1; return 1;
} }
@ -79,7 +74,7 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
public T? Remove(int position) public T? Remove(int position)
{ {
if (position < 0 || position > Count) if (position < 0 || position > Count)
throw new PositionOutOfCollectionException(position); return null;
T? temp = _collection[position]; T? temp = _collection[position];
_collection.RemoveAt(position); _collection.RemoveAt(position);

View File

@ -1,6 +1,4 @@
 
using ProjectAirplaneWithRadar.Exceptions;
namespace ProjectAirplaneWithRadar.CollectionGenericObjects namespace ProjectAirplaneWithRadar.CollectionGenericObjects
{ {
/// <summary> /// <summary>
@ -53,11 +51,7 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
public T? Get(int position) public T? Get(int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
throw new PositionOutOfCollectionException(position); return null;
if (position >= _collection.Length && _collection[position] == null)
throw new ObjectNotFoundException(position);
return _collection[position]; return _collection[position];
} }
@ -71,13 +65,13 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
return i; return i;
} }
} }
throw new CollectionOverflowException(Count); return -1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
throw new PositionOutOfCollectionException(position); return -1;
if (_collection[position] == null) if (_collection[position] == null)
{ {
@ -106,16 +100,19 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects
} }
temp--; temp--;
} }
throw new CollectionOverflowException(Count);
return -1;
} }
public T? Remove(int position) public T? Remove(int position)
{ {
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
throw new PositionOutOfCollectionException(position); return null;
if (_collection[position] == null) if (_collection[position] == null)
throw new ObjectNotFoundException(position); {
return null;
}
T? temp = _collection[position]; T? temp = _collection[position];
_collection[position] = null; _collection[position] = null;

View File

@ -66,11 +66,9 @@
groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(855, 30); groupBoxTools.Location = new Point(883, 24);
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Padding = new Padding(3, 4, 3, 4); groupBoxTools.Size = new Size(206, 583);
groupBoxTools.Size = new Size(235, 779);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -84,19 +82,17 @@
panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false; panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 526); panelCompanyTools.Location = new Point(3, 393);
panelCompanyTools.Margin = new Padding(3, 4, 3, 4);
panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(229, 249); panelCompanyTools.Size = new Size(200, 187);
panelCompanyTools.TabIndex = 8; panelCompanyTools.TabIndex = 8;
// //
// buttonAddAirplane // buttonAddAirplane
// //
buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirplane.Location = new Point(0, 4); buttonAddAirplane.Location = new Point(0, 3);
buttonAddAirplane.Margin = new Padding(3, 4, 3, 4);
buttonAddAirplane.Name = "buttonAddAirplane"; buttonAddAirplane.Name = "buttonAddAirplane";
buttonAddAirplane.Size = new Size(111, 75); buttonAddAirplane.Size = new Size(97, 56);
buttonAddAirplane.TabIndex = 1; buttonAddAirplane.TabIndex = 1;
buttonAddAirplane.Text = "Добавить самолет"; buttonAddAirplane.Text = "Добавить самолет";
buttonAddAirplane.UseVisualStyleBackColor = true; buttonAddAirplane.UseVisualStyleBackColor = true;
@ -104,21 +100,19 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
maskedTextBoxPosition.Location = new Point(0, 108); maskedTextBoxPosition.Location = new Point(0, 81);
maskedTextBoxPosition.Margin = new Padding(3, 4, 3, 4);
maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(89, 27); maskedTextBoxPosition.Size = new Size(78, 23);
maskedTextBoxPosition.TabIndex = 3; maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int); maskedTextBoxPosition.ValidatingType = typeof(int);
// //
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(118, 164); buttonRefresh.Location = new Point(103, 123);
buttonRefresh.Margin = new Padding(3, 4, 3, 4);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(111, 75); buttonRefresh.Size = new Size(97, 56);
buttonRefresh.TabIndex = 6; buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить"; buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
@ -127,10 +121,9 @@
// buttonRemoveAirplane // buttonRemoveAirplane
// //
buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveAirplane.Location = new Point(118, 93); buttonRemoveAirplane.Location = new Point(103, 70);
buttonRemoveAirplane.Margin = new Padding(3, 4, 3, 4);
buttonRemoveAirplane.Name = "buttonRemoveAirplane"; buttonRemoveAirplane.Name = "buttonRemoveAirplane";
buttonRemoveAirplane.Size = new Size(111, 57); buttonRemoveAirplane.Size = new Size(97, 43);
buttonRemoveAirplane.TabIndex = 4; buttonRemoveAirplane.TabIndex = 4;
buttonRemoveAirplane.Text = "Удалить самолет"; buttonRemoveAirplane.Text = "Удалить самолет";
buttonRemoveAirplane.UseVisualStyleBackColor = true; buttonRemoveAirplane.UseVisualStyleBackColor = true;
@ -139,10 +132,9 @@
// buttonGoToCheck // buttonGoToCheck
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(0, 164); buttonGoToCheck.Location = new Point(0, 123);
buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(111, 75); buttonGoToCheck.Size = new Size(97, 56);
buttonGoToCheck.TabIndex = 5; buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true; buttonGoToCheck.UseVisualStyleBackColor = true;
@ -150,10 +142,9 @@
// //
// buttonCreateCompany // buttonCreateCompany
// //
buttonCreateCompany.Location = new Point(7, 407); buttonCreateCompany.Location = new Point(6, 305);
buttonCreateCompany.Margin = new Padding(3, 4, 3, 4);
buttonCreateCompany.Name = "buttonCreateCompany"; buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(222, 31); buttonCreateCompany.Size = new Size(194, 23);
buttonCreateCompany.TabIndex = 7; buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true; buttonCreateCompany.UseVisualStyleBackColor = true;
@ -169,18 +160,16 @@
panelStorage.Controls.Add(textBoxCollectionName); panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Controls.Add(labelCollectionName); panelStorage.Controls.Add(labelCollectionName);
panelStorage.Dock = DockStyle.Top; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 24); panelStorage.Location = new Point(3, 19);
panelStorage.Margin = new Padding(3, 4, 3, 4);
panelStorage.Name = "panelStorage"; panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(229, 335); panelStorage.Size = new Size(200, 251);
panelStorage.TabIndex = 7; panelStorage.TabIndex = 7;
// //
// buttonCollectionDel // buttonCollectionDel
// //
buttonCollectionDel.Location = new Point(3, 295); buttonCollectionDel.Location = new Point(3, 221);
buttonCollectionDel.Margin = new Padding(3, 4, 3, 4);
buttonCollectionDel.Name = "buttonCollectionDel"; buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(222, 31); buttonCollectionDel.Size = new Size(194, 23);
buttonCollectionDel.TabIndex = 6; buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true; buttonCollectionDel.UseVisualStyleBackColor = true;
@ -189,18 +178,17 @@
// listBoxCollection // listBoxCollection
// //
listBoxCollection.FormattingEnabled = true; listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(3, 161); listBoxCollection.ItemHeight = 15;
listBoxCollection.Margin = new Padding(3, 4, 3, 4); listBoxCollection.Location = new Point(3, 121);
listBoxCollection.Name = "listBoxCollection"; listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(221, 124); listBoxCollection.Size = new Size(194, 94);
listBoxCollection.TabIndex = 5; listBoxCollection.TabIndex = 5;
// //
// buttonCollectionAdd // buttonCollectionAdd
// //
buttonCollectionAdd.Location = new Point(3, 109); buttonCollectionAdd.Location = new Point(3, 82);
buttonCollectionAdd.Margin = new Padding(3, 4, 3, 4);
buttonCollectionAdd.Name = "buttonCollectionAdd"; buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(222, 31); buttonCollectionAdd.Size = new Size(194, 23);
buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true; buttonCollectionAdd.UseVisualStyleBackColor = true;
@ -209,10 +197,9 @@
// radioButtonList // radioButtonList
// //
radioButtonList.AutoSize = true; radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(121, 76); radioButtonList.Location = new Point(106, 57);
radioButtonList.Margin = new Padding(3, 4, 3, 4);
radioButtonList.Name = "radioButtonList"; radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24); radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3; radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true; radioButtonList.TabStop = true;
radioButtonList.Text = "Список"; radioButtonList.Text = "Список";
@ -221,10 +208,9 @@
// radioButtonMassive // radioButtonMassive
// //
radioButtonMassive.AutoSize = true; radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(31, 76); radioButtonMassive.Location = new Point(27, 57);
radioButtonMassive.Margin = new Padding(3, 4, 3, 4);
radioButtonMassive.Name = "radioButtonMassive"; radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(82, 24); radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2; radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true; radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив"; radioButtonMassive.Text = "Массив";
@ -232,18 +218,17 @@
// //
// textBoxCollectionName // textBoxCollectionName
// //
textBoxCollectionName.Location = new Point(3, 37); textBoxCollectionName.Location = new Point(3, 28);
textBoxCollectionName.Margin = new Padding(3, 4, 3, 4);
textBoxCollectionName.Name = "textBoxCollectionName"; textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(221, 27); textBoxCollectionName.Size = new Size(194, 23);
textBoxCollectionName.TabIndex = 1; textBoxCollectionName.TabIndex = 1;
// //
// labelCollectionName // labelCollectionName
// //
labelCollectionName.AutoSize = true; labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(43, 13); labelCollectionName.Location = new Point(38, 10);
labelCollectionName.Name = "labelCollectionName"; labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(158, 20); labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0; labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:"; labelCollectionName.Text = "Название коллекции:";
// //
@ -253,31 +238,27 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(7, 368); comboBoxSelectorCompany.Location = new Point(6, 276);
comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(221, 28); comboBoxSelectorCompany.Size = new Size(194, 23);
comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 30); pictureBox.Location = new Point(0, 24);
pictureBox.Margin = new Padding(3, 4, 3, 4);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(855, 779); pictureBox.Size = new Size(883, 583);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// menuStrip // menuStrip
// //
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(7, 3, 0, 3); menuStrip.Size = new Size(1089, 24);
menuStrip.Size = new Size(1090, 30);
menuStrip.TabIndex = 2; menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip"; menuStrip.Text = "menuStrip";
// //
@ -285,14 +266,14 @@
// //
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem"; файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(59, 24); файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл"; файлToolStripMenuItem.Text = "Файл";
// //
// saveToolStripMenuItem // saveToolStripMenuItem
// //
saveToolStripMenuItem.Name = "saveToolStripMenuItem"; saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(227, 26); saveToolStripMenuItem.Size = new Size(181, 22);
saveToolStripMenuItem.Text = "Сохранение"; saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
// //
@ -300,7 +281,7 @@
// //
loadToolStripMenuItem.Name = "loadToolStripMenuItem"; loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(227, 26); loadToolStripMenuItem.Size = new Size(181, 22);
loadToolStripMenuItem.Text = "Загрузка"; loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
// //
@ -314,14 +295,13 @@
// //
// FormAirplaneCollection // FormAirplaneCollection
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1090, 809); ClientSize = new Size(1089, 607);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip); Controls.Add(menuStrip);
MainMenuStrip = menuStrip; MainMenuStrip = menuStrip;
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirplaneCollection"; Name = "FormAirplaneCollection";
Text = "Коллекция самолетов"; Text = "Коллекция самолетов";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);

View File

@ -1,8 +1,5 @@
using System.Numerics; using ProjectAirplaneWithRadar.CollectionGenericObjects;
using Microsoft.Extensions.Logging;
using ProjectAirplaneWithRadar.CollectionGenericObjects;
using ProjectAirplaneWithRadar.Drawnings; using ProjectAirplaneWithRadar.Drawnings;
using ProjectAirplaneWithRadar.Exceptions;
namespace ProjectAirplaneWithRadar namespace ProjectAirplaneWithRadar
{ {
@ -21,20 +18,13 @@ namespace ProjectAirplaneWithRadar
/// </summary> /// </summary>
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormAirplaneCollection(ILogger<FormAirplaneCollection> logger) public FormAirplaneCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new(); _storageCollection = new();
_logger = logger;
_logger.LogInformation("Форма загрузилась");
} }
/// <summary> /// <summary>
@ -66,26 +56,18 @@ namespace ProjectAirplaneWithRadar
private void SetAirplane(DrawningAirplane airplane) private void SetAirplane(DrawningAirplane airplane)
{ {
if (_company == null || airplane == null) if (_company == null || airplane == null)
{
return; return;
}
try if (_company + airplane != -1)
{ {
if (_company + airplane != -1) MessageBox.Show("Объект добавлен");
{ pictureBox.Image = _company.Show();
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
_logger.LogInformation("Добавлен объект: " + airplane.GetDataForSave());
}
} }
catch (CollectionOverflowException ex) else
{ {
MessageBox.Show(ex.Message); MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
catch (ObjectNotFoundException ex)
{
MessageBox.Show(ex.Message);
_logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
@ -107,23 +89,14 @@ namespace ProjectAirplaneWithRadar
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
try
{ {
if (_company - pos != null) MessageBox.Show("Объект удален");
{ pictureBox.Image = _company.Show();
MessageBox.Show("Объект удален"); }
pictureBox.Image = _company.Show(); else
_logger.LogInformation("Удален объект по позиции " + pos);
}
} catch (PositionOutOfCollectionException ex)
{ {
MessageBox.Show(ex.Message); MessageBox.Show("Не удалось удалить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
} catch (ObjectNotFoundException ex)
{
MessageBox.Show(ex.Message);
_logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
@ -143,22 +116,11 @@ namespace ProjectAirplaneWithRadar
int counter = 100; int counter = 100;
while (plane == null) while (plane == null)
{ {
try plane = _company.GetRandomObject();
counter--;
if (counter <= 0)
{ {
plane = _company.GetRandomObject(); break;
counter--;
if (counter <= 0)
{
break;
}
}
catch (PositionOutOfCollectionException ex)
{
MessageBox.Show(ex.Message);
}
catch (ObjectNotFoundException ex)
{
MessageBox.Show(ex.Message);
} }
} }
@ -202,34 +164,14 @@ namespace ProjectAirplaneWithRadar
return; return;
} }
//CollectionType collectionType = CollectionType.None; CollectionType collectionType = CollectionType.None;
//if (radioButtonMassive.Checked) if (radioButtonMassive.Checked)
// collectionType = CollectionType.Massive; collectionType = CollectionType.Massive;
//else if (radioButtonList.Checked) else if (radioButtonList.Checked)
// collectionType = CollectionType.List; collectionType = CollectionType.List;
//_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
//RefreshListBoxItems(); RefreshListBoxItems();
try
{
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);
}
catch (Exception ex)
{
_logger.LogError("Ошибка: {Message}", ex.Message);
}
} }
/// <summary> /// <summary>
@ -244,28 +186,13 @@ namespace ProjectAirplaneWithRadar
MessageBox.Show("Коллекция не выбрана"); MessageBox.Show("Коллекция не выбрана");
return; return;
} }
//if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
//{
// return;
//}
//_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
//RefreshListBoxItems();
try
{ {
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
{
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();
} }
/// <summary> /// <summary>
@ -326,12 +253,10 @@ namespace ProjectAirplaneWithRadar
{ {
_storageCollection.SaveData(saveFileDialog.FileName); _storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
} }
catch(Exception ex) catch(Exception ex)
{ {
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
} }
@ -350,12 +275,10 @@ namespace ProjectAirplaneWithRadar
_storageCollection.LoadData(openFileDialog.FileName); _storageCollection.LoadData(openFileDialog.FileName);
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RefreshListBoxItems(); RefreshListBoxItems();
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
} }
catch(Exception ex) catch(Exception ex)
{ {
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
} }

View File

@ -1,8 +1,3 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
namespace ProjectAirplaneWithRadar namespace ProjectAirplaneWithRadar
{ {
internal static class Program internal static class Program
@ -16,33 +11,7 @@ namespace ProjectAirplaneWithRadar
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
ServiceCollection services = new(); Application.Run(new FormAirplaneCollection());
ConfigureServices(services);
using ServiceProvider serviceProvider = services.BuildServiceProvider();
Application.Run(serviceProvider.GetRequiredService<FormAirplaneCollection>());
} }
/// <summary>
/// Êîíôèãóðàöèÿ ñåðâèñà DI
/// </summary>
/// <param name="services"></param>
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<FormAirplaneCollection>()
.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder().AddJsonFile($"{pathNeed}serilog.json").Build()).CreateLogger());
});
}
} }
} }

View File

@ -8,19 +8,6 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
@ -36,10 +23,4 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="serilog.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,15 +0,0 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": { "path": "log.log" }
}
],
"Properties": {
"Application": "Sample"
}
}
}