Compare commits
4 Commits
LabWork06.
...
LabWork08
| Author | SHA1 | Date | |
|---|---|---|---|
| 13860fad44 | |||
| 26b6a7c8f0 | |||
| 696f879bad | |||
| bacf66aad8 |
3
11.txt
3
11.txt
@@ -1,3 +0,0 @@
|
||||
CollectionsStorage
|
||||
11|Massive|45|EntityMilitaryAircraft:100:100:Gray;EntityAirFighter:100:100:Gray:True:True:Gray;EntityAirFighter:100:100:Gray:True:True:Gray;
|
||||
12|Massive|45|EntityAirFighter:100:100:BlueViolet:True:True:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;EntityAirFighter:100:100:BlueViolet:True:True:BlueViolet;
|
||||
2
111.txt
Normal file
2
111.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
CollectionsStorage
|
||||
111|Massive|45|EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;
|
||||
3
12.txt
3
12.txt
@@ -1,3 +0,0 @@
|
||||
CollectionsStorage
|
||||
11|Massive|45|EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;
|
||||
12|Massive|45|EntityMilitaryAircraft:100:100:Yellow;EntityMilitaryAircraft:100:100:Yellow;EntityMilitaryAircraft:100:100:Yellow;
|
||||
@@ -1,4 +1,5 @@
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
@@ -59,7 +60,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningMilitaryAircraft militaryAircraft)
|
||||
{
|
||||
return company._collection.Insert(militaryAircraft);
|
||||
return company._collection.Insert(militaryAircraft, new DrawiningCarEqutables());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,14 +96,29 @@ public abstract class AbstractCompany
|
||||
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
DrawningMilitaryAircraft? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (ObjectNotFoundException e)
|
||||
{ }
|
||||
catch (PositionOutOfCollectionException e)
|
||||
{ }
|
||||
catch (CollectionOverflowException e)
|
||||
{ }
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningMilitaryAircraft?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
@@ -42,11 +43,13 @@ public class Angar : AbstractCompany
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
try
|
||||
{
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
|
||||
}
|
||||
catch (ObjectNotFoundException) { }
|
||||
catch (PositionOutOfCollectionException e) { }
|
||||
|
||||
if (curWidth > 0)
|
||||
curWidth--;
|
||||
@@ -55,7 +58,7 @@ public class Angar : AbstractCompany
|
||||
curWidth = width - 1;
|
||||
curHeight--;
|
||||
}
|
||||
if (curHeight > height)
|
||||
if (curHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
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 bool IsEmpty()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Name) && CollectionType != CollectionType.None) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@@ -32,7 +32,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@@ -58,4 +58,10 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@@ -46,38 +48,45 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position >= Count || position < 0) return null;
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (Count + 1 > _maxCount) return -1;
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
//TODO
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (Count + 1 > _maxCount) return -1;
|
||||
if (position < 0 || position > Count) return -1;
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
_collection.Insert(position, obj);
|
||||
return 1;
|
||||
return position;
|
||||
//TODO
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > Count) return null;
|
||||
T? pos = _collection[position];
|
||||
if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
T obj = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return pos;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; ++i)
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
using AirFighter;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@@ -48,65 +51,91 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return null; }
|
||||
if (position < 0 || position >= Count - 3) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionInsertException(obj);
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < Count - 3; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return -1; }
|
||||
if (position < 0 || position >= Count - 3) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
if (_collection[position] == null)
|
||||
if (comparer != null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
int index;
|
||||
|
||||
for (index = position + 1; index < _collection.Length; ++index)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionInsertException(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (index = position - 1; index >= 0; --index)
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
bool pushed = false;
|
||||
for (int index = position + 1; index < Count; index++)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
position = index;
|
||||
pushed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushed)
|
||||
{
|
||||
for (int index = position - 1; index >= 0; index--)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
position = index;
|
||||
pushed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushed)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
||||
// вставка
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (position >= Count - 3 || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||
T obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
@@ -119,4 +148,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using AirFighter;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
@@ -39,22 +43,21 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>(); //вот тут какое-то свойство
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление коллекции в хранилище
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
/// <param name="collectionInfo">тип коллекции</param>
|
||||
public void AddCollection(CollectionInfo collectionInfo)
|
||||
{
|
||||
if (name == null || _storages.ContainsKey(name)) { return; }
|
||||
if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
|
||||
switch (collectionType)
|
||||
|
||||
{
|
||||
case CollectionType.None:
|
||||
return;
|
||||
throw new CollectionTypeException("Пустой тип коллекции");
|
||||
case CollectionType.Massive:
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
return;
|
||||
@@ -68,10 +71,10 @@ public class StorageCollection<T>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
public void DelCollection(CollectionInfo collectionInfo)
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
_storages.Remove(collectionInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,12 +82,13 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
public ICollectionGenericObjects<T>? this[CollectionInfo collectionInfo]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (name == null || !_storages.ContainsKey(name)) { return null; }
|
||||
return _storages[name];
|
||||
if(_storages.ContainsKey(collectionInfo))
|
||||
return _storages[collectionInfo];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,11 +98,11 @@ public class StorageCollection<T>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
return false;
|
||||
throw new InvalidOperationException("В хранилище отсутствуют коллекции для сохранения");
|
||||
}
|
||||
|
||||
if (File.Exists(filename))
|
||||
@@ -123,8 +127,6 @@ public class StorageCollection<T>
|
||||
|
||||
sb.Append(value.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.GetCollectionType);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
|
||||
@@ -141,10 +143,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
writer.Write(sb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,11 +151,11 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new FileNotFoundException(filename);
|
||||
}
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
@@ -164,12 +163,12 @@ public class StorageCollection<T>
|
||||
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new FormatException("В файле неверные данные");
|
||||
}
|
||||
|
||||
if (!str.StartsWith(_collectionKey))
|
||||
{
|
||||
return false;
|
||||
throw new FormatException(filename);
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
@@ -180,36 +179,36 @@ public class StorageCollection<T>
|
||||
{
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (record.Length != 4)
|
||||
if (record.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции:" + record[0]);
|
||||
|
||||
if (collection == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawningMilitaryAircraft() is T militaryAircraft)
|
||||
{
|
||||
if (collection.Insert(militaryAircraft) == -1)
|
||||
try
|
||||
{
|
||||
return false;
|
||||
collection.Insert(militaryAircraft);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new FileFormatException(filename, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using ProjectAirFighter.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawiningCarEqutables : IEqualityComparer<DrawningMilitaryAircraft?>
|
||||
{
|
||||
public bool Equals(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityMilitaryAircraft.Speed != y.EntityMilitaryAircraft.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityMilitaryAircraft.Weight != y.EntityMilitaryAircraft.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityMilitaryAircraft.BodyColor != y.EntityMilitaryAircraft.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x is DrawningAirFighter && y is DrawningAirFighter)
|
||||
{
|
||||
EntityAirFighter xAirFighter = (EntityAirFighter)x.EntityMilitaryAircraft;
|
||||
EntityAirFighter yAirFighter = (EntityAirFighter)y.EntityMilitaryAircraft;
|
||||
|
||||
if (xAirFighter.AdditionalColor != yAirFighter.AdditionalColor)
|
||||
return false;
|
||||
|
||||
if (xAirFighter.Wings != yAirFighter.Wings)
|
||||
return false;
|
||||
|
||||
if (xAirFighter.Rockets != yAirFighter.Rockets)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningMilitaryAircraft obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по типу, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraftCompareByType : IComparer<DrawningMilitaryAircraft?>
|
||||
{
|
||||
public int Compare(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityMilitaryAircraft.Speed.CompareTo(y.EntityMilitaryAircraft.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityMilitaryAircraft.Weight.CompareTo(y.EntityMilitaryAircraft.Weight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
internal class DrawningMilitaryAircraftCompareByColor : IComparer<DrawningMilitaryAircraft?>
|
||||
{
|
||||
public int Compare(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityMilitaryAircraft.BodyColor.Name.CompareTo(y.EntityMilitaryAircraft.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityMilitaryAircraft.Speed.CompareTo(y.EntityMilitaryAircraft.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityMilitaryAircraft.Weight.CompareTo(y.EntityMilitaryAircraft.Weight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class CollectionAlreadyExistsException : Exception
|
||||
{
|
||||
public CollectionAlreadyExistsException() : base() { }
|
||||
public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base($"Коллекция {collectionInfo} уже существует!") { }
|
||||
public CollectionAlreadyExistsException(string name, Exception exception) :
|
||||
base($"Коллекция {name} уже существует!", exception)
|
||||
{ }
|
||||
protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
14
AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
Normal file
14
AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class CollectionInfoException : Exception
|
||||
{
|
||||
public CollectionInfoException() : base() { }
|
||||
public CollectionInfoException(string message) : base(message) { }
|
||||
public CollectionInfoException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected CollectionInfoException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
namespace AirFighter;
|
||||
|
||||
public class CollectionInsertException : Exception
|
||||
{
|
||||
public CollectionInsertException(object obj) : base($"Объект {obj} не удволетворяет уникальности") { }
|
||||
public CollectionInsertException() : base() { }
|
||||
public CollectionInsertException(string message) : base(message) { }
|
||||
public CollectionInsertException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected CollectionInsertException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAirFighter.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) { }
|
||||
}
|
||||
14
AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
Normal file
14
AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class CollectionTypeException : Exception
|
||||
{
|
||||
public CollectionTypeException() : base() { }
|
||||
public CollectionTypeException(string message) : base(message) { }
|
||||
public CollectionTypeException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected CollectionTypeException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class DrawningEquitablesException : Exception
|
||||
{
|
||||
public DrawningEquitablesException() : base("Объекты прорисовки одинаковые") { }
|
||||
public DrawningEquitablesException(string message) : base(message) { }
|
||||
public DrawningEquitablesException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected DrawningEquitablesException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
15
AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
Normal file
15
AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class EmptyFileExeption : Exception
|
||||
{
|
||||
public EmptyFileExeption(string name) : base($"Файл {name} пустой ") { }
|
||||
public EmptyFileExeption() : base("В хранилище отсутствуют коллекции для сохранения") { }
|
||||
public EmptyFileExeption(string name, string message) : base(message) { }
|
||||
public EmptyFileExeption(string name, string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected EmptyFileExeption(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
14
AirFighter/AirFighter/Exceptions/FileFormatException.cs
Normal file
14
AirFighter/AirFighter/Exceptions/FileFormatException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class FileFormatException : Exception
|
||||
{
|
||||
public FileFormatException() : base() { }
|
||||
public FileFormatException(string message) : base(message) { }
|
||||
public FileFormatException(string name, Exception exception) :
|
||||
base($"Файл {name} имеет неверный формат. Ошибка: {exception.Message}", exception)
|
||||
{ }
|
||||
protected FileFormatException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
15
AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
Normal file
15
AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirFighter;
|
||||
|
||||
public class FileNotFoundException : Exception
|
||||
{
|
||||
public FileNotFoundException(string name) : base($"Файл {name} не существует ") { }
|
||||
public FileNotFoundException() : base() { }
|
||||
public FileNotFoundException(string name, string message) : base(message) { }
|
||||
public FileNotFoundException(string name, string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected FileNotFoundException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
20
AirFighter/AirFighter/Exceptions/ObjectNotFoundException.cs
Normal file
20
AirFighter/AirFighter/Exceptions/ObjectNotFoundException.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAirFighter.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,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAirFighter.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) { }
|
||||
}
|
||||
@@ -52,6 +52,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
buttonSortByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@@ -68,13 +70,15 @@
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(744, 28);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(206, 639);
|
||||
groupBoxTools.Size = new Size(206, 711);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveMilitaryAircraft);
|
||||
@@ -82,15 +86,15 @@
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 357);
|
||||
panelCompanyTools.Location = new Point(3, 360);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(200, 279);
|
||||
panelCompanyTools.Size = new Size(200, 348);
|
||||
panelCompanyTools.TabIndex = 10;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(0, 227);
|
||||
buttonRefresh.Location = new Point(8, 195);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(192, 49);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
@@ -101,7 +105,7 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(3, 178);
|
||||
buttonGoToCheck.Location = new Point(3, 140);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(192, 49);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
@@ -112,7 +116,7 @@
|
||||
// buttonRemoveMilitaryAircraft
|
||||
//
|
||||
buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveMilitaryAircraft.Location = new Point(4, 129);
|
||||
buttonRemoveMilitaryAircraft.Location = new Point(4, 91);
|
||||
buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft";
|
||||
buttonRemoveMilitaryAircraft.Size = new Size(191, 49);
|
||||
buttonRemoveMilitaryAircraft.TabIndex = 5;
|
||||
@@ -134,7 +138,7 @@
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxPosition.Location = new Point(3, 96);
|
||||
maskedTextBoxPosition.Location = new Point(3, 58);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(192, 27);
|
||||
@@ -250,7 +254,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 28);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(744, 639);
|
||||
pictureBox.Size = new Size(744, 711);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@@ -295,11 +299,33 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(4, 296);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(192, 49);
|
||||
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(6, 250);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(191, 49);
|
||||
buttonSortByType.TabIndex = 8;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// FormMilitaryAircraftCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(950, 667);
|
||||
ClientSize = new Size(950, 739);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@@ -344,5 +370,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using ProjectAirFighter.CollectionGenericObjects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectAirFighter.CollectionGenericObjects;
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter;
|
||||
|
||||
@@ -15,13 +17,19 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMilitaryAircraftCollection()
|
||||
public FormMilitaryAircraftCollection(ILogger<FormMilitaryAircraftCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,14 +66,18 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + militaryAircraft != -1)
|
||||
try
|
||||
{
|
||||
var res = _company + militaryAircraft;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation($"Объект добавлен под индексом {res}");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
MessageBox.Show($"Объект не добавлен: {ex.Message}", "Результат", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,14 +100,18 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos != null)
|
||||
try
|
||||
{
|
||||
var res = _company - pos;
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation($"Объект удален под индексом {pos}");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show(ex.Message, "Не удалось удалить объект",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +184,17 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RerfreshListBoxItems();
|
||||
try
|
||||
{
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
_logger.LogInformation("Добавление коллекции");
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||
@@ -184,6 +209,7 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
_logger.LogInformation("Коллекция удалена");
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
|
||||
@@ -220,6 +246,7 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new Angar(pictureBox.Width, pictureBox.Height, collection);
|
||||
_logger.LogInformation("Компания создана");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -231,13 +258,16 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,15 +276,53 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_storageCollection.LoadData(openFileDialog.FileName);
|
||||
RerfreshListBoxItems();
|
||||
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
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)
|
||||
{
|
||||
CompareCars(new DrawningMilitaryAircraftCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareCars(new DrawningMilitaryAircraftCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
private void CompareCars(IComparer<DrawningMilitaryAircraft?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,4 +126,7 @@
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>310, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>71</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -1,17 +1,50 @@
|
||||
namespace ProjectAirFighter
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace ProjectAirFighter;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static class Program
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(serviceProvider.GetRequiredService <FormMilitaryAircraftCollection>());
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMilitaryAircraftCollection>().AddLogging(option =>
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMilitaryAircraftCollection());
|
||||
}
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string pathNeed = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
pathNeed += path[i] + "\\";
|
||||
}
|
||||
|
||||
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(path: $"{pathNeed}serilogConfig.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,16 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
20
AirFighter/AirFighter/serilogConfig.json
Normal file
20
AirFighter/AirFighter/serilogConfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "AirFighter"
|
||||
}
|
||||
}
|
||||
}
|
||||
2
тренировочный.txt
Normal file
2
тренировочный.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
CollectionsStorage
|
||||
11|Massive|45|EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;EntityMilitaryAircraft:100:100:Black;
|
||||
Reference in New Issue
Block a user