From 2bba67161c1370f8f1c4c946cda480cd7594820f Mon Sep 17 00:00:00 2001 From: "leonteva.v" Date: Fri, 21 Jun 2024 13:10:51 +0400 Subject: [PATCH] lab8 --- .gitignore | 1 + .../Typography/DataGridViewExtension.cs | 46 ++++++++ Typography/Typography/FormClients.cs | 10 +- Typography/Typography/FormComponents.cs | 40 +++---- Typography/Typography/FormImplementers.cs | 30 ++--- Typography/Typography/FormMain.Designer.cs | 11 +- Typography/Typography/FormMain.cs | 103 +++++++++--------- Typography/Typography/FormMain.resx | 62 ++++++++++- Typography/Typography/FormMessages.cs | 10 +- Typography/Typography/FormPrinted.cs | 74 ++++++------- Typography/Typography/FormPrinteds.cs | 36 +++--- Typography/Typography/Program.cs | 99 ++++++++--------- .../BusinessLogics/BackUpLogic.cs | 94 ++++++++++++++++ .../Attributes/ColumnAttribute.cs | 25 +++++ .../Attributes/GridViewAutoSize.cs | 14 +++ .../BindingModels/BackUpSaveBinidngModel.cs | 7 ++ .../BindingModels/MessageInfoBindingModel.cs | 1 + .../BusinessLogicsContracts/IBackUpLogic.cs | 9 ++ .../DI/DependencyManager.cs | 51 +++++++++ .../DI/IDependencyContainer.cs | 15 +++ .../DI/IImplementationExtension.cs | 9 ++ .../DI/ServiceDependencyContainer.cs | 58 ++++++++++ .../DI/ServiceProviderLoader.cs | 46 ++++++++ .../DI/UnityDependencyContainer.cs | 50 +++++++++ .../StoragesContracts/IBackUpInfo.cs | 9 ++ .../TypographyContracts.csproj | 6 + .../ViewModels/ClientViewModel.cs | 16 +-- .../ViewModels/ComponentViewModel.cs | 12 +- .../ViewModels/ImplementerViewModel.cs | 20 ++-- .../ViewModels/MessageInfoViewModel.cs | 13 ++- .../ViewModels/OrderViewModel.cs | 45 ++++---- .../ViewModels/PrintedViewModel.cs | 15 ++- .../Models/IMessageInfoModel.cs | 2 +- .../DatabaseImplementationExtension.cs | 22 ++++ .../Implements/BackUpInfo.cs | 27 +++++ .../Models/Client.cs | 17 ++- .../Models/Component.cs | 13 ++- .../Models/Implementer.cs | 19 +++- .../Models/MessageInfo.cs | 19 ++++ .../Models/Order.cs | 31 ++++-- .../Models/Printed.cs | 13 ++- .../Models/PrintedComponent.cs | 1 + .../TypographyDatabaseImplement.csproj | 4 + .../FileImplementationExtension.cs | 22 ++++ .../Implements/BackUpInfo.cs | 38 +++++++ .../TypographyFileImplement/Models/Client.cs | 16 ++- .../Models/Component.cs | 13 ++- .../Models/Implementer.cs | 19 +++- .../Models/MessageInfo.cs | 9 ++ .../TypographyFileImplement/Models/Order.cs | 31 ++++-- .../TypographyFileImplement/Models/Printed.cs | 13 ++- .../TypographyFileImplement.csproj | 4 + .../Implements/BackUpInfo.cs | 16 +++ .../ListImplementationExtension.cs | 22 ++++ .../Models/MessageInfo.cs | 1 + .../TypographyListImplement.csproj | 4 + 56 files changed, 1073 insertions(+), 340 deletions(-) create mode 100644 Typography/Typography/DataGridViewExtension.cs create mode 100644 Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 Typography/TypographyContracts/Attributes/ColumnAttribute.cs create mode 100644 Typography/TypographyContracts/Attributes/GridViewAutoSize.cs create mode 100644 Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 Typography/TypographyContracts/DI/DependencyManager.cs create mode 100644 Typography/TypographyContracts/DI/IDependencyContainer.cs create mode 100644 Typography/TypographyContracts/DI/IImplementationExtension.cs create mode 100644 Typography/TypographyContracts/DI/ServiceDependencyContainer.cs create mode 100644 Typography/TypographyContracts/DI/ServiceProviderLoader.cs create mode 100644 Typography/TypographyContracts/DI/UnityDependencyContainer.cs create mode 100644 Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs create mode 100644 Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 Typography/TypographyFileImplement/FileImplementationExtension.cs create mode 100644 Typography/TypographyFileImplement/Implements/BackUpInfo.cs create mode 100644 Typography/TypographyListImplement/Implements/BackUpInfo.cs create mode 100644 Typography/TypographyListImplement/ListImplementationExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..ae28e95 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +*.dll # Mono auto generated files mono_crash.* diff --git a/Typography/Typography/DataGridViewExtension.cs b/Typography/Typography/DataGridViewExtension.cs new file mode 100644 index 0000000..f4a4b39 --- /dev/null +++ b/Typography/Typography/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using TypographyContracts.Attributes; + +namespace TypographyView +{ + internal static class DataGridViewExtension + { + 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; + } + } + } + } + } +} \ No newline at end of file diff --git a/Typography/Typography/FormClients.cs b/Typography/Typography/FormClients.cs index 1ef36c5..30e1f41 100644 --- a/Typography/Typography/FormClients.cs +++ b/Typography/Typography/FormClients.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyView; namespace Typography { @@ -23,13 +25,7 @@ namespace Typography { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewClients.DataSource = list; - dataGridViewClients.Columns["Id"].Visible = false; - dataGridViewClients.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewClients.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/Typography/Typography/FormComponents.cs b/Typography/Typography/FormComponents.cs index 4671fc1..6aad11d 100644 --- a/Typography/Typography/FormComponents.cs +++ b/Typography/Typography/FormComponents.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -18,15 +20,9 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewComponents.DataSource = list; - dataGridViewComponents.Columns["Id"].Visible = false; - dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); - } + dataGridViewComponents.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки компонентов"); @@ -35,27 +31,23 @@ namespace TypographyView } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } private void buttonUpd_Click(object sender, EventArgs e) { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } diff --git a/Typography/Typography/FormImplementers.cs b/Typography/Typography/FormImplementers.cs index b9638d4..d6a6b73 100644 --- a/Typography/Typography/FormImplementers.cs +++ b/Typography/Typography/FormImplementers.cs @@ -2,6 +2,8 @@ using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using TypographyView; +using System.Windows.Forms; +using TypographyContracts.DI; namespace Typography { @@ -26,13 +28,7 @@ namespace Typography { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewImplementers.DataSource = list; - dataGridViewImplementers.Columns["Id"].Visible = false; - dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewImplementers.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -44,13 +40,10 @@ namespace Typography 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(); } } @@ -58,14 +51,11 @@ namespace Typography { if (dataGridViewImplementers.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) { - form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } } diff --git a/Typography/Typography/FormMain.Designer.cs b/Typography/Typography/FormMain.Designer.cs index c756755..375172f 100644 --- a/Typography/Typography/FormMain.Designer.cs +++ b/Typography/Typography/FormMain.Designer.cs @@ -44,6 +44,7 @@ ordersListToolStripMenuItem = new ToolStripMenuItem(); workLaunchToolStripMenuItem = new ToolStripMenuItem(); messagesToolStripMenuItem = new ToolStripMenuItem(); + CreateBackUpToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -94,7 +95,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, reportsToolStripMenuItem, workLaunchToolStripMenuItem, messagesToolStripMenuItem, CreateBackUpToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1482, 28); @@ -178,6 +179,13 @@ messagesToolStripMenuItem.Text = "Письма"; messagesToolStripMenuItem.Click += MessagesToolStripMenuItem_Click; // + // CreateBackUpToolStripMenuItem + // + CreateBackUpToolStripMenuItem.Name = "CreateBackUpToolStripMenuItem"; + CreateBackUpToolStripMenuItem.Size = new Size(63, 24); + CreateBackUpToolStripMenuItem.Text = "Бэкап"; + CreateBackUpToolStripMenuItem.Click += CreateBackUpToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -218,5 +226,6 @@ private ToolStripMenuItem implementersToolStripMenuItem; private ToolStripMenuItem workLaunchToolStripMenuItem; private ToolStripMenuItem messagesToolStripMenuItem; + private ToolStripMenuItem CreateBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/Typography/Typography/FormMain.cs b/Typography/Typography/FormMain.cs index a6a2d65..933a629 100644 --- a/Typography/Typography/FormMain.cs +++ b/Typography/Typography/FormMain.cs @@ -2,6 +2,9 @@ using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using Typography; +using System.Windows.Forms; +using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.DI; namespace TypographyView { @@ -11,14 +14,16 @@ namespace TypographyView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; 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; } private void FormMain_Load(object sender, EventArgs e) @@ -30,16 +35,7 @@ namespace TypographyView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridViewOrders.DataSource = list; - dataGridViewOrders.Columns["ClientId"].Visible = false; - dataGridViewOrders.Columns["ClientEmail"].Visible = false; - dataGridViewOrders.Columns["ImplementerId"].Visible = false; - dataGridViewOrders.Columns["PrintedId"].Visible = false; - dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewOrders.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -51,38 +47,26 @@ namespace TypographyView private void ComponentsToolStripMenuItem_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(); } private void PrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); - if (service is FormPrinteds form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ClientsToolStripMenuItem_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(); } private void ImplementersToolStripMenuItem_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(); } private void PrintedsListToolStripMenuItem_Click(object sender, EventArgs e) @@ -97,45 +81,33 @@ namespace TypographyView private void ComponentPrintedsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPrintedComponents)); - if (service is FormReportPrintedComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersListToolStripMenuItem_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(); } private void WorkLaunchToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void MessagesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMessages)); - if (service is FormMessages form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } 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(); } private void ButtonIssuedOrder_Click(object sender, EventArgs e) @@ -161,10 +133,33 @@ namespace TypographyView } } } - private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); } + private void CreateBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } \ No newline at end of file diff --git a/Typography/Typography/FormMain.resx b/Typography/Typography/FormMain.resx index 81a9e3d..6c82d08 100644 --- a/Typography/Typography/FormMain.resx +++ b/Typography/Typography/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/Typography/Typography/FormMessages.cs b/Typography/Typography/FormMessages.cs index fe66a35..78dcb44 100644 --- a/Typography/Typography/FormMessages.cs +++ b/Typography/Typography/FormMessages.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; using TypographyContracts.BusinessLogicsContracts; +using System.Windows.Forms; namespace TypographyView { @@ -25,14 +26,7 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewMessages.DataSource = list; - dataGridViewMessages.Columns["MessageId"].Visible = false; - dataGridViewMessages.Columns["ClientId"].Visible = false; - dataGridViewMessages.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridViewMessages.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка входящих писем"); } catch (Exception ex) diff --git a/Typography/Typography/FormPrinted.cs b/Typography/Typography/FormPrinted.cs index deb09db..87ceb86 100644 --- a/Typography/Typography/FormPrinted.cs +++ b/Typography/Typography/FormPrinted.cs @@ -3,6 +3,7 @@ using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.SearchModels; using TypographyDataModels.Models; using Microsoft.Extensions.Logging; +using TypographyContracts.DI; namespace TypographyView { @@ -57,50 +58,47 @@ namespace TypographyView } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", - form.ComponentModel.ComponentName, form.Count); - if (_printedComponents.ContainsKey(form.Id)) - { - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); - } - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + if (_printedComponents.ContainsKey(form.Id)) + { + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } } private void buttonUpd_Click(object sender, EventArgs e) { if (dataGridViewComponents.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); - if (service is FormPrintedComponent form) - { - int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _printedComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[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); - _printedComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } } } } diff --git a/Typography/Typography/FormPrinteds.cs b/Typography/Typography/FormPrinteds.cs index 21a817c..0833e09 100644 --- a/Typography/Typography/FormPrinteds.cs +++ b/Typography/Typography/FormPrinteds.cs @@ -1,6 +1,8 @@ using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Windows.Forms; +using TypographyContracts.DI; namespace TypographyView { @@ -19,16 +21,9 @@ namespace TypographyView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridViewPrinteds.DataSource = list; - dataGridViewPrinteds.Columns["Id"].Visible = false; - dataGridViewPrinteds.Columns["PrintedComponents"].Visible = false; - dataGridViewPrinteds.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка печатной продукции"); - } + dataGridViewPrinteds.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка печатной продукции"); + } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки печатной продукции"); @@ -37,10 +32,10 @@ namespace TypographyView } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) - { - if (form.ShowDialog() == DialogResult.OK) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ShowDialog() == DialogResult.OK) { LoadData(); } @@ -50,14 +45,11 @@ namespace TypographyView { if (dataGridViewPrinteds.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); - if (service is FormPrinted form) - { - form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } diff --git a/Typography/Typography/Program.cs b/Typography/Typography/Program.cs index 7d12560..c113ecb 100644 --- a/Typography/Typography/Program.cs +++ b/Typography/Typography/Program.cs @@ -11,29 +11,24 @@ using System; using TypographyBusinessLogic.MailWorker; using TypographyContracts.BindingModels; using Typography; +using TypographyContracts.DI; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace TypographyView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - 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, @@ -48,53 +43,47 @@ namespace TypographyView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); } - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - 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.AddSingleton(); - - 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(); + Application.Run(DependencyManager.Instance.Resolve()); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void InitDependency() + { + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + 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(true); + 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(); + DependencyManager.Instance.RegisterType(); + } + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..b4f9ec5 --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,94 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.StoragesContracts; +using TypographyDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace TypographyBusinessLogic.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(BackUpSaveBinidngModel 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); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/Attributes/ColumnAttribute.cs b/Typography/TypographyContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..2ba5e00 --- /dev/null +++ b/Typography/TypographyContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace TypographyContracts.Attributes +{ + [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; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs b/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..7fe23b0 --- /dev/null +++ b/Typography/TypographyContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace TypographyContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs b/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..2defbbd --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace TypographyContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs index 894fc75..2722c64 100644 --- a/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Typography/TypographyContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace TypographyContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + public int Id { get; set; } } } \ No newline at end of file diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..df549a5 --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using TypographyContracts.BindingModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/DependencyManager.cs b/Typography/TypographyContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..b04c746 --- /dev/null +++ b/Typography/TypographyContracts/DI/DependencyManager.cs @@ -0,0 +1,51 @@ +using Microsoft.Extensions.Logging; + +namespace TypographyContracts.DI +{ + 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(); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/IDependencyContainer.cs b/Typography/TypographyContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..a281080 --- /dev/null +++ b/Typography/TypographyContracts/DI/IDependencyContainer.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.Logging; + +namespace TypographyContracts.DI +{ + 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(); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/IImplementationExtension.cs b/Typography/TypographyContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..37ca704 --- /dev/null +++ b/Typography/TypographyContracts/DI/IImplementationExtension.cs @@ -0,0 +1,9 @@ +namespace TypographyContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs b/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..991bdb6 --- /dev/null +++ b/Typography/TypographyContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; + +namespace TypographyContracts.DI +{ + 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()!; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/ServiceProviderLoader.cs b/Typography/TypographyContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..a9a676e --- /dev/null +++ b/Typography/TypographyContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace TypographyContracts.DI +{ + public class ServiceProviderLoader + { + 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; + } + + 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"; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/DI/UnityDependencyContainer.cs b/Typography/TypographyContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..a43085d --- /dev/null +++ b/Typography/TypographyContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace TypographyContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly UnityContainer _unityContainer; + + public UnityDependencyContainer() + { + _unityContainer = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + _unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure))); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _unityContainer.RegisterSingleton(); + } + else + { + _unityContainer.RegisterType(); + } + } + + public T Resolve() + { + return _unityContainer.Resolve(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs b/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..22cb2fc --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace TypographyContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/TypographyContracts.csproj b/Typography/TypographyContracts/TypographyContracts.csproj index 1e83ad8..9343afd 100644 --- a/Typography/TypographyContracts/TypographyContracts.csproj +++ b/Typography/TypographyContracts/TypographyContracts.csproj @@ -6,6 +6,12 @@ enable + + + + + + diff --git a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs index d804823..f7dfc14 100644 --- a/Typography/TypographyContracts/ViewModels/ClientViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ using TypographyDataModels.Models; using System.ComponentModel; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs index 41c5070..14e46b2 100644 --- a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -1,16 +1,18 @@ using System.ComponentModel; using TypographyDataModels.Models; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } + [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: 100)] + public double Cost { get; set; } } } \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs index 3921a6a..022a5c7 100644 --- a/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ImplementerViewModel.cs @@ -1,18 +1,20 @@ using TypographyDataModels.Models; using System.ComponentModel; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } - [DisplayName("ФИО исполнителя")] - public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] - public int WorkExperience { get; set; } - [DisplayName("Квалификация")] - public int Qualification { get; set; } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ImplementerFIO { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; + [Column(title: "Стаж работы", width: 80)] + public int WorkExperience { get; set; } + [Column(title: "Квалификация", width: 120)] + public int Qualification { get; set; } } } \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs index f87398b..10b5a24 100644 --- a/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/MessageInfoViewModel.cs @@ -5,20 +5,25 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TypographyDataModels.Models; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [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: 120)] 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; } } } \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs index b7a3419..85dad85 100644 --- a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs @@ -1,32 +1,37 @@ using System.ComponentModel; using TypographyDataModels.Enums; +using TypographyContracts.Attributes; using TypographyDataModels.Models; namespace TypographyContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int ClientId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Номер", width: 80)] + public int Id { get; set; } + [Column(visible: false)] + public int ClientId { get; set; } + [Column(title: "Клиент", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] - public string? ImplementerFIO { get; set; } = string.Empty; - public int PrintedId { get; set; } - [DisplayName("Изделие")] - public string PrintedName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } + [Column(title: "Исполнитель", width: 150)] + public string? ImplementerFIO { get; set; } = string.Empty; + [Column(visible: false)] + public int PrintedId { get; set; } + [Column(title: "Изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; + [Column(title: "Количество", width: 100)] + public int Count { get; set; } + [Column(title: "Сумма", width: 100)] + public double Sum { get; set; } + [Column(title: "Статус", width: 150)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 120)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 120)] + public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs index bee3caa..8a40b44 100644 --- a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -1,17 +1,20 @@ using System.ComponentModel; using TypographyDataModels.Models; +using TypographyContracts.Attributes; namespace TypographyContracts.ViewModels { public class PrintedViewModel : IPrintedModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название изделия")] - public string PrintedName { get; set; } = string.Empty; + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string PrintedName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary PrintedComponents { get; set; } = new(); + [Column(title: "Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary PrintedComponents { get; set; } = new(); } } \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs index 7f95db3..11c9d8d 100644 --- a/Typography/TypographyDataModels/Models/IMessageInfoModel.cs +++ b/Typography/TypographyDataModels/Models/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace TypographyDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs b/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..aad27dd --- /dev/null +++ b/Typography/TypographyDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyDatabaseImplement.Implements; + +namespace TypographyDatabaseImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs b/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5749133 --- /dev/null +++ b/Typography/TypographyDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using TypographyContracts.StoragesContracts; + +namespace TypographyDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new TypographyDatabase(); + 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; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyDatabaseImplement/Models/Client.cs b/Typography/TypographyDatabaseImplement/Models/Client.cs index 09da7cf..42350cd 100644 --- a/Typography/TypographyDatabaseImplement/Models/Client.cs +++ b/Typography/TypographyDatabaseImplement/Models/Client.cs @@ -3,17 +3,24 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List ClientOrders { get; set; } = new(); diff --git a/Typography/TypographyDatabaseImplement/Models/Component.cs b/Typography/TypographyDatabaseImplement/Models/Component.cs index 6ef71a8..fbb008a 100644 --- a/Typography/TypographyDatabaseImplement/Models/Component.cs +++ b/Typography/TypographyDatabaseImplement/Models/Component.cs @@ -6,15 +6,20 @@ using System.Threading.Tasks; using TypographyDataModels.Models; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public string ComponentName { get; private set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List PrintedComponents { get; set; } = new(); diff --git a/Typography/TypographyDatabaseImplement/Models/Implementer.cs b/Typography/TypographyDatabaseImplement/Models/Implementer.cs index dc568aa..af577c0 100644 --- a/Typography/TypographyDatabaseImplement/Models/Implementer.cs +++ b/Typography/TypographyDatabaseImplement/Models/Implementer.cs @@ -3,19 +3,26 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string ImplementerFIO { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Password { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public int WorkExperience { get; set; } - [Required] + [DataMember] + [Required] public int Qualification { get; set; } [ForeignKey("ImplementerId")] public virtual List ImplementerOrders { get; set; } = new(); diff --git a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs index a21cc37..f6d87ea 100644 --- a/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs +++ b/Typography/TypographyDatabaseImplement/Models/MessageInfo.cs @@ -2,23 +2,42 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; +using System.ComponentModel.DataAnnotations.Schema; namespace TypographyDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] [Key] public string MessageId { get; private set; } = string.Empty; + + [DataMember] public int? ClientId { get; private set; } + public virtual Client? Client { get; private set; } + + [DataMember] [Required] public string SenderName { get; private set; } = string.Empty; + + [DataMember] [Required] public DateTime DateDelivery { get; private set; } + + [DataMember] [Required] public string Subject { get; private set; } = string.Empty; + + [DataMember] [Required] public string Body { get; private set; } = string.Empty; + + [NotMapped] + public int Id { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel? model) { if (model == null) diff --git a/Typography/TypographyDatabaseImplement/Models/Order.cs b/Typography/TypographyDatabaseImplement/Models/Order.cs index 6abe678..96c6faf 100644 --- a/Typography/TypographyDatabaseImplement/Models/Order.cs +++ b/Typography/TypographyDatabaseImplement/Models/Order.cs @@ -6,29 +6,40 @@ using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Enums; using TypographyDataModels.Models; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - [Required] + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] public int ClientId { get; private set; } public virtual Client Client { get; set; } = new(); - public int? ImplementerId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } = new(); - [Required] + [DataMember] + [Required] public int PrintedId { get; private set; } public virtual Printed Printed { get; set; } = new(); - [Required] + [DataMember] + [Required] public int Count { get; private set; } - [Required] + [DataMember] + [Required] public double Sum { get; private set; } - [Required] + [DataMember] + [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] + [DataMember] + [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model, TypographyDatabase context) { if (model == null) diff --git a/Typography/TypographyDatabaseImplement/Models/Printed.cs b/Typography/TypographyDatabaseImplement/Models/Printed.cs index 8a274c3..0cda023 100644 --- a/Typography/TypographyDatabaseImplement/Models/Printed.cs +++ b/Typography/TypographyDatabaseImplement/Models/Printed.cs @@ -6,15 +6,20 @@ using System.Threading.Tasks; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; set; } - [Required] + [DataMember] + public int Id { get; set; } + [DataMember] + [Required] public string PrintedName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public double Price { get; set; } private Dictionary? _printedComponents = null; [NotMapped] diff --git a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs index b3ed1e5..5261d96 100644 --- a/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs +++ b/Typography/TypographyDatabaseImplement/Models/PrintedComponent.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace TypographyDatabaseImplement.Models { diff --git a/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj b/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj index b9a9dc3..114d602 100644 --- a/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj +++ b/Typography/TypographyDatabaseImplement/TypographyDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Typography/TypographyFileImplement/FileImplementationExtension.cs b/Typography/TypographyFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..5847dcb --- /dev/null +++ b/Typography/TypographyFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyFileImplement.Implements; + +namespace TypographyFileImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Implements/BackUpInfo.cs b/Typography/TypographyFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..db6080c --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using TypographyContracts.StoragesContracts; + +namespace TypographyFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProps; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProps = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + return (List?)sourceProps + .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; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Client.cs b/Typography/TypographyFileImplement/Models/Client.cs index 400a7d6..7edceb8 100644 --- a/Typography/TypographyFileImplement/Models/Client.cs +++ b/Typography/TypographyFileImplement/Models/Client.cs @@ -3,15 +3,21 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; using System.Reflection; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string Email { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Component.cs b/Typography/TypographyFileImplement/Models/Component.cs index b1287d5..56f9ce3 100644 --- a/Typography/TypographyFileImplement/Models/Component.cs +++ b/Typography/TypographyFileImplement/Models/Component.cs @@ -2,14 +2,19 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } - public string ComponentName { get; private set; } = string.Empty; - public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Implementer.cs b/Typography/TypographyFileImplement/Models/Implementer.cs index 4cc6492..be5499c 100644 --- a/Typography/TypographyFileImplement/Models/Implementer.cs +++ b/Typography/TypographyFileImplement/Models/Implementer.cs @@ -3,16 +3,23 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; using System.Reflection; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public int Id { get; private set; } - public string ImplementerFIO { get; private set; } = string.Empty; - public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } - public int Qualification { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; + [DataMember] + public int WorkExperience { get; private set; } + [DataMember] + public int Qualification { get; private set; } public static Implementer? Create(ImplementerBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/MessageInfo.cs b/Typography/TypographyFileImplement/Models/MessageInfo.cs index 0952518..1f7b32c 100644 --- a/Typography/TypographyFileImplement/Models/MessageInfo.cs +++ b/Typography/TypographyFileImplement/Models/MessageInfo.cs @@ -2,17 +2,26 @@ using TypographyContracts.ViewModels; using TypographyDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] public string SenderName { get; private set; } = string.Empty; + [DataMember] public DateTime DateDelivery { get; private set; } + [DataMember] public string Subject { get; private set; } = string.Empty; + [DataMember] public string Body { get; private set; } = string.Empty; + public int Id { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Order.cs b/Typography/TypographyFileImplement/Models/Order.cs index 180c389..ef6ae55 100644 --- a/Typography/TypographyFileImplement/Models/Order.cs +++ b/Typography/TypographyFileImplement/Models/Order.cs @@ -8,20 +8,31 @@ using TypographyDataModels.Enums; using TypographyDataModels.Models; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } - public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } - public int PrintedId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int? ImplementerId { get; private set; } + [DataMember] + public int PrintedId { get; private set; } + [DataMember] + public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel model) { if (model == null) diff --git a/Typography/TypographyFileImplement/Models/Printed.cs b/Typography/TypographyFileImplement/Models/Printed.cs index 8932855..a7f2031 100644 --- a/Typography/TypographyFileImplement/Models/Printed.cs +++ b/Typography/TypographyFileImplement/Models/Printed.cs @@ -7,14 +7,19 @@ using System.Xml.Linq; using TypographyContracts.BindingModels; using TypographyContracts.ViewModels; using TypographyDataModels.Models; +using System.Runtime.Serialization; namespace TypographyFileImplement.Models { - public class Printed : IPrintedModel + [DataContract] + public class Printed : IPrintedModel { - public int Id { get; private set; } - public string PrintedName { get; private set; } = string.Empty; - public double Price { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string PrintedName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _productComponents = null; public Dictionary PrintedComponents diff --git a/Typography/TypographyFileImplement/TypographyFileImplement.csproj b/Typography/TypographyFileImplement/TypographyFileImplement.csproj index db73c6b..20a41b8 100644 --- a/Typography/TypographyFileImplement/TypographyFileImplement.csproj +++ b/Typography/TypographyFileImplement/TypographyFileImplement.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/Typography/TypographyListImplement/Implements/BackUpInfo.cs b/Typography/TypographyListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..ad9b87a --- /dev/null +++ b/Typography/TypographyListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,16 @@ +using TypographyContracts.StoragesContracts; + +namespace TypographyListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/ListImplementationExtension.cs b/Typography/TypographyListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..7b7355c --- /dev/null +++ b/Typography/TypographyListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using TypographyContracts.DI; +using TypographyContracts.StoragesContracts; +using TypographyListImplement.Implements; + +namespace TypographyListImplement +{ + 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(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Models/MessageInfo.cs b/Typography/TypographyListImplement/Models/MessageInfo.cs index 11d8ca9..2575f48 100644 --- a/Typography/TypographyListImplement/Models/MessageInfo.cs +++ b/Typography/TypographyListImplement/Models/MessageInfo.cs @@ -17,6 +17,7 @@ namespace TypographyListImplement.Models public DateTime DateDelivery { get; private set; } public string Subject { get; private set; } = string.Empty; public string Body { get; private set; } = string.Empty; + public int Id { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel? model) { if (model == null) diff --git a/Typography/TypographyListImplement/TypographyListImplement.csproj b/Typography/TypographyListImplement/TypographyListImplement.csproj index db73c6b..20a41b8 100644 --- a/Typography/TypographyListImplement/TypographyListImplement.csproj +++ b/Typography/TypographyListImplement/TypographyListImplement.csproj @@ -10,4 +10,8 @@ + + + +