some modifies in classStorage
This commit is contained in:
parent
64018e06bd
commit
1896637638
@ -99,7 +99,7 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
public bool SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -117,25 +117,25 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
}
|
}
|
||||||
if (data.Length == 0)
|
if (data.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Нет данных для записи, ошибка");
|
||||||
}
|
}
|
||||||
using StreamWriter fs = new StreamWriter(filename);
|
using StreamWriter fs = new StreamWriter(filename);
|
||||||
{
|
{
|
||||||
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
|
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
|
||||||
fs.WriteLine(data);
|
fs.WriteLine(data);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Загрузка информации по автомобилям в хранилище из файла
|
/// Загрузка информации по автомобилям в хранилище из файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
public bool LoadData(string filename)
|
public void LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Файл не найден");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader fs = File.OpenText(filename))
|
using (StreamReader fs = File.OpenText(filename))
|
||||||
@ -145,13 +145,13 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
|
|
||||||
if (str == null || str.Length == 0)
|
if (str == null || str.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Нет данных для загрузки");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str.StartsWith("LocomotiveStorage"))
|
if (!str.StartsWith("LocomotiveStorage"))
|
||||||
{
|
{
|
||||||
//если нет такой записи, то это не те данные
|
//если нет такой записи, то это не те данные
|
||||||
return false;
|
throw new Exception("Неверный формат данных");
|
||||||
}
|
}
|
||||||
|
|
||||||
_locomotivesStorage.Clear();
|
_locomotivesStorage.Clear();
|
||||||
@ -163,7 +163,7 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
|
|
||||||
if (strs == null)
|
if (strs == null)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Нет данных для загрузки");
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
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
|
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);
|
_locomotivesStorage.Add(record[0], collection);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ namespace ProjectElectricLocomotive
|
|||||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
public StorageOverflowException() : base() { }
|
public StorageOverflowException() : base() { }
|
||||||
public StorageOverflowException(string message) : base(message) { }
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
public StorageOverflowException(string message, Exception exception)
|
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
: base(message, exception) { }
|
|
||||||
protected StorageOverflowException(SerializationInfo info,
|
protected StorageOverflowException(SerializationInfo info,
|
||||||
StreamingContext contex) : base(info, contex) { }
|
StreamingContext contex) : base(info, contex) { }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user