From bcf72b173ef6d7082b4046e9e8dc1867020e4724 Mon Sep 17 00:00:00 2001
From: easynickname1 <7326033@gmail.com>
Date: Tue, 21 May 2024 00:52:52 +0400
Subject: [PATCH 1/6] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=20=D0=BD?=
=?UTF-8?q?=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B9=20=D1=81=D0=B5=D0=B9?=
=?UTF-8?q?=D0=B2=20=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ProjectMotorBoat/ProjectMotorBoat.csproj | 10 ++++------
ProjectMotorBoat/ProjectMotorBoat/nlog.config | 15 ---------------
ProjectMotorBoat/ProjectMotorBoat/save2.txt | 2 --
3 files changed, 4 insertions(+), 23 deletions(-)
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/nlog.config
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/save2.txt
diff --git a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
index 659ff05..fda71c6 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
+++ b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
@@ -8,6 +8,10 @@
enable
+
+
+
+
@@ -29,10 +33,4 @@
-
-
- Always
-
-
-
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/nlog.config b/ProjectMotorBoat/ProjectMotorBoat/nlog.config
deleted file mode 100644
index d94f71a..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/nlog.config
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/save2.txt b/ProjectMotorBoat/ProjectMotorBoat/save2.txt
deleted file mode 100644
index 458d81f..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/save2.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-CollectionsStorage
-1|Massive|55|EntityMotorBoat:100:100:Yellow:Pink:False:True:True;EntityMotorBoat:100:100:Yellow:Pink:False:True:True;EntityMotorBoat:100:100:Yellow:Pink:False:True:True;EntityMotorBoat:100:100:Yellow:Pink:False:True:True;EntityMotorBoat:100:100:Yellow:Pink:False:True:True;
\ No newline at end of file
From 01275ea1dd16833d07b00b74a66d1d8a0ea8e09b Mon Sep 17 00:00:00 2001
From: easynickname1 <7326033@gmail.com>
Date: Sun, 26 May 2024 21:09:44 +0400
Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?=
=?UTF-8?q?=D1=8B=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?=
=?UTF-8?q?=D1=8F=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B=20?=
=?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0?=
=?UTF-8?q?=D0=B9=D0=BB=D1=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../StorageCollection.cs | 139 ++++++++----------
1 file changed, 65 insertions(+), 74 deletions(-)
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
index 8001079..a99fec6 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
@@ -116,41 +116,40 @@ public class StorageCollection
File.Delete(filename);
}
- StringBuilder sb = new();
-
- sb.Append(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ using (StreamWriter wr = new StreamWriter(filename))
{
- sb.Append(Environment.NewLine);
- // Не сохраняем пустые коллекции
- if (value.Value.Count == 0)
+ wr.Write(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
{
- 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))
+ StringBuilder sb = new StringBuilder();
+ sb.Append(Environment.NewLine);
+ // Не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
{
continue;
}
- sb.Append(data);
- sb.Append(_separatorItems);
+ 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);
+ }
+ wr.Write(sb);
}
}
-
- using FileStream fs = new(filename, FileMode.Create);
- byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
- fs.Write(info, 0, info.Length);
return true;
}
@@ -166,62 +165,54 @@ public class StorageCollection
return false;
}
- string bufferTextFromFile = "";
- using (FileStream fs = new(filename, FileMode.Open))
+ using (StreamReader sr = new StreamReader(filename))
{
- 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)
+ string str = sr.ReadLine();
+ if (str == null || str.Length == 0)
{
return false;
}
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
+ if (!str.Equals(_collectionKey))
{
- if (elem?.CreateDrawingBoat() is T boat)
- {
- if (collection.Insert(boat) == 0)
- {
- return false;
- }
- }
+ // Если нет такой записи, то это не те данные
+ return false;
}
- _storages.Add(record[0], collection);
- }
+ _storages.Clear();
+ string data = "";
+ while ((data = sr.ReadLine()) != null)
+ {
+ 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?.CreateDrawingBoat() is T boat)
+ {
+ if (collection.Insert(boat) == 0)
+ {
+ return false;
+ }
+ }
+ }
+
+ _storages.Add(record[0], collection);
+ }
+ }
return true;
}
From 595f6a9dbcf642176742aa908261c704b0e21de6 Mon Sep 17 00:00:00 2001
From: easynickname1 <7326033@gmail.com>
Date: Sun, 26 May 2024 21:09:44 +0400
Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?=
=?UTF-8?q?=D1=8B=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?=
=?UTF-8?q?=D1=8F=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B=20?=
=?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0?=
=?UTF-8?q?=D0=B9=D0=BB=D1=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../StorageCollection.cs | 132 ++++++++----------
1 file changed, 62 insertions(+), 70 deletions(-)
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
index 2c0555f..b0d3ff6 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
@@ -116,41 +116,40 @@ public class StorageCollection
File.Delete(filename);
}
- StringBuilder sb = new();
-
- sb.Append(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ using (StreamWriter wr = new StreamWriter(filename))
{
- sb.Append(Environment.NewLine);
- // Не сохраняем пустые коллекции
- if (value.Value.Count == 0)
+ wr.Write(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
{
- 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))
+ StringBuilder sb = new StringBuilder();
+ sb.Append(Environment.NewLine);
+ // Не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
{
continue;
}
- sb.Append(data);
- sb.Append(_separatorItems);
+ 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);
+ }
+ wr.Write(sb);
}
}
-
- using FileStream fs = new(filename, FileMode.Create);
- byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
- fs.Write(info, 0, info.Length);
}
///
@@ -164,61 +163,54 @@ public class StorageCollection
throw new Exception("Файл не существует");
}
- string bufferTextFromFile = "";
- using (FileStream fs = new(filename, FileMode.Open))
+ using (StreamReader sr = new StreamReader(filename))
{
- byte[] b = new byte[fs.Length];
- UTF8Encoding temp = new(true);
- while (fs.Read(b, 0, b.Length) > 0)
+ string str = sr.ReadLine();
+ if (str == null || str.Length == 0)
{
- bufferTextFromFile += temp.GetString(b);
- }
- }
-
- string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
- if (strs == null || strs.Length == 0)
- {
- throw new Exception("В файле нет данных");
- }
-
- if (!strs[0].Equals(_collectionKey))
- {
- throw new Exception("В файле неверные данные");
- }
-
- _storages.Clear();
- foreach (string data in strs)
- {
- string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
- {
- continue;
+ throw new Exception("В файле нет данных");
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
- throw new Exception("Не удалось определить тип коллекции:" + record[1]);
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
+ if (!str.Equals(_collectionKey))
{
- if (elem?.CreateDrawingBoat() is T boat)
+ throw new Exception("В файле неверные данные");
+ }
+
+ _storages.Clear();
+ string data = "";
+ while ((data = sr.ReadLine()) != null)
+ {
+ string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 4)
{
- try
+ continue;
+ }
+
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
+ throw new Exception("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[2]);
+
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
+ {
+ if (elem?.CreateDrawingBoat() is T boat)
{
- if (collection.Insert(boat) == -1)
+ try
{
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ if (collection.Insert(boat) == -1)
+ {
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ }
+ }
+ catch (CollectionOverflowException ex)
+ {
+ throw new Exception("Коллекция переполнена", ex);
}
}
- catch (CollectionOverflowException ex)
- {
- throw new Exception("Коллекция переполнена", ex);
- }
+ _storages.Add(record[0], collection);
}
}
- _storages.Add(record[0], collection);
}
}
From 88b25bd0d47de3b6812dd1264176ff996cc9cb42 Mon Sep 17 00:00:00 2001
From: easynickname1 <7326033@gmail.com>
Date: Sun, 26 May 2024 21:41:55 +0400
Subject: [PATCH 4/6] =?UTF-8?q?Revert=20"=D0=94=D0=BE=D0=B4=D0=B5=D0=BB?=
=?UTF-8?q?=D0=B0=D0=BD=D1=8B=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0?=
=?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?=
=?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5?=
=?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit fe943481a9c1f4f5d0a08fbd511856b5a145ffb1.
---
.../StorageCollection.cs | 132 ++++++++++--------
1 file changed, 70 insertions(+), 62 deletions(-)
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
index b0d3ff6..2c0555f 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
@@ -116,40 +116,41 @@ public class StorageCollection
File.Delete(filename);
}
- using (StreamWriter wr = new StreamWriter(filename))
+ StringBuilder sb = new();
+
+ sb.Append(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
{
- wr.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ sb.Append(Environment.NewLine);
+ // Не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
{
- StringBuilder sb = new StringBuilder();
- 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(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);
- }
- wr.Write(sb);
+ 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);
}
///
@@ -163,54 +164,61 @@ public class StorageCollection
throw new Exception("Файл не существует");
}
- using (StreamReader sr = new StreamReader(filename))
+ string bufferTextFromFile = "";
+ using (FileStream fs = new(filename, FileMode.Open))
{
- string str = sr.ReadLine();
- if (str == null || str.Length == 0)
+ byte[] b = new byte[fs.Length];
+ UTF8Encoding temp = new(true);
+ while (fs.Read(b, 0, b.Length) > 0)
{
- throw new Exception("В файле нет данных");
+ bufferTextFromFile += temp.GetString(b);
+ }
+ }
+
+ string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
+ if (strs == null || strs.Length == 0)
+ {
+ throw new Exception("В файле нет данных");
+ }
+
+ if (!strs[0].Equals(_collectionKey))
+ {
+ throw new Exception("В файле неверные данные");
+ }
+
+ _storages.Clear();
+ foreach (string data in strs)
+ {
+ string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 4)
+ {
+ continue;
}
- if (!str.Equals(_collectionKey))
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
+ throw new Exception("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[2]);
+
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
{
- throw new Exception("В файле неверные данные");
- }
-
- _storages.Clear();
- string data = "";
- while ((data = sr.ReadLine()) != null)
- {
- string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (elem?.CreateDrawingBoat() is T boat)
{
- continue;
- }
-
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
- throw new Exception("Не удалось определить тип коллекции:" + record[1]);
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
- {
- if (elem?.CreateDrawingBoat() is T boat)
+ try
{
- try
+ if (collection.Insert(boat) == -1)
{
- if (collection.Insert(boat) == -1)
- {
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
- }
- }
- catch (CollectionOverflowException ex)
- {
- throw new Exception("Коллекция переполнена", ex);
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
- _storages.Add(record[0], collection);
+ catch (CollectionOverflowException ex)
+ {
+ throw new Exception("Коллекция переполнена", ex);
+ }
}
}
+ _storages.Add(record[0], collection);
}
}
From 8a3e041126ce48dba51abe9ef99cfceb0226e83f Mon Sep 17 00:00:00 2001
From: Pyro <732603@gmail.com>
Date: Mon, 17 Jun 2024 00:15:50 +0400
Subject: [PATCH 5/6] =?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?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 12 +--
.../BoatHarborService.cs | 21 ++--
.../ICollectionGenericObjects.cs | 6 +-
.../ListGenericObjects.cs | 47 ++++----
.../MassiveGenericObjects.cs | 47 ++++----
.../StorageCollection.cs | 50 +++++----
.../Exceptions/CollectionOverflowException.cs | 20 ----
.../Exceptions/ObjectNotFoundException.cs | 20 ----
.../PositionOutOfCollectionException.cs | 20 ----
.../FormBoatCollection.Designer.cs | 16 +--
.../ProjectMotorBoat/FormBoatCollection.cs | 102 ++++++------------
ProjectMotorBoat/ProjectMotorBoat/Program.cs | 29 +----
.../ProjectMotorBoat/ProjectMotorBoat.csproj | 10 --
ProjectMotorBoat/ProjectMotorBoat/save.txt | 2 -
14 files changed, 133 insertions(+), 269 deletions(-)
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs
delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/save.txt
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs
index 524d736..5a87d1f 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs
@@ -10,7 +10,7 @@ public abstract class AbstractCompany
///
/// Размер места (ширина)
///
- protected readonly int _placeSizeWidth = 126;
+ protected readonly int _placeSizeWidth = 120;
///
/// Размер места (высота)
@@ -35,7 +35,7 @@ public abstract class AbstractCompany
///
/// Вычисление максимального количества элементов, который можно разместить в окне
///
- private int GetMaxCount => (_pictureWidth * _pictureHeight) / (_placeSizeWidth * _placeSizeHeight);
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
///
/// Конструктор
@@ -96,12 +96,8 @@ public abstract class AbstractCompany
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
- try
- {
- DrawingBoat? obj = _collection?.Get(i);
- obj?.DrawTransport(graphics);
- }
- catch (Exception) { }
+ DrawingBoat? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
}
return bitmap;
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs
index 58ee77b..0854001 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs
@@ -1,6 +1,5 @@
using ProjectMotorBoat.Drawings;
using ProjectMotorBoat.Entities;
-using ProjectMotorBoat.Exceptions;
using System.Drawing;
namespace ProjectMotorBoat.CollectionGenericObjects;
@@ -25,9 +24,9 @@ public class BoatHarborService : AbstractCompany
{
Pen pen = new(Color.BurlyWood, 4);
- for (int startPosX = 0; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += _placeSizeWidth)
+ for (int startPosX = 5; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += _placeSizeWidth)
{
- for (int startPosY = 0; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += _placeSizeHeight)
+ for (int startPosY = 5; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += _placeSizeHeight)
{
Point[] points =
{
@@ -43,23 +42,19 @@ public class BoatHarborService : AbstractCompany
protected override void SetObjectsPosition()
{
- int startPosX = 5;
- int startPosY = 5;
+ int startPosX = 10;
+ int startPosY = 10;
- for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ for (int i = 0; _collection?.Get(i) != null; i++)
{
if (startPosX + _placeSizeWidth > _pictureWidth)
{
- startPosX = 5;
+ startPosX = 10;
startPosY += _placeSizeHeight;
}
- try
- {
- _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
- _collection.Get(i).SetPosition(startPosX, startPosY);
- }
- catch (Exception) { }
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(startPosX, startPosY);
startPosX += _placeSizeWidth;
}
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs
index 329018d..b405892 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -21,7 +21,7 @@ public interface ICollectionGenericObjects
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
- /// Count - вставка прошла удачно, -1 - вставка не удалась
+ /// true - вставка прошла удачно, false - вставка не удалась
int Insert(T obj);
///
@@ -29,14 +29,14 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// Позиция
- /// Count - вставка прошла удачно, -1 - вставка не удалась
+ /// true - вставка прошла удачно, false - вставка не удалась
int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
- /// Объект
+ /// true - удаление прошло удачно, false - удаление не удалось
T? Remove(int position);
///
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs
index ff3e277..f815ab9 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,6 +1,4 @@
-using ProjectMotorBoat.Exceptions;
-
-namespace ProjectMotorBoat.CollectionGenericObjects;
+namespace ProjectMotorBoat.CollectionGenericObjects;
///
/// Параметризованный набор объектов
@@ -41,41 +39,46 @@ public class ListGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- // выброс ошибки, если выход за границы массива
- if (position < 0 || position > _collection.Count) throw new PositionOutOfCollectionException(position);
- return _collection[position];
+ if (position < Count && _collection[position] != null)
+ {
+ return _collection[position];
+ }
+ return null;
}
public int Insert(T obj)
{
- // выброс ошибки, если переполнение
- if (Count >= _maxCount) throw new CollectionOverflowException(Count);
- _collection.Add(obj);
- return _collection.Count;
+ if (Count < _maxCount)
+ {
+ _collection.Add(obj);
+ return _collection.Count;
+ }
+ return -1;
}
public int Insert(T obj, int position)
{
- // выброс ошибки, если переполнение
- if (Count >= _maxCount) throw new CollectionOverflowException();
-
- if (_collection[position] == null)
+ if (Count < _maxCount)
{
- _collection.Insert(position, obj);
- return position;
+ if (_collection[position] == null)
+ {
+ _collection.Insert(position, obj);
+ return position;
+ }
}
return -1;
}
public T? Remove(int position)
{
- // выброс ошибки, если выход за границы массива
- if (position < 0 || position > _collection.Count) throw new PositionOutOfCollectionException(position);
- if (_collection[position] != null)
+ if (Count < _maxCount)
{
- T? obj = _collection[position];
- _collection.RemoveAt(position);
- return obj;
+ if (_collection[position] != null)
+ {
+ T? obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
+ }
}
return null;
}
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs
index a0ca361..27cc790 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,6 +1,4 @@
-using ProjectMotorBoat.Exceptions;
-
-namespace ProjectMotorBoat.CollectionGenericObjects;
+namespace ProjectMotorBoat.CollectionGenericObjects;
///
/// Параметризованный набор объектов
@@ -50,12 +48,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- // выброс ошибки, если выход за границы массива
- if (position >= Count) throw new PositionOutOfCollectionException(position);
- // выброс ошибки, если объект пустой
- if (_collection[position] == null) throw new ObjectNotFoundException(position);
-
- return _collection[position];
+ // проверка позиции ✔
+ if (_collection[position] != null && position < Count - 1)
+ {
+ return _collection[position];
+ }
+ return null;
}
public int Insert(T obj)
@@ -69,15 +67,16 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return Count;
}
}
- // выброс ошибки, если переполнение
- throw new CollectionOverflowException(Count);
+ return -1;
}
public int Insert(T obj, int position)
{
- // выброс ошибки, если выход за границы массива
- if (position >= Count) throw new PositionOutOfCollectionException(position);
-
+ // проверка позиции ✔
+ // проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до ✔
+ // вставка ✔
if (_collection[position] != null)
{
for (int i = position; i < Count; i++)
@@ -98,20 +97,22 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
}
- // выброс ошибки, если переполнение
- throw new CollectionOverflowException(Count);
+
+ return -1;
}
public T? Remove(int position)
{
- // выброс ошибки, если выход за границы массива
- if (position >= Count) throw new PositionOutOfCollectionException(position);
- // выброс ошибки, если объект пустой
- if (_collection[position] == null) throw new ObjectNotFoundException(position);
+ // проверка позиции ✔
+ // удаление объекта из массива, присвоив элементу массива значение null ✔
+ if (_collection[position] != null)
+ {
+ T? obj = _collection[position];
+ _collection[position] = null;
+ return obj;
+ }
- T? obj = _collection[position];
- _collection[position] = null;
- return obj;
+ return null;
}
public IEnumerable GetItems()
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
index 58cdd3e..8555feb 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
@@ -1,5 +1,4 @@
using ProjectMotorBoat.Drawings;
-using ProjectMotorBoat.Exceptions;
using ProjectMotorBoat.MovementStrategy;
using System.Text;
using System.Windows.Forms;
@@ -108,7 +107,7 @@ public class StorageCollection
{
if (_storages.Count == 0)
{
- throw new Exception("В хранилище отсутствуют коллекции для сохранения");
+ return false;
}
if (File.Exists(filename))
@@ -172,11 +171,16 @@ public class StorageCollection
return false;
}
- if (!str.Equals(_collectionKey))
- {
- // Если нет такой записи, то это не те данные
- return false;
- }
+ string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
+ if (strs == null || strs.Length == 0)
+ {
+ throw new Exception("В файле нет данных");
+ }
+
+ if (!strs[0].Equals(_collectionKey))
+ {
+ throw new Exception("В файле неверные данные");
+ }
_storages.Clear();
string data = "";
@@ -188,31 +192,31 @@ public class StorageCollection
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
- return false;
- }
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
+ throw new Exception("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[2]);
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
+ {
+ if (elem?.CreateDrawingBoat() is T boat)
{
- if (elem?.CreateDrawingBoat() is T boat)
+ try
{
- if (collection.Insert(boat) == 0)
+ if (collection.Insert(boat) == -1)
{
- return false;
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
+ catch (CollectionOverflowException ex)
+ {
+ throw new Exception("Коллекция переполнена", ex);
+ }
}
-
- _storages.Add(record[0], collection);
}
+ _storages.Add(record[0], collection);
}
- return true;
}
///
diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs
deleted file mode 100644
index 25aa59b..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Runtime.Serialization;
-
-namespace ProjectMotorBoat.Exceptions;
-
-///
-/// Класс, описывающий ошибку переполнения коллекции
-///
-[Serializable]
-internal class CollectionOverflowException : ApplicationException
-{
- public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
-
- public CollectionOverflowException() : base() { }
-
- public CollectionOverflowException(string message) : base(message) { }
-
- public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
-
- protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
-}
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs
deleted file mode 100644
index d4bdf6d..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Runtime.Serialization;
-
-namespace ProjectMotorBoat.Exceptions;
-
-///
-/// Класс, описывающий ошибку, что по указанной позиции нет элемента
-///
-[Serializable]
-internal class ObjectNotFoundException : ApplicationException
-{
- public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { }
-
- public ObjectNotFoundException() : base() { }
-
- public ObjectNotFoundException(string message) : base(message) { }
-
- public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
-
- protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
-}
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs
deleted file mode 100644
index 7bbfa51..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Runtime.Serialization;
-
-namespace ProjectMotorBoat.Exceptions;
-
-///
-/// Класс, описывающий ошибку выхода за границы коллекции
-///
-[Serializable]
-internal class PositionOutOfCollectionException : ApplicationException
-{
- public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { }
-
- public PositionOutOfCollectionException() : base() { }
-
- public PositionOutOfCollectionException(string message) : base(message) { }
-
- public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
-
- protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
-}
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs
index f6297f9..fcf7995 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs
@@ -66,9 +66,9 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(763, 24);
+ groupBoxTools.Location = new Point(777, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(201, 544);
+ groupBoxTools.Size = new Size(201, 561);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -82,15 +82,15 @@
panelCompanyTools.Controls.Add(buttonRemoveBoat);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(3, 322);
+ panelCompanyTools.Location = new Point(3, 329);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(195, 219);
+ panelCompanyTools.Size = new Size(195, 229);
panelCompanyTools.TabIndex = 8;
//
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBoat.Location = new Point(3, 3);
+ buttonAddBoat.Location = new Point(3, 4);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(184, 32);
buttonAddBoat.TabIndex = 1;
@@ -249,7 +249,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(763, 544);
+ pictureBox.Size = new Size(777, 561);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -258,7 +258,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
- menuStrip.Size = new Size(964, 24);
+ menuStrip.Size = new Size(978, 24);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
@@ -297,7 +297,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(964, 568);
+ ClientSize = new Size(978, 585);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs
index 525a334..a830c41 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs
@@ -1,5 +1,4 @@
-using Microsoft.Extensions.Logging;
-using ProjectMotorBoat.CollectionGenericObjects;
+using ProjectMotorBoat.CollectionGenericObjects;
using ProjectMotorBoat.Drawings;
namespace ProjectMotorBoat;
@@ -19,19 +18,13 @@ public partial class FormBoatCollection : Form
///
private AbstractCompany? _company = null;
- ///
- /// Логер
- ///
- private readonly ILogger _logger;
-
///
/// Конструктор
///
- public FormBoatCollection(ILogger logger)
+ public FormBoatCollection()
{
InitializeComponent();
_storageCollection = new();
- _logger = logger;
}
///
@@ -68,19 +61,14 @@ public partial class FormBoatCollection : Form
return;
}
- try
+ if (_company + boat >= 0)
{
- if (_company + boat >= 0)
- {
- MessageBox.Show("Объект добавлен");
- _logger.LogInformation("Добавлен объект: {boat}", boat.GetDataForSave());
- pictureBox.Image = _company.Show();
- }
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
}
- catch (Exception ex)
+ else
{
- MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ MessageBox.Show("Не удалось добавить объект");
}
}
@@ -102,20 +90,14 @@ public partial class FormBoatCollection : Form
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
-
- try
+ if (_company - pos != null)
{
- if (_company - pos != null)
- {
- MessageBox.Show("Объект удален");
- _logger.LogInformation("Удалён объект по позиции: {pos}", pos);
- pictureBox.Image = _company.Show();
- }
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
}
- catch (Exception ex)
+ else
{
- MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ MessageBox.Show("Не удалось удалить объект");
}
}
@@ -133,33 +115,26 @@ public partial class FormBoatCollection : Form
DrawingBoat? boat = null;
int counter = 100;
- try
+ while (boat == null)
{
- while (boat == null)
+ boat = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
{
- boat = _company.GetRandomObject();
- counter--;
- if (counter <= 0)
- {
- break;
- }
+ break;
}
-
- if (boat == null)
- {
- return;
- }
-
- FormMotorBoat form = new()
- {
- SetBoat = boat
- };
- form.ShowDialog();
}
- catch (Exception ex)
+
+ if (boat == null)
{
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ return;
}
+
+ FormMotorBoat form = new()
+ {
+ SetBoat = boat
+ };
+ form.ShowDialog();
}
///
@@ -201,7 +176,6 @@ public partial class FormBoatCollection : Form
}
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
- _logger.LogInformation("Добавлена коллекция: {collection} Типа: {type}", textBoxCollectionName.Text, collectionType.ToString());
RerfreshListBoxItems();
}
@@ -221,11 +195,8 @@ public partial class FormBoatCollection : Form
return;
}
if (_storageCollection.Keys.Contains(listBoxCollection.SelectedItem.ToString() ?? string.Empty))
- {
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString() ?? string.Empty);
- }
- _logger.LogInformation("Удалена коллекция: {collection}", listBoxCollection.SelectedItem.ToString());
RerfreshListBoxItems();
}
@@ -270,7 +241,6 @@ public partial class FormBoatCollection : Form
{
case "Хранилище":
_company = new BoatHarborService(pictureBox.Width, pictureBox.Height, collection);
- _logger.LogInformation("Создана компания на коллекции: {collection}", listBoxCollection.SelectedItem.ToString());
break;
}
@@ -287,16 +257,13 @@ public partial class FormBoatCollection : Form
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
- try
+ if (_storageCollection.SaveData(saveFileDialog.FileName))
{
- _storageCollection.SaveData(saveFileDialog.FileName);
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
- _logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
}
- catch (Exception ex)
+ else
{
- MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@@ -308,21 +275,18 @@ public partial class FormBoatCollection : Form
///
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
+ // TODO продумать логику
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
- try
+ if (_storageCollection.LoadData(openFileDialog.FileName))
{
- _storageCollection.LoadData(openFileDialog.FileName);
RerfreshListBoxItems();
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
- _logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
}
- catch (Exception ex)
+ else
{
- MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
-
}
}
}
diff --git a/ProjectMotorBoat/ProjectMotorBoat/Program.cs b/ProjectMotorBoat/ProjectMotorBoat/Program.cs
index 843a24c..bcbd11e 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/Program.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/Program.cs
@@ -1,7 +1,3 @@
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using Serilog;
-
namespace ProjectMotorBoat
{
internal static class Program
@@ -15,30 +11,7 @@ namespace ProjectMotorBoat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
-
- Log.Logger = new LoggerConfiguration()
- .MinimumLevel.Information()
- .WriteTo.File("boatlog-.log", rollingInterval: RollingInterval.Day)
- .CreateLogger();
-
- ServiceCollection services = new();
- ConfigureServices(services);
- using ServiceProvider serviceProvider = services.BuildServiceProvider();
- Application.Run(serviceProvider.GetRequiredService());
- }
-
- ///
- /// Конфигурация сервиса DI
- ///
- ///
- private static void ConfigureServices(ServiceCollection services)
- {
- services.AddSingleton()
- .AddLogging(option =>
- {
- option.SetMinimumLevel(LogLevel.Information);
- option.AddSerilog(Log.Logger);
- });
+ Application.Run(new FormBoatCollection());
}
}
}
\ No newline at end of file
diff --git a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
index fda71c6..13ee123 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
+++ b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj
@@ -8,16 +8,6 @@
enable
-
-
-
-
-
-
-
-
-
-
True
diff --git a/ProjectMotorBoat/ProjectMotorBoat/save.txt b/ProjectMotorBoat/ProjectMotorBoat/save.txt
deleted file mode 100644
index 36db68b..0000000
--- a/ProjectMotorBoat/ProjectMotorBoat/save.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-CollectionsStorage
-Коллекция|Massive|60|EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;
\ No newline at end of file
From 847ecf21d8c1a78acb932955db36f20f8442b15d Mon Sep 17 00:00:00 2001
From: Pyro <732603@gmail.com>
Date: Mon, 17 Jun 2024 00:34:43 +0400
Subject: [PATCH 6/6] fix
---
.../StorageCollection.cs | 49 +++++++------------
1 file changed, 18 insertions(+), 31 deletions(-)
diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
index 8555feb..18ecd0e 100644
--- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs
@@ -54,7 +54,7 @@ public class StorageCollection
{
// проверка, что name не пустой и нет в словаре записи с таким ключом ✔
// Прописать логику для добавления ✔
- if (name != null && !_storages.ContainsKey(name))
+ if (name != null && !_storages.ContainsKey(name))
{
switch (collectionType)
{
@@ -103,7 +103,7 @@ public class StorageCollection
/// Сохранение информации по автомобилям в хранилище в файл
///
/// Путь и имя файла
- public void SaveData(string filename)
+ public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
@@ -156,11 +156,11 @@ public class StorageCollection
/// Загрузка информации по автомобилям в хранилище из файла
///
/// Путь и имя файла
- public void LoadData(string filename)
+ public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
- throw new Exception("Файл не существует");
+ return false;
}
using (StreamReader sr = new StreamReader(filename))
@@ -171,16 +171,10 @@ public class StorageCollection
return false;
}
- string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
- if (strs == null || strs.Length == 0)
- {
- throw new Exception("В файле нет данных");
- }
-
- if (!strs[0].Equals(_collectionKey))
- {
- throw new Exception("В файле неверные данные");
- }
+ if (!str[0].Equals(_collectionKey))
+ {
+ return false;
+ }
_storages.Clear();
string data = "";
@@ -192,30 +186,23 @@ public class StorageCollection
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
- throw new Exception("Не удалось определить тип коллекции:" + record[1]);
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
- {
- if (elem?.CreateDrawingBoat() is T boat)
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
+ collection.MaxCount = Convert.ToInt32(record[2]);
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
{
- try
+ if (elem?.CreateDrawingBoat() is T boat)
{
if (collection.Insert(boat) == -1)
{
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ return false;
}
}
- catch (CollectionOverflowException ex)
- {
- throw new Exception("Коллекция переполнена", ex);
- }
}
+ _storages.Add(record[0], collection);
}
- _storages.Add(record[0], collection);
+ return true;
}
}
@@ -233,4 +220,4 @@ public class StorageCollection
_ => null,
};
}
-}
+}
\ No newline at end of file