WIP: ПИбд-23 Волков Никита Андреевич Лабораторная работа №8 #10
@ -127,10 +127,17 @@ namespace Bulldozer
|
|||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
_logger.LogInformation("Объект добавлен");
|
_logger.LogInformation("Объект добавлен");
|
||||||
pictureBoxCollection.Image = obj.ShowBulldozers();
|
pictureBoxCollection.Image = obj.ShowBulldozers();
|
||||||
} catch(Exception ex) {
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
|
{
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
_logger.LogWarning($"Объект не добавлен в набор {listBoxBulldozerStorages.SelectedItem.ToString()}");
|
_logger.LogWarning($"Объект не добавлен в набор {listBoxBulldozerStorages.SelectedItem.ToString()}");
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||||
|
_logger.LogWarning($"Добавляемый объект уже существует в коллекции {listBoxBulldozerStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
33
Bulldozer/Bulldozer/Generics/BulldozerCollectionInfo.cs
Normal file
33
Bulldozer/Bulldozer/Generics/BulldozerCollectionInfo.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class BulldozerCollectionInfo: IEquatable<BulldozerCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public BulldozerCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(BulldozerCollectionInfo other)
|
||||||
|
{
|
||||||
|
if (Name != other?.Name)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -60,7 +60,7 @@ namespace Bulldozer.Generics
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return false;
|
return false;
|
||||||
return collect._collection.Insert(obj);
|
return collect?._collection.Insert(obj, new DrawingBulldozerEqutables()) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -3,6 +3,7 @@ using Bulldozer.MovementStrategy;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Bulldozer.Exceptions;
|
using Bulldozer.Exceptions;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Bulldozer.Generics
|
namespace Bulldozer.Generics
|
||||||
{
|
{
|
||||||
@ -14,11 +15,11 @@ namespace Bulldozer.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище)
|
/// Словарь (хранилище)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> _bulldozerStorages;
|
readonly Dictionary<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> _bulldozerStorages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий наборов
|
/// Возвращение списка названий наборов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _bulldozerStorages.Keys.ToList();
|
public List<BulldozerCollectionInfo> Keys => _bulldozerStorages.Keys.ToList();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,7 +35,7 @@ namespace Bulldozer.Generics
|
|||||||
/// <param name="pictureHeight"></param>
|
/// <param name="pictureHeight"></param>
|
||||||
public BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
public BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_bulldozerStorages = new Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>>();
|
_bulldozerStorages = new Dictionary<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -44,9 +45,9 @@ namespace Bulldozer.Generics
|
|||||||
/// <param name="name">Название набора</param>
|
/// <param name="name">Название набора</param>
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
if (!_bulldozerStorages.ContainsKey(name))
|
if (!_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(name, string.Empty)))
|
||||||
{
|
{
|
||||||
_bulldozerStorages.Add(name, new BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>(_pictureWidth, _pictureHeight));
|
_bulldozerStorages.Add(new BulldozerCollectionInfo(name, string.Empty), new BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>(_pictureWidth, _pictureHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -58,9 +59,9 @@ namespace Bulldozer.Generics
|
|||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
// TODO: Прописать логику для удаления набора
|
// TODO: Прописать логику для удаления набора
|
||||||
if (_bulldozerStorages.ContainsKey(name))
|
if (_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(name, string.Empty)))
|
||||||
{
|
{
|
||||||
_bulldozerStorages.Remove(name);
|
_bulldozerStorages.Remove(new BulldozerCollectionInfo(name, string.Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -73,14 +74,11 @@ namespace Bulldozer.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_bulldozerStorages.ContainsKey(ind))
|
if (_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(ind, string.Empty)))
|
||||||
{
|
{
|
||||||
return _bulldozerStorages[ind];
|
return _bulldozerStorages[new BulldozerCollectionInfo(ind, string.Empty)];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Разделитель для записи ключа и значения элемента словаря
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
@ -107,7 +105,7 @@ namespace Bulldozer.Generics
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
StringBuilder data = new();
|
StringBuilder data = new();
|
||||||
foreach (KeyValuePair<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> record in _bulldozerStorages)
|
foreach (KeyValuePair<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> record in _bulldozerStorages)
|
||||||
{
|
{
|
||||||
StringBuilder records = new();
|
StringBuilder records = new();
|
||||||
foreach (DrawingBulldozer? elem in record.Value.GetBulldozers)
|
foreach (DrawingBulldozer? elem in record.Value.GetBulldozers)
|
||||||
@ -189,7 +187,7 @@ namespace Bulldozer.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_bulldozerStorages.Add(record[0], collection);
|
_bulldozerStorages.Add(new BulldozerCollectionInfo(record[0], string.Empty), collection);
|
||||||
|
|
||||||
str = sr.ReadLine();
|
str = sr.ReadLine();
|
||||||
} while (str != null);
|
} while (str != null);
|
||||||
|
@ -45,7 +45,10 @@ namespace Bulldozer.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T bulldozer, IEqualityComparer<T?>? equal = null)
|
public bool Insert(T bulldozer, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
return Insert(bulldozer, 0, equal);
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Insert(bulldozer, 0, equal);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -55,10 +58,14 @@ namespace Bulldozer.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T bulldozer , int position, IEqualityComparer<T?>? equal = null)
|
public bool Insert(T bulldozer , int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount) {
|
if (_places.Count >= _maxCount)
|
||||||
throw new StorageOverflowException("Вставка невозможна.");
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (Count >= _maxCount) throw new StorageOverflowException(_maxCount);
|
|
||||||
if (equal != null)
|
if (equal != null)
|
||||||
{
|
{
|
||||||
if (_places.Contains(bulldozer, equal))
|
if (_places.Contains(bulldozer, equal))
|
||||||
|
Loading…
Reference in New Issue
Block a user