PIbd-11 Tarasov V.D. LabWork 8 Simple #8
ProjectMonorail
36
ProjectMonorail/FormMonorailCollection.Designer.cs
generated
36
ProjectMonorail/FormMonorailCollection.Designer.cs
generated
@ -30,6 +30,8 @@
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
buttonAddMonorail = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonRefresh = new Button();
|
||||
@ -75,6 +77,8 @@
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddMonorail);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
@ -88,10 +92,30 @@
|
||||
panelCompanyTools.Size = new Size(235, 322);
|
||||
panelCompanyTools.TabIndex = 8;
|
||||
//
|
||||
// buttonByColor
|
||||
//
|
||||
buttonByColor.Location = new Point(8, 279);
|
||||
buttonByColor.Name = "buttonByColor";
|
||||
buttonByColor.Size = new Size(217, 23);
|
||||
buttonByColor.TabIndex = 8;
|
||||
buttonByColor.Text = "Сортировать по значению";
|
||||
buttonByColor.UseVisualStyleBackColor = true;
|
||||
buttonByColor.Click += buttonByColor_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(8, 250);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(217, 23);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировать по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonAddMonorail
|
||||
//
|
||||
buttonAddMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMonorail.Location = new Point(8, 32);
|
||||
buttonAddMonorail.Location = new Point(8, 5);
|
||||
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||
buttonAddMonorail.Size = new Size(221, 48);
|
||||
buttonAddMonorail.TabIndex = 1;
|
||||
@ -101,7 +125,7 @@
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(5, 130);
|
||||
maskedTextBox.Location = new Point(5, 59);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(223, 23);
|
||||
@ -111,7 +135,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(8, 267);
|
||||
buttonRefresh.Location = new Point(8, 196);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(219, 48);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
@ -122,7 +146,7 @@
|
||||
// buttonRemoveMonorail
|
||||
//
|
||||
buttonRemoveMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveMonorail.Location = new Point(8, 159);
|
||||
buttonRemoveMonorail.Location = new Point(8, 88);
|
||||
buttonRemoveMonorail.Name = "buttonRemoveMonorail";
|
||||
buttonRemoveMonorail.Size = new Size(221, 48);
|
||||
buttonRemoveMonorail.TabIndex = 4;
|
||||
@ -133,7 +157,7 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(8, 213);
|
||||
buttonGoToCheck.Location = new Point(8, 142);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(220, 48);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
@ -351,5 +375,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using ProjectMonorail.Scripts.Exceptions;
|
||||
using ProjectMonorail.Scripts.Monorail.CollectionGenericObjects;
|
||||
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ProjectMonorail
|
||||
{
|
||||
@ -74,6 +75,7 @@ namespace ProjectMonorail
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
Debug.WriteLine(ex.Message);
|
||||
LogException(ex);
|
||||
}
|
||||
}
|
||||
@ -95,7 +97,7 @@ namespace ProjectMonorail
|
||||
_logger.LogInformation("Объект удален");
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
LogException(ex);
|
||||
@ -137,7 +139,7 @@ namespace ProjectMonorail
|
||||
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);
|
||||
@ -312,10 +314,34 @@ namespace ProjectMonorail
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((PositionOutOfCollectionException)ex).Message);
|
||||
}
|
||||
else if (ex is ObjectIsEqualException)
|
||||
{
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMonorail(new DrawningMonorailCompareByType());
|
||||
}
|
||||
|
||||
private void buttonByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMonorail(new DrawningMonorailCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareMonorail(IComparer<DrawingMonorail?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
ProjectMonorail/Scripts/Exceptions/ObjectIsEqualException.cs
Normal file
19
ProjectMonorail/Scripts/Exceptions/ObjectIsEqualException.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 ProjectMonorail.Scripts.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class ObjectIsEqualException : ApplicationException
|
||||
{
|
||||
public ObjectIsEqualException(int count) : base("В коллекции содержится равный элемент: " + count) { }
|
||||
public ObjectIsEqualException() : base() { }
|
||||
public ObjectIsEqualException(string message) : base(message) { }
|
||||
public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
|
||||
protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawingMonorail monorail)
|
||||
{
|
||||
return company._collection?.Insert(monorail) ?? throw new PositionOutOfCollectionException();
|
||||
return company._collection?.Insert(monorail, new DrawiningMonorailEqutables()) ?? -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -113,5 +113,11 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawingMonorail?> comparer) => _collection?.CollectionSort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
namespace ProjectMonorail.Scripts.Monorail.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 override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// </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 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <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,5 +58,11 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// </summary>
|
||||
/// <returns>Поэлементный вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
|
||||
using ProjectMonorail.Scripts.Exceptions;
|
||||
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
@ -40,27 +43,48 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _collection.Count) throw new PositionOutOfCollectionException(position);
|
||||
if (position < 0 || position >= _collection.Count) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
|
||||
if (_collection.Count + 1 > _maxCount) throw new CollectionOverflowException(_maxCount);
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
|
||||
{
|
||||
if (item == null) continue;
|
||||
if ((comparer as IEqualityComparer<DrawingMonorail>).Equals(obj as DrawingMonorail, item as DrawingMonorail))
|
||||
{
|
||||
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_collection.Add(obj);
|
||||
return _collection.Count + 1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (position < 0 || position > _collection.Count || _collection[position] != null) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawingMonorail>).Equals(obj as DrawingMonorail, item as DrawingMonorail))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
|
||||
@ -88,5 +112,10 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using ProjectMonorail.Scripts.Exceptions;
|
||||
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
@ -52,9 +54,20 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawingMonorail>).Equals(obj as DrawingMonorail, item as DrawingMonorail))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (InsertingElementCollection(i, obj)) return i;
|
||||
@ -63,13 +76,22 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
throw new CollectionOverflowException("Превышение лимита Count");
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawingMonorail>).Equals(obj as DrawingMonorail, item as DrawingMonorail))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (!(position >= 0 && position < Count)) throw new PositionOutOfCollectionException(position);
|
||||
if (InsertingElementCollection(position, obj)) return position;
|
||||
|
||||
@ -120,5 +142,10 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
||||
using ProjectMonorail.Scripts.Exceptions;
|
||||
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
@ -14,12 +15,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <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>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
@ -41,7 +42,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -53,24 +54,13 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (!_storages.ContainsKey(name))
|
||||
{
|
||||
ICollectionGenericObjects<T> collection;
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||
|
||||
switch (collectionType)
|
||||
{
|
||||
case CollectionType.List:
|
||||
collection = new ListGenericObjects<T>();
|
||||
break;
|
||||
case CollectionType.Massive:
|
||||
collection = new MassiveGenericObjects<T>();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_storages.ContainsKey(collectionInfo)) return;
|
||||
|
||||
_storages.Add(name, collection);
|
||||
}
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive) _storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List) _storages[collectionInfo] = new ListGenericObjects<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -81,7 +71,9 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
|
||||
_storages.Remove(name);
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
_storages.Remove(collectionInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -95,7 +87,9 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
// TODO Продумать логику получения
|
||||
|
||||
if (_storages.TryGetValue(name, out var value)) return value;
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
return _storages[collectionInfo];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -118,7 +112,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(Environment.NewLine);
|
||||
@ -130,8 +124,6 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
|
||||
stringBuilder.Append(value.Key);
|
||||
stringBuilder.Append(_separatorForKeyValue);
|
||||
stringBuilder.Append(value.Value.GetCollectionType);
|
||||
stringBuilder.Append(_separatorForKeyValue);
|
||||
stringBuilder.Append(value.Value.MaxCount);
|
||||
stringBuilder.Append(_separatorForKeyValue);
|
||||
|
||||
@ -181,29 +173,34 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
while ((strs = streamRader.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 Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ?? throw new Exception("Не удалось создать коллекцию");
|
||||
|
||||
if (collection == null)
|
||||
{
|
||||
throw new Exceptions.ObjectNotFoundException();
|
||||
}
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawingMonorail() is T ship)
|
||||
var obj = elem?.CreateDrawingMonorail();
|
||||
if (obj is T monorail)
|
||||
{
|
||||
if (collection.Insert(ship) == -1)
|
||||
if (collection.Insert(monorail) == -1)
|
||||
{
|
||||
throw new Exceptions.PositionOutOfCollectionException();
|
||||
throw new Exception("Объект не удалось добавить в коллекию: " + record[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
using ProjectMonorail.Scripts.Monorail.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectMonorail.Scripts.Monorail.Drawnings
|
||||
{
|
||||
public class DrawiningMonorailEqutables : IEqualityComparer<DrawingMonorail?>
|
||||
{
|
||||
public bool Equals(DrawingMonorail? x, DrawingMonorail? y)
|
||||
{
|
||||
if (x == null || x.EntityMonorail == null) return false;
|
||||
|
||||
if (y == null || y.EntityMonorail == null) return false;
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name) return false;
|
||||
|
||||
if (x.EntityMonorail.Speed != y.EntityMonorail.Speed) return false;
|
||||
|
||||
if (x.EntityMonorail.Weight != y.EntityMonorail.Weight) return false;
|
||||
|
||||
if (x.EntityMonorail.BodyColor != y.EntityMonorail.BodyColor) return false;
|
||||
|
||||
if (x is DrawingModernMonorail xa && y is DrawingModernMonorail ya)
|
||||
{
|
||||
if (xa.EntityMonorail is EntityModernMonorail left && ya.EntityMonorail is EntityModernMonorail right)
|
||||
{
|
||||
if (left.AdditionalColor != right.AdditionalColor) return false;
|
||||
|
||||
if (left.MonorailTrack != right.MonorailTrack) return false;
|
||||
|
||||
if (left.Cabin != right.Cabin) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawingMonorail obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
namespace ProjectMonorail.Scripts.Monorail.Drawnings
|
||||
{
|
||||
public class DrawningMonorailCompareByColor : IComparer<DrawingMonorail?>
|
||||
{
|
||||
public int Compare(DrawingMonorail? x, DrawingMonorail? y)
|
||||
{
|
||||
if (x == null || x.EntityMonorail == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMonorail == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityMonorail.BodyColor.Name.CompareTo(y.EntityMonorail.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityMonorail.Speed.CompareTo(y.EntityMonorail.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityMonorail.Weight.CompareTo(y.EntityMonorail.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
namespace ProjectMonorail.Scripts.Monorail.Drawnings
|
||||
{
|
||||
public class DrawningMonorailCompareByType : IComparer<DrawingMonorail?>
|
||||
{
|
||||
public int Compare(DrawingMonorail? x, DrawingMonorail? y)
|
||||
{
|
||||
if (x == null || x.EntityMonorail == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityMonorail == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityMonorail.Speed.CompareTo(y.EntityMonorail.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityMonorail.Weight.CompareTo(y.EntityMonorail.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,3 +12,88 @@
|
||||
2024-05-06 14:08:05.188 +04:00 [ERR] Ошибка Превышение лимита Count
|
||||
2024-05-06 14:08:10.722 +04:00 [INF] Объект удален
|
||||
2024-05-06 14:08:14.155 +04:00 [ERR] Ошибка Не найден объект по позиции 1
|
||||
2024-05-20 13:43:49.154 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 13:43:55.063 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 13:44:04.649 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 13:44:09.741 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 13:47:59.503 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 13:48:03.958 +04:00 [INF] Коллекция добавлена sd
|
||||
2024-05-20 13:48:14.843 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 13:48:20.763 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 13:58:38.538 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 13:58:45.165 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 13:58:53.797 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 13:59:04.575 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:00:26.792 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:00:32.892 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:00:41.174 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:00:46.607 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:01:34.975 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:01:47.505 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:01:57.118 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:02:02.793 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:04:33.102 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:04:37.518 +04:00 [INF] Коллекция добавлена d
|
||||
2024-05-20 14:04:48.752 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:04:54.597 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:10:18.005 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:10:23.363 +04:00 [INF] Коллекция добавлена фыв
|
||||
2024-05-20 14:10:23.582 +04:00 [INF] Коллекция добавлена фыв
|
||||
2024-05-20 14:10:31.911 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:10:44.893 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:10:56.657 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:11:02.746 +04:00 [INF] Коллекция добавлена йцу
|
||||
2024-05-20 14:11:10.587 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:11:17.218 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:14:46.591 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:14:50.377 +04:00 [INF] Коллекция добавлена sd
|
||||
2024-05-20 14:14:57.882 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:15:03.383 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:15:15.539 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:22:19.625 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:22:25.017 +04:00 [INF] Коллекция добавлена as
|
||||
2024-05-20 14:22:39.180 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:22:47.090 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:23:01.997 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:30:56.095 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:31:01.668 +04:00 [INF] Коллекция добавлена sdasd
|
||||
2024-05-20 14:31:12.459 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:35:16.467 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:35:21.147 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:35:34.782 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:35:42.981 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:36:10.064 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 2
|
||||
2024-05-20 14:36:19.247 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:36:24.255 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:36:33.903 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:36:39.670 +04:00 [INF] Коллекция добавлена asdd
|
||||
2024-05-20 14:36:50.550 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:38:31.068 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:38:36.057 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:38:44.485 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:40:08.313 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:40:12.550 +04:00 [INF] Коллекция добавлена sd
|
||||
2024-05-20 14:40:21.582 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:41:34.646 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:41:39.595 +04:00 [INF] Коллекция добавлена dasd
|
||||
2024-05-20 14:41:48.820 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:43:17.465 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:43:21.815 +04:00 [INF] Коллекция добавлена sd
|
||||
2024-05-20 14:44:28.308 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:44:33.543 +04:00 [INF] Коллекция добавлена sdf
|
||||
2024-05-20 14:44:45.760 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:46:16.617 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:46:22.102 +04:00 [INF] Коллекция добавлена asd
|
||||
2024-05-20 14:46:30.969 +04:00 [ERR] Ошибка Выход за границы коллекции.Позиция 1
|
||||
2024-05-20 14:47:34.012 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:47:39.072 +04:00 [INF] Коллекция добавлена dasd
|
||||
2024-05-20 14:47:47.580 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:47:55.617 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:49:02.503 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 14:49:08.880 +04:00 [INF] Коллекция добавлена asda
|
||||
2024-05-20 14:49:52.278 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:49:58.310 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:50:15.658 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:50:29.201 +04:00 [ERR] Ошибка: Error in the application.
|
||||
2024-05-20 14:50:36.583 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 14:50:56.225 +04:00 [INF] Объект добавлен
|
||||
|
Loading…
x
Reference in New Issue
Block a user
У списка есть метод Contains для проверки