diff --git a/.gitignore b/.gitignore index ca1c7a3..7ccc4e3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +ImplementationExtensions # Mono auto generated files mono_crash.* diff --git a/SushiBar/SushiBar/DataGridViewExtension.cs b/SushiBar/SushiBar/DataGridViewExtension.cs new file mode 100644 index 0000000..58f5aa1 --- /dev/null +++ b/SushiBar/SushiBar/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using SushiBarContracts.Attributes; + +namespace SushiBarView +{ + 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/SushiBar/SushiBar/FormClients.cs b/SushiBar/SushiBar/FormClients.cs index 4781843..0e25a27 100644 --- a/SushiBar/SushiBar/FormClients.cs +++ b/SushiBar/SushiBar/FormClients.cs @@ -26,13 +26,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormImplementers.cs b/SushiBar/SushiBar/FormImplementers.cs index a578d4b..1062f5a 100644 --- a/SushiBar/SushiBar/FormImplementers.cs +++ b/SushiBar/SushiBar/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -22,13 +23,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) @@ -40,7 +35,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { if (form.ShowDialog() == DialogResult.OK) @@ -53,7 +48,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementer form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 781205f..8294890 100644 --- a/SushiBar/SushiBar/FormIngredients.cs +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -22,13 +23,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка ингредиентов"); } catch (Exception ex) @@ -40,7 +35,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { if (form.ShowDialog() == DialogResult.OK) @@ -53,7 +48,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredient form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index d20376b..9b44467 100644 --- a/SushiBar/SushiBar/FormListSushi.cs +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -23,14 +24,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["SushiIngredients"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка суши"); } catch (Exception ex) @@ -42,7 +36,7 @@ namespace SushiBarView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { if (form.ShowDialog() == DialogResult.OK) @@ -56,7 +50,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushi form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/SushiBar/SushiBar/FormMails.cs b/SushiBar/SushiBar/FormMails.cs index 799addb..fe75477 100644 --- a/SushiBar/SushiBar/FormMails.cs +++ b/SushiBar/SushiBar/FormMails.cs @@ -19,14 +19,7 @@ namespace SushiBarView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 365940f..f9d8057 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -39,11 +39,12 @@ this.ингредиентыПоСушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.createBackUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -54,7 +55,8 @@ this.справочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.письмаToolStripMenuItem}); + this.письмаToolStripMenuItem, + this.createBackUpToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1086, 24); @@ -138,6 +140,20 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click); // + // письмаToolStripMenuItem + // + this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; + this.письмаToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.письмаToolStripMenuItem.Text = "Письма"; + this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); + // + // createBackUpToolStripMenuItem + // + this.createBackUpToolStripMenuItem.Name = "createBackUpToolStripMenuItem"; + this.createBackUpToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.createBackUpToolStripMenuItem.Text = "Создать бекап"; + this.createBackUpToolStripMenuItem.Click += new System.EventHandler(this.CreateBackUpToolStripMenuItem_Click); + // // buttonUpdate // this.buttonUpdate.Location = new System.Drawing.Point(905, 253); @@ -183,13 +199,6 @@ this.dataGridView.Size = new System.Drawing.Size(899, 426); this.dataGridView.TabIndex = 7; // - // письмаToolStripMenuItem - // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(62, 20); - this.письмаToolStripMenuItem.Text = "Письма"; - this.письмаToolStripMenuItem.Click += new System.EventHandler(this.MailsToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -230,5 +239,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem письмаToolStripMenuItem; + private ToolStripMenuItem createBackUpToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 2497490..ab6b906 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; namespace SushiBarView { @@ -10,13 +11,15 @@ namespace SushiBarView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + 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) { @@ -27,17 +30,7 @@ namespace SushiBarView _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SushiId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -48,7 +41,7 @@ namespace SushiBarView } private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormIngredients form) { form.ShowDialog(); @@ -56,7 +49,7 @@ namespace SushiBarView } private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormListSushi)); + var service = DependencyManager.Instance.Resolve(); if (service is FormListSushi form) { form.ShowDialog(); @@ -64,7 +57,7 @@ namespace SushiBarView } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = DependencyManager.Instance.Resolve(); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -163,7 +156,7 @@ namespace SushiBarView private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportSushiIngredients form) { form.ShowDialog(); @@ -172,7 +165,7 @@ namespace SushiBarView private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + var service = DependencyManager.Instance.Resolve(); if (service is FormReportOrders form) { form.ShowDialog(); @@ -181,7 +174,7 @@ namespace SushiBarView private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormClients form) { form.ShowDialog(); @@ -190,7 +183,7 @@ namespace SushiBarView private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + var service = DependencyManager.Instance.Resolve(); if (service is FormImplementers form) { form.ShowDialog(); @@ -200,7 +193,7 @@ namespace SushiBarView private void DoWorkToolStripMenuItem_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); @@ -208,11 +201,36 @@ namespace SushiBarView private void MailsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + var service = DependencyManager.Instance.Resolve(); if (service is FormMails form) { form.ShowDialog(); } } + + 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/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 515011f..9cc303e 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.DI; using SushiBarContracts.SearchModels; using SushiBarDataModels.Models; @@ -70,7 +71,7 @@ namespace SushiBarView } private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiIngredients form) { if (form.ShowDialog() == DialogResult.OK) @@ -96,7 +97,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + var service = DependencyManager.Instance.Resolve(); if (service is FormSushiIngredients form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 79f031c..8405ac9 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -9,29 +9,26 @@ using SushiBarContracts.StoragesContracts; using SushiBarDatabaseImplement.Implements; using SushiBarBusinessLogic.MailWorker; using SushiBarContracts.BindingModels; +using SushiBarContracts.DI; namespace SushiBarView { 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, + // To customize application configuration such as set high DPIsettings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); + InitDependency(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,56 +44,53 @@ namespace SushiBarView } 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) + Application.Run(DependencyManager.Instance.Resolve()); + } + 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(); } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..3d0cd11 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,98 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushiBarDataModels; +using Microsoft.Extensions.Logging; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace SushiBarBusinessLogic.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/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..6f9c44b --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..abe4f32 --- /dev/null +++ b/SushiBar/SushiBarContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,21 @@ +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..fe2ca2d --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace SushiBarContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs index 453ceb5..23e2789 100644 --- a/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ namespace SushiBarContracts.BindingModels public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } + + public int Id => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..91ae4a0 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using SushiBarContracts.BindingModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/DependencyManager.cs b/SushiBar/SushiBarContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..b791e60 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/DependencyManager.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..7421027 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..7973eab --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/IImplementationExtension.cs @@ -0,0 +1,11 @@ +namespace SushiBarContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..9ffd5f2 --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace SushiBarContracts.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/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..8c1e02f --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,50 @@ +using System.Reflection; + +namespace SushiBarContracts.DI +{ + public 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; + } + + 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/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..9b971ee --- /dev/null +++ b/SushiBar/SushiBarContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.Logging; +using Unity; +using Unity.Microsoft.Logging; + +namespace SushiBarContracts.DI +{ + 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/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..7e18631 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace SushiBarContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj index 3794008..b943900 100644 --- a/SushiBar/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -14,6 +14,8 @@ + + diff --git a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs index ca155f5..af0be8c 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ClientViewModel.cs @@ -1,19 +1,20 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class ClientViewModel : IClientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Клиент")] + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column(title: "Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs index 943aa6d..66f6537 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using SushiBarDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using System.ComponentModel; namespace SushiBarContracts.ViewModels @@ -8,18 +9,19 @@ namespace SushiBarContracts.ViewModels /// public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", width: 50)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 50)] public int Qualification { get; set; } } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs index eada9d4..1f3da5c 100644 --- a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs @@ -1,14 +1,15 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.ViewModels { public class IngredientViewModel : IIngredientModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название ингредиента")] + [Column(title: "Ингредиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string IngredientName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } diff --git a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs index ba77305..9ce1768 100644 --- a/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,29 @@ -using SushiBarDataModels.Models; -using System.ComponentModel; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; namespace SushiBarContracts.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: 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 => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index c22a7a9..14d3cd8 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -1,31 +1,34 @@ -using SushiBarDataModels.Enums; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Enums; using SushiBarDataModels.Models; -using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 50)] public int Id { get; set; } + [Column(visible: false)] public int SushiId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Суши")] + [Column(title: "Суши", width: 100)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(title: "Клиент", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Исполнитель", width: 130)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 50)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 50)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs index 12c51a0..9863d16 100644 --- a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -1,15 +1,18 @@ -using SushiBarDataModels.Models; +using SushiBarContracts.Attributes; +using SushiBarDataModels.Models; using System.ComponentModel; namespace SushiBarContracts.ViewModels { public class SushiViewModel : ISushiModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column(title: "Суши", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string SushiName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Price { get; set; } + [Column(visible: false)] public Dictionary SushiIngredients { get; diff --git a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs index 0443646..13a8eeb 100644 --- a/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ namespace SushiBarDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } diff --git a/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs b/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..6bc0a58 --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarDatabaseImplement.Implements; + +namespace SushiBarDatabaseImplement +{ + 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/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..c9ed4db --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SushiBarDatabase(); + 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/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index 28ee46e..49fc9b8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -3,16 +3,22 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] - public string ClientFIO { get; set; } = string.Empty; + public string ClientFIO { get; set; } = string.Empty; + [DataMember] [Required] - public string Email { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs index b63d057..4392901 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Implementer.cs @@ -3,18 +3,25 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; private set; } = string.Empty; + [DataMember] [Required] public int WorkExperience { get; private set; } + [DataMember] [Required] public int Qualification { get; private set; } [ForeignKey("ImplementerId")] diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs index 37d313f..f6cfb41 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs @@ -3,19 +3,21 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } - + [DataMember] [Required] public string IngredientName { get; private set; } = string.Empty; - + [DataMember] [Required] public double Cost { get; set; } - [ForeignKey("IngredientId")] public virtual List SushiIngredients { get; set; } = new(); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs index f6b7173..f574d8e 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Message.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Message.cs @@ -2,20 +2,28 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Message : IMessageInfoModel { + [DataMember] [Key] - public string MessageId { get; private set; } = string.Empty; + public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] [Required] public string SenderName { get; private set; } = string.Empty; + [DataMember] [Required] public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] [Required] public string Subject { get; private set; } = string.Empty; + [DataMember] [Required] public string Body { get; private set; } = string.Empty; @@ -45,5 +53,7 @@ namespace SushiBarDatabaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; + + public int Id => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index f15634f..1bba7c8 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -3,25 +3,36 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] [Required] public int SushiId { get; set; } + [DataMember] [Required] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] [Required] public int Count { get; set; } + [DataMember] [Required] public double Sum { get; set; } + [DataMember] [Required] public OrderStatus Status { get; set; } + [DataMember] [Required] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } + [DataMember] public int Id { get; set; } public Sushi Sushi { get; set; } public Client Client { get; set; } diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs index 009329f..e195fdc 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs @@ -3,21 +3,24 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SushiBarDatabaseImplement.Models { + [DataContract] public class Sushi : ISushiModel { + [DataMember] public int Id { get; set; } - + [DataMember] [Required] public string SushiName { get; set; } = string.Empty; - + [DataMember] [Required] public double Price { get; set; } private Dictionary? _sushiIngredients = null; - + [DataMember] [NotMapped] public Dictionary SushiIngredients { diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj index 1211e5e..b04acdd 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..2bcad25 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarFileImplement.Implements; + +namespace SushiBarFileImplement +{ + 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/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..248c84b --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,29 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarFileImplement.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/SushiBar/SushiBarFileImplement/Models/Client.cs b/SushiBar/SushiBarFileImplement/Models/Client.cs index feb71c4..2da6c39 100644 --- a/SushiBar/SushiBarFileImplement/Models/Client.cs +++ b/SushiBar/SushiBarFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; + [DataMember] + public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/SushiBar/SushiBarFileImplement/Models/Implementer.cs b/SushiBar/SushiBarFileImplement/Models/Implementer.cs index 0537bcd..648f80c 100644 --- a/SushiBar/SushiBarFileImplement/Models/Implementer.cs +++ b/SushiBar/SushiBarFileImplement/Models/Implementer.cs @@ -1,20 +1,23 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [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) diff --git a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs index d940c5a..5079484 100644 --- a/SushiBar/SushiBarFileImplement/Models/Ingredient.cs +++ b/SushiBar/SushiBarFileImplement/Models/Ingredient.cs @@ -1,14 +1,19 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Ingredient : IIngredientModel { + [DataMember] public int Id { get; private set; } - public string IngredientName { get; private set; } = string.Empty; + [DataMember] + public string IngredientName { get; private set; } = string.Empty; + [DataMember] public double Cost { get; set; } public static Ingredient? Create(IngredientBindingModel model) { diff --git a/SushiBar/SushiBarFileImplement/Models/Message.cs b/SushiBar/SushiBarFileImplement/Models/Message.cs index 2fdb025..ee7437d 100644 --- a/SushiBar/SushiBarFileImplement/Models/Message.cs +++ b/SushiBar/SushiBarFileImplement/Models/Message.cs @@ -2,22 +2,25 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; using System.Reflection; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Message : 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; } = DateTime.Now; - + [DataMember] public string Subject { get; private set; } = string.Empty; - + [DataMember] public string Body { get; private set; } = string.Empty; public static Message? Create(MessageInfoBindingModel model) @@ -72,5 +75,7 @@ namespace SushiBarFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); + + public int Id => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index a52d7fa..36160e1 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -2,20 +2,31 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] public int SushiId { get; private set; } + [DataMember] public int Count { get; private set; } + [DataMember] public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; + [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) { diff --git a/SushiBar/SushiBarFileImplement/Models/Sushi.cs b/SushiBar/SushiBarFileImplement/Models/Sushi.cs index ec3518c..f2497ce 100644 --- a/SushiBar/SushiBarFileImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -1,17 +1,23 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SushiBarFileImplement.Models { + [DataContract] public class Sushi : ISushiModel { + [DataMember] public int Id { get; private set; } - public string SushiName { get; private set; } = string.Empty; + [DataMember] + public string SushiName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Ingredients { get; private set; } = new(); private Dictionary? _sushiIngredients = null; + [DataMember] public Dictionary SushiIngredients { get diff --git a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj index 428ac20..7e4bebe 100644 --- a/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj +++ b/SushiBar/SushiBarFileImplement/SushiBarFileImplement.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..93f3057 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.StoragesContracts; + +namespace SushiBarListImplement.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/SushiBar/SushiBarListImplement/ListImplementationExtension.cs b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..c737e3e --- /dev/null +++ b/SushiBar/SushiBarListImplement/ListImplementationExtension.cs @@ -0,0 +1,22 @@ +using SushiBarContracts.DI; +using SushiBarContracts.StoragesContracts; +using SushiBarListImplement.Implements; + +namespace SushiBarListImplement +{ + 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/SushiBar/SushiBarListImplement/Models/Message.cs b/SushiBar/SushiBarListImplement/Models/Message.cs index e6a08d4..185f1e9 100644 --- a/SushiBar/SushiBarListImplement/Models/Message.cs +++ b/SushiBar/SushiBarListImplement/Models/Message.cs @@ -44,5 +44,7 @@ namespace SushiBarListImplement.Models ClientId = ClientId, MessageId = MessageId }; + + public int Id => throw new NotImplementedException(); } } diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj index 6a2b0ac..d77cc96 100644 --- a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -21,4 +21,8 @@ + + + +