файлы лабораторной
This commit is contained in:
parent
a8df138423
commit
7d86b06bea
@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace ProjectLainer.Generics
|
||||
{
|
||||
internal class LainersGenericStorage
|
||||
internal class LainersGenericStorage
|
||||
{
|
||||
|
||||
readonly Dictionary<LainersCollectionInfo, LainersGenericCollection<DrawingEntity, DrawningObjectLainer>> _lainerStorages;
|
||||
@ -26,7 +26,7 @@ namespace ProjectLainer.Generics
|
||||
{
|
||||
//проверка
|
||||
var addItem = new LainersCollectionInfo(name, null);
|
||||
foreach(LainersCollectionInfo elem in Keys)
|
||||
foreach (LainersCollectionInfo elem in Keys)
|
||||
{
|
||||
if (addItem.Equals(elem))
|
||||
{
|
||||
@ -54,7 +54,7 @@ namespace ProjectLainer.Generics
|
||||
get
|
||||
{
|
||||
var getItem = new LainersCollectionInfo(ind, null);
|
||||
foreach(LainersCollectionInfo elem in Keys)
|
||||
foreach (LainersCollectionInfo elem in Keys)
|
||||
{
|
||||
if (getItem.Equals(elem))
|
||||
{
|
||||
@ -74,10 +74,10 @@ namespace ProjectLainer.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<LainersCollectionInfo, LainersGenericCollection<DrawingEntity, DrawningObjectLainer>> record in _lainerStorages)
|
||||
foreach (KeyValuePair<LainersCollectionInfo, LainersGenericCollection<DrawingLainer, DrawningObjectLainer>> record in _lainerStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingEntity? elem in record.Value.GetLainers)
|
||||
foreach (DrawingLainer? elem in record.Value.GetLainers)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
@ -87,69 +87,56 @@ namespace ProjectLainer.Generics
|
||||
{
|
||||
throw new ArgumentException("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"LainerStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
return;
|
||||
|
||||
using (StreamWriter sw = new(filename))
|
||||
{
|
||||
sw.WriteLine($"LainerStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
}
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new Exception("Файл не найден");
|
||||
throw new NullReferenceException("Файл не найден");
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
string str = sr.ReadLine();
|
||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
throw new NullReferenceException("нет данных для загрузки");
|
||||
}
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!strs[0].StartsWith("CarStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new ArgumentException("Неверный формат данных");
|
||||
}
|
||||
_lainerStorages.Clear();
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
if (!strs[0].StartsWith("LainerStorage"))
|
||||
{
|
||||
continue;
|
||||
throw new ArgumentException("неверный фориат данных");
|
||||
}
|
||||
LainersGenericCollection<DrawingEntity, DrawningObjectLainer>
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
_lainerStorages.Clear();
|
||||
do
|
||||
{
|
||||
DrawingEntity? lainer =
|
||||
elem?.CreateDrawningLainer(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (lainer != null)
|
||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
if (!(collection + lainer))
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
}
|
||||
LainersGenericCollection<DrawingLainer, DrawningObjectLainer> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawingLainer? lainer = elem?.CreateDrawningLainer(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (lainer != null)
|
||||
{
|
||||
throw new OverflowException("Ошибка добавления в коллекцию");
|
||||
if (!(collection + lainer))
|
||||
{
|
||||
throw new IOException("Ошибка добавления в коллекцию");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_lainerStorages.Add(new LainersCollectionInfo(record[0],
|
||||
string.Empty), collection);
|
||||
_lainerStorages.Add(new LainerCollectionInfo(record[0], null), collection);
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user