Изменение методов в классе LocomotivesGenericStorage
This commit is contained in:
parent
a1d6167007
commit
fb1f7abf5c
@ -1,5 +1,4 @@
|
||||
using ProjectElectricLocomotive.DrawingObjects;
|
||||
using ProjectElectricLocomotive.Generics;
|
||||
using ProjectElectricLocomotive.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -7,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive
|
||||
namespace ProjectElectricLocomotive.Generics
|
||||
{
|
||||
internal class LocomotivesGenericStorage
|
||||
{
|
||||
@ -103,8 +102,7 @@ namespace ProjectElectricLocomotive
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record in _locomotivesStorage)
|
||||
foreach (KeyValuePair<string, LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record in _locomotivesStorage)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingLocomotive? elem in record.Value.GetLocomotives)
|
||||
@ -117,10 +115,11 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new
|
||||
UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}");
|
||||
fs.Write(info, 0, info.Length);
|
||||
using StreamWriter fs = new StreamWriter(filename);
|
||||
{
|
||||
fs.WriteLine($"LocomotiveStorage{Environment.NewLine}");
|
||||
fs.WriteLine(data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -134,46 +133,48 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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)
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
}
|
||||
}
|
||||
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
|
||||
string str = fs.ReadLine();
|
||||
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!strs[0].StartsWith("CarStorage"))
|
||||
|
||||
if (!str.StartsWith("LocomotiveStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
|
||||
_locomotivesStorage.Clear();
|
||||
foreach (string data in strs)
|
||||
string strs = "";
|
||||
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (strs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>
|
||||
collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string thing in set)
|
||||
{
|
||||
DrawingLocomotive? loco = elem?.CreateDrawningCar(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
DrawingLocomotive? loco = thing?.CreateDrawingLocomotive(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (loco != null)
|
||||
{
|
||||
if (collection + loco == -1)
|
||||
if ((collection + loco) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -185,5 +186,5 @@ namespace ProjectElectricLocomotive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user