Files
hcs/Hcs.WebApp/Data/Hcs/Campaign.cs

66 lines
1.8 KiB
C#

using Hcs.WebApp.Data.Hcs.CampaignArgs;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Hcs.WebApp.Data.Hcs
{
public class Campaign
{
public enum CampaignType
{
[Display(Description = "Экспорт общих справочников")]
ExportCommonRegistryElements_15_7_0_1,
[Display(Description = "Экспорт частных справочников")]
ExportPrivateRegistryElements_15_7_0_1,
[Display(Description = "Парсинг данных домов")]
ParseHousesData_15_7_0_1
}
public int Id { get; set; }
public CampaignType Type { get; set; }
public string InitiatorId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? StartedAt { get; set; }
public DateTime? EndedAt { get; set; }
public int Step { get; set; } = 0;
public int Progress { get; set; } = 0;
public string? FailureReason { get; set; }
public string? Args { get; set; }
public virtual ICollection<Operation>? Operations { get; set; } = null;
[NotMapped]
public bool Completed => EndedAt.HasValue;
public ICampaignArgs? DeserializeArgs()
{
if (Args == null) return null;
return JsonConvert.DeserializeObject<ICampaignArgs>(Args, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.Auto
});
}
public void SerializeArgs(ICampaignArgs args)
{
Args = JsonConvert.SerializeObject(args, Formatting.None, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.Auto
});
}
}
}