Final version
This commit is contained in:
parent
cf07e0696e
commit
326e4cf801
@ -77,23 +77,24 @@ namespace Catamaran.CollectionGenericObjects
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new();
|
|
||||||
|
|
||||||
sb.Append(_collectionKey);
|
using (StreamWriter writer = new(filename))
|
||||||
|
{
|
||||||
|
writer.Write(_collectionKey);
|
||||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||||
{
|
{
|
||||||
sb.Append(Environment.NewLine);
|
writer.Write(Environment.NewLine);
|
||||||
if (value.Value.Count == 0)
|
if (value.Value.Count == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(value.Key);
|
writer.Write(value.Key);
|
||||||
sb.Append(_separatorKeyValue);
|
writer.Write(_separatorKeyValue);
|
||||||
sb.Append(value.Value.GetCollectionType);
|
writer.Write(value.Value.GetCollectionType);
|
||||||
sb.Append(_separatorKeyValue);
|
writer.Write(_separatorKeyValue);
|
||||||
sb.Append(value.Value.MaxCount);
|
writer.Write(value.Value.MaxCount);
|
||||||
sb.Append(_separatorKeyValue);
|
writer.Write(_separatorKeyValue);
|
||||||
|
|
||||||
foreach (T? item in value.Value.GetItems())
|
foreach (T? item in value.Value.GetItems())
|
||||||
{
|
{
|
||||||
@ -103,15 +104,14 @@ namespace Catamaran.CollectionGenericObjects
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(data);
|
writer.Write(data);
|
||||||
sb.Append(_separatorItems);
|
writer.Write(_separatorItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
writer.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
using FileStream fs = new(filename, FileMode.Create);
|
|
||||||
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
|
|
||||||
fs.Write(info, 0, info.Length);
|
|
||||||
fs.Close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,32 +122,22 @@ namespace Catamaran.CollectionGenericObjects
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string bufferTextFromFile = "";
|
using (StreamReader reader = new(filename))
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
|
||||||
{
|
{
|
||||||
byte[] b = new byte[fs.Length];
|
string line = reader.ReadLine();
|
||||||
UTF8Encoding temp = new(true);
|
if (line == null || line.Length == 0)
|
||||||
while (fs.Read(b, 0, b.Length) > 0)
|
|
||||||
{
|
|
||||||
bufferTextFromFile += temp.GetString(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (strs == null || strs.Length == 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!line.Equals(_collectionKey))
|
||||||
if (!strs[0].Equals(_collectionKey))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
foreach (string data in strs)
|
while ((line = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
string[] record = data.Split(_separatorKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
string[] record = line.Split(_separatorKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (record.Length != 4)
|
if (record.Length != 4)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -173,8 +163,10 @@ namespace Catamaran.CollectionGenericObjects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_storages.Add(record[0], collection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user