ещё раз
This commit is contained in:
parent
26b6a7c8f0
commit
13860fad44
@ -1,8 +1,7 @@
|
|||||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
using ProjectAirFighter.CollectionGenericObjects;
|
||||||
|
|
||||||
|
namespace AirFighter;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс, хранящиий информацию по коллекции
|
|
||||||
/// </summary>
|
|
||||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,7 +30,8 @@ public class CollectionInfo : IEquatable<CollectionInfo>
|
|||||||
/// <param name="name">Название</param>
|
/// <param name="name">Название</param>
|
||||||
/// <param name="collectionType">Тип</param>
|
/// <param name="collectionType">Тип</param>
|
||||||
/// <param name="description">Описание</param>
|
/// <param name="description">Описание</param>
|
||||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
public CollectionInfo(string name, CollectionType collectionType, string
|
||||||
|
description)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
CollectionType = collectionType;
|
CollectionType = collectionType;
|
||||||
@ -45,13 +45,15 @@ public class CollectionInfo : IEquatable<CollectionInfo>
|
|||||||
/// <returns>Объект или null</returns>
|
/// <returns>Объект или null</returns>
|
||||||
public static CollectionInfo? GetCollectionInfo(string data)
|
public static CollectionInfo? GetCollectionInfo(string data)
|
||||||
{
|
{
|
||||||
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
|
string[] strs = data.Split(_separator,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (strs.Length < 1 || strs.Length > 3)
|
if (strs.Length < 1 || strs.Length > 3)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
|
return new CollectionInfo(strs[0],
|
||||||
|
(CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -69,6 +71,12 @@ public class CollectionInfo : IEquatable<CollectionInfo>
|
|||||||
return Equals(obj as CollectionInfo);
|
return Equals(obj as CollectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Name) && CollectionType != CollectionType.None) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return Name.GetHashCode();
|
return Name.GetHashCode();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ProjectAirFighter.Exceptions;
|
using AirFighter;
|
||||||
|
using ProjectAirFighter.Exceptions;
|
||||||
|
|
||||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
using ProjectAirFighter.Drawnings;
|
using AirFighter;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using ProjectAirFighter.Drawnings;
|
||||||
using ProjectAirFighter.Exceptions;
|
using ProjectAirFighter.Exceptions;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ProjectAirFighter.CollectionGenericObjects;
|
namespace ProjectAirFighter.CollectionGenericObjects;
|
||||||
@ -46,16 +49,15 @@ public class StorageCollection<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление коллекции в хранилище
|
/// Добавление коллекции в хранилище
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="collectionInfo">тип коллекции</param>
|
||||||
/// <param name="collectionType">тип коллекции</param>
|
public void AddCollection(CollectionInfo collectionInfo)
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
|
||||||
{
|
{
|
||||||
if (name == null || _storages.ContainsKey(name)) { return; }
|
if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
|
||||||
switch (collectionType)
|
switch (collectionType)
|
||||||
|
|
||||||
{
|
{
|
||||||
case CollectionType.None:
|
case CollectionType.None:
|
||||||
return;
|
throw new CollectionTypeException("Пустой тип коллекции");
|
||||||
case CollectionType.Massive:
|
case CollectionType.Massive:
|
||||||
_storages[name] = new MassiveGenericObjects<T>();
|
_storages[name] = new MassiveGenericObjects<T>();
|
||||||
return;
|
return;
|
||||||
@ -69,10 +71,10 @@ public class StorageCollection<T>
|
|||||||
/// Удаление коллекции
|
/// Удаление коллекции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
public void DelCollection(string name)
|
public void DelCollection(CollectionInfo collectionInfo)
|
||||||
{
|
{
|
||||||
if (_storages.ContainsKey(name))
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
_storages.Remove(name);
|
_storages.Remove(collectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -80,12 +82,13 @@ public class StorageCollection<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ICollectionGenericObjects<T>? this[string name]
|
public ICollectionGenericObjects<T>? this[CollectionInfo collectionInfo]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (name == null || !_storages.ContainsKey(name)) { return null; }
|
if(_storages.ContainsKey(collectionInfo))
|
||||||
return _storages[name];
|
return _storages[collectionInfo];
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +155,7 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException("Файл не существует");
|
throw new FileNotFoundException(filename);
|
||||||
}
|
}
|
||||||
using (StreamReader fs = File.OpenText(filename))
|
using (StreamReader fs = File.OpenText(filename))
|
||||||
{
|
{
|
||||||
@ -165,7 +168,7 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
if (!str.StartsWith(_collectionKey))
|
if (!str.StartsWith(_collectionKey))
|
||||||
{
|
{
|
||||||
throw new FormatException("В файле неверные данные");
|
throw new FormatException(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
@ -196,14 +199,11 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (collection.Insert(militaryAircraft) == -1)
|
collection.Insert(militaryAircraft);
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (CollectionOverflowException ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new CollectionOverflowException("Коллекция переполнена", ex);
|
throw new FileFormatException(filename, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace AirFighter;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AirFighter;
|
||||||
|
|
||||||
public class CollectionInfoException : Exception
|
public class CollectionInfoException : Exception
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
namespace AirFighter;
|
using System.Runtime.Serialization;
|
||||||
|
namespace AirFighter;
|
||||||
|
|
||||||
public class CollectionInsertException : Exception
|
public class CollectionInsertException : Exception
|
||||||
{
|
{
|
||||||
|
@ -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) { }
|
||||||
|
}
|
@ -14,7 +14,7 @@
|
|||||||
],
|
],
|
||||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Application": "Stormtrooper"
|
"Application": "AirFighter"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user