Esempio n. 1
0
        private void SetSelectedSession()
        {
            SessionDropDownItem item = sessionId_ComboBox.SelectedItem as SessionDropDownItem;

            if (item != null)
            {
                _sessionId    = item.SessionId;
                _scenarioName = item.SessionName;
                RefreshGraphs();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshes the scenario list.
        /// </summary>
        public void RefreshScenarioList()
        {
            List <SessionDropDownItem> items = new List <SessionDropDownItem>();

            using (DataLogContext context = DbConnect.DataLogContext())
            {
                var sessions = context.Sessions
                               .OrderByDescending(n => n.StartDateTime)
                               .Select(n => new
                {
                    n.SessionId,
                    n.SessionName,
                    n.Owner,
                    n.StartDateTime
                })
                               .AsEnumerable()
                               .Select(n => new SessionDropDownItem
                {
                    SessionId   = n.SessionId,
                    SessionName = n.SessionName ?? "Undefined",
                    Owner       = n.Owner ?? "Undefined",
                    StartDate   = n.StartDateTime?.LocalDateTime ?? DateTime.MinValue
                }).ToList();

                // Only include sessions that have activities
                var sessionCounts = context.SessionActivityCounts();
                items.AddRange(sessions.Where(n => sessionCounts.ContainsKey(n.SessionId)));
            }

            sessionId_ComboBox.DataSource = null;
            sessionId_ComboBox.DataSource = items;

            if (items.Count() > 0)
            {
                if (!string.IsNullOrEmpty(_sessionId))
                {
                    SessionDropDownItem itemToSelect = items.FirstOrDefault(i => i.SessionId == _sessionId);
                    if (itemToSelect != null)
                    {
                        sessionId_ComboBox.SelectedItem = itemToSelect;
                        SetSelectedSession();
                    }
                }
                else
                {
                    // Default to the most recent session run by the logged in user
                    SessionDropDownItem mostRecentSession = items.FirstOrDefault(i => i.Owner == UserManager.CurrentUserName);
                    sessionId_ComboBox.SelectedItem = mostRecentSession ?? sessionId_ComboBox.Items[0];
                    SetSelectedSession();
                }
            }
        }