2021-04-02 15:53:15 +04:00
|
|
|
|
using ModuleTools.BusinessLogics;
|
|
|
|
|
using ModuleTools.Enums;
|
2021-04-02 20:04:46 +04:00
|
|
|
|
using ModuleTools.Extensions;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.Interfaces;
|
|
|
|
|
using System;
|
2021-04-02 20:04:46 +04:00
|
|
|
|
using System.IO;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
|
|
|
|
|
namespace SecurityBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логика работы с бекапом
|
|
|
|
|
/// </summary>
|
2021-04-02 20:46:41 +04:00
|
|
|
|
public class BackupBusinessLogic : CoreBusinessLogic
|
2021-04-02 15:53:15 +04:00
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Серивс для работы с бекапом
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IBackupService _service;
|
2021-04-02 15:53:15 +04:00
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логика работы с бекапом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="service"></param>
|
2021-04-05 10:08:49 +04:00
|
|
|
|
public BackupBusinessLogic(IBackupService service)
|
|
|
|
|
{
|
|
|
|
|
_service = service;
|
|
|
|
|
_serviceOperation = AccessOperation.РаботасБекапом;
|
|
|
|
|
_entity = "Работа с Бекапом";
|
|
|
|
|
}
|
2021-04-02 15:53:15 +04:00
|
|
|
|
|
2021-04-02 20:04:46 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание бекапа с данными
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-04-02 15:53:15 +04:00
|
|
|
|
public bool CreateBackUp(BackupBindingModel model)
|
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
if (model.FolderName.IsEmpty())
|
2021-04-02 15:53:15 +04:00
|
|
|
|
{
|
2021-04-02 20:04:46 +04:00
|
|
|
|
Errors.Add(("Ошибка", "Путь до папки не указан"));
|
2021-04-02 15:53:15 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-02 20:04:46 +04:00
|
|
|
|
try
|
2021-04-02 15:53:15 +04:00
|
|
|
|
{
|
2021-04-05 10:08:49 +04:00
|
|
|
|
if (NoAccess(null, AccessType.Delete))
|
2021-04-02 20:04:46 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var result = _service.CreateBackUp(model);
|
|
|
|
|
if (!result.IsSucceeded)
|
|
|
|
|
{
|
|
|
|
|
Errors.AddRange(result.Errors);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка", ex.Message));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Восстанволение данных через бекап
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool RestoreBackUp(BackupBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.FolderName.IsEmpty() && model.ArchiveFileName.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка", "Путь до папки/архива не указан"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (model.ArchiveFileName.IsNotEmpty() && !File.Exists(model.ArchiveFileName))
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка", "Файл с архивом не найден"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (model.ArchiveFileName.IsEmpty() && !Directory.Exists(model.FolderName))
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка", "Папка с даными не найдена"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-05 10:08:49 +04:00
|
|
|
|
if (NoAccess(null, AccessType.Delete))
|
2021-04-02 20:04:46 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var result = _service.RestoreBackUp(model);
|
|
|
|
|
if (!result.IsSucceeded)
|
|
|
|
|
{
|
|
|
|
|
Errors.AddRange(result.Errors);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка", ex.Message));
|
2021-04-02 15:53:15 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|