From d583f3c9afac3363fd50967cea7da7f8024c9909 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sat, 19 Nov 2022 20:07:56 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPlane/FormMapWithSetPlanes.cs | 42 ++++++++---- ProjectPlane/ProjectPlane/MapsCollection.cs | 66 +++++++++---------- .../ProjectPlane/PlaneNotFoundException.cs | 19 ++++++ ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 4 +- .../ProjectPlane/StorageOverflowException.cs | 21 ++++++ 5 files changed, 104 insertions(+), 48 deletions(-) create mode 100644 ProjectPlane/ProjectPlane/PlaneNotFoundException.cs create mode 100644 ProjectPlane/ProjectPlane/StorageOverflowException.cs diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index aa927a9..0d4865a 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -120,15 +120,27 @@ namespace ProjectPlane return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + try { - MessageBox.Show("Object removed"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + { + MessageBox.Show("Object removed"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Error with object removing"); + } } - else + catch(PlaneNotFoundException ex) { - MessageBox.Show("Error with object removing"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); + } + } /// /// Вывод набора @@ -235,16 +247,19 @@ namespace ProjectPlane { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + + try { + _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Succesfull loading", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMaps(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } - else + catch (Exception ex) { - MessageBox.Show("Loading failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Loading failed {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } - ReloadMaps(); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } } @@ -252,13 +267,14 @@ namespace ProjectPlane { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) + try { + _mapsCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Succesfull saving", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch(Exception ex) { - MessageBox.Show("Savingfailed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Saving failed {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/ProjectPlane/ProjectPlane/MapsCollection.cs b/ProjectPlane/ProjectPlane/MapsCollection.cs index 491c9f5..000063e 100644 --- a/ProjectPlane/ProjectPlane/MapsCollection.cs +++ b/ProjectPlane/ProjectPlane/MapsCollection.cs @@ -58,7 +58,7 @@ namespace ProjectPlane /// Название карты public void DelMap(string name) { - if (_mapStorages.ContainsKey(name)) + if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name); } /// @@ -84,69 +84,69 @@ namespace ProjectPlane byte[] info = new UTF8Encoding(true).GetBytes(text); stream.Write(info, 0, info.Length); } - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new(filename, FileMode.Create)) + using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { - WriteToFile($"MapsCollection{Environment.NewLine}", fs); + sw.WriteLine("MapsCollection"); foreach (var storage in _mapStorages) { - WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs); + + sw.WriteLine( + $"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + ); } } return true; } + /// /// Загрузка нформации по автомобилям на парковках из файла /// /// /// - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("File not found"); } string bufferTextFromFile = ""; using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string curLine = sr.ReadLine(); + + if (!curLine.Contains("MapsCollection")) { - bufferTextFromFile += temp.GetString(b); + throw new Exception("Incorrect format"); } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - return false; - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Length; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) + + _mapStorages.Clear(); + while ((curLine = sr.ReadLine()) != null) { - case "SimpleMap": - map = new SimpleMap(); - break; - case "SkyMap": - map = new SkyMap(); - break; + var elem = curLine.Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "SkyMap": + map = new SkyMap(); + break; + } + _mapStorages.Add(elem[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } - _mapStorages.Add(elem[0], new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + } - return true; } } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/PlaneNotFoundException.cs b/ProjectPlane/ProjectPlane/PlaneNotFoundException.cs new file mode 100644 index 0000000..edd1ef0 --- /dev/null +++ b/ProjectPlane/ProjectPlane/PlaneNotFoundException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace ProjectPlane +{ + internal class PlaneNotFoundException : ApplicationException + { + public PlaneNotFoundException(int i) : base($"Не найден объект по позиции { i}") { } + public PlaneNotFoundException() : base() { } + public PlaneNotFoundException(string message) : base(message) { } + public PlaneNotFoundException(string message, Exception exception) : base(message, exception) + { } + protected PlaneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index 2f299af..58869f1 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -43,7 +43,7 @@ namespace ProjectPlane /// public int Insert(T plane, int position) { - if (position < 0 || position >= _maxCount) return -1; + if (position < 0 || position >= _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(position, plane); return position; } @@ -54,7 +54,7 @@ namespace ProjectPlane /// public T Remove(int position) { - if (position < 0 || position >= _maxCount) return null; + if (position < 0 || position >= _maxCount) throw new PlaneNotFoundException(position); T temp = _places[position]; _places.RemoveAt(position); return temp; diff --git a/ProjectPlane/ProjectPlane/StorageOverflowException.cs b/ProjectPlane/ProjectPlane/StorageOverflowException.cs new file mode 100644 index 0000000..8232c9c --- /dev/null +++ b/ProjectPlane/ProjectPlane/StorageOverflowException.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace ProjectPlane +{ + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) : + base(message, exception) + { } + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + + } +} -- 2.25.1 From 5ded8113103c276c0ae5ed88e25cea33ddea8386 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sat, 19 Nov 2022 20:36:37 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPlane/FormMapWithSetPlanes.cs | 8 +++++-- ProjectPlane/ProjectPlane/MapsCollection.cs | 1 - ProjectPlane/ProjectPlane/Program.cs | 22 ++++++++++++++++++- ProjectPlane/ProjectPlane/ProjectPlane.csproj | 17 ++++++++++++++ ProjectPlane/ProjectPlane/nlog.config | 13 +++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 ProjectPlane/ProjectPlane/nlog.config diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index 0d4865a..ca3a3bf 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -27,6 +28,7 @@ namespace ProjectPlane /// /// Заполнение listBoxMaps /// + private readonly ILogger _logger; private void ReloadMaps() { int index = listBoxMaps.SelectedIndex; @@ -53,9 +55,10 @@ namespace ProjectPlane /// /// Конструктор /// - public FormMapWithSetPlanes() + public FormMapWithSetPlanes(ILogger logger) { InitializeComponent(); + _logger = logger; _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); comboBoxSelectorMap.Items.Clear(); foreach (var elem in _mapsDict) @@ -214,6 +217,7 @@ namespace ProjectPlane } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + _logger.LogInformation($"Map added {textBoxNewMapName.Text}"); } /// /// Выбор карты diff --git a/ProjectPlane/ProjectPlane/MapsCollection.cs b/ProjectPlane/ProjectPlane/MapsCollection.cs index 000063e..b443f07 100644 --- a/ProjectPlane/ProjectPlane/MapsCollection.cs +++ b/ProjectPlane/ProjectPlane/MapsCollection.cs @@ -102,7 +102,6 @@ namespace ProjectPlane ); } } - return true; } diff --git a/ProjectPlane/ProjectPlane/Program.cs b/ProjectPlane/ProjectPlane/Program.cs index 3fa0fe7..833eb87 100644 --- a/ProjectPlane/ProjectPlane/Program.cs +++ b/ProjectPlane/ProjectPlane/Program.cs @@ -1,3 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace ProjectPlane { internal static class Program @@ -9,7 +13,23 @@ namespace ProjectPlane static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormMapWithSetPlanes()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + + Application.Run(serviceProvider.GetRequiredService()); + } } + 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/ProjectPlane/ProjectPlane/ProjectPlane.csproj b/ProjectPlane/ProjectPlane/ProjectPlane.csproj index d702356..e0a1709 100644 --- a/ProjectPlane/ProjectPlane/ProjectPlane.csproj +++ b/ProjectPlane/ProjectPlane/ProjectPlane.csproj @@ -8,10 +8,27 @@ enable + + + + + + + Always + + + + + + + + + + True diff --git a/ProjectPlane/ProjectPlane/nlog.config b/ProjectPlane/ProjectPlane/nlog.config new file mode 100644 index 0000000..e235958 --- /dev/null +++ b/ProjectPlane/ProjectPlane/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 0fb6ab23dc5749abc983f1f46748b03946967cfe Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 22 Nov 2022 00:41:03 +0400 Subject: [PATCH 3/5] com --- .../ProjectPlane/FormMapWithSetPlanes.cs | 59 +++++++++++++------ ProjectPlane/ProjectPlane/Program.cs | 21 +++++-- ProjectPlane/ProjectPlane/ProjectPlane.csproj | 10 +++- ProjectPlane/ProjectPlane/appsettings.json | 17 ++++++ 4 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 ProjectPlane/ProjectPlane/appsettings.json diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index ca3a3bf..f5437cf 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; namespace ProjectPlane { @@ -28,7 +29,7 @@ namespace ProjectPlane /// /// Заполнение listBoxMaps /// - private readonly ILogger _logger; + private void ReloadMaps() { int index = listBoxMaps.SelectedIndex; @@ -51,7 +52,8 @@ namespace ProjectPlane /// /// Объект от класса карты с набором объектов /// - //private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric = null; + + private readonly ILogger _logger; /// /// Конструктор /// @@ -87,21 +89,32 @@ namespace ProjectPlane } private void AddPlane(DrawingPlane plane) { - if (listBoxMaps.SelectedIndex == -1) + + try { - return; - } + if (listBoxMaps.SelectedIndex == -1) + { + _logger.LogInformation("Ошибка при добавлении объекта: карта не выбрана"); + return; + } - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObject(plane) != -1) - { - MessageBox.Show("Object added"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObject(plane) != -1) + { + MessageBox.Show("Object added"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation("Ошибка при добавлении:"); + } + else + { + MessageBox.Show("Failed to add object"); + _logger.LogInformation($"Ошибка при добавлении {plane} объекта"); + } } - else + catch(StorageOverflowException ex) { - MessageBox.Show("Failed to add object"); + _logger.LogWarning($"Хранилище переполнено {0}", ex.Message); + MessageBox.Show($"Storage overflow { ex.Message }", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } /// /// Удаление объекта @@ -110,6 +123,7 @@ namespace ProjectPlane /// private void ButtonRemovePlane_Click(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) { return; @@ -129,6 +143,7 @@ namespace ProjectPlane { MessageBox.Show("Object removed"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation("Удален объект с позиции {0}", pos); } else { @@ -137,11 +152,13 @@ namespace ProjectPlane } catch(PlaneNotFoundException ex) { + _logger.LogWarning("Ошибка: не удалось удалить объект. {0}", ex.Message); MessageBox.Show($"Ошибка удаления: {ex.Message}"); } catch (Exception ex) { MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); + _logger.LogWarning("Произошла неизвестная ошибка: {0}", ex.Message); } } @@ -208,16 +225,18 @@ namespace ProjectPlane if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) { MessageBox.Show("Data is not all completed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogInformation("Ошибка: карта {0} не была добавлена: ", comboBoxSelectorMap.SelectedIndex == -1 ? "карта не выбрана" : "карта не названа"); return; } if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) { MessageBox.Show("This map doesn't exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogInformation($"Ошибка: карта не существует: { textBoxNewMapName.Text }"); return; } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); - _logger.LogInformation($"Map added {textBoxNewMapName.Text}"); + _logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}"); } /// /// Выбор карты @@ -227,6 +246,7 @@ namespace ProjectPlane private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + _logger.LogInformation("Смена карты на {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); } /// /// Удаление карты @@ -237,12 +257,14 @@ namespace ProjectPlane { if (listBoxMaps.SelectedIndex == -1) { + _logger.LogInformation($"Карта { textBoxNewMapName.Text } не может быть удалена: карта существует") ; return; } if (MessageBox.Show($"Delete {listBoxMaps.SelectedItem}?", "Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + _logger.LogInformation($"Карта { listBoxMaps.SelectedItem?.ToString() } удалена"); ReloadMaps(); } } @@ -251,19 +273,19 @@ namespace ProjectPlane { if (openFileDialog.ShowDialog() == DialogResult.OK) { - try { _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Succesfull loading", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogWarning("Успешная загрузка из файла: {0}", saveFileDialog.FileName); ReloadMaps(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } catch (Exception ex) { + _logger.LogWarning("Ошибка при загрузке из файла: {0}", saveFileDialog.FileName); MessageBox.Show($"Loading failed {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - + } } } @@ -274,13 +296,14 @@ namespace ProjectPlane try { _mapsCollection.SaveData(saveFileDialog.FileName); + _logger.LogWarning("Успех при сохранении в файл: {0}", saveFileDialog.FileName); MessageBox.Show("Succesfull saving", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch(Exception ex) { + _logger.LogWarning("Ошибка при сохранении в файл: {0}", saveFileDialog.FileName); MessageBox.Show($"Saving failed {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - + } } } } diff --git a/ProjectPlane/ProjectPlane/Program.cs b/ProjectPlane/ProjectPlane/Program.cs index 833eb87..b3449e2 100644 --- a/ProjectPlane/ProjectPlane/Program.cs +++ b/ProjectPlane/ProjectPlane/Program.cs @@ -1,6 +1,7 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Serilog; namespace ProjectPlane { @@ -12,24 +13,32 @@ namespace ProjectPlane [STAThread] static void Main() { + ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); using (ServiceProvider serviceProvider = services.BuildServiceProvider()) { - Application.Run(serviceProvider.GetRequiredService()); } } private static void ConfigureServices(ServiceCollection services) { - services.AddSingleton() - .AddLogging(option => + services.AddSingleton().AddLogging(option => { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) + .Build(); + + var logger = new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .CreateLogger(); + option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); + option.AddSerilog(logger); + }); } - } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/ProjectPlane.csproj b/ProjectPlane/ProjectPlane/ProjectPlane.csproj index e0a1709..f2e5711 100644 --- a/ProjectPlane/ProjectPlane/ProjectPlane.csproj +++ b/ProjectPlane/ProjectPlane/ProjectPlane.csproj @@ -23,10 +23,18 @@ + + + - + + + + + + diff --git a/ProjectPlane/ProjectPlane/appsettings.json b/ProjectPlane/ProjectPlane/appsettings.json new file mode 100644 index 0000000..fb814f9 --- /dev/null +++ b/ProjectPlane/ProjectPlane/appsettings.json @@ -0,0 +1,17 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/log_.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ] + } +} \ No newline at end of file -- 2.25.1 From 6977781923e7d7370b64ebc3fd8c90f149e0338b Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 22 Nov 2022 01:02:51 +0400 Subject: [PATCH 4/5] finally? --- ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index f5437cf..b9f2a19 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -153,11 +153,11 @@ namespace ProjectPlane catch(PlaneNotFoundException ex) { _logger.LogWarning("Ошибка: не удалось удалить объект. {0}", ex.Message); - MessageBox.Show($"Ошибка удаления: {ex.Message}"); + MessageBox.Show($"Removing error: {ex.Message}"); } catch (Exception ex) { - MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); + MessageBox.Show($"Unknown error: {ex.Message}"); _logger.LogWarning("Произошла неизвестная ошибка: {0}", ex.Message); } @@ -246,7 +246,7 @@ namespace ProjectPlane private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - _logger.LogInformation("Смена карты на {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + _logger.LogInformation("Открыта карта {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty); } /// /// Удаление карты @@ -257,7 +257,7 @@ namespace ProjectPlane { if (listBoxMaps.SelectedIndex == -1) { - _logger.LogInformation($"Карта { textBoxNewMapName.Text } не может быть удалена: карта существует") ; + _logger.LogInformation($"Карта { textBoxNewMapName.Text } не может быть удалена: не карта существует") ; return; } @@ -277,13 +277,13 @@ namespace ProjectPlane { _mapsCollection.LoadData(openFileDialog.FileName); MessageBox.Show("Succesfull loading", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogWarning("Успешная загрузка из файла: {0}", saveFileDialog.FileName); + _logger.LogWarning("Успешная загрузка из файла: {0}", openFileDialog.FileName); ReloadMaps(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } catch (Exception ex) { - _logger.LogWarning("Ошибка при загрузке из файла: {0}", saveFileDialog.FileName); + _logger.LogWarning("Ошибка при загрузке из файла: {0}", openFileDialog.FileName); MessageBox.Show($"Loading failed {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } } -- 2.25.1 From c920e6c1d5df7665e5542b66d02889a4ee2b98e0 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 22 Nov 2022 16:46:49 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'ProjectPlane/ProjectPlane/SetPlanesGe?= =?UTF-8?q?neric.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index 58869f1..ef15c44 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -43,9 +43,12 @@ namespace ProjectPlane /// public int Insert(T plane, int position) { - if (position < 0 || position >= _maxCount) throw new StorageOverflowException(_maxCount); + if (Count == _maxCount) throw new StorageOverflowException(_maxCount); + + if (position < 0 || position >= _maxCount) return -1; _places.Insert(position, plane); return position; + } /// /// Удаление объекта из набора с конкретной позиции -- 2.25.1