some modifies in classStorage

This commit is contained in:
ekallin 2023-11-19 13:35:09 +04:00
parent 64018e06bd
commit 1896637638
2 changed files with 11 additions and 12 deletions

View File

@ -99,7 +99,7 @@ namespace ProjectElectricLocomotive.Generics
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
public void SaveData(string filename)
{
if (File.Exists(filename))
{
@ -117,25 +117,25 @@ namespace ProjectElectricLocomotive.Generics
}
if (data.Length == 0)
{
return false;
throw new Exception("Нет данных для записи, ошибка");
}
using StreamWriter fs = new StreamWriter(filename);
{
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
fs.WriteLine(data);
}
return true;
return;
}
/// <summary>
/// Загрузка информации по автомобилям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename)
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
throw new Exception("Файл не найден");
}
using (StreamReader fs = File.OpenText(filename))
@ -145,13 +145,13 @@ namespace ProjectElectricLocomotive.Generics
if (str == null || str.Length == 0)
{
return false;
throw new Exception("Нет данных для загрузки");
}
if (!str.StartsWith("LocomotiveStorage"))
{
//если нет такой записи, то это не те данные
return false;
throw new Exception("Неверный формат данных");
}
_locomotivesStorage.Clear();
@ -163,7 +163,7 @@ namespace ProjectElectricLocomotive.Generics
if (strs == null)
{
return false;
throw new Exception("Нет данных для загрузки");
}
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
@ -180,13 +180,13 @@ namespace ProjectElectricLocomotive.Generics
{
if ((collection + loco) == -1) // for my realization it's -1, for eegov's realization it's boolean
{
return false;
throw new Exception("Ошибка добавления ");
}
}
}
_locomotivesStorage.Add(record[0], collection);
}
return true;
return;
}
}
}

View File

@ -13,8 +13,7 @@ namespace ProjectElectricLocomotive
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(string message, Exception exception) : base(message, exception) { }
protected StorageOverflowException(SerializationInfo info,
StreamingContext contex) : base(info, contex) { }
}