Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db711f274e | |||
| dda318fce5 |
@@ -1,5 +1,4 @@
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -54,7 +53,7 @@ public abstract class AbstractCompany
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.MaxCount = GetMaxCount;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,18 +64,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningMachine machine)
|
||||
{
|
||||
try
|
||||
{
|
||||
return company._collection.Insert(machine, 0, new DrawningMachineEqutables());
|
||||
}
|
||||
catch (ObjectAlreadyInCollectionException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
catch (CollectionOverflowException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return company._collection.Insert(machine, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,21 +87,14 @@ public abstract class AbstractCompany
|
||||
public DrawningMachine? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
try
|
||||
{
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
catch (ObjectNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
@@ -122,26 +103,13 @@ public abstract class AbstractCompany
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
DrawningMachine? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (ObjectNotFoundException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
DrawningMachine? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningMachine?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -42,28 +41,21 @@ public class Autopark : AbstractCompany
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
try
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
if (_collection?.Get(i) != null)
|
||||
{
|
||||
int x = 5 + _placeSizeWidth * n;
|
||||
int y = (-3 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
|
||||
int x = 5 + _placeSizeWidth * n;
|
||||
int y = (-3 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
|
||||
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(x, y);
|
||||
}
|
||||
|
||||
if (n < _pictureWidth / _placeSizeWidth)
|
||||
n++;
|
||||
else
|
||||
{
|
||||
n = 0;
|
||||
m++;
|
||||
}
|
||||
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i)?.SetPosition(x, y);
|
||||
}
|
||||
catch (ObjectNotFoundException)
|
||||
|
||||
if (n < _pictureWidth / _placeSizeWidth)
|
||||
n++;
|
||||
else
|
||||
{
|
||||
break;
|
||||
n = 0;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, хранящиий информацию по коллекции
|
||||
/// </summary>
|
||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип
|
||||
/// </summary>
|
||||
public CollectionType CollectionType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Описание
|
||||
/// </summary>
|
||||
public string Description { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly string _separator = "-";
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="name">Название</param>
|
||||
/// <param name="collectionType">Тип</param>
|
||||
/// <param name="description">Описание</param>
|
||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||
{
|
||||
Name = name;
|
||||
CollectionType = collectionType;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="data">Строка</param>
|
||||
/// <returns>Объект или null</returns>
|
||||
public static CollectionInfo? GetCollectionInfo(string data)
|
||||
{
|
||||
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs.Length < 1 || strs.Length > 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]),
|
||||
strs.Length > 2 ? strs[2] : string.Empty);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name + _separator + CollectionType + _separator + Description;
|
||||
}
|
||||
|
||||
public bool Equals(CollectionInfo? other)
|
||||
{
|
||||
return Name == other?.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as CollectionInfo);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
namespace ProjectGasMachine;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
@@ -22,24 +21,22 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int MaxCount { get; set; }
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="comparer">Сравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <param name="comparer">Сравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@@ -54,21 +51,4 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа коллекции
|
||||
/// </summary>
|
||||
CollectionType GetCollectionType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции по одному
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@@ -24,10 +19,7 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int MaxCount { get { return _collection.Count; } set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@@ -39,52 +31,30 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы списка
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO выброс ошибки, если переполнение
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_collection.Add(obj);
|
||||
return _collection.Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы списка
|
||||
// TODO выброс ошибки, если переполнение
|
||||
if (comparer != null)
|
||||
if (Count == _maxCount || position < 0 || position > Count)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
@@ -93,10 +63,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы списка
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
T? obj = _collection[position];
|
||||
@@ -104,17 +73,4 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@@ -19,13 +15,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int MaxCount
|
||||
public int SetMaxCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _collection.Length;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
@@ -42,8 +33,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
@@ -54,36 +43,17 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы массива
|
||||
// TODO выброс ошибки, если объект пустой
|
||||
if (position < 0 || position >= Count)
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return null;
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new ObjectNotFoundException(position);
|
||||
}
|
||||
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO выброс ошибки, если переполнение
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningMachine>).Equals(obj as DrawningMachine, item as DrawningMachine))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO вставка в свободное место набора
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
@@ -92,28 +62,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CollectionOverflowException(Count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы массива
|
||||
// TODO выброс ошибки, если переполнение
|
||||
if (comparer != null)
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningMachine>).Equals(obj as DrawningMachine, item as DrawningMachine))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
@@ -127,7 +82,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,42 +91,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CollectionOverflowException(Count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы массива
|
||||
// TODO выброс ошибки, если объект пустой
|
||||
if (position < 0 || position >= Count)
|
||||
if (position < 0 || position > Count || _collection[position] == null)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new ObjectNotFoundException(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
T? obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Length; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,28 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// класс-хранилище
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class StorageCollection<T>
|
||||
where T : DrawningMachine
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
private Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
/// </summary>
|
||||
private readonly string _collectionKey = "CollectionsStorage";
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private readonly string _separatorForKeyValue = "|";
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly string _separatorItems = ";";
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,21 +30,21 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(CollectionInfo info)
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (info == null || _storages.ContainsKey(info))
|
||||
if (name == null || _storages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.CollectionType == CollectionType.Massive)
|
||||
if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(info, new MassiveGenericObjects<T>());
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
}
|
||||
|
||||
if (info.CollectionType == CollectionType.List)
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(info, new ListGenericObjects<T>());
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,14 +52,14 @@ public class StorageCollection<T>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void DelCollection(CollectionInfo info)
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (info == null || !_storages.ContainsKey(info))
|
||||
if (name == null || !_storages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storages.Remove(info);
|
||||
_storages.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,150 +67,17 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[CollectionInfo info]
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storages.ContainsKey(info))
|
||||
if (_storages.ContainsKey(name))
|
||||
{
|
||||
return _storages[info];
|
||||
return _storages[name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
throw new NullReferenceException("В хранилище отсутствуют коллекции для сохранения");
|
||||
}
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
|
||||
using (StreamWriter sw = new StreamWriter(filename))
|
||||
{
|
||||
sw.Write(_collectionKey);
|
||||
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
sw.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sw.Write(value.Key);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Value.MaxCount);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
{
|
||||
string data = item?.GetDataForSave() ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sw.Write(data);
|
||||
sw.Write(_separatorItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не существует");
|
||||
}
|
||||
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
|
||||
if (line == null || line.Length == 0)
|
||||
{
|
||||
throw new FileFormatException("В файле нет данных");
|
||||
}
|
||||
if (!line.Equals(_collectionKey))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new FileFormatException("В файле неверные данные");
|
||||
}
|
||||
_storages.Clear();
|
||||
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
throw new Exception("Не удалось создать коллекцию");
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawningMachine() is T machine)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(machine, new DrawningMachineEqutables()) == -1)
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
{
|
||||
throw new OverflowException("Коллекция переполнена", ex);
|
||||
}
|
||||
catch (ObjectAlreadyInCollectionException ex)
|
||||
{
|
||||
throw new InvalidOperationException("Объект уже присутствует в коллекции", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание коллекции по типу
|
||||
/// </summary>
|
||||
/// <param name="collectionType"></param>
|
||||
/// <returns></returns>
|
||||
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||
{
|
||||
return collectionType switch
|
||||
{
|
||||
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
||||
CollectionType.List => new ListGenericObjects<T>(),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,15 +23,6 @@ public class DrawningGasMachine : DrawningMachine
|
||||
EntityGas = new EntityMachine(speed, weight, bodyColor, additionalColor, gas, beacon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для класса Extention
|
||||
/// </summary>
|
||||
/// <param name="gasmachine"></param>
|
||||
public DrawningGasMachine(EntityGas? gasmachine) : base(gasmachine)
|
||||
{
|
||||
EntityGas = gasmachine;
|
||||
}
|
||||
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
|
||||
@@ -97,18 +97,6 @@ public class DrawningMachine
|
||||
_drawningMachineWidth = drawningMachineWidth;
|
||||
_pictureHeight = drawningMachineHeight;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для класса Extention
|
||||
/// </summary>
|
||||
/// <param name="machine"></param>
|
||||
public DrawningMachine(EntityGas? machine) : this()
|
||||
{
|
||||
EntityGas = machine;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using ProjectGasMachine.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
|
||||
public class DrawningMachineCompareByColor : IComparer<DrawningMachine?>
|
||||
{
|
||||
public int Compare(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodyColorCompare = y.EntityGas.BodyColor.Name.CompareTo(x.EntityGas.BodyColor.Name);
|
||||
if (bodyColorCompare != 0)
|
||||
{
|
||||
return bodyColorCompare;
|
||||
}
|
||||
if (x is DrawningGasMachine && y is DrawningGasMachine)
|
||||
{
|
||||
var additionalColorCompare = (y.EntityGas as EntityMachine).AdditionalColor.Name.CompareTo(
|
||||
(x.EntityGas as EntityMachine).AdditionalColor.Name);
|
||||
if (additionalColorCompare != 0)
|
||||
{
|
||||
return additionalColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = y.EntityGas.Speed.CompareTo(x.EntityGas.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return y.EntityGas.Weight.CompareTo(x.EntityGas.Weight);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по типу, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningMachineCompareByType : IComparer<DrawningMachine?>
|
||||
{
|
||||
public int Compare(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return y.GetType().Name.CompareTo(x.GetType().Name);
|
||||
}
|
||||
var speedCompare = y.EntityGas.Speed.CompareTo(x.EntityGas.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return y.EntityGas.Weight.CompareTo(x.EntityGas.Weight);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using ProjectGasMachine.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawningMachineEqutables : IEqualityComparer<DrawningMachine?>
|
||||
{
|
||||
public bool Equals(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.Speed != y.EntityGas.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.Weight != y.EntityGas.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.BodyColor != y.EntityGas.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningGasMachine && y is DrawningGasMachine)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
if ((x.EntityGas as EntityMachine)?.AdditionalColor !=
|
||||
(y.EntityGas as EntityMachine)?.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityGas as EntityMachine)?.Gas !=
|
||||
(y.EntityGas as EntityMachine)?.Gas)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityGas as EntityMachine)?.Beacon !=
|
||||
(y.EntityGas as EntityMachine)?.Beacon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningMachine? obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using ProjectGasMachine.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.Drawnings;
|
||||
|
||||
public static class ExtentionDrawningGas
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly string _separatorForObject = ":";
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningMachine? CreateDrawningMachine(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
EntityGas? machine = EntityMachine.CreateEntityMachine(strs);
|
||||
if (machine != null)
|
||||
{
|
||||
return new DrawningGasMachine(machine);
|
||||
}
|
||||
|
||||
machine = EntityGas.CreateEntityGas(strs);
|
||||
if (machine != null)
|
||||
{
|
||||
return new DrawningMachine(machine);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningMachine">Сохраняемый объект</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningMachine drawningMachine)
|
||||
{
|
||||
string[]? array = drawningMachine?.EntityGas?.GetStringRepresentation();
|
||||
|
||||
if (array == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return string.Join(_separatorForObject, array);
|
||||
}
|
||||
}
|
||||
@@ -51,29 +51,4 @@ public class EntityGas
|
||||
{
|
||||
BodyColor = newColor;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение строк со значениями свойств объекта класса-сущности
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string[] GetStringRepresentation()
|
||||
{
|
||||
return new[] { nameof(EntityGas), Speed.ToString(), Weight.ToString(), BodyColor.Name };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из массива строк
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
public static EntityGas? CreateEntityGas(string[] strs)
|
||||
{
|
||||
if (strs.Length != 4 || strs[0] != nameof(EntityGas))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EntityGas(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,34 +36,4 @@ public class EntityMachine : EntityGas
|
||||
{
|
||||
AdditionalColor = newColor;
|
||||
}
|
||||
|
||||
public override string[] GetStringRepresentation()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
nameof(EntityMachine),
|
||||
Speed.ToString(),
|
||||
Weight.ToString(),
|
||||
BodyColor.Name,
|
||||
AdditionalColor.Name,
|
||||
Gas.ToString(),
|
||||
Beacon.ToString(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из массива строк
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
public static EntityMachine? CreateEntityMachine(string[] strs)
|
||||
{
|
||||
if (strs.Length != 7 || strs[0] != nameof(EntityMachine))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EntityMachine(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]),
|
||||
Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasMachine.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку переполнения коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
|
||||
public 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) { }
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasMachine.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку переполнения коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ObjectAlreadyInCollectionException : ApplicationException
|
||||
{
|
||||
public ObjectAlreadyInCollectionException(int count) : base("Такой объект уже присутствует в коллекции. Позиция " + count) { }
|
||||
|
||||
public ObjectAlreadyInCollectionException() : base() { }
|
||||
|
||||
public ObjectAlreadyInCollectionException(string message) : base(message) { }
|
||||
|
||||
public ObjectAlreadyInCollectionException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected ObjectAlreadyInCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasMachine.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) { }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace ProjectGasMachine.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) { }
|
||||
}
|
||||
@@ -46,19 +46,10 @@
|
||||
labelCollectionName = new Label();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
menuStrip = new MenuStrip();
|
||||
FileToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
ButtonSortByColor = new Button();
|
||||
ButtonSortByType = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
@@ -68,17 +59,15 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(780, 24);
|
||||
groupBoxTools.Location = new Point(727, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(196, 557);
|
||||
groupBoxTools.Size = new Size(196, 543);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(ButtonSortByColor);
|
||||
panelCompanyTools.Controls.Add(ButtonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddMachine);
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
@@ -86,15 +75,15 @@
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 292);
|
||||
panelCompanyTools.Location = new Point(3, 323);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(190, 262);
|
||||
panelCompanyTools.Size = new Size(190, 217);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonAddMachine
|
||||
//
|
||||
buttonAddMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMachine.Location = new Point(10, 3);
|
||||
buttonAddMachine.Location = new Point(10, 14);
|
||||
buttonAddMachine.Name = "buttonAddMachine";
|
||||
buttonAddMachine.Size = new Size(174, 33);
|
||||
buttonAddMachine.TabIndex = 2;
|
||||
@@ -104,7 +93,7 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(3, 42);
|
||||
maskedTextBoxPosition.Location = new Point(3, 83);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(184, 23);
|
||||
@@ -114,7 +103,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(10, 144);
|
||||
buttonRefresh.Location = new Point(10, 185);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(174, 32);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
@@ -125,7 +114,7 @@
|
||||
// buttonRemoveMachine
|
||||
//
|
||||
buttonRemoveMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveMachine.Location = new Point(10, 71);
|
||||
buttonRemoveMachine.Location = new Point(10, 112);
|
||||
buttonRemoveMachine.Name = "buttonRemoveMachine";
|
||||
buttonRemoveMachine.Size = new Size(174, 32);
|
||||
buttonRemoveMachine.TabIndex = 5;
|
||||
@@ -136,7 +125,7 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(10, 109);
|
||||
buttonGoToCheck.Location = new Point(10, 150);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(174, 29);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
@@ -146,7 +135,7 @@
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(6, 263);
|
||||
buttonCreateCompany.Location = new Point(6, 294);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(184, 23);
|
||||
buttonCreateCompany.TabIndex = 7;
|
||||
@@ -166,12 +155,12 @@
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 19);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(190, 209);
|
||||
panelStorage.Size = new Size(190, 239);
|
||||
panelStorage.TabIndex = 8;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(3, 176);
|
||||
buttonCollectionDel.Location = new Point(3, 206);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(184, 23);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
@@ -185,7 +174,7 @@
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(3, 106);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(184, 64);
|
||||
listBoxCollection.Size = new Size(184, 94);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
@@ -242,7 +231,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 234);
|
||||
comboBoxSelectorCompany.Location = new Point(6, 265);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(184, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@@ -251,83 +240,19 @@
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(780, 557);
|
||||
pictureBox.Size = new Size(727, 543);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(976, 24);
|
||||
menuStrip.TabIndex = 4;
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// FileToolStripMenuItem
|
||||
//
|
||||
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||
FileToolStripMenuItem.Size = new Size(48, 20);
|
||||
FileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||
saveToolStripMenuItem.Size = new Size(181, 22);
|
||||
saveToolStripMenuItem.Text = "Сохранение";
|
||||
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||
loadToolStripMenuItem.Size = new Size(181, 22);
|
||||
loadToolStripMenuItem.Text = "Загрузка";
|
||||
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonSortByColor.Location = new Point(10, 217);
|
||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
ButtonSortByColor.Size = new Size(174, 32);
|
||||
ButtonSortByColor.TabIndex = 9;
|
||||
ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
ButtonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonSortByType.Location = new Point(10, 182);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(174, 29);
|
||||
ButtonSortByType.TabIndex = 8;
|
||||
ButtonSortByType.Text = "Сортировка по типу";
|
||||
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// FormGasMachineCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(976, 581);
|
||||
ClientSize = new Size(923, 543);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormGasMachineCollection";
|
||||
Text = "Коллекция газовозов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
@@ -336,10 +261,7 @@
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -362,13 +284,5 @@
|
||||
private Button buttonCollectionDel;
|
||||
private ListBox listBoxCollection;
|
||||
private Panel panelCompanyTools;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem FileToolStripMenuItem;
|
||||
private ToolStripMenuItem saveToolStripMenuItem;
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasMachine.CollectionGenericObjects;
|
||||
using ProjectGasMachine.CollectionGenericObjects;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
|
||||
|
||||
namespace ProjectGasMachine
|
||||
@@ -21,19 +19,13 @@ namespace ProjectGasMachine
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// </summary>
|
||||
public FormGasMachineCollection(ILogger<FormGasMachineCollection> logger)
|
||||
public FormGasMachineCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,29 +47,15 @@ namespace ProjectGasMachine
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (_company + machine != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation($"Добавлен объект {machine.GetDataForSave()}");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
catch (CollectionOverflowException ex)
|
||||
if (_company + machine != -1)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +67,7 @@ namespace ProjectGasMachine
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddMachine_Click(object sender, EventArgs e)
|
||||
private void ButtonAddMachine_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormGasConfig form = new();
|
||||
// TODO передать метод +
|
||||
@@ -115,25 +93,15 @@ namespace ProjectGasMachine
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation($"Удален объект по позиции {pos}");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
catch (ObjectNotFoundException ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (PositionOutOfCollectionException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError($"Ошибка: {ex.Message}");
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +167,6 @@ namespace ProjectGasMachine
|
||||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: Заполнены не все данные для добавления коллекции");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,10 +179,8 @@ namespace ProjectGasMachine
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
CollectionInfo collectionInfo = new CollectionInfo(textBoxCollectionName.Text, collectionType, string.Empty);
|
||||
|
||||
_storageCollection.AddCollection(collectionInfo);
|
||||
_logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text} типа: {collectionType}");
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
@@ -236,10 +201,7 @@ namespace ProjectGasMachine
|
||||
{
|
||||
return;
|
||||
}
|
||||
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
|
||||
|
||||
_storageCollection.DelCollection(collectionInfo);
|
||||
_logger.LogInformation($"Удалена коллекция: {listBoxCollection.SelectedItem.ToString()}");
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
@@ -251,7 +213,7 @@ namespace ProjectGasMachine
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i].Name;
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
@@ -272,8 +234,7 @@ namespace ProjectGasMachine
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
|
||||
ICollectionGenericObjects<DrawningMachine>? collection = _storageCollection[collectionInfo];
|
||||
ICollectionGenericObjects<DrawningMachine>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
@@ -289,86 +250,5 @@ namespace ProjectGasMachine
|
||||
panelCompanyTools.Enabled = true;
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storageCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
RerfreshListBoxItems();
|
||||
_logger.LogInformation("Загрузка из фала: {filename}", openFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMachines(new DrawningMachineCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMachines(new DrawningMachineCompareByColor());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
private void CompareMachines(IComparer<DrawningMachine?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,16 +117,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>126, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>261, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -1,8 +1,3 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace ProjectGasMachine
|
||||
{
|
||||
internal static class Program
|
||||
@@ -16,26 +11,7 @@ namespace ProjectGasMachine
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
||||
ServiceCollection services = new();
|
||||
ConfigureServices(services);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(serviceProvider.GetRequiredService<FormGasMachineCollection>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddSingleton<FormGasMachineCollection>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddJsonFile("serilogConfig.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
option.AddSerilog(Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(config)
|
||||
.CreateLogger());
|
||||
});
|
||||
Application.Run(new FormGasMachineCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,6 @@
|
||||
<None Include="ProjectGasMachine.csproj.user" />
|
||||
</ItemGroup>
|
||||
|
||||
<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" Version="8.0.0" />
|
||||
<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>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
@@ -40,10 +28,4 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="serilogConfig.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"AllowedHosts": "*",
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"System": "Warning"
|
||||
}
|
||||
},
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" },
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "C:\\Пользователи\\artem\\OneDrive\\Рабочий стол\\уник\\ООП\\log.txt",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user