diff --git a/.gitignore b/.gitignore
index ca1c7a3..359c4db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
+ImplementationExtensions
+BusinessLogicExtensions
# Mono auto generated files
mono_crash.*
diff --git a/AircraftPlant/AircraftPlant.log.2024-04-21 b/AircraftPlant/AircraftPlant.log.2024-04-21
deleted file mode 100644
index ed787cd..0000000
--- a/AircraftPlant/AircraftPlant.log.2024-04-21
+++ /dev/null
@@ -1,41 +0,0 @@
-2024-04-21 02:01:49,249 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-21 02:01:49,313 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-21 02:01:49,318 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-21 02:01:49,321 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-21 02:01:49,322 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-21 02:20:52,936 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-21 02:20:52,958 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-21 02:20:52,964 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-21 02:20:52,966 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-21 02:20:52,967 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-21 02:21:14,577 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:21:16,912 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:21:40,373 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:21:40,397 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:21:40,453 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:4
- 2024-04-21 02:21:40,562 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:4
- 2024-04-21 02:21:45,409 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:5
- 2024-04-21 02:21:45,412 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:5
- 2024-04-21 02:21:47,533 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:4
- 2024-04-21 02:21:47,535 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:4
- 2024-04-21 02:23:50,172 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-21 02:23:50,194 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-21 02:23:50,198 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-21 02:23:50,201 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-21 02:23:50,201 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-21 02:24:06,733 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:24:08,724 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:24:10,746 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:24:10,764 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:26:31,564 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-21 02:26:31,586 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-21 02:26:31,592 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-21 02:26:31,594 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-21 02:26:31,595 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-21 02:26:50,068 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:26:52,105 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:26:53,568 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-21 02:26:53,583 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-21 02:26:53,599 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [48] - MESSAGE: ReadList. PlaneName:(null).Id:(null)
- 2024-04-21 02:26:53,668 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [57] - MESSAGE: ReadList. Count:2
-
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlant.log.2024-04-22 b/AircraftPlant/AircraftPlant.log.2024-04-22
deleted file mode 100644
index 74e80ca..0000000
--- a/AircraftPlant/AircraftPlant.log.2024-04-22
+++ /dev/null
@@ -1,65 +0,0 @@
-2024-04-22 01:54:32,867 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-22 01:54:32,897 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-22 01:54:32,904 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-22 01:54:32,906 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-22 01:54:32,907 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-22 01:54:46,181 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:54:48,412 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-22 01:55:30,608 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:55:30,634 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:2
- 2024-04-22 01:56:13,348 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.CheckModel [247] - MESSAGE: Shop. ShopName:Магазин 3.Address:Улица 3. Id:0
- 2024-04-22 01:56:13,576 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:56:13,581 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 01:56:21,121 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:56:21,124 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 01:56:21,142 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [48] - MESSAGE: ReadList. PlaneName:(null).Id:(null)
- 2024-04-22 01:56:21,160 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [57] - MESSAGE: ReadList. Count:2
- 2024-04-22 01:56:34,923 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [159] - MESSAGE: AddPlaneInShop. ShopName:(null).Id:6
- 2024-04-22 01:56:34,931 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [166] - MESSAGE: AddPlaneInShop find. Id:6
- 2024-04-22 01:56:34,935 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [183] - MESSAGE: AddPlaneInShop. Added 5 new plane to 'Магазин 3' shop
- 2024-04-22 01:56:34,989 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:56:34,991 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 01:56:45,267 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 01:56:45,269 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 01:56:45,301 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:4
- 2024-04-22 01:56:45,303 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:4
- 2024-04-22 01:56:49,512 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:6
- 2024-04-22 01:56:49,515 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:6
- 2024-04-22 10:34:20,669 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-22 10:34:20,716 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-22 10:34:20,721 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-22 10:34:20,724 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-22 10:34:20,725 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-22 10:42:07,542 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-22 10:42:07,564 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-22 10:42:07,570 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-22 10:42:07,572 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-22 10:42:07,573 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-22 10:42:26,255 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:42:28,411 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 10:43:50,297 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: https://localhost:7122
- 2024-04-22 10:43:50,324 INFO Microsoft.Hosting.Lifetime.? [?] - MESSAGE: Now listening on: http://localhost:5092
- 2024-04-22 10:43:50,329 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Application started. Press Ctrl+C to shut down.
- 2024-04-22 10:43:50,331 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Hosting environment: Development
- 2024-04-22 10:43:50,333 INFO Microsoft.Hosting.Lifetime.OnApplicationStarted [0] - MESSAGE: Content root path: D:\ULSTU\Семестр 4\РПП\AircraftPlant\AircraftPlantRestApi\
- 2024-04-22 10:48:54,048 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:48:56,110 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:3
- 2024-04-22 10:49:15,718 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.CheckModel [247] - MESSAGE: Shop. ShopName:shop.Address:street. Id:0
- 2024-04-22 10:49:16,089 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:49:16,094 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:4
- 2024-04-22 10:49:20,397 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:49:20,400 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:4
- 2024-04-22 10:49:20,417 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [48] - MESSAGE: ReadList. PlaneName:(null).Id:(null)
- 2024-04-22 10:49:20,446 INFO AircraftPlantBusinessLogic.BusinessLogics.PlaneLogic.ReadList [57] - MESSAGE: ReadList. Count:2
- 2024-04-22 10:49:26,177 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [159] - MESSAGE: AddPlaneInShop. ShopName:(null).Id:7
- 2024-04-22 10:49:26,189 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [166] - MESSAGE: AddPlaneInShop find. Id:7
- 2024-04-22 10:49:26,204 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.AddPlaneInShop [183] - MESSAGE: AddPlaneInShop. Added 3 new plane to 'shop' shop
- 2024-04-22 10:49:26,300 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:49:26,303 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:4
- 2024-04-22 10:49:29,404 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [49] - MESSAGE: ReadList. ShopName:(null).Id:(null)
- 2024-04-22 10:49:29,407 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadList [58] - MESSAGE: ReadList. Count:4
- 2024-04-22 10:49:29,437 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:4
- 2024-04-22 10:49:29,440 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:4
- 2024-04-22 10:49:31,043 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [75] - MESSAGE: ReadElement. ShopName:(null).Id:7
- 2024-04-22 10:49:31,046 INFO AircraftPlantBusinessLogic.BusinessLogics.ShopLogic.ReadElement [84] - MESSAGE: ReadElement find. Id:7
-
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs
new file mode 100644
index 0000000..a218613
--- /dev/null
+++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/BackUpLogic.cs
@@ -0,0 +1,131 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.IO.Compression;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantBusinessLogic.BusinessLogics
+{
+ ///
+ /// Реализация интерфейса бизнес-логики для создания бэкапа
+ ///
+ public class BackUpLogic : IBackUpLogic
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Получение данных из хранилища
+ ///
+ private readonly IBackUpInfo _backUpInfo;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public BackUpLogic(ILogger logger, IBackUpInfo backUpInfo)
+ {
+ _logger = logger;
+ _backUpInfo = backUpInfo;
+ }
+
+ ///
+ /// Создать бэкап
+ ///
+ ///
+ public void CreateBackUp(BackUpSaveBindingModel model)
+ {
+ if (_backUpInfo == null)
+ {
+ return;
+ }
+
+ try
+ {
+ _logger.LogDebug("Clear folder");
+ // Зачистка папки и удаление старого архива
+ var dirInfo = new DirectoryInfo(model.FolderName);
+ if (dirInfo.Exists)
+ {
+ foreach (var file in dirInfo.GetFiles())
+ {
+ file.Delete();
+ }
+ }
+
+ _logger.LogDebug("Delete archive");
+ string fileName = $"{model.FolderName}.zip";
+ if (File.Exists(fileName))
+ {
+ File.Delete(fileName);
+ }
+
+ // Берем метод для сохранения
+ _logger.LogDebug("Get assembly");
+ var typeIId = typeof(IId);
+ var assembly = typeIId.Assembly;
+ if (assembly == null)
+ {
+ throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
+ }
+
+ var types = assembly.GetTypes();
+ var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
+ _logger.LogDebug("Find {count} types", types.Length);
+ foreach (var type in types)
+ {
+ if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
+ {
+ var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
+ if (modelType == null)
+ {
+ throw new InvalidOperationException($"Не найден класс-модель для {type.Name}");
+ }
+ _logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
+ // Вызываем метод на выполнение
+ method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
+ }
+ }
+
+ _logger.LogDebug("Create zip and remove folder");
+ // Архивируем
+ ZipFile.CreateFromDirectory(model.FolderName, fileName);
+ // Удаляем папку
+ dirInfo.Delete(true);
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+
+ ///
+ /// Сохранить в файл
+ ///
+ ///
+ ///
+ private void SaveToFile(string folderName) where T : class, new()
+ {
+ var records = _backUpInfo.GetList();
+ if (records == null)
+ {
+ _logger.LogWarning("{type} type get null list", typeof(T).Name);
+ return;
+ }
+ var jsonFormatter = new DataContractJsonSerializer(typeof(List));
+ using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
+ jsonFormatter.WriteObject(fs, records);
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/AircraftPlantContracts.csproj b/AircraftPlant/AircraftPlantContracts/AircraftPlantContracts.csproj
index cf0ac69..a4b58c7 100644
--- a/AircraftPlant/AircraftPlantContracts/AircraftPlantContracts.csproj
+++ b/AircraftPlant/AircraftPlantContracts/AircraftPlantContracts.csproj
@@ -6,6 +6,12 @@
enable
+
+
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantContracts/Attributes/ColumnAttribute.cs b/AircraftPlant/AircraftPlantContracts/Attributes/ColumnAttribute.cs
new file mode 100644
index 0000000..d16314f
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/Attributes/ColumnAttribute.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.Attributes
+{
+ ///
+ /// Класс-атрибут для конифгурации колонки DataGridView
+ ///
+ [AttributeUsage(AttributeTargets.Property)]
+ public class ColumnAttribute : Attribute
+ {
+ ///
+ /// Заголовок колонки
+ ///
+ public string Title { get; private set; }
+
+ ///
+ /// Признак видмости колонки
+ ///
+ public bool Visible { get; private set; }
+
+ ///
+ /// Ширина колонки
+ ///
+ public int Width { get; private set; }
+
+ ///
+ /// Автоширина колонки
+ ///
+ public GridViewAutoSize GridViewAutoSize { get; private set; }
+
+ ///
+ /// Признак использования автоширины колонки
+ ///
+ public bool IsUseAutoSize { get; private set; }
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false)
+ {
+ Title = title;
+ Visible = visible;
+ Width = width;
+ GridViewAutoSize = gridViewAutoSize;
+ IsUseAutoSize = isUseAutoSize;
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/Attributes/GridViewAutoSize.cs b/AircraftPlant/AircraftPlantContracts/Attributes/GridViewAutoSize.cs
new file mode 100644
index 0000000..68eae74
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/Attributes/GridViewAutoSize.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.Attributes
+{
+ ///
+ /// Автоширина колонки DataGridView
+ ///
+ public enum GridViewAutoSize
+ {
+ NotSet = 0,
+
+ None = 1,
+
+ ColumnHeader = 2,
+
+ AllCellsExceptHeader = 4,
+
+ AllCells = 6,
+
+ DisplayedCellsExceptHeader = 8,
+
+ DisplayedCells = 10,
+
+ Fill = 16
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/BindingModels/BackUpSaveBindingModel.cs b/AircraftPlant/AircraftPlantContracts/BindingModels/BackUpSaveBindingModel.cs
new file mode 100644
index 0000000..77618f6
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/BindingModels/BackUpSaveBindingModel.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BindingModels
+{
+ ///
+ /// Модель привязки для создания бэкапа
+ ///
+ public class BackUpSaveBindingModel
+ {
+ ///
+ /// Путь и имя файла
+ ///
+ public string FolderName { get; set; } = string.Empty;
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/BindingModels/MessageInfoBindingModel.cs b/AircraftPlant/AircraftPlantContracts/BindingModels/MessageInfoBindingModel.cs
index 5521fef..e2819f1 100644
--- a/AircraftPlant/AircraftPlantContracts/BindingModels/MessageInfoBindingModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/BindingModels/MessageInfoBindingModel.cs
@@ -42,5 +42,7 @@ namespace AircraftPlantContracts.BindingModels
/// Тело письма
///
public string Body { get; set; } = string.Empty;
+
+ public int Id => throw new NotImplementedException();
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs
new file mode 100644
index 0000000..a49a78c
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs
@@ -0,0 +1,21 @@
+using AircraftPlantContracts.BindingModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BusinessLogicsContracts
+{
+ ///
+ /// Интерфейс бизнес-логики для создания бэкапа
+ ///
+ public interface IBackUpLogic
+ {
+ ///
+ /// Создать бэкап
+ ///
+ ///
+ void CreateBackUp(BackUpSaveBindingModel model);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/DependencyManager.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/DependencyManager.cs
new file mode 100644
index 0000000..0ecd857
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/DependencyManager.cs
@@ -0,0 +1,84 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Менеджер для работы с зависимостями
+ ///
+ public class DependencyManager
+ {
+ ///
+ /// Установка зависимостей
+ ///
+ private readonly IDependencyContainer _dependencyManager;
+
+ ///
+ /// Менеджер для работы с зависимостями
+ ///
+ private static DependencyManager? _manager;
+
+ ///
+ /// Блокировка
+ ///
+ private static readonly object _locjObject = new();
+
+ ///
+ /// Конструктор
+ ///
+ private DependencyManager()
+ {
+ _dependencyManager = new UnityDependencyContainer();
+ }
+
+ ///
+ /// Получить ссылку
+ ///
+ public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
+
+ ///
+ /// Иницализация библиотек, в которых идут установки зависомстей
+ ///
+ public static void InitDependency()
+ {
+ var ext = ServiceProviderLoader.GetImplementationExtensions();
+ if (ext == null)
+ {
+ throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
+ }
+ // регистрируем зависимости
+ ext.RegisterServices();
+ }
+
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ public void AddLogging(Action configure) => _dependencyManager.AddLogging(configure);
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle);
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle);
+
+ ///
+ /// Получение класса со всеми зависмостями
+ ///
+ ///
+ ///
+ public T Resolve() => _dependencyManager.Resolve();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/IDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/IDependencyContainer.cs
new file mode 100644
index 0000000..91bdf09
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/IDependencyContainer.cs
@@ -0,0 +1,43 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Интерфейс установки зависмости между элементами
+ ///
+ public interface IDependencyContainer
+ {
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ void AddLogging(Action configure);
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ ///
+ void RegisterType(bool isSingle) where U : class, T where T : class;
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ void RegisterType(bool isSingle) where T : class;
+
+ ///
+ /// Получение класса со всеми зависимостями
+ ///
+ ///
+ ///
+ T Resolve();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/IImplementationExtension.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/IImplementationExtension.cs
new file mode 100644
index 0000000..628d4fb
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/IImplementationExtension.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Интерфейс для регистрации зависимостей в модулях
+ ///
+ public interface IImplementationExtension
+ {
+ ///
+ /// Приоритет
+ ///
+ public int Priority { get; }
+
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceDependencyContainer.cs
new file mode 100644
index 0000000..4d19647
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceDependencyContainer.cs
@@ -0,0 +1,94 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Реализация интерфейса установки зависимости между элементами
+ ///
+ public class ServiceDependencyContainer : IDependencyContainer
+ {
+ ///
+ /// Провайдер сервисов для разрешения зависимостей
+ ///
+ private ServiceProvider? _serviceProvider;
+
+ ///
+ /// Коллекция сервисов для регистрации зависимостей
+ ///
+ private readonly ServiceCollection _serviceCollection;
+
+ ///
+ /// Конструктор
+ ///
+ public ServiceDependencyContainer()
+ {
+ _serviceCollection = new ServiceCollection();
+ }
+
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ public void AddLogging(Action configure)
+ {
+ _serviceCollection.AddLogging(configure);
+ }
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle) where U : class, T where T : class
+ {
+ if (isSingle)
+ {
+ _serviceCollection.AddSingleton();
+ }
+ else
+ {
+ _serviceCollection.AddTransient();
+ }
+ _serviceProvider = null;
+ }
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle) where T : class
+ {
+ if (isSingle)
+ {
+ _serviceCollection.AddSingleton();
+ }
+ else
+ {
+ _serviceCollection.AddTransient();
+ }
+ _serviceProvider = null;
+ }
+
+ ///
+ /// Получение класса со всеми зависимостями
+ ///
+ ///
+ ///
+ public T Resolve()
+ {
+ if (_serviceProvider == null)
+ {
+ _serviceProvider = _serviceCollection.BuildServiceProvider();
+ }
+ return _serviceProvider.GetService()!;
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceProviderLoader.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceProviderLoader.cs
new file mode 100644
index 0000000..459efea
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/ServiceProviderLoader.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Загрузка данных
+ ///
+ public static partial class ServiceProviderLoader
+ {
+ ///
+ /// Загрузка всех классов-реализаций IImplementationExtension
+ ///
+ ///
+ public static IImplementationExtension? GetImplementationExtensions()
+ {
+ IImplementationExtension? source = null;
+ var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
+ foreach (var file in files.Distinct())
+ {
+ Assembly asm = Assembly.LoadFrom(file);
+ foreach (var t in asm.GetExportedTypes())
+ {
+ if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
+ {
+ if (source == null)
+ {
+ source = (IImplementationExtension)Activator.CreateInstance(t)!;
+ }
+ else
+ {
+ var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
+ if (newSource.Priority > source.Priority)
+ {
+ source = newSource;
+ }
+ }
+ }
+ }
+ }
+ return source;
+ }
+
+ ///
+ /// Получить ImplementationExtensions
+ ///
+ ///
+ private static string TryGetImplementationExtensionsFolder()
+ {
+ var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
+ while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
+ {
+ directory = directory.Parent;
+ }
+ return $"{directory?.FullName}\\ImplementationExtensions";
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/DependencyInjections/UnityDependencyContainer.cs b/AircraftPlant/AircraftPlantContracts/DependencyInjections/UnityDependencyContainer.cs
new file mode 100644
index 0000000..dc9f4d0
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/DependencyInjections/UnityDependencyContainer.cs
@@ -0,0 +1,84 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Unity;
+using Unity.Microsoft.Logging;
+
+namespace AircraftPlantContracts.DependencyInjections
+{
+ ///
+ /// Реализация интерфейса установки зависимости между элементами
+ ///
+ public class UnityDependencyContainer : IDependencyContainer
+ {
+ ///
+ /// Контейнер сервисов для регистрации зависимостей
+ ///
+ private readonly UnityContainer _container;
+
+ ///
+ /// Конструктор
+ ///
+ public UnityDependencyContainer()
+ {
+ _container = new UnityContainer();
+ }
+
+ ///
+ /// Регистрация логгера
+ ///
+ ///
+ public void AddLogging(Action configure)
+ {
+ _container.AddExtension(new LoggingExtension(LoggerFactory.Create(configure)));
+ }
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle) where U : class, T where T : class
+ {
+ if (isSingle)
+ {
+ _container.RegisterSingleton();
+ }
+ else
+ {
+ _container.RegisterType();
+ }
+ }
+
+ ///
+ /// Добавление зависимости
+ ///
+ ///
+ ///
+ public void RegisterType(bool isSingle) where T : class
+ {
+ if (isSingle)
+ {
+ _container.RegisterSingleton();
+ }
+ else
+ {
+ _container.RegisterType();
+ }
+ }
+
+ ///
+ /// Получение класса со всеми зависимостями
+ ///
+ ///
+ ///
+ public T Resolve()
+ {
+ return _container.Resolve();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/StoragesContracts/IBackUpInfo.cs b/AircraftPlant/AircraftPlantContracts/StoragesContracts/IBackUpInfo.cs
new file mode 100644
index 0000000..f36a95f
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/StoragesContracts/IBackUpInfo.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.StoragesContracts
+{
+ ///
+ /// Интерфейс для получения данных из хранилища
+ ///
+ public interface IBackUpInfo
+ {
+ ///
+ /// Получить список объектов
+ ///
+ ///
+ ///
+ List? GetList() where T : class, new();
+
+ ///
+ /// Получить тип
+ ///
+ ///
+ ///
+ Type? GetTypeByModelInterface(string modelInterfaceName);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/ClientViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/ClientViewModel.cs
index 0829695..a74ed1f 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/ClientViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/ClientViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -17,25 +18,26 @@ namespace AircraftPlantContracts.ViewModels
///
/// Идентификатор
///
+ [Column(visible: false)]
public int Id { get; set; }
- ///
- /// ФИО клиента
- ///
- [DisplayName("ФИО клиента")]
- public string ClientFIO { get; set; } = string.Empty;
+ ///
+ /// ФИО клиента
+ ///
+ [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ClientFIO { get; set; } = string.Empty;
- ///
- /// Логин (электронная почта)
- ///
- [DisplayName("Логин (эл. почта)")]
- public string Email { get; set; } = string.Empty;
+ ///
+ /// Логин (электронная почта)
+ ///
+ [Column(title: "Логин (эл. почта)", width: 150)]
+ public string Email { get; set; } = string.Empty;
- ///
- /// Пароль
- ///
- [DisplayName("Пароль")]
- public string Password { get; set; } = string.Empty;
+ ///
+ /// Пароль
+ ///
+ [Column(title: "Пароль", width: 150)]
+ public string Password { get; set; } = string.Empty;
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/ComponentViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/ComponentViewModel.cs
index 9eb4c3e..5234409 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/ComponentViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/ComponentViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -17,18 +18,19 @@ namespace AircraftPlantContracts.ViewModels
///
/// Идентификатор
///
+ [Column(visible: false)]
public int Id { get; set; }
- ///
- /// Название компонента
- ///
- [DisplayName("Название компонента")]
- public string ComponentName { get; set; } = string.Empty;
+ ///
+ /// Название компонента
+ ///
+ [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ComponentName { get; set; } = string.Empty;
- ///
- /// Стоимость компонента
- ///
- [DisplayName("Цена")]
- public double Cost { get; set; }
+ ///
+ /// Стоимость компонента
+ ///
+ [Column(title: "Цена", width: 150)]
+ public double Cost { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/ImplementerViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/ImplementerViewModel.cs
index b40ec35..264f22c 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/ImplementerViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/ImplementerViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -14,33 +15,34 @@ namespace AircraftPlantContracts.ViewModels
///
public class ImplementerViewModel : IImplementerModel
{
- ///
- /// Идентификатор
- ///
- public int Id { get; set; }
+ ///
+ /// Идентификатор
+ ///
+ [Column(visible: false)]
+ public int Id { get; set; }
- ///
- /// ФИО исполнителя
- ///
- [DisplayName("ФИО исполнителя")]
- public string ImplementerFIO { get; set; } = string.Empty;
+ ///
+ /// ФИО исполнителя
+ ///
+ [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ImplementerFIO { get; set; } = string.Empty;
- ///
- /// Пароль
- ///
- [DisplayName("Пароль")]
- public string Password { get; set; } = string.Empty;
+ ///
+ /// Пароль
+ ///
+ [Column(title: "Пароль", width: 150)]
+ public string Password { get; set; } = string.Empty;
- ///
- /// Опыт работы
- ///
- [DisplayName("Опыт работы")]
- public int WorkExperience { get; set; }
+ ///
+ /// Опыт работы
+ ///
+ [Column(title: "Опыт работы", width: 100)]
+ public int WorkExperience { get; set; }
- ///
- /// Квалификация
- ///
- [DisplayName("Квалификация")]
- public int Qualification { get; set; }
+ ///
+ /// Квалификация
+ ///
+ [Column(title: "Квалификация", width: 100)]
+ public int Qualification { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/MessageInfoViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/MessageInfoViewModel.cs
index ab64fd8..a115517 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/MessageInfoViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/MessageInfoViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -17,35 +18,40 @@ namespace AircraftPlantContracts.ViewModels
///
/// Идентификатор
///
+ [Column(visible: false)]
public string MessageId { get; set; } = string.Empty;
///
/// Идентификатор клиента
///
+ [Column(visible: false)]
public int? ClientId { get; set; }
///
/// Адрес электронной почты отправителя
///
- [DisplayName("Отправитель")]
+ [Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
///
/// Дата получения письма
///
- [DisplayName("Дата письма")]
+ [Column(title: "Дата письма", width: 150)]
public DateTime DateDelivery { get; set; }
///
/// Заголовок письма
///
- [DisplayName("Заголовок")]
+ [Column(title: "Заголовок", width: 150)]
public string Subject { get; set; } = string.Empty;
///
/// Тело письма
///
- [DisplayName("Текст")]
+ [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty;
+
+ [Column(visible: false)]
+ public int Id { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/OrderViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/OrderViewModel.cs
index e44dc84..2051476 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/OrderViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/OrderViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Enums;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
@@ -15,73 +16,76 @@ namespace AircraftPlantContracts.ViewModels
///
public class OrderViewModel : IOrderModel
{
- ///
- /// Идентификатор
- ///
- [DisplayName("Номер")]
- public int Id { get; set; }
+ ///
+ /// Идентификатор
+ ///
+ [Column(title: "Номер", width: 50)]
+ public int Id { get; set; }
- ///
- /// Идентификатор изделия
- ///
- public int PlaneId { get; set; }
+ ///
+ /// Идентификатор изделия
+ ///
+ [Column(visible: false)]
+ public int PlaneId { get; set; }
- ///
- /// Название изделия
- ///
- [DisplayName("Изделие")]
- public string PlaneName { get; set; } = string.Empty;
+ ///
+ /// Название изделия
+ ///
+ [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string PlaneName { get; set; } = string.Empty;
- ///
- /// Идентификатор клиента
- ///
- public int ClientId { get; set; }
+ ///
+ /// Идентификатор клиента
+ ///
+ [Column(visible: false)]
+ public int ClientId { get; set; }
- ///
- /// ФИО клиента
- ///
- [DisplayName("ФИО клиента")]
- public string ClientFIO { get; set; } = string.Empty;
+ ///
+ /// ФИО клиента
+ ///
+ [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ClientFIO { get; set; } = string.Empty;
- ///
- /// Идентификатор исполнителя
- ///
- public int? ImplementerId { get; set; }
+ ///
+ /// Идентификатор исполнителя
+ ///
+ [Column(visible: false)]
+ public int? ImplementerId { get; set; }
- ///
- /// ФИО клиента
- ///
- [DisplayName("ФИО исполнителя")]
- public string ImplementerFIO { get; set; } = string.Empty;
+ ///
+ /// ФИО клиента
+ ///
+ [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string ImplementerFIO { get; set; } = string.Empty;
- ///
- /// Количество изделий
- ///
- [DisplayName("Количество")]
- public int Count { get; set; }
+ ///
+ /// Количество изделий
+ ///
+ [Column(title: "Количество", width: 100)]
+ public int Count { get; set; }
- ///
- /// Сумма заказа
- ///
- [DisplayName("Сумма")]
- public double Sum { get; set; }
+ ///
+ /// Сумма заказа
+ ///
+ [Column(title: "Сумма", width: 100)]
+ public double Sum { get; set; }
- ///
- /// Статус заказа
- ///
- [DisplayName("Статус")]
- public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ ///
+ /// Статус заказа
+ ///
+ [Column(title: "Статус", width: 70)]
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
- ///
- /// Дата создания заказа
- ///
- [DisplayName("Дата создания")]
- public DateTime DateCreate { get; set; } = DateTime.Now;
+ ///
+ /// Дата создания заказа
+ ///
+ [Column(title: "Дата создания", width: 100)]
+ public DateTime DateCreate { get; set; } = DateTime.Now;
///
/// Дата выполнения заказа
///
- [DisplayName("Дата выполнения")]
+ [Column(title: "Дата выполнения", width: 100)]
public DateTime? DateImplement { get; set; }
}
}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/PlaneViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/PlaneViewModel.cs
index 0e60ba4..47dcc9c 100644
--- a/AircraftPlant/AircraftPlantContracts/ViewModels/PlaneViewModel.cs
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/PlaneViewModel.cs
@@ -1,4 +1,5 @@
-using AircraftPlantDataModels.Models;
+using AircraftPlantContracts.Attributes;
+using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -14,27 +15,29 @@ namespace AircraftPlantContracts.ViewModels
///
public class PlaneViewModel : IPlaneModel
{
- ///
- /// Идентификатор
- ///
- public int Id { get; set; }
+ ///
+ /// Идентификатор
+ ///
+ [Column(visible: false)]
+ public int Id { get; set; }
- ///
- /// Название изделия
- ///
- [DisplayName("Название изделия")]
- public string PlaneName { get; set; } = string.Empty;
+ ///
+ /// Название изделия
+ ///
+ [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
+ public string PlaneName { get; set; } = string.Empty;
- ///
- /// Стоимость изделия
- ///
- [DisplayName("Цена")]
- public double Price { get; set; }
+ ///
+ /// Стоимость изделия
+ ///
+ [Column(title: "Цена", width: 150)]
+ public double Price { get; set; }
- ///
- /// Коллекция компонентов изделия
- ///
- public Dictionary PlaneComponents
+ ///
+ /// Коллекция компонентов изделия
+ ///
+ [Column(visible: false)]
+ public Dictionary PlaneComponents
{
get;
set;
diff --git a/AircraftPlant/AircraftPlantDataModels/Enums/OrderStatus.cs b/AircraftPlant/AircraftPlantDataModels/Enums/OrderStatus.cs
index ac2308f..4ad0c9b 100644
--- a/AircraftPlant/AircraftPlantDataModels/Enums/OrderStatus.cs
+++ b/AircraftPlant/AircraftPlantDataModels/Enums/OrderStatus.cs
@@ -19,6 +19,8 @@ namespace AircraftPlantDataModels.Enums
Готов = 2,
- Выдан = 3
+ Выдан = 3,
+
+ Ожидание = 4 // Иначе возникает исключение ArgumentException
}
}
diff --git a/AircraftPlant/AircraftPlantDataModels/Models/IMessageInfoModel.cs b/AircraftPlant/AircraftPlantDataModels/Models/IMessageInfoModel.cs
index 05ffd3e..d715ad2 100644
--- a/AircraftPlant/AircraftPlantDataModels/Models/IMessageInfoModel.cs
+++ b/AircraftPlant/AircraftPlantDataModels/Models/IMessageInfoModel.cs
@@ -9,7 +9,7 @@ namespace AircraftPlantDataModels.Models
///
/// Интерфейс для модели письма
///
- public interface IMessageInfoModel
+ public interface IMessageInfoModel : IId
{
///
/// Идентификатор
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj b/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
index 6881766..52fffc1 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/AircraftPlantDatabaseImplement.csproj
@@ -20,4 +20,8 @@
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/DatabaseImplementationExtension.cs b/AircraftPlant/AircraftPlantDatabaseImplement/DatabaseImplementationExtension.cs
new file mode 100644
index 0000000..e6b3f3f
--- /dev/null
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/DatabaseImplementationExtension.cs
@@ -0,0 +1,36 @@
+using AircraftPlantContracts.DependencyInjections;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantDatabaseImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantDatabaseImplement
+{
+ ///
+ /// Реализация интерфейса для регистрации зависимостей
+ ///
+ public class DatabaseImplementationExtension : IImplementationExtension
+ {
+ ///
+ /// Приоритет
+ ///
+ public int Priority => 2;
+
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs
new file mode 100644
index 0000000..378393d
--- /dev/null
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/BackUpInfo.cs
@@ -0,0 +1,45 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantDatabaseImplement.Implements
+{
+ ///
+ /// Реализация интерфейса получения данных из хранилища
+ ///
+ public class BackUpInfo : IBackUpInfo
+ {
+ ///
+ /// Получить список объектов
+ ///
+ ///
+ ///
+ public List? GetList() where T : class, new()
+ {
+ using var context = new AircraftPlantDatabase();
+ return context.Set().ToList();
+ }
+
+ ///
+ /// Получить тип
+ ///
+ ///
+ ///
+ public Type? GetTypeByModelInterface(string modelInterfaceName)
+ {
+ var assembly = typeof(BackUpInfo).Assembly;
+ var types = assembly.GetTypes();
+ foreach (var type in types)
+ {
+ if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
+ {
+ return type;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
index 50aae1e..7e79241 100644
--- a/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
+++ b/AircraftPlant/AircraftPlantDatabaseImplement/Models/Message.cs
@@ -4,6 +4,7 @@ using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -55,6 +56,9 @@ namespace AircraftPlantDatabaseImplement.Models
[Required]
public string Body { get; set; } = string.Empty;
+ [NotMapped]
+ public int Id { get; private set; }
+
///
/// Создание модели письма
///
diff --git a/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj b/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
index 8b75aa9..4bc3332 100644
--- a/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
+++ b/AircraftPlant/AircraftPlantFileImplement/AircraftPlantFileImplement.csproj
@@ -11,4 +11,8 @@
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantFileImplement/FileImplementationExtension.cs b/AircraftPlant/AircraftPlantFileImplement/FileImplementationExtension.cs
new file mode 100644
index 0000000..e6942d1
--- /dev/null
+++ b/AircraftPlant/AircraftPlantFileImplement/FileImplementationExtension.cs
@@ -0,0 +1,36 @@
+using AircraftPlantContracts.DependencyInjections;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantFileImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantFileImplement
+{
+ ///
+ /// Реализация интерфейса для регистрации зависимостей
+ ///
+ public class FileImplementationExtension : IImplementationExtension
+ {
+ ///
+ /// Приоритет
+ ///
+ public int Priority => 1;
+
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantFileImplement/Implements/BackUpInfo.cs b/AircraftPlant/AircraftPlantFileImplement/Implements/BackUpInfo.cs
new file mode 100644
index 0000000..02bcbda
--- /dev/null
+++ b/AircraftPlant/AircraftPlantFileImplement/Implements/BackUpInfo.cs
@@ -0,0 +1,48 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantFileImplement.Implements
+{
+ ///
+ /// Реализация интерфейса получения данных из хранилища
+ ///
+ public class BackUpInfo : IBackUpInfo
+ {
+ ///
+ /// Получить список объектов
+ ///
+ ///
+ ///
+ public List? GetList() where T : class, new()
+ {
+ var source = DataFileSingleton.GetInstance();
+ return (List?)source.GetType()
+ .GetProperties()
+ .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
+ ?.GetValue(source);
+ }
+
+ ///
+ /// Получить тип
+ ///
+ ///
+ ///
+ public Type? GetTypeByModelInterface(string modelInterfaceName)
+ {
+ var assembly = typeof(BackUpInfo).Assembly;
+ var types = assembly.GetTypes();
+ foreach (var type in types)
+ {
+ if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
+ {
+ return type;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantFileImplement/Models/Message.cs b/AircraftPlant/AircraftPlantFileImplement/Models/Message.cs
index 0cc1bc4..10b4cfa 100644
--- a/AircraftPlant/AircraftPlantFileImplement/Models/Message.cs
+++ b/AircraftPlant/AircraftPlantFileImplement/Models/Message.cs
@@ -45,6 +45,8 @@ namespace AircraftPlantFileImplement.Models
///
public string Body { get; set; } = string.Empty;
+ public int Id => throw new NotImplementedException();
+
///
/// Создание модели письма
///
diff --git a/AircraftPlant/AircraftPlantListImplement/AircraftPlantListImplement.csproj b/AircraftPlant/AircraftPlantListImplement/AircraftPlantListImplement.csproj
index 229b307..cdd5bf4 100644
--- a/AircraftPlant/AircraftPlantListImplement/AircraftPlantListImplement.csproj
+++ b/AircraftPlant/AircraftPlantListImplement/AircraftPlantListImplement.csproj
@@ -11,4 +11,8 @@
+
+
+
+
diff --git a/AircraftPlant/AircraftPlantListImplement/Implements/BackUpInfo.cs b/AircraftPlant/AircraftPlantListImplement/Implements/BackUpInfo.cs
new file mode 100644
index 0000000..f3a6a59
--- /dev/null
+++ b/AircraftPlant/AircraftPlantListImplement/Implements/BackUpInfo.cs
@@ -0,0 +1,35 @@
+using AircraftPlantContracts.StoragesContracts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement.Implements
+{
+ ///
+ /// Реализация интерфейса получения данных из хранилища
+ ///
+ public class BackUpInfo : IBackUpInfo
+ {
+ ///
+ /// Получить список объектов
+ ///
+ ///
+ ///
+ public List? GetList() where T : class, new()
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Получить тип
+ ///
+ ///
+ ///
+ public Type? GetTypeByModelInterface(string modelInterfaceName)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantListImplement/ListImplementationExtension.cs b/AircraftPlant/AircraftPlantListImplement/ListImplementationExtension.cs
new file mode 100644
index 0000000..b57564a
--- /dev/null
+++ b/AircraftPlant/AircraftPlantListImplement/ListImplementationExtension.cs
@@ -0,0 +1,36 @@
+using AircraftPlantContracts.DependencyInjections;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantListImplement.Implements;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement
+{
+ ///
+ /// Реализация интерфейса для регистрации зависимостей
+ ///
+ public class ListImplementationExtension : IImplementationExtension
+ {
+ ///
+ /// Приоритет
+ ///
+ public int Priority => 0;
+
+ ///
+ /// Регистрация сервисов
+ ///
+ public void RegisterServices()
+ {
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantListImplement/Models/Message.cs b/AircraftPlant/AircraftPlantListImplement/Models/Message.cs
index 6e0441a..723f1a4 100644
--- a/AircraftPlant/AircraftPlantListImplement/Models/Message.cs
+++ b/AircraftPlant/AircraftPlantListImplement/Models/Message.cs
@@ -44,6 +44,8 @@ namespace AircraftPlantListImplement.Models
///
public string Body { get; set; } = string.Empty;
+ public int Id => throw new NotImplementedException();
+
///
/// Создание модели письма
///
diff --git a/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs b/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs
new file mode 100644
index 0000000..a170229
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/DataGridViewExtension.cs
@@ -0,0 +1,63 @@
+using AircraftPlantContracts.Attributes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantView
+{
+ ///
+ /// Класс-расширение для DataGridView
+ ///
+ public static class DataGridViewExtension
+ {
+ ///
+ /// Настройка и заполнение DataGridView
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void FillAndConfigGrid(this DataGridView grid, List? data)
+ {
+ if (data == null)
+ {
+ return;
+ }
+ grid.DataSource = data;
+
+ var type = typeof(T);
+ var properties = type.GetProperties();
+ foreach (DataGridViewColumn column in grid.Columns)
+ {
+ var property = properties.FirstOrDefault(x => x.Name == column.Name);
+ if (property == null)
+ {
+ throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}");
+ }
+
+ var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
+ if (attribute == null)
+ {
+ throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}");
+ }
+
+ // Ищем нужный нам атрибут
+ if (attribute is ColumnAttribute columnAttr)
+ {
+ column.HeaderText = columnAttr.Title;
+ column.Visible = columnAttr.Visible;
+ if (columnAttr.IsUseAutoSize)
+ {
+ column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode), columnAttr.GridViewAutoSize.ToString());
+ }
+ else
+ {
+ column.Width = columnAttr.Width;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantView/FormClients.cs b/AircraftPlant/AircraftPlantView/FormClients.cs
index 8c6456d..8193fd9 100644
--- a/AircraftPlant/AircraftPlantView/FormClients.cs
+++ b/AircraftPlant/AircraftPlantView/FormClients.cs
@@ -97,14 +97,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormComponents.cs b/AircraftPlant/AircraftPlantView/FormComponents.cs
index aa9143b..1f46676 100644
--- a/AircraftPlant/AircraftPlantView/FormComponents.cs
+++ b/AircraftPlant/AircraftPlantView/FormComponents.cs
@@ -1,5 +1,6 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DependencyInjections;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -57,13 +58,10 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
@@ -76,14 +74,11 @@ namespace AircraftPlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
@@ -135,14 +130,8 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
- _logger.LogInformation("Загрузка компонентов");
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
+ _logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
{
diff --git a/AircraftPlant/AircraftPlantView/FormImplementers.cs b/AircraftPlant/AircraftPlantView/FormImplementers.cs
index 0d725d5..14456bd 100644
--- a/AircraftPlant/AircraftPlantView/FormImplementers.cs
+++ b/AircraftPlant/AircraftPlantView/FormImplementers.cs
@@ -1,5 +1,6 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DependencyInjections;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -57,13 +58,10 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
- if (service is FormImplementer form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
@@ -76,14 +74,11 @@ namespace AircraftPlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
- if (service is FormImplementer form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
@@ -135,14 +130,8 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
- _logger.LogInformation("Загрузка списка исполнителей");
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
+ _logger.LogInformation("Загрузка списка исполнителей");
}
catch (Exception ex)
{
diff --git a/AircraftPlant/AircraftPlantView/FormMail.cs b/AircraftPlant/AircraftPlantView/FormMail.cs
index 6b03878..0bf9040 100644
--- a/AircraftPlant/AircraftPlantView/FormMail.cs
+++ b/AircraftPlant/AircraftPlantView/FormMail.cs
@@ -57,14 +57,7 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["MessageId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка писем");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
index e4f9e4c..8a2673f 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
@@ -44,6 +44,7 @@
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem();
почтаToolStripMenuItem = new ToolStripMenuItem();
+ создатьБэкапToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout();
@@ -98,7 +99,7 @@
//
// menuStrip
//
- menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem });
+ menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem, создатьБэкапToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(984, 24);
@@ -182,6 +183,13 @@
почтаToolStripMenuItem.Text = "Почта";
почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click;
//
+ // создатьБэкапToolStripMenuItem
+ //
+ создатьБэкапToolStripMenuItem.Name = "создатьБэкапToolStripMenuItem";
+ создатьБэкапToolStripMenuItem.Size = new Size(97, 20);
+ создатьБэкапToolStripMenuItem.Text = "Создать бэкап";
+ создатьБэкапToolStripMenuItem.Click += создатьБэкапToolStripMenuItem_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -221,5 +229,6 @@
private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem почтаToolStripMenuItem;
+ private ToolStripMenuItem создатьБэкапToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs
index 66302e5..1988159 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.cs
@@ -1,6 +1,7 @@
using AircraftPlantBusinessLogic.BusinessLogics;
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DependencyInjections;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -39,18 +40,24 @@ namespace AircraftPlantView
///
private readonly IWorkProcess _workProcess;
+ ///
+ /// Бизнес-логика для создания бэкапа
+ ///
+ private readonly IBackUpLogic _backUpLogic;
+
///
/// Конструктор
///
///
///
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
+ _backUpLogic = backUpLogic;
}
///
@@ -70,11 +77,8 @@ namespace AircraftPlantView
///
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
- if (service is FormComponents form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -84,11 +88,8 @@ namespace AircraftPlantView
///
private void изделияToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlanes));
- if (service is FormPlanes form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -98,11 +99,8 @@ namespace AircraftPlantView
///
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormClients));
- if (service is FormClients form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -112,11 +110,8 @@ namespace AircraftPlantView
///
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
- if (service is FormImplementers form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -141,11 +136,8 @@ namespace AircraftPlantView
///
private void изделияСКомпонентамиToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportPlaneComponents));
- if (service is FormReportPlaneComponents form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -155,11 +147,8 @@ namespace AircraftPlantView
///
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
- if (service is FormReportOrders form)
- {
- form.ShowDialog();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
}
///
@@ -170,7 +159,7 @@ namespace AircraftPlantView
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((
- Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,
+ DependencyManager.Instance.Resolve() as IImplementerLogic)!,
_orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@@ -182,10 +171,35 @@ namespace AircraftPlantView
///
private void почтаToolStripMenuItem_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormMail));
- if (service is FormMail form)
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ }
+
+ ///
+ /// Создать бэкап
+ ///
+ ///
+ ///
+ private void создатьБэкапToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ try
{
- form.ShowDialog();
+ if (_backUpLogic != null)
+ {
+ var fbd = new FolderBrowserDialog();
+ if (fbd.ShowDialog() == DialogResult.OK)
+ {
+ _backUpLogic.CreateBackUp(new BackUpSaveBindingModel
+ {
+ FolderName = fbd.SelectedPath
+ });
+ MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@@ -196,12 +210,9 @@ namespace AircraftPlantView
///
private void buttonCreateOrder_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
- if (service is FormCreateOrder form)
- {
- form.ShowDialog();
- LoadData();
- }
+ var form = DependencyManager.Instance.Resolve();
+ form.ShowDialog();
+ LoadData();
}
///
@@ -251,14 +262,7 @@ namespace AircraftPlantView
_logger.LogInformation("Загрузка заказов");
try
{
- var list = _orderLogic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["PlaneId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["ImplementerId"].Visible = false;
- }
+ dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
diff --git a/AircraftPlant/AircraftPlantView/FormPlane.cs b/AircraftPlant/AircraftPlantView/FormPlane.cs
index cb62d77..6498896 100644
--- a/AircraftPlant/AircraftPlantView/FormPlane.cs
+++ b/AircraftPlant/AircraftPlantView/FormPlane.cs
@@ -1,5 +1,6 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DependencyInjections;
using AircraftPlantContracts.SearchModels;
using AircraftPlantDataModels.Models;
using Microsoft.Extensions.Logging;
@@ -90,26 +91,23 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlaneComponent));
- if (service is FormPlaneComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
+ if (form.ComponentModel == null)
{
- if (form.ComponentModel == null)
- {
- return;
- }
- _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
- if (_planeComponents.ContainsKey(form.Id))
- {
- _planeComponents[form.Id] = (form.ComponentModel, form.Count);
- }
- else
- {
- _planeComponents.Add(form.Id, (form.ComponentModel, form.Count));
- }
- LoadData();
+ return;
}
+ _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_planeComponents.ContainsKey(form.Id))
+ {
+ _planeComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _planeComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
}
}
@@ -122,22 +120,19 @@ namespace AircraftPlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlaneComponent));
- if (service is FormPlaneComponent form)
+ var form = DependencyManager.Instance.Resolve();
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _planeComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
- form.Id = id;
- form.Count = _planeComponents[id].Item2;
- if (form.ShowDialog() == DialogResult.OK)
+ if (form.ComponentModel == null)
{
- if (form.ComponentModel == null)
- {
- return;
- }
- _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
- _planeComponents[form.Id] = (form.ComponentModel, form.Count);
- LoadData();
+ return;
}
+ _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
+ _planeComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
}
}
}
diff --git a/AircraftPlant/AircraftPlantView/FormPlanes.cs b/AircraftPlant/AircraftPlantView/FormPlanes.cs
index ae7f5bd..034842f 100644
--- a/AircraftPlant/AircraftPlantView/FormPlanes.cs
+++ b/AircraftPlant/AircraftPlantView/FormPlanes.cs
@@ -1,5 +1,6 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.DependencyInjections;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -57,13 +58,10 @@ namespace AircraftPlantView
///
private void buttonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlane));
- if (service is FormPlane form)
+ var form = DependencyManager.Instance.Resolve();
+ if (form.ShowDialog() == DialogResult.OK)
{
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
@@ -76,14 +74,11 @@ namespace AircraftPlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormPlane));
- if (service is FormPlane form)
+ var form = DependencyManager.Instance.Resolve();
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
{
- form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- if (form.ShowDialog() == DialogResult.OK)
- {
- LoadData();
- }
+ LoadData();
}
}
}
@@ -138,15 +133,8 @@ namespace AircraftPlantView
{
try
{
- var list = _logic.ReadList(null);
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["Id"].Visible = false;
- dataGridView.Columns["PlaneName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- dataGridView.Columns["PlaneComponents"].Visible = false;
- }
- _logger.LogInformation("Загрузка изделий");
+ dataGridView.FillAndConfigGrid(_logic.ReadList(null));
+ _logger.LogInformation("Загрузка изделий");
}
catch (Exception ex)
{
diff --git a/AircraftPlant/AircraftPlantView/Program.cs b/AircraftPlant/AircraftPlantView/Program.cs
index bc6969b..4f2c580 100644
--- a/AircraftPlant/AircraftPlantView/Program.cs
+++ b/AircraftPlant/AircraftPlantView/Program.cs
@@ -10,17 +10,12 @@ using NLog.Extensions.Logging;
using System;
using AircraftPlantBusinessLogic.MailWorker;
using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.DependencyInjections;
namespace AircraftPlantView
{
internal static class Program
{
- ///
- /// IoC-
- ///
- private static ServiceProvider? _serviceProvider;
- public static ServiceProvider? ServiceProvider => _serviceProvider;
-
///
/// The main entry point for the application.
///
@@ -30,15 +25,12 @@ namespace AircraftPlantView
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
-
- var services = new ServiceCollection();
- ConfigureServices(services);
- _serviceProvider = services.BuildServiceProvider();
+ InitDependency();
//
try
{
- var mailSender = _serviceProvider.GetService();
+ var mailSender = DependencyManager.Instance.Resolve();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
@@ -54,66 +46,62 @@ namespace AircraftPlantView
}
catch (Exception ex)
{
- var logger = _serviceProvider.GetService();
+ var logger = DependencyManager.Instance.Resolve();
logger?.LogError(ex, " ");
}
- Application.Run(_serviceProvider.GetRequiredService());
+ Application.Run(DependencyManager.Instance.Resolve());
}
///
- /// IoC-
+ ///
///
///
- private static void ConfigureServices(ServiceCollection services)
+ private static void InitDependency()
{
- services.AddLogging(option =>
+ DependencyManager.InitDependency();
+
+ DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType(true);
- services.AddTransient();
- services.AddSingleton();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
-
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
}
///
///
///
///
- private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck();
+ private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck();
}
}
\ No newline at end of file