Завершённая лабораторная работа №07
This commit is contained in:
parent
5066020b8a
commit
04c5f77319
4
Project_airbus/.editorconfig
Normal file
4
Project_airbus/.editorconfig
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[*.cs]
|
||||||
|
|
||||||
|
# IDE0022: Использовать тело блока для метода
|
||||||
|
csharp_style_expression_bodied_methods = false
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34024.191
|
VisualStudioVersion = 17.7.34024.191
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Project_airbus", "Project_airbus\Project_airbus.csproj", "{FC3C3CBD-935E-443F-81BB-982419FEA510}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Project_airbus", "Project_airbus\Project_airbus.csproj", "{FC3C3CBD-935E-443F-81BB-982419FEA510}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -91,10 +91,14 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
SetObjectsPosition();
|
SetObjectsPosition();
|
||||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
DrawingAirplan? obj = _collection?.Get(i);
|
DrawingAirplan? obj = _collection?.Get(i);
|
||||||
obj?.DrawTransport(graphics);
|
obj?.DrawTransport(graphics);
|
||||||
}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,12 @@ public class AirplanSharingService : AbstractCompany
|
|||||||
|
|
||||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||||
{
|
{
|
||||||
if (_collection?.Get(i) != null)
|
try
|
||||||
{
|
{
|
||||||
_collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
_collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
_collection.Get(i)?.SetPosition(_placeSizeWidth * AirplanWidth + 20, AirplanHeight * _placeSizeHeight + 20);
|
_collection.Get(i)?.SetPosition(_placeSizeWidth * AirplanWidth + 20, AirplanHeight * _placeSizeHeight +20);
|
||||||
}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
|
||||||
if (AirplanWidth < width - 1)
|
if (AirplanWidth < width - 1)
|
||||||
AirplanWidth++;
|
AirplanWidth++;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Project_airbus.CollectionGenericObjects;
|
using Project_airbus.Exceptions;
|
||||||
|
|
||||||
|
namespace Project_airbus.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
@ -44,30 +46,30 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection = new();
|
_collection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0) return null;
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount) return -1;
|
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount) return -1;
|
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||||
if (position >= Count || position < 0) return -1;
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= _collection.Count || position < 0) return null;
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
T obj = _collection[position];
|
T obj = _collection[position];
|
||||||
_collection.RemoveAt(position);
|
_collection.RemoveAt(position);
|
||||||
return obj;
|
return obj;
|
||||||
@ -80,5 +82,4 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace Project_airbus.CollectionGenericObjects;
|
using Project_airbus.Exceptions;
|
||||||
|
|
||||||
|
namespace Project_airbus.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
@ -48,7 +50,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= _collection.Length || position < 0) return null;
|
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +67,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return -1;
|
throw new CollectionOverflowException(Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (position >= _collection.Length || position < 0) return -1;
|
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
|
||||||
if (_collection[position] == null)
|
if (_collection[position] == null)
|
||||||
{
|
{
|
||||||
@ -96,12 +99,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
return -1;
|
throw new CollectionOverflowException(Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= _collection.Length || position < 0) return null;
|
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
T? removeObj = _collection[position];
|
T? removeObj = _collection[position];
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return removeObj;
|
return removeObj;
|
||||||
@ -114,6 +118,4 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Project_airbus.Drawings;
|
using Project_airbus.Drawings;
|
||||||
|
using Project_airbus.Exceptions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Project_airbus.CollectionGenericObjects;
|
namespace Project_airbus.CollectionGenericObjects;
|
||||||
@ -88,12 +89,11 @@ public class StorageCollection<T>
|
|||||||
/// Сохранение информации по автомобилям в хранилище в файл
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
public void SaveData(string filename)
|
||||||
public bool SaveData(string filename)
|
|
||||||
{
|
{
|
||||||
if (_storages.Count == 0)
|
if (_storages.Count == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("В хранилище отсутствуют коллекции для сохранения");
|
||||||
}
|
}
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -131,30 +131,28 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузка информации по автомобилям в хранилище из файла
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
public void LoadData(string filename)
|
||||||
public bool LoadData(string filename)
|
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Файл не существует");
|
||||||
}
|
}
|
||||||
using (StreamReader fs = File.OpenText(filename))
|
using (StreamReader fs = File.OpenText(filename))
|
||||||
{
|
{
|
||||||
string str = fs.ReadLine();
|
string str = fs.ReadLine();
|
||||||
if (str == null || str.Length == 0)
|
if (str == null || str.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("В файле нет данных");
|
||||||
}
|
}
|
||||||
if (!str.StartsWith(_collectionKey))
|
if (!str.StartsWith(_collectionKey))
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("В файле неверные данные");
|
||||||
}
|
}
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
string strs = "";
|
string strs = "";
|
||||||
@ -169,23 +167,29 @@ public class StorageCollection<T>
|
|||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||||
}
|
}
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
{
|
||||||
if (elem?. CreateDrawingAirplan() is T ship)
|
if (elem?.CreateDrawingAirplan() is T airplan)
|
||||||
{
|
{
|
||||||
if (collection.Insert(ship) == -1)
|
try
|
||||||
{
|
{
|
||||||
return false;
|
if (collection.Insert(airplan) == -1)
|
||||||
|
{
|
||||||
|
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CollectionOverflowException ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Коллекция переполнена", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(record[0], collection);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Project_airbus.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку переполнения коллекции
|
||||||
|
/// </summary>
|
||||||
|
[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) { }
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Project_airbus.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку, что по указанной позиции нет элемента
|
||||||
|
/// </summary>
|
||||||
|
[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) { }
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Project_airbus.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку выхода за границы коллекции
|
||||||
|
/// </summary>
|
||||||
|
[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) { }
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
using Project_airbus.CollectionGenericObjects;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Project_airbus.CollectionGenericObjects;
|
||||||
using Project_airbus.Drawings;
|
using Project_airbus.Drawings;
|
||||||
|
using Project_airbus.Exceptions;
|
||||||
|
|
||||||
namespace Project_airbus;
|
namespace Project_airbus;
|
||||||
|
|
||||||
@ -18,13 +20,20 @@ public partial class FormAirplanCollection : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractCompany? _company = null;
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Логер
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormAirplanCollection()
|
public FormAirplanCollection(ILogger<FormAirplanCollection> logger)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_storageCollection = new();
|
_storageCollection = new();
|
||||||
|
_logger = logger;
|
||||||
|
_logger.LogInformation("Форма загрузилась");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -50,21 +59,31 @@ public partial class FormAirplanCollection : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void SetAirplan(DrawingAirplan? airplan)
|
private void SetAirplan(DrawingAirplan? airplan)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (_company == null || airplan == null)
|
if (_company == null || airplan == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + airplan != -1)
|
if (_company + airplan < 32)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
|
_logger.LogInformation("Добавлен объект: " + airplan.GetDataForSave());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ObjectNotFoundException) { }
|
||||||
|
catch (CollectionOverflowException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта
|
/// Удаление объекта
|
||||||
@ -77,21 +96,24 @@ public partial class FormAirplanCollection : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
try
|
||||||
|
{
|
||||||
if (_company - pos != null)
|
if (_company - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
|
_logger.LogInformation("Удален объект по позиции " + pos);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +131,8 @@ public partial class FormAirplanCollection : Form
|
|||||||
|
|
||||||
DrawingAirplan? airplan = null;
|
DrawingAirplan? airplan = null;
|
||||||
int counter = 100;
|
int counter = 100;
|
||||||
|
try
|
||||||
|
{
|
||||||
while (airplan == null)
|
while (airplan == null)
|
||||||
{
|
{
|
||||||
airplan = _company.GetRandomObject();
|
airplan = _company.GetRandomObject();
|
||||||
@ -118,17 +142,16 @@ public partial class FormAirplanCollection : Form
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airplan == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FormAirbus form = new()
|
FormAirbus form = new()
|
||||||
{
|
{
|
||||||
SetAirplan = airplan
|
SetAirplan = airplan
|
||||||
};
|
};
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,10 +196,13 @@ public partial class FormAirplanCollection : Form
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
CollectionType collectionType = CollectionType.None;
|
CollectionType collectionType = CollectionType.None;
|
||||||
if (radioButtonMassive.Checked)
|
if (radioButtonMassive.Checked)
|
||||||
{
|
{
|
||||||
@ -186,9 +212,14 @@ public partial class FormAirplanCollection : Form
|
|||||||
{
|
{
|
||||||
collectionType = CollectionType.List;
|
collectionType = CollectionType.List;
|
||||||
}
|
}
|
||||||
|
|
||||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
|
_logger.LogInformation("Коллекция добавлена " + textBoxCollectionName.Text);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -202,12 +233,21 @@ public partial class FormAirplanCollection : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
|
_logger.LogInformation("Коллекция: " + listBoxCollection.SelectedItem.ToString() + " удалена");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -222,21 +262,19 @@ public partial class FormAirplanCollection : Form
|
|||||||
MessageBox.Show("Коллекция не выбрана");
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ICollectionGenericObjects<DrawingAirplan>? collection =
|
||||||
ICollectionGenericObjects<DrawingAirplan>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Коллекция не проинициализирована");
|
MessageBox.Show("Коллекция не проинициализирована");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (comboBoxSelectorCompany.Text)
|
switch (comboBoxSelectorCompany.Text)
|
||||||
{
|
{
|
||||||
case "Хранилище":
|
case "Хранилище":
|
||||||
_company = new AirplanSharingService(pictureBox.Width, pictureBox.Height, collection);
|
_company = new AirplanSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
panelCompanyTools.Enabled = true;
|
panelCompanyTools.Enabled = true;
|
||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
}
|
}
|
||||||
@ -250,13 +288,16 @@ public partial class FormAirplanCollection : Form
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,16 +312,18 @@ public partial class FormAirplanCollection : Form
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storageCollection.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
MessageBox.Show("Загрузка прошла успешно",
|
_storageCollection.LoadData(openFileDialog.FileName);
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
|
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не сохранилось", "Результат",
|
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Project_airbus
|
namespace Project_airbus
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -11,7 +16,31 @@ namespace Project_airbus
|
|||||||
// 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();
|
||||||
Application.Run(new FormAirplanCollection());
|
|
||||||
|
ServiceCollection services = new();
|
||||||
|
ConfigureServices(services);
|
||||||
|
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(serviceProvider.GetRequiredService<FormAirplanCollection>());
|
||||||
|
}
|
||||||
|
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<FormAirplanCollection>()
|
||||||
|
.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.AddJsonFile($"{pathNeed}Serillog.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,10 +9,43 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="GradientColorPicker" Version="1.0.0" />
|
<None Remove="jsconfig.json" />
|
||||||
|
<None Remove="jsconfig1.json" />
|
||||||
|
<None Remove="Serilog.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="GradientColorPicker" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="NuGet.Configuration" Version="6.9.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File.Header" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.NUnit" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Stashbox" Version="5.14.1" />
|
||||||
|
<PackageReference Include="Stashbox.Extensions.DependencyInjection" Version="5.5.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Program.cs">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Compile>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
|
15
Project_airbus/Project_airbus/Serillog.json
Normal file
15
Project_airbus/Project_airbus/Serillog.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": { "path": "log.log" }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "Sample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
Project_airbus/Project_airbus/Serilog.json
Normal file
16
Project_airbus/Project_airbus/Serilog.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "log.txt" }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "Sample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
Project_airbus/Project_airbus/jsconfig.json
Normal file
15
Project_airbus/Project_airbus/jsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"jsconfig": {
|
||||||
|
"Using": [ "jsconfig.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": { "path": "log.log" }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Properties": {
|
||||||
|
"Application": "Sample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
Project_airbus/Project_airbus/jsconfig1.json
Normal file
10
Project_airbus/Project_airbus/jsconfig1.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"exclude": [
|
||||||
|
"**/bin",
|
||||||
|
"**/bower_components",
|
||||||
|
"**/jspm_packages",
|
||||||
|
"**/node_modules",
|
||||||
|
"**/obj",
|
||||||
|
"**/platforms"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user