diff --git a/ProjectLiner/.vs/ProjectEvaluation/projectliner.metadata.v7.bin b/ProjectLiner/.vs/ProjectEvaluation/projectliner.metadata.v7.bin index dc77309..d14171d 100644 Binary files a/ProjectLiner/.vs/ProjectEvaluation/projectliner.metadata.v7.bin and b/ProjectLiner/.vs/ProjectEvaluation/projectliner.metadata.v7.bin differ diff --git a/ProjectLiner/.vs/ProjectEvaluation/projectliner.projects.v7.bin b/ProjectLiner/.vs/ProjectEvaluation/projectliner.projects.v7.bin index eb612d7..8f9021c 100644 Binary files a/ProjectLiner/.vs/ProjectEvaluation/projectliner.projects.v7.bin and b/ProjectLiner/.vs/ProjectEvaluation/projectliner.projects.v7.bin differ diff --git a/ProjectLiner/.vs/ProjectLiner/DesignTimeBuild/.dtbcache.v2 b/ProjectLiner/.vs/ProjectLiner/DesignTimeBuild/.dtbcache.v2 index 5c1b17e..e427f25 100644 Binary files a/ProjectLiner/.vs/ProjectLiner/DesignTimeBuild/.dtbcache.v2 and b/ProjectLiner/.vs/ProjectLiner/DesignTimeBuild/.dtbcache.v2 differ diff --git a/ProjectLiner/.vs/ProjectLiner/v17/.futdcache.v2 b/ProjectLiner/.vs/ProjectLiner/v17/.futdcache.v2 index 53498cf..e3e8403 100644 Binary files a/ProjectLiner/.vs/ProjectLiner/v17/.futdcache.v2 and b/ProjectLiner/.vs/ProjectLiner/v17/.futdcache.v2 differ diff --git a/ProjectLiner/.vs/ProjectLiner/v17/DocumentLayout.json b/ProjectLiner/.vs/ProjectLiner/v17/DocumentLayout.json index 06c5f61..5d87d90 100644 --- a/ProjectLiner/.vs/ProjectLiner/v17/DocumentLayout.json +++ b/ProjectLiner/.vs/ProjectLiner/v17/DocumentLayout.json @@ -2,6 +2,14 @@ "Version": 1, "WorkspaceRootPath": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\", "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|c:\\somegitstuff\\isebd-11_khatypov_k.r_fundamental\\projectliner\\projectliner\\exceptions\\collectionoverflowexception.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\exceptions\\collectionoverflowexception.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, + { + "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\projectliner\\collectiongenericobjects\\storagecollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\collectiongenericobjects\\storagecollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, { "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|c:\\somegitstuff\\isebd-11_khatypov_k.r_fundamental\\projectliner\\projectliner\\drawnings\\extentiondrawningliner.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\drawnings\\extentiondrawningliner.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" @@ -14,10 +22,6 @@ "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\projectliner\\entities\\entityliner.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\entities\\entityliner.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" }, - { - "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\projectliner\\collectiongenericobjects\\storagecollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", - "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\collectiongenericobjects\\storagecollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" - }, { "AbsoluteMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\projectliner\\formlinercollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", "RelativeMoniker": "D:0:0:{7FB62E78-175F-490A-B5F2-2FF676947033}|ProjectLiner\\ProjectLiner.csproj|solutionrelative:projectliner\\formlinercollection.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" @@ -107,32 +111,45 @@ { "$type": "Document", "DocumentIndex": 0, + "Title": "CollectionOverflowException.cs", + "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Exceptions\\CollectionOverflowException.cs", + "RelativeDocumentMoniker": "ProjectLiner\\Exceptions\\CollectionOverflowException.cs", + "ToolTip": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Exceptions\\CollectionOverflowException.cs", + "RelativeToolTip": "ProjectLiner\\Exceptions\\CollectionOverflowException.cs", + "ViewState": "AQIAAAAAAAAAAAAAAAAAABAAAAABAAAA", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-05-10T08:27:45.099Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 2, "Title": "ExtentionDrawningLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Drawnings\\ExtentionDrawningLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\Drawnings\\ExtentionDrawningLiner.cs", "ToolTip": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Drawnings\\ExtentionDrawningLiner.cs", "RelativeToolTip": "ProjectLiner\\Drawnings\\ExtentionDrawningLiner.cs", - "ViewState": "AQIAAAUAAAAAAAAAAAAIwBUAAAAJAAAA", + "ViewState": "AQIAAAUAAAAAAAAAAAAIwB4AAAAEAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-05-09T09:04:11.58Z", "EditorCaption": "" }, { "$type": "Document", - "DocumentIndex": 3, + "DocumentIndex": 1, "Title": "StorageCollection.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\StorageCollection.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\StorageCollection.cs", "ToolTip": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\StorageCollection.cs", "RelativeToolTip": "ProjectLiner\\CollectionGenericObjects\\StorageCollection.cs", - "ViewState": "AQIAAKgAAAAAAAAAAAAcwLsAAAAQAAAA", + "ViewState": "AQIAALoAAAAAAAAAAAAcwMUAAAAUAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-05-08T06:09:32.467Z", "EditorCaption": "" }, { "$type": "Document", - "DocumentIndex": 7, + "DocumentIndex": 8, "Title": "FormLinerCollection.Designer.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLinerCollection.Designer.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLinerCollection.Designer.cs", @@ -145,7 +162,7 @@ }, { "$type": "Document", - "DocumentIndex": 4, + "DocumentIndex": 5, "Title": "FormLinerCollection.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLinerCollection.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLinerCollection.cs", @@ -158,20 +175,20 @@ }, { "$type": "Document", - "DocumentIndex": 1, + "DocumentIndex": 3, "Title": "EntityBetterLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Entities\\EntityBetterLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\Entities\\EntityBetterLiner.cs", "ToolTip": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Entities\\EntityBetterLiner.cs", "RelativeToolTip": "ProjectLiner\\Entities\\EntityBetterLiner.cs", - "ViewState": "AQIAAB8AAAAAAAAAAAAywDMAAAA8AAAA", + "ViewState": "AQIAAC4AAAAAAAAAAAAUwDsAAAAEAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-05-07T12:57:41.304Z", "EditorCaption": "" }, { "$type": "Document", - "DocumentIndex": 2, + "DocumentIndex": 4, "Title": "EntityLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Entities\\EntityLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\Entities\\EntityLiner.cs", @@ -184,7 +201,7 @@ }, { "$type": "Document", - "DocumentIndex": 5, + "DocumentIndex": 6, "Title": "DrawningBetterLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Drawnings\\DrawningBetterLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\Drawnings\\DrawningBetterLiner.cs", @@ -197,7 +214,7 @@ }, { "$type": "Document", - "DocumentIndex": 8, + "DocumentIndex": 9, "Title": "DrawningLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Drawnings\\DrawningLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\Drawnings\\DrawningLiner.cs", @@ -210,7 +227,7 @@ }, { "$type": "Document", - "DocumentIndex": 6, + "DocumentIndex": 7, "Title": "MassiveGenericObjects.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\MassiveGenericObjects.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\MassiveGenericObjects.cs", @@ -223,7 +240,7 @@ }, { "$type": "Document", - "DocumentIndex": 9, + "DocumentIndex": 10, "Title": "AbstractCompany.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\AbstractCompany.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\AbstractCompany.cs", @@ -236,7 +253,7 @@ }, { "$type": "Document", - "DocumentIndex": 12, + "DocumentIndex": 13, "Title": "DockService.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\DockService.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\DockService.cs", @@ -248,7 +265,7 @@ }, { "$type": "Document", - "DocumentIndex": 11, + "DocumentIndex": 12, "Title": "ICollectionGenericObjects.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\ICollectionGenericObjects.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\ICollectionGenericObjects.cs", @@ -260,7 +277,7 @@ }, { "$type": "Document", - "DocumentIndex": 10, + "DocumentIndex": 11, "Title": "FormLinerConfig.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLinerConfig.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLinerConfig.cs", @@ -272,7 +289,7 @@ }, { "$type": "Document", - "DocumentIndex": 13, + "DocumentIndex": 14, "Title": "ListGenericObjects.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\ListGenericObjects.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\ListGenericObjects.cs", @@ -284,7 +301,7 @@ }, { "$type": "Document", - "DocumentIndex": 14, + "DocumentIndex": 15, "Title": "CollectionType.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\CollectionGenericObjects\\CollectionType.cs", "RelativeDocumentMoniker": "ProjectLiner\\CollectionGenericObjects\\CollectionType.cs", @@ -296,7 +313,7 @@ }, { "$type": "Document", - "DocumentIndex": 15, + "DocumentIndex": 16, "Title": "Resources.Designer.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Properties\\Resources.Designer.cs", "RelativeDocumentMoniker": "ProjectLiner\\Properties\\Resources.Designer.cs", @@ -308,7 +325,7 @@ }, { "$type": "Document", - "DocumentIndex": 16, + "DocumentIndex": 17, "Title": "FormLinerCollection.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435]", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLinerCollection.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLinerCollection.cs", @@ -320,7 +337,7 @@ }, { "$type": "Document", - "DocumentIndex": 17, + "DocumentIndex": 18, "Title": "Program.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\Program.cs", "RelativeDocumentMoniker": "ProjectLiner\\Program.cs", @@ -332,7 +349,7 @@ }, { "$type": "Document", - "DocumentIndex": 18, + "DocumentIndex": 19, "Title": "FormLiner.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLiner.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLiner.cs", @@ -344,7 +361,7 @@ }, { "$type": "Document", - "DocumentIndex": 19, + "DocumentIndex": 20, "Title": "FormLiner.Designer.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\FormLiner.Designer.cs", "RelativeDocumentMoniker": "ProjectLiner\\FormLiner.Designer.cs", @@ -356,7 +373,7 @@ }, { "$type": "Document", - "DocumentIndex": 20, + "DocumentIndex": 21, "Title": "AbstractStrategy.cs", "DocumentMoniker": "C:\\SomeGitStuff\\ISEbd-11_Khatypov_K.R_fundamental\\ProjectLiner\\ProjectLiner\\MovementStrategy\\AbstractStrategy.cs", "RelativeDocumentMoniker": "ProjectLiner\\MovementStrategy\\AbstractStrategy.cs", diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs index 8a7e6bb..1b7acbc 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs @@ -37,14 +37,14 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { // TODO проверка позиции - if (position >= Count || position < 0) return null; + if (position >= Count || position < 0) throw new Exceptions.PositionOutOfCollectionException(); return _collection[position]; } public bool Insert(T obj) { // TODO проверка, что не превышено максимальное количество элементов // TODO вставка в конец набора - if (Count == _maxCount) return false; + if (Count == _maxCount) throw new Exceptions.CollectionOverflowException(); _collection.Add(obj); return true;//возможна проблема } @@ -53,8 +53,8 @@ public class ListGenericObjects : ICollectionGenericObjects // TODO проверка, что не превышено максимальное количество элементов // TODO проверка позиции // TODO вставка по позиции - if (Count == _maxCount) return false; - if (position >= Count || position < 0) return false; + if (Count == _maxCount) throw new Exceptions.CollectionOverflowException(); + if (position >= Count || position < 0) throw new Exceptions.PositionOutOfCollectionException(); _collection.Insert(position, obj); return true; } @@ -62,7 +62,7 @@ public class ListGenericObjects : ICollectionGenericObjects { // TODO проверка позиции // TODO удаление объекта из списка - if (position >= Count || position < 0) return false; + if (position >= Count || position < 0) throw new Exceptions.PositionOutOfCollectionException(); _collection.RemoveAt(position); return true; } diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs index 51fa3a0..7c17058 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ using ProjectLiner.Drawnings; +using ProjectLiner.Exceptions; using System.Text; namespace ProjectLiner.CollectionGenericObjects; @@ -79,7 +80,8 @@ public class StorageCollection // TODO Продумать логику получения объекта if (_storages.ContainsKey(name)) return _storages[name]; - return null; + throw new Exceptions.ObjectNotFoundException(); + } } @@ -92,7 +94,7 @@ public bool SaveData(string filename) { if (_storages.Count == 0) { - return false; + throw new Exception("В хранилище отсутствуют коллекции для сохранения"); } if (File.Exists(filename)) { @@ -140,7 +142,7 @@ public bool SaveData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не существует"); } string bufferTextFromFile = ""; using (FileStream fs = new(filename, FileMode.Open)) @@ -156,12 +158,11 @@ public bool SaveData(string filename) StringSplitOptions.RemoveEmptyEntries); if (strs == null || strs.Length == 0) { - return false; + throw new Exception("В файле нет данных"); } if (!strs[0].Equals(_collectionKey)) { - //если нет такой записи, то это не те данные - return false; + throw new Exception("В файле неверные данные"); } _storages.Clear(); foreach (string data in strs) @@ -175,11 +176,8 @@ public bool SaveData(string filename) CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); ICollectionGenericObjects? collection = - StorageCollection.CreateCollection(collectionType); - if (collection == null) - { - return false; - } + StorageCollection.CreateCollection(collectionType)?? throw new Exception("Не удалось определить тип коллекции: " + record[1]); + collection.MaxCount = Convert.ToInt32(record[2]); string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); @@ -187,9 +185,16 @@ public bool SaveData(string filename) { if (elem?.CreateDrawningLiner() is T liner) { - if (!collection.Insert(liner)) + try { - return false; + if (!collection.Insert(liner)) + { + throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); + } + } + catch (CollectionOverflowException ex) + { + throw new Exception("Коллекция переполнена", ex); } } } diff --git a/ProjectLiner/ProjectLiner/Exceptions/CollectionOverflowException.cs b/ProjectLiner/ProjectLiner/Exceptions/CollectionOverflowException.cs new file mode 100644 index 0000000..f201d5a --- /dev/null +++ b/ProjectLiner/ProjectLiner/Exceptions/CollectionOverflowException.cs @@ -0,0 +1,17 @@ +using System.Runtime.Serialization; +namespace ProjectLiner.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/ProjectLiner/ProjectLiner/Exceptions/ObjectNotFoundException.cs b/ProjectLiner/ProjectLiner/Exceptions/ObjectNotFoundException.cs new file mode 100644 index 0000000..41cafa2 --- /dev/null +++ b/ProjectLiner/ProjectLiner/Exceptions/ObjectNotFoundException.cs @@ -0,0 +1,16 @@ +using System.Runtime.Serialization; +namespace ProjectLiner.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/ProjectLiner/ProjectLiner/Exceptions/PositionOutOfCollectionException.cs b/ProjectLiner/ProjectLiner/Exceptions/PositionOutOfCollectionException.cs new file mode 100644 index 0000000..22263bf --- /dev/null +++ b/ProjectLiner/ProjectLiner/Exceptions/PositionOutOfCollectionException.cs @@ -0,0 +1,15 @@ +using System.Runtime.Serialization; +namespace ProjectLiner.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/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs index da044ad..0469c66 100644 --- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs +++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs @@ -1,4 +1,5 @@ -using ProjectLiner.CollectionGenericObjects; +using Microsoft.Extensions.Logging; +using ProjectLiner.CollectionGenericObjects; using ProjectLiner.Drawnings; using System.Windows.Forms; @@ -8,10 +9,19 @@ public partial class FormLinerCollection : Form { private AbstractCompany? _company = null; private readonly StorageCollection _storageCollection; - public FormLinerCollection() + /// + /// Логер + /// + private readonly ILogger _logger; + /// + /// Конструктор + /// + public FormLinerCollection(ILogger logger) { InitializeComponent(); _storageCollection = new(); + + _logger = logger; } private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { @@ -180,15 +190,19 @@ public partial class FormLinerCollection : Form { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.SaveData(saveFileDialog.FileName)) + try { + _storageCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation("Сохранение в файл: {filename}", + saveFileDialog.FileName); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError("Ошибка: {Message}", ex.Message); } } } diff --git a/ProjectLiner/ProjectLiner/Program.cs b/ProjectLiner/ProjectLiner/Program.cs index 49d860e..55f75b8 100644 --- a/ProjectLiner/ProjectLiner/Program.cs +++ b/ProjectLiner/ProjectLiner/Program.cs @@ -1,17 +1,36 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; namespace ProjectLiner { - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new FormLinerCollection()); - } - } + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + ApplicationConfiguration.Initialize(); + 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.AddNLog("nlog.config"); + }); + } + } } \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/ProjectLiner.csproj b/ProjectLiner/ProjectLiner/ProjectLiner.csproj index 244387d..6d62c1f 100644 --- a/ProjectLiner/ProjectLiner/ProjectLiner.csproj +++ b/ProjectLiner/ProjectLiner/ProjectLiner.csproj @@ -8,6 +8,11 @@ enable + + + + + True @@ -23,4 +28,10 @@ + + + Always + + + \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/nlog.config b/ProjectLiner/ProjectLiner/nlog.config new file mode 100644 index 0000000..7df8c4d --- /dev/null +++ b/ProjectLiner/ProjectLiner/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file