aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.UI/Tiles/Events/EventsTile.cs
blob: 9730acd32781dfaa428c69ad24d307e6ee1429a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.BL.Enumerations;
using Tango.FSE.Common;

namespace Tango.FSE.UI.Tiles.Events
{
    public class EventsTile : DashboardTile
    {
        private double _InfoEvents;
        public double InfoEvents
        {
            get { return _InfoEvents; }
            set { _InfoEvents = value; RaisePropertyChangedAuto(); }
        }

        private double _warningEvents;
        public double WarningEvents
        {
            get { return _warningEvents; }
            set { _warningEvents = value; RaisePropertyChangedAuto(); }
        }

        private double _errorEvents;
        public double ErrorEvents
        {
            get { return _errorEvents; }
            set { _errorEvents = value; RaisePropertyChangedAuto(); }
        }

        private double _criticalEvents;
        public double CriticalEvents
        {
            get { return _criticalEvents; }
            set { _criticalEvents = value; RaisePropertyChangedAuto(); }
        }

        private bool _canExecuteJob;
        public bool CanExecuteJob
        {
            get { return _canExecuteJob; }
            set { _canExecuteJob = value; RaisePropertyChangedAuto(); }
        }

        public EventsTile()
        {
            Name = "Active Events";
            AutoContainerStyle = false;
            AutoTitleAlignment = System.Windows.Controls.Dock.Right;
            Column = 8;
            Row = 0;
            ColumnSpan = 4;
            RowSpan = 6;
            CanExecuteJob = true;
        }

        public override void OnApplicationStarted()
        {
            EventsProvider.ActiveEvents.CollectionChanged += ActiveEvents_CollectionChanged;
        }

        private void ActiveEvents_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            InfoEvents = EventsProvider.ActiveEvents.ToList().Where(x => x.Category == EventTypeCategories.Info).Count();
            WarningEvents = EventsProvider.ActiveEvents.ToList().Where(x => x.Category == EventTypeCategories.Warning).Count();
            ErrorEvents = EventsProvider.ActiveEvents.ToList().Where(x => x.Category == EventTypeCategories.Error).Count();
            CriticalEvents = EventsProvider.ActiveEvents.ToList().Where(x => x.Category == EventTypeCategories.Critical).Count();

            CanExecuteJob = !EventsProvider.ActiveEvents.Any(x => x.EventType.Actions.Contains(EventTypeActions.PreventJob));
        }

        public override FrameworkElement GetView()
        {
            return new EventsTileView();
        }
    }
}