From 3914438f645b160f189eebd059ea8ff0a60ccdc3 Mon Sep 17 00:00:00 2001 From: IlyasValiulov <148232695+IlyasValiulov@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:36:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=966=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageCollection.cs | 115 ++---------------- 1 file changed, 9 insertions(+), 106 deletions(-) diff --git a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/StorageCollection.cs b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/StorageCollection.cs index 76a322f..cc77b06 100644 --- a/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectWarmlyShip/ProjectWarmlyShip/CollectionGenericObjects/StorageCollection.cs @@ -96,19 +96,18 @@ public class StorageCollection writer.Write(_collectionKey); foreach (KeyValuePair> 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; @@ -116,52 +115,11 @@ public class StorageCollection { continue; } - sb.Append(data); - sb.Append(_separatorItems); + writer.Write(data); + writer.Write(_separatorItems); } - writer.Write(sb); } - } - //if (_storages.Count == 0) - //{ - // return false; - //} - //if (File.Exists(filename)) - //{ - // File.Delete(filename); - //} - //StringBuilder sb = new(); - //sb.Append(_collectionKey); - //foreach (KeyValuePair> value in _storages) - //{ - // sb.Append(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); - // foreach (T? item in value.Value.GetItems()) - // { - // string data = item?.GetDataForSave() ?? string.Empty; - // if (string.IsNullOrEmpty(data)) - // { - // continue; - // } - // sb.Append(data); - // sb.Append(_separatorItems); - // } - //} - //using FileStream fs = new(filename, FileMode.Create); - //byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString()); - //fs.Write(info, 0, info.Length); - return true; } /// @@ -190,11 +148,6 @@ public class StorageCollection string strs = ""; while ((strs = fs.ReadLine()) != null) { - //по идее этого произойти не должно - //if (strs == null) - //{ - // return false; - //} string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); if (record.Length != 4) { @@ -221,56 +174,6 @@ public class StorageCollection _storages.Add(record[0], collection); } return true; - //string bufferTextFromFile = ""; - //using (FileStream fs = new(filename, FileMode.Open)) - //{ - // byte[] b = new byte[fs.Length]; - // UTF8Encoding temp = new(true); - // 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; - //} - //if (!strs[0].Equals(_collectionKey)) - //{ - // //если нет такой записи, то это не те данные - // return false; - //} - //_storages.Clear(); - //foreach (string data in strs) - //{ - // string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - // if (record.Length != 4) - // { - // continue; - // } - // CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); - // ICollectionGenericObjects? collection = StorageCollection.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?.CreateDrawningShip() is T ship) - // { - // if (collection.Insert(ship) == -1) - // { - // return false; - // } - // } - // } - // _storages.Add(record[0], collection); - //} - //return true; } } ///