fix
This commit is contained in:
parent
8a3e041126
commit
847ecf21d8
@ -103,7 +103,7 @@ public class StorageCollection<T>
|
|||||||
/// Сохранение информации по автомобилям в хранилище в файл
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
public void SaveData(string filename)
|
public bool SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (_storages.Count == 0)
|
if (_storages.Count == 0)
|
||||||
{
|
{
|
||||||
@ -156,11 +156,11 @@ public class StorageCollection<T>
|
|||||||
/// Загрузка информации по автомобилям в хранилище из файла
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
public void LoadData(string filename)
|
public bool LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
throw new Exception("Файл не существует");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader sr = new StreamReader(filename))
|
using (StreamReader sr = new StreamReader(filename))
|
||||||
@ -171,15 +171,9 @@ public class StorageCollection<T>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
if (!str[0].Equals(_collectionKey))
|
||||||
if (strs == null || strs.Length == 0)
|
|
||||||
{
|
{
|
||||||
throw new Exception("В файле нет данных");
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (!strs[0].Equals(_collectionKey))
|
|
||||||
{
|
|
||||||
throw new Exception("В файле неверные данные");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
@ -193,30 +187,23 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType) ??
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||||
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||||
|
|
||||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
{
|
||||||
if (elem?.CreateDrawingBoat() is T boat)
|
if (elem?.CreateDrawingBoat() is T boat)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (collection.Insert(boat) == -1)
|
if (collection.Insert(boat) == -1)
|
||||||
{
|
{
|
||||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (CollectionOverflowException ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Коллекция переполнена", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(record[0], collection);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user