LongoMatch.Core.Store.ProjectLongoMatch.UpdateEventTypesAndTimers C# (CSharp) Method

UpdateEventTypesAndTimers() public method

public UpdateEventTypesAndTimers ( ) : void
return void
        public override void UpdateEventTypesAndTimers()
        {
            IEnumerable<EventType> dashboardtypes = new List<EventType> ();
            IEnumerable<EventType> timelinetypes;

            if (Dashboard != null) {
                /* Timers */
                IEnumerable<TimerLongoMatch> timers = Dashboard.List.OfType<TimerButton> ().Select (b => b.Timer).OfType<TimerLongoMatch> ();
                Timers.AddRange (timers.Except (Timers));

                /* Update event types list that changes when the user adds or remove a
                 * a new button to the dashboard or after importing a project with events
                 * tagged with a different dashboard */
                dashboardtypes = Dashboard.List.OfType<EventButton> ().Select (b => b.EventType);
            }

            /* Remove event types that have no events and are not in the dashboard anymore */
            foreach (EventType evt in EventTypes.Except (dashboardtypes).ToList ()) {
                if (evt == SubstitutionsEventType) {
                    continue;
                }
                if (Timeline.Count (e => e.EventType == evt) == 0) {
                    EventTypes.Remove (evt);
                }
            }
            EventTypes.AddRange (dashboardtypes.Except (EventTypes));
            timelinetypes = Timeline.Select (t => t.EventType).Distinct ().Except (EventTypes);
            EventTypes.AddRange (timelinetypes.Except (EventTypes));
            if (!EventTypes.Contains (SubstitutionsEventType)) {
                EventTypes.Add (SubstitutionsEventType);
            }

            /* Remove null EventTypes just in case */
            EventTypes = new ObservableCollection<EventType> (EventTypes.Where (e => e != null));
        }

Usage Example

Example #1
0
        public void TestUpdateEventTypesAndTimers()
        {
            ProjectLongoMatch p = new ProjectLongoMatch ();
            p.Dashboard = DashboardLongoMatch.DefaultTemplate (5);
            Assert.AreEqual (0, p.Timers.Count);
            Assert.AreEqual (0, p.EventTypes.Count);
            p.UpdateEventTypesAndTimers ();
            Assert.AreEqual (1, p.Timers.Count);
            Assert.AreEqual (10, p.EventTypes.Count);

            // Delete a category button with no events
            p.Dashboard.List.Remove (p.Dashboard.List.OfType<AnalysisEventButton> ().First ());
            p.UpdateEventTypesAndTimers ();
            Assert.AreEqual (1, p.Timers.Count);
            Assert.AreEqual (9, p.EventTypes.Count);

            // Delete a category button with events in the timeline
            AnalysisEventButton button = p.Dashboard.List.OfType<AnalysisEventButton> ().First ();
            p.Timeline.Add (new TimelineEventLongoMatch { EventType = button.EventType });
            p.UpdateEventTypesAndTimers ();
            Assert.AreEqual (1, p.Timers.Count);
            Assert.AreEqual (9, p.EventTypes.Count);
            p.Dashboard.List.Remove (button);
            p.UpdateEventTypesAndTimers ();
            Assert.AreEqual (1, p.Timers.Count);
            Assert.AreEqual (9, p.EventTypes.Count);

            // Remove the event from the timeline, the event type is no longuer in the dashboard or the timeline
            p.Timeline.Clear ();
            p.UpdateEventTypesAndTimers ();
            Assert.AreEqual (1, p.Timers.Count);
            Assert.AreEqual (8, p.EventTypes.Count);
        }
All Usage Examples Of LongoMatch.Core.Store.ProjectLongoMatch::UpdateEventTypesAndTimers