using SecurityContract.Logics;
using System;
using System.Windows.Forms;
using System.Xml.Linq;
using ToolsDesktop.Helpers;
using ToolsDesktop.Interfaces;
using ToolsDesktop.Models;
using ToolsModule.ManagmentDependency;
using ToolsModule.ManagmentSecurity;
namespace SecurityWindowsDesktop.SpecialControls
{
///
/// Контрол для работы с синхронизацией
///
public partial class SynchronizationControl : UserControl, IControl
{
///
/// Класс с бизнес-логикой работы с синхронизацией
///
private readonly ISynchronizationLogic _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;
}
}
}