using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Enumerations; using Tango.PMR.Diagnostics; namespace Tango.BL.Entities { [Serializable] public partial class MachinesEvent : MachinesEventBase { private static Dictionary _eventTypesGuids; private static bool _eventFactoryInitialized; private void InitializeEventFactory() { if (!_eventFactoryInitialized) { _eventFactoryInitialized = true; _eventTypesGuids = new Dictionary(); foreach (var type in ObservablesStaticCollections.Instance.EventTypes) { _eventTypesGuids.Add((EventTypes)type.Code, type); } } } public MachinesEvent(Event pmrEvent) : this() { InitializeEventFactory(); DateTime = DateTime.UtcNow; Description = pmrEvent.Message; if (_eventTypesGuids.ContainsKey((EventTypes)pmrEvent.Type)) { EventType = _eventTypesGuids[(EventTypes)pmrEvent.Type]; } else { EventType = _eventTypesGuids[EventTypes.APPLICATION_INFORMATION]; } } [NotMapped] public int Code { get { return EventType.Code; } } [NotMapped] public String Name { get { return EventType.Name; } } [NotMapped] public EventTypes Type { get { return EventType.Type; } } [NotMapped] public EventTypeCategories Category { get { return (EventTypeCategories)EventType.EventCategory; } } [NotMapped] public EventTypeGroups Group { get { return (EventTypeGroups)EventType.EventGroup; } } [NotMapped] public EventTypeNotificationTimes NotificationTime { get { return EventType.NotificationTime; } } [NotMapped] public IReadOnlyCollection Actions { get { return EventType.Actions; } } [NotMapped] public DateTime ResolvedDateTime { get; set; } [NotMapped] public TimeSpan Duration { get { return ResolvedDateTime - DateTime; } } private User _eventUser; [NotMapped] [JsonIgnore] public User EventUser { get { return _eventUser; } set { _eventUser = value; RaisePropertyChangedAuto(); } } [JsonIgnore] [NotMapped] public EventType RelatedEventType { get; set; } protected override void OnUserChanged(User user) { base.OnUserChanged(user); if (user != null) { EventUser = user; } } public bool IsJobProgressEvent() { return Type == EventTypes.JOB_STARTED || Type == EventTypes.JOB_ABORTED || Type == EventTypes.JOB_COMPLETED || Type == EventTypes.JOB_FAILED; } /// /// Initializes a new instance of the class. /// public MachinesEvent() : base() { } } }