Compare commits

..

2 Commits

Author SHA1 Message Date
d85edc7af6 lastkonflict 2024-06-12 18:11:50 +03:00
2d8d0c28a9 so ism 2024-04-24 14:48:16 +03:00

View File

@ -116,7 +116,7 @@ public class StorageCollection<T>
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
writer.Write(Environment.NewLine);
// не сохраняем пустые коллекции
if (value.Value.Count == 0)
{
continue;
@ -154,68 +154,50 @@ public class StorageCollection<T>
{
throw new Exception("Файл не существует");
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader fs = File.OpenText(filename))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
bufferTextFromFile += temp.GetString(b);
return false;
}
}
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
if (!str.StartsWith(_collectionKey))
{
throw new Exception("В файле нет данных");
return false;
}
if (!strs[0].Equals(_collectionKey))
{
throw new Exception("В файле неверные данные");
}
_storages.Clear();
foreach (string data in strs)
string strs = "";
while ((strs = fs.ReadLine()) != null)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType) ??
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
return false;
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningWarmlyShip() is T car)
if (elem?.CreateDrawningWarmlyShip() is T warmlyship)
{
try
if (!collection.Insert(warmlyship))
{
if (!collection.Insert(car))
{
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
{
throw new Exception("Коллекция переполнена", ex);
return false;
}
}
}
_storages.Add(record[0], collection);
}
return true;
}
}
/// <summary>
/// Создание коллекции по типу