изменения
This commit is contained in:
parent
0c37935388
commit
258eb869bd
@ -34,18 +34,16 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (name == null || _storages.ContainsKey(name)) { return; }
|
||||
switch (collectionType)
|
||||
|
||||
if (string.IsNullOrEmpty(name)) return;
|
||||
if (_storages.ContainsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
case CollectionType.None:
|
||||
return;
|
||||
case CollectionType.Massive:
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
return;
|
||||
case CollectionType.List:
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
return;
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
}
|
||||
else if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,28 +95,31 @@ public class StorageCollection<T>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.Append(Environment.NewLine);
|
||||
|
||||
writer.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sb.Append(value.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.GetCollectionType);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.GetCollectionType);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
{
|
||||
string data = item?.GetDataForSave() ?? string.Empty;
|
||||
@ -126,12 +127,11 @@ public class StorageCollection<T>
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sb.Append(data);
|
||||
sb.Append(_separatorItems);
|
||||
}
|
||||
writer.Write(sb);
|
||||
}
|
||||
|
||||
writer.Write(data);
|
||||
writer.Write(_separatorItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -147,9 +147,10 @@ public class StorageCollection<T>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
|
||||
using (StreamReader reader = File.OpenText(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
string? str = reader.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
return false;
|
||||
@ -159,31 +160,31 @@ public class StorageCollection<T>
|
||||
return false;
|
||||
}
|
||||
_storages.Clear();
|
||||
string strs = "";
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
string? strs = "";
|
||||
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
||||
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?.CreateDrawningTrackedVehicle() is T locomotive)
|
||||
if (elem?.CreateDrawningTrackedVehicle() is T ship)
|
||||
{
|
||||
if (collection.Insert(locomotive) == -1)
|
||||
if (collection.Insert(ship) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -191,6 +192,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +107,9 @@ public class DrawningTrackedVehicle
|
||||
|
||||
}
|
||||
|
||||
public DrawningTrackedVehicle(EntityTrackedVehicle car)
|
||||
public DrawningTrackedVehicle(EntityTrackedVehicle car) : this()
|
||||
{
|
||||
this.car = car;
|
||||
EntityTrackedVehicle = car;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ public static class ExtentionDrawningTrackedVehicle
|
||||
{
|
||||
return new DrawningExcavator(car);
|
||||
}
|
||||
car = EntityExcavator.CreateEntityExcavator(strs);
|
||||
car = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
|
||||
if (car != null)
|
||||
{
|
||||
return new DrawningTrackedVehicle(car);
|
||||
|
@ -59,7 +59,7 @@ public class EntityTrackedVehicle
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
public static EntityTrackedVehicle? CreateEntityShip(string[] strs)
|
||||
public static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs)
|
||||
{
|
||||
if (strs.Length != 4 || strs[0] != nameof(EntityTrackedVehicle))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user