diff --git a/DepartmentPortal/Common/ModuleTools/BusinessLogics/CoreBusinessLogic.cs b/DepartmentPortal/Common/ModuleTools/BusinessLogics/CoreBusinessLogic.cs
new file mode 100644
index 0000000..8080e8b
--- /dev/null
+++ b/DepartmentPortal/Common/ModuleTools/BusinessLogics/CoreBusinessLogic.cs
@@ -0,0 +1,31 @@
+using ModuleTools.Interfaces;
+using System.Collections.Generic;
+
+namespace ModuleTools.BusinessLogics
+{
+ ///
+ /// Основа всех бизнес-логик
+ ///
+ public class CoreBusinessLogic
+ {
+ ///
+ /// Менеджер безопасности
+ ///
+ protected readonly ISecurityManager _security;
+
+ ///
+ /// Перечень ошибок при выполнении операции
+ ///
+ public List<(string Title, string Message)> Errors { get; protected set; }
+
+ ///
+ /// Основа всех бизнес-логик
+ ///
+ ///
+ public CoreBusinessLogic()
+ {
+ _security = DependencyManager.Instance.Resolve();
+ Errors = new();
+ }
+ }
+}
\ No newline at end of file
diff --git a/DepartmentPortal/Common/ModuleTools/BusinessLogics/GenericBusinessLogic.cs b/DepartmentPortal/Common/ModuleTools/BusinessLogics/GenericBusinessLogic.cs
index 39f72b4..5bea787 100644
--- a/DepartmentPortal/Common/ModuleTools/BusinessLogics/GenericBusinessLogic.cs
+++ b/DepartmentPortal/Common/ModuleTools/BusinessLogics/GenericBusinessLogic.cs
@@ -4,7 +4,6 @@ using ModuleTools.Interfaces;
using ModuleTools.Models;
using ModuleTools.ViewModels;
using System;
-using System.Collections.Generic;
namespace ModuleTools.BusinessLogics
{
@@ -15,27 +14,17 @@ namespace ModuleTools.BusinessLogics
///
///
///
- public class GenericBusinessLogic
+ public class GenericBusinessLogic : CoreBusinessLogic
where G : GetBindingModel
where S : SetBindingModel
where L : ListViewModel
where E : ElementViewModel
{
- ///
- /// Перечень ошибок при выполнении операции
- ///
- public List<(string Title, string Message)> Errors { get; protected set; }
-
///
/// Сервис с хранилищем данных
///
protected IGenerticEntityService Service { get; set; }
- ///
- /// Менеджер безопасности
- ///
- protected ISecurityManager Security { get; set; }
-
///
/// Тип операции, скоторым работает логика
///
@@ -54,8 +43,6 @@ namespace ModuleTools.BusinessLogics
public GenericBusinessLogic(IGenerticEntityService service, string entity, AccessOperation serviceOperation)
{
Service = service;
- Errors = new List<(string Title, string Message)>();
- Security = DependencyManager.Instance.Resolve();
_entity = entity;
_serviceOperation = serviceOperation;
}
@@ -68,11 +55,11 @@ namespace ModuleTools.BusinessLogics
///
protected bool NoAccess(AccessBindingModel model, AccessType type)
{
- if (Security.CheckAccess(new SecurityManagerCheckAccessModel(model, _serviceOperation, type, _entity)))
+ if (_security.CheckAccess(new SecurityManagerCheckAccessModel(model, _serviceOperation, type, _entity)))
{
return false;
}
- Errors.Add(("Ошибка безопасности", Security.ErrorMessage));
+ Errors.Add(("Ошибка безопасности", _security.ErrorMessage));
return true;
}
diff --git a/DepartmentPortal/Common/ModuleTools/Enums/AccessOperation.cs b/DepartmentPortal/Common/ModuleTools/Enums/AccessOperation.cs
index f49ffcb..407ea76 100644
--- a/DepartmentPortal/Common/ModuleTools/Enums/AccessOperation.cs
+++ b/DepartmentPortal/Common/ModuleTools/Enums/AccessOperation.cs
@@ -19,6 +19,8 @@
ПользователиРоли = 5,
РаботасБекапом = 10,
+
+ Синхронизация = 11,
#endregion
#region База
diff --git a/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/BackupBusinessLogic.cs b/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/BackupBusinessLogic.cs
index 916bc94..f6a0fc5 100644
--- a/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/BackupBusinessLogic.cs
+++ b/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/BackupBusinessLogic.cs
@@ -1,12 +1,10 @@
using ModuleTools.BusinessLogics;
using ModuleTools.Enums;
using ModuleTools.Extensions;
-using ModuleTools.Interfaces;
using ModuleTools.Models;
using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.Interfaces;
using System;
-using System.Collections.Generic;
using System.IO;
namespace SecurityBusinessLogic.BusinessLogics
@@ -14,33 +12,18 @@ namespace SecurityBusinessLogic.BusinessLogics
///
/// Логика работы с бекапом
///
- public class BackupBusinessLogic
+ public class BackupBusinessLogic : CoreBusinessLogic
{
///
/// Серивс для работы с бекапом
///
private readonly IBackupService _service;
- ///
- /// Менеджер безопасности
- ///
- private readonly ISecurityManager _security;
-
- ///
- /// Перечень ошибок при выполнении операции
- ///
- public List<(string Title, string Message)> Errors { get; protected set; }
-
///
/// Логика работы с бекапом
///
///
- public BackupBusinessLogic(IBackupService service)
- {
- _service = service;
- _security = DependencyManager.Instance.Resolve();
- Errors = new();
- }
+ public BackupBusinessLogic(IBackupService service) => _service = service;
///
/// Создание бекапа с данными
diff --git a/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/SynchronizationBusinessLogic.cs b/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/SynchronizationBusinessLogic.cs
new file mode 100644
index 0000000..977618e
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/SynchronizationBusinessLogic.cs
@@ -0,0 +1,67 @@
+using ModuleTools.BusinessLogics;
+using ModuleTools.Enums;
+using ModuleTools.Models;
+using SecurityBusinessLogic.Interfaces;
+using System;
+
+namespace SecurityBusinessLogic.BusinessLogics
+{
+ ///
+ /// Логика синхронизации пользователей
+ ///
+ public class SynchronizationBusinessLogic : CoreBusinessLogic
+ {
+ ///
+ /// Серивс для работы с бекапом
+ ///
+ private readonly ISynchronizationService _service;
+
+ ///
+ /// Логика работы с бекапом
+ ///
+ ///
+ public SynchronizationBusinessLogic(ISynchronizationService service) => _service = service;
+
+ ///
+ /// Запуск синхронизации
+ ///
+ ///
+ ///
+ public bool RunSynchronization()
+ {
+ try
+ {
+ if (NoAccess())
+ {
+ return false;
+ }
+ var result = _service.RunSynchronization();
+ if (!result.IsSucceeded)
+ {
+ Errors.AddRange(result.Errors);
+ return false;
+ }
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Errors.Add(("Ошибка", ex.Message));
+ return false;
+ }
+ }
+
+ ///
+ /// Проверка доступности операции для пользователя
+ ///
+ ///
+ private bool NoAccess()
+ {
+ if (_security.CheckAccess(new SecurityManagerCheckAccessModel(null, AccessOperation.Синхронизация, AccessType.Delete, "Синхронизация")))
+ {
+ return false;
+ }
+ Errors.Add(("Ошибка безопасности", _security.ErrorMessage));
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityBusinessLogic/Interfaces/ISynchronizationService.cs b/DepartmentPortal/Security/SecurityBusinessLogic/Interfaces/ISynchronizationService.cs
new file mode 100644
index 0000000..6dd23e2
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityBusinessLogic/Interfaces/ISynchronizationService.cs
@@ -0,0 +1,17 @@
+using ModuleTools.Models;
+
+namespace SecurityBusinessLogic.Interfaces
+{
+ ///
+ /// Синхронизация пользователей (преподаватели, сотрудники, студенты)
+ ///
+ public interface ISynchronizationService
+ {
+ ///
+ /// Синхронизация
+ ///
+ ///
+ ///
+ OperationResultModel RunSynchronization();
+ }
+}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/SynchronizationService.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/SynchronizationService.cs
new file mode 100644
index 0000000..7cb9717
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/SynchronizationService.cs
@@ -0,0 +1,17 @@
+using ModuleTools.Models;
+using SecurityBusinessLogic.Interfaces;
+
+namespace SecurityDatabaseImplementation.Implementations
+{
+ ///
+ /// Реализация ISynchronizationService
+ ///
+ public class SynchronizationService : ISynchronizationService
+ {
+ public OperationResultModel RunSynchronization()
+ {
+ // пока нечего синхронизировать
+ return OperationResultModel.Success(null);
+ }
+ }
+}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/SecurityImplementationExtensions.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/SecurityImplementationExtensions.cs
index dbb1deb..d4a4eb3 100644
--- a/DepartmentPortal/Security/SecurityDatabaseImplementation/SecurityImplementationExtensions.cs
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/SecurityImplementationExtensions.cs
@@ -16,6 +16,7 @@ namespace SecurityDatabaseImplementation
DependencyManager.Instance.RegisterType();
DependencyManager.Instance.RegisterType();
+ DependencyManager.Instance.RegisterType();
}
}
}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SecurityWindowDesktopExtension.cs b/DepartmentPortal/Security/SecurityWindowsDesktop/SecurityWindowDesktopExtension.cs
index f4dc9e2..7207913 100644
--- a/DepartmentPortal/Security/SecurityWindowsDesktop/SecurityWindowDesktopExtension.cs
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SecurityWindowDesktopExtension.cs
@@ -76,7 +76,8 @@ namespace SecurityWindowsDesktop
};
List _controls = new()
{
- new BackupControl()
+ new BackupControl(),
+ new SynchronizationControl()
};
foreach (var cntrl in _controls)
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.Designer.cs b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.Designer.cs
index 5074b61..c762c45 100644
--- a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.Designer.cs
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.Designer.cs
@@ -131,7 +131,6 @@ namespace SecurityWindowsDesktop.SpecialControls
this.toolStripHeader.Size = new System.Drawing.Size(708, 25);
this.toolStripHeader.TabIndex = 1;
this.toolStripHeader.Text = "toolStrip1";
- this.toolStripHeader.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ToolStripHeader_ItemClicked);
//
// toolStripButtonClose
//
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.cs b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.cs
index 7717bf1..60395bd 100644
--- a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.cs
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/BackupControl.cs
@@ -17,7 +17,7 @@ namespace SecurityWindowsDesktop.SpecialControls
public partial class BackupControl : UserControl, IControl
{
///
- /// Класс с бизнес-лоникой работы с бекапом
+ /// Класс с бизнес-логикой работы с бекапом
///
private readonly BackupBusinessLogic _businessLogic;
@@ -36,6 +36,11 @@ namespace SecurityWindowsDesktop.SpecialControls
Title = "Работа с бекапом";
ControlId = new Guid("cc9844e6-5d92-4c89-b817-4c17ec382bc1");
AccessOperation = AccessOperation.РаботасБекапом;
+ toolStripButtonClose.Click += (object sender, EventArgs e) =>
+ {
+ CloseEvent?.Invoke(ControlId);
+ Dispose();
+ };
}
#region IControl
@@ -71,17 +76,6 @@ namespace SecurityWindowsDesktop.SpecialControls
}
#endregion
- ///
- /// Закрытие контрола
- ///
- ///
- ///
- private void ToolStripHeader_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- CloseEvent?.Invoke(ControlId);
- Dispose();
- }
-
///
/// Выбор пути для папки сохранения бекапа
///
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.Designer.cs b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.Designer.cs
new file mode 100644
index 0000000..f97f337
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.Designer.cs
@@ -0,0 +1,89 @@
+
+namespace SecurityWindowsDesktop.SpecialControls
+{
+ partial class SynchronizationControl
+ {
+ ///
+ /// Обязательная переменная конструктора.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Освободить все используемые ресурсы.
+ ///
+ /// истинно, если управляемый ресурс должен быть удален; иначе ложно.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Код, автоматически созданный конструктором компонентов
+
+ ///
+ /// Требуемый метод для поддержки конструктора — не изменяйте
+ /// содержимое этого метода с помощью редактора кода.
+ ///
+ private void InitializeComponent()
+ {
+ this.toolStripHeader = new System.Windows.Forms.ToolStrip();
+ this.toolStripButtonClose = new System.Windows.Forms.ToolStripButton();
+ this.buttonRunSynchronization = new System.Windows.Forms.Button();
+ this.toolStripHeader.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // toolStripHeader
+ //
+ this.toolStripHeader.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripButtonClose});
+ this.toolStripHeader.Location = new System.Drawing.Point(0, 0);
+ this.toolStripHeader.Name = "toolStripHeader";
+ this.toolStripHeader.Size = new System.Drawing.Size(647, 25);
+ this.toolStripHeader.TabIndex = 0;
+ this.toolStripHeader.Text = "toolStrip1";
+ //
+ // toolStripButtonClose
+ //
+ this.toolStripButtonClose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.toolStripButtonClose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButtonClose.Image = global::SecurityWindowsDesktop.Properties.Resources.Close;
+ this.toolStripButtonClose.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonClose.Name = "toolStripButtonClose";
+ this.toolStripButtonClose.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButtonClose.Text = "Закрыть";
+ //
+ // buttonRunSynchronization
+ //
+ this.buttonRunSynchronization.Location = new System.Drawing.Point(124, 59);
+ this.buttonRunSynchronization.Name = "buttonRunSynchronization";
+ this.buttonRunSynchronization.Size = new System.Drawing.Size(375, 151);
+ this.buttonRunSynchronization.TabIndex = 1;
+ this.buttonRunSynchronization.Text = "Сделай за**ись";
+ this.buttonRunSynchronization.UseVisualStyleBackColor = true;
+ this.buttonRunSynchronization.Click += new System.EventHandler(this.ButtonRunSynchronization_Click);
+ //
+ // SynchronizationControl
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.buttonRunSynchronization);
+ this.Controls.Add(this.toolStripHeader);
+ this.Name = "SynchronizationControl";
+ this.Size = new System.Drawing.Size(647, 508);
+ this.toolStripHeader.ResumeLayout(false);
+ this.toolStripHeader.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ToolStrip toolStripHeader;
+ private System.Windows.Forms.ToolStripButton toolStripButtonClose;
+ private System.Windows.Forms.Button buttonRunSynchronization;
+ }
+}
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.cs b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.cs
new file mode 100644
index 0000000..4e8562f
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.cs
@@ -0,0 +1,98 @@
+using DesktopTools.Helpers;
+using DesktopTools.Interfaces;
+using DesktopTools.Models;
+using ModuleTools.BusinessLogics;
+using ModuleTools.Enums;
+using SecurityBusinessLogic.BusinessLogics;
+using System;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace SecurityWindowsDesktop.SpecialControls
+{
+ ///
+ /// Контрол для работы с синхронизацией
+ ///
+ public partial class SynchronizationControl : UserControl, IControl
+ {
+ ///
+ /// Класс с бизнес-логикой работы с синхронизацией
+ ///
+ private readonly SynchronizationBusinessLogic _businessLogic;
+
+ ///
+ /// Событие, вызываемое при закрытии контрола
+ ///
+ private event Action CloseEvent;
+
+ ///
+ /// Контрол для работы с синхронизацией
+ ///
+ public SynchronizationControl()
+ {
+ InitializeComponent();
+ _businessLogic = DependencyManager.Instance.Resolve();
+ Title = "Синхронизация";
+ ControlId = new Guid("c392818b-9036-4c4b-8a57-8ff935115e6a");
+ AccessOperation = AccessOperation.Синхронизация;
+ toolStripButtonClose.Click += (object sender, EventArgs e) =>
+ {
+ CloseEvent?.Invoke(ControlId);
+ Dispose();
+ };
+ }
+
+ #region IControl
+ public Guid ControlId { get; private set; }
+
+ public string Title { get; private set; }
+
+ public AccessOperation AccessOperation { get; private set; }
+
+ public IControl GetInstance() => new SynchronizationControl() { ControlId = Guid.NewGuid() };
+
+ public void Open(ControlOpenModel model)
+ {
+ if (model.CloseList != null)
+ {
+ CloseEvent += model.CloseList;
+ }
+ Dock = DockStyle.Fill;
+ }
+
+ public string SaveToXml() => new XElement("Control",
+ new XAttribute("Type", GetType().FullName),
+ new XAttribute("ControlId", ControlId),
+ new XAttribute("Title", Title),
+ new XAttribute("AccessOperation", AccessOperation)).ToString();
+
+ public void LoadFromXml(string xml)
+ {
+ var control = XElement.Parse(xml);
+ ControlId = new Guid(control.Attribute("ControlId").Value.ToString());
+ Title = control.Attribute("Title").Value.ToString();
+ AccessOperation = (AccessOperation)Enum.Parse(typeof(AccessOperation), control.Attribute("AccessOperation").Value.ToString());
+ }
+ #endregion
+
+ ///
+ /// Запуск синхронизации
+ ///
+ ///
+ ///
+ private void ButtonRunSynchronization_Click(object sender, EventArgs e)
+ {
+ var cursor = Cursor.Current;
+ Cursor.Current = Cursors.WaitCursor;
+ if (_businessLogic.RunSynchronization())
+ {
+ DialogHelper.MessageInformation("Синхронизация прошла успешно", "Результат");
+ }
+ else
+ {
+ DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при синхронизации");
+ }
+ Cursor.Current = cursor;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.resx b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/DepartmentPortal/Security/SecurityWindowsDesktop/SpecialControls/SynchronizationControl.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file