2022-03-18 22:48:14 +04:00
|
|
|
|
using ToolsDesktop.Helpers;
|
|
|
|
|
using ToolsDesktop.Interfaces;
|
|
|
|
|
using ToolsDesktop.Models;
|
2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.BusinessLogics;
|
|
|
|
|
using ToolsModule.Enums;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.BusinessLogics;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2021-04-02 20:04:46 +04:00
|
|
|
|
using System.Xml.Linq;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
|
|
|
|
|
namespace SecurityWindowsDesktop.SpecialControls
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контрол для работы с бекапом
|
|
|
|
|
/// </summary>
|
2021-04-02 15:53:15 +04:00
|
|
|
|
public partial class BackupControl : UserControl, IControl
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
2021-04-02 20:46:41 +04:00
|
|
|
|
/// Класс с бизнес-логикой работы с бекапом
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// </summary>
|
2021-04-02 15:53:15 +04:00
|
|
|
|
private readonly BackupBusinessLogic _businessLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Событие, вызываемое при закрытии контрола
|
|
|
|
|
/// </summary>
|
|
|
|
|
private event Action<Guid> CloseEvent;
|
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контрол для работы с бекапом
|
|
|
|
|
/// </summary>
|
2021-04-02 15:53:15 +04:00
|
|
|
|
public BackupControl()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_businessLogic = DependencyManager.Instance.Resolve<BackupBusinessLogic>();
|
|
|
|
|
Title = "Работа с бекапом";
|
|
|
|
|
ControlId = new Guid("cc9844e6-5d92-4c89-b817-4c17ec382bc1");
|
|
|
|
|
AccessOperation = AccessOperation.РаботасБекапом;
|
2021-04-02 20:46:41 +04:00
|
|
|
|
toolStripButtonClose.Click += (object sender, EventArgs e) =>
|
|
|
|
|
{
|
|
|
|
|
CloseEvent?.Invoke(ControlId);
|
|
|
|
|
Dispose();
|
|
|
|
|
};
|
2021-04-02 15:53:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
#region IControl
|
2021-04-02 15:53:15 +04:00
|
|
|
|
public Guid ControlId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public string Title { get; private set; }
|
|
|
|
|
|
|
|
|
|
public AccessOperation AccessOperation { get; private set; }
|
|
|
|
|
|
|
|
|
|
public IControl GetInstance() => new BackupControl() { ControlId = Guid.NewGuid() };
|
|
|
|
|
|
|
|
|
|
public void Open(ControlOpenModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.CloseList != null)
|
|
|
|
|
{
|
|
|
|
|
CloseEvent += model.CloseList;
|
|
|
|
|
}
|
|
|
|
|
Dock = DockStyle.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор пути для папки сохранения бекапа
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonSaveSelectFolder_Click(object sender, EventArgs e)
|
2021-04-02 15:53:15 +04:00
|
|
|
|
{
|
|
|
|
|
var fbd = new FolderBrowserDialog();
|
|
|
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
textBoxSaveFolderName.Text = fbd.SelectedPath;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание бекапа
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2021-04-02 15:53:15 +04:00
|
|
|
|
private void ButtonCreateBackup_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
var cursor = Cursor.Current;
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
if (_businessLogic.CreateBackUp(new BackupBindingModel
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
FolderName = textBoxSaveFolderName.Text,
|
2021-04-02 15:53:15 +04:00
|
|
|
|
FullData = checkBoxFullLoad.Checked,
|
|
|
|
|
CreateArchive = checkBoxCreateArchive.Checked
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageInformation("Сохранение прошло успешно", "Результат");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при сохранении");
|
|
|
|
|
}
|
2021-04-02 20:04:46 +04:00
|
|
|
|
Cursor.Current = cursor;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор пути для папки восстановления бекапа
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonLoadSelectFolder_Click(object sender, EventArgs e)
|
2021-04-02 15:53:15 +04:00
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
var fbd = new FolderBrowserDialog();
|
|
|
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
textBoxLoadFolderName.Text = fbd.SelectedPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор пути для файла-архива с бекапом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonLoadArchiveSelect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
textBoxLoadArchiveName.Text = ofd.FileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Восстановление
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRestoreBackup_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var cursor = Cursor.Current;
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
if (_businessLogic.RestoreBackUp(new BackupBindingModel
|
|
|
|
|
{
|
|
|
|
|
FolderName = textBoxLoadFolderName.Text,
|
|
|
|
|
ArchiveFileName = textBoxLoadArchiveName.Text
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageInformation("Сохранение прошло успешно", "Результат");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при сохранении");
|
|
|
|
|
}
|
|
|
|
|
Cursor.Current = cursor;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|