Compare commits
5 Commits
ae6e3cac02
...
469dc33087
Author | SHA1 | Date | |
---|---|---|---|
469dc33087 | |||
dd34fcbfa9 | |||
1a799909f9 | |||
e1b3695a42 | |||
2306f8b82c |
28
AirBomber/Exceptions/EntityNotFoundException.cs
Normal file
28
AirBomber/Exceptions/EntityNotFoundException.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirBomber.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class EntityNotFoundException : ApplicationException
|
||||
{
|
||||
public EntityNotFoundException(int i)
|
||||
: base($"Не найден объект по позиции {i}")
|
||||
{ }
|
||||
|
||||
public EntityNotFoundException()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public EntityNotFoundException(string Message)
|
||||
: base(Message)
|
||||
{ }
|
||||
|
||||
public EntityNotFoundException(string Message, Exception Exception)
|
||||
: base(Message, Exception)
|
||||
{ }
|
||||
|
||||
public EntityNotFoundException(SerializationInfo Info, StreamingContext Context)
|
||||
: base(Info, Context)
|
||||
{ }
|
||||
}
|
||||
}
|
28
AirBomber/Exceptions/StorageOverflowException.cs
Normal file
28
AirBomber/Exceptions/StorageOverflowException.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace AirBomber.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int Count)
|
||||
: base($"В наборе превышено допустимое количество {Count}")
|
||||
{ }
|
||||
|
||||
public StorageOverflowException()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public StorageOverflowException(string Message)
|
||||
: base(Message)
|
||||
{ }
|
||||
|
||||
public StorageOverflowException(string Message, Exception Exception)
|
||||
: base(Message, Exception)
|
||||
{ }
|
||||
|
||||
public StorageOverflowException(SerializationInfo Info, StreamingContext Context)
|
||||
: base(Info, Context)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ namespace AirBomber.Generics
|
||||
public bool SaveData(string FileName)
|
||||
{
|
||||
if (_entityStorages.Count == 0)
|
||||
return false;
|
||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(FileName, false))
|
||||
{
|
||||
@ -80,10 +80,13 @@ namespace AirBomber.Generics
|
||||
|
||||
public bool LoadData(string FileName)
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
throw new Exception("Файл не найден");
|
||||
|
||||
using (StreamReader reader = new StreamReader(FileName))
|
||||
{
|
||||
if (reader.ReadLine() != "BomberStorage")
|
||||
return false;
|
||||
throw new Exception("Неверный формат данных");
|
||||
|
||||
_entityStorages.Clear();
|
||||
|
||||
@ -105,7 +108,7 @@ namespace AirBomber.Generics
|
||||
if (Renderer != null)
|
||||
{
|
||||
if ((Collection + Renderer) == -1)
|
||||
return false;
|
||||
throw new Exception("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace AirBomber.Generics
|
||||
using AirBomber.Exceptions;
|
||||
|
||||
namespace AirBomber.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
@ -27,13 +29,13 @@
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
throw new StorageOverflowException();
|
||||
}
|
||||
|
||||
public int Insert(T Entity, int Position)
|
||||
{
|
||||
if (Position >= _maxCount)
|
||||
return -1;
|
||||
throw new StorageOverflowException();
|
||||
|
||||
if (_objects[Position] is null)
|
||||
{
|
||||
@ -41,13 +43,16 @@
|
||||
return Position;
|
||||
}
|
||||
|
||||
return -1;
|
||||
throw new StorageOverflowException();
|
||||
}
|
||||
|
||||
public bool Remove(int Position)
|
||||
{
|
||||
if (Position >= _maxCount)
|
||||
return false;
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
if (_objects[Position] is null)
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
_objects[Position] = default(T);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user