virtual public void UpdateEventTypesAndTimers() { IEnumerable <EventType> dashboardtypes = new List <EventType> (); IEnumerable <EventType> timelinetypes; if (Dashboard != null) { /* Timers */ IEnumerable <Timer> timers = Dashboard.List.OfType <TimerButton> ().Select(b => b.Timer).OfType <Timer> (); 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 (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)); /* Remove null EventTypes just in case */ EventTypes = new RangeObservableCollection <EventType> (EventTypes.Where(e => e != null)); }
private async Task LoadEventTypes() { EventTypes.AddRange(await eventTypeRestService.GetEventTypesAsync()); }