8 лабораторная работа
This commit is contained in:
parent
3ed0fd1ce0
commit
73cb9e1a29
@ -60,7 +60,8 @@ 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 DrawiningMilitaryAircraftEqutables()) ??
|
||||
throw new DrawningEquitablesException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -113,6 +114,8 @@ public abstract class AbstractCompany
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public void Sort(IComparer<DrawningMilitaryAircraft?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,51 @@
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public CollectionType CollectionType { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
private static readonly string _separator = "-";
|
||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||
{
|
||||
Name = name;
|
||||
CollectionType = collectionType;
|
||||
Description = description;
|
||||
}
|
||||
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,6 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
@ -52,14 +52,14 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
@ -82,4 +82,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ProjectAirFighter.Exceptions;
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using ProjectAirFighter.Exceptions;
|
||||
|
||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||
|
||||
@ -55,9 +56,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
for (int i = 0; i < Count - 3; i++)
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningMilitaryAircraft>).Equals(obj as DrawningMilitaryAircraft, item as DrawningMilitaryAircraft))
|
||||
throw new CollectionInsertException();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
@ -66,47 +76,46 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
}
|
||||
throw new CollectionOverflowException(Count);
|
||||
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (position < 0 || position >= Count - 3) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
if (_collection[position] != null)
|
||||
if (comparer != null)
|
||||
{
|
||||
bool pushed = false;
|
||||
for (int index = position + 1; index < Count; index++)
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
position = index;
|
||||
pushed = true;
|
||||
break;
|
||||
}
|
||||
if ((comparer as IEqualityComparer<DrawningMilitaryAircraft>).Equals(obj as DrawningMilitaryAircraft, item as DrawningMilitaryAircraft))
|
||||
throw new CollectionInsertException();
|
||||
}
|
||||
}
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
if (!pushed)
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < Count; ++i)
|
||||
{
|
||||
for (int index = position - 1; index >= 0; index--)
|
||||
if (_collection[position + i] == null)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
_collection[position + i] = obj;
|
||||
return position + i;
|
||||
}
|
||||
for (i = position - 1; i >= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
position = index;
|
||||
pushed = true;
|
||||
break;
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushed)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
}
|
||||
|
||||
// вставка
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
@ -125,4 +134,11 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
List<T?> value = new List<T?>(_collection);
|
||||
value.Sort(comparer);
|
||||
value.CopyTo(_collection, 0);
|
||||
}
|
||||
}
|
@ -14,12 +14,12 @@ public class StorageCollection<T>
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
/// </summary>
|
||||
@ -40,7 +40,7 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -50,18 +50,15 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (name == null || _storages.ContainsKey(name)) { return; }
|
||||
switch (collectionType)
|
||||
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
case CollectionType.None:
|
||||
return;
|
||||
case CollectionType.Massive:
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
return;
|
||||
case CollectionType.List:
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
return;
|
||||
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||
}
|
||||
else if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,8 +68,11 @@ public class StorageCollection<T>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
{
|
||||
_storages.Remove(collectionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -84,8 +84,12 @@ public class StorageCollection<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
if (name == null || !_storages.ContainsKey(name)) { return null; }
|
||||
return _storages[name];
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
{
|
||||
return _storages[collectionInfo];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,36 +115,30 @@ public class StorageCollection<T>
|
||||
{
|
||||
writer.Write(_collectionKey);
|
||||
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.Append(Environment.NewLine);
|
||||
writer.Write(Environment.NewLine);
|
||||
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.Append(value.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.GetCollectionType);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
{
|
||||
string data = item?.GetDataForSave() ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sb.Append(data);
|
||||
sb.Append(_separatorItems);
|
||||
writer.Write(data);
|
||||
writer.Write(_separatorItems);
|
||||
}
|
||||
writer.Write(sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,65 +152,58 @@ public class StorageCollection<T>
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не существует");
|
||||
throw new Exceptions.FileNotFoundException(filename);
|
||||
}
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
|
||||
if (str == null || str.Length == 0)
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new FormatException("В файле неверные данные");
|
||||
throw new EmptyFileExeption(filename);
|
||||
}
|
||||
|
||||
if (!str.StartsWith(_collectionKey))
|
||||
{
|
||||
throw new FormatException("В файле неверные данные");
|
||||
throw new Exceptions.FileFormatException(filename);
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
|
||||
string strs = "";
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
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 CollectionInfoException("Не удалось определить информацию коллекции:" + record[0]);
|
||||
|
||||
if (collection == null)
|
||||
{
|
||||
throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
|
||||
}
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
ICollectionGenericObjects<T>? collection =
|
||||
StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawningMilitaryAircraft() is T militaryAircraft)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(militaryAircraft) == -1)
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
collection.Insert(militaryAircraft);
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CollectionOverflowException("Коллекция переполнена", ex);
|
||||
throw new Exceptions.FileFormatException(filename, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
using ProjectAirFighter.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawiningMilitaryAircraftEqutables : 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 EntityX = (EntityAirFighter)x.EntityMilitaryAircraft;
|
||||
EntityAirFighter EntityY = (EntityAirFighter)y.EntityMilitaryAircraft;
|
||||
|
||||
if (EntityX.Wings != EntityY.Wings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityX.Rockets != EntityY.Rockets)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningMilitaryAircraft obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using ProjectAirFighter.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraftCompareByColor : IComparer<DrawningMilitaryAircraft?>
|
||||
{
|
||||
public int Compare(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
|
||||
{
|
||||
if (x == null && y == null) return 0;
|
||||
if (x == null || x.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMilitaryAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ToHex(x.EntityMilitaryAircraft.BodyColor) != ToHex(y.EntityMilitaryAircraft.BodyColor))
|
||||
{
|
||||
return String.Compare(ToHex(x.EntityMilitaryAircraft.BodyColor), ToHex(y.EntityMilitaryAircraft.BodyColor),
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityMilitaryAircraft.Speed.CompareTo(y.EntityMilitaryAircraft.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityMilitaryAircraft.Weight.CompareTo(y.EntityMilitaryAircraft.Weight);
|
||||
}
|
||||
|
||||
private static String ToHex(Color c)
|
||||
=> $"#{c.R:X2}{c.G:X2}{c.B:X2}";
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
namespace ProjectAirFighter.Drawnings;
|
||||
|
||||
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,20 @@
|
||||
using ProjectAirFighter.CollectionGenericObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
19
AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
Normal file
19
AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
19
AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
Normal file
19
AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
20
AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
Normal file
20
AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
15
AirFighter/AirFighter/Exceptions/FileFormatException.cs
Normal file
15
AirFighter/AirFighter/Exceptions/FileFormatException.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
16
AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
Normal file
16
AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace ProjectAirFighter.Exceptions;
|
||||
|
||||
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) { }
|
||||
}
|
@ -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();
|
||||
@ -66,15 +68,17 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(744, 28);
|
||||
groupBoxTools.Location = new Point(765, 28);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(206, 639);
|
||||
groupBoxTools.Size = new Size(206, 714);
|
||||
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);
|
||||
@ -84,13 +88,13 @@
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 357);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(200, 279);
|
||||
panelCompanyTools.Size = new Size(200, 354);
|
||||
panelCompanyTools.TabIndex = 10;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(0, 227);
|
||||
buttonRefresh.Location = new Point(0, 189);
|
||||
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, 137);
|
||||
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(3, 82);
|
||||
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(4, 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(765, 714);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -260,7 +264,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(950, 28);
|
||||
menuStrip.Size = new Size(971, 28);
|
||||
menuStrip.TabIndex = 4;
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
@ -295,11 +299,33 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonSortByColor.Location = new Point(3, 299);
|
||||
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(3, 244);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(192, 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(971, 742);
|
||||
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;
|
||||
}
|
||||
}
|
@ -219,7 +219,7 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
string? colName = _storageCollection.Keys?[i].Name;
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
@ -291,4 +291,24 @@ public partial class FormMilitaryAircraftCollection : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMilitaryAircraft(new DrawningMilitaryAircraftCompareByType());
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMilitaryAircraft(new DrawningMilitaryAircraftCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareMilitaryAircraft(IComparer<DrawningMilitaryAircraft?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
2
тренировочный.txt
Normal file
2
тренировочный.txt
Normal file
@ -0,0 +1,2 @@
|
||||
CollectionsStorage
|
||||
12-Massive-|52|EntityMilitaryAircraft:100:100:Black;EntityAirFighter:100:100:White:False:True:BlueViolet;EntityMilitaryAircraft:100:100:Green;EntityAirFighter:100:100:Blue:True:True:Black;
|
Loading…
Reference in New Issue
Block a user