Example #1
0
        private async void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == Settings.TrackExecutionKey)
            {
                if (!Settings.TrackExecution)
                {
                    EndTrackExecution();
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        // Show mini window with latest output
                        var latestTask = ActiveListCollection.Select(x => x.Task).Where(t => t.LatestTaskRunStatus == TaskStatus.Running).DefaultIfEmpty(null).LastOrDefault();
                        if (latestTask == null)
                        {
                            latestTask = ActiveListCollection.Select(x => x.Task).Where(t => t.LatestTaskRunStatus == TaskStatus.RunPending).DefaultIfEmpty(null).FirstOrDefault();
                        }

                        if (latestTask != null)
                        {
                            await TrackTaskExecution(latestTask, true).ConfigureAwait(true);
                        }
                    });
                }
            }
        }
Example #2
0
        private void TaskListsView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (TaskListsView.SelectedItem != null)
            {
                var selectedTaskListGuid = ((TaskListSummary)TaskListsView.SelectedItem).Guid;

                // Selection changed might have been due to updating a template, compare to _selectedTaskList
                if (_selectedTaskList != TaskListsView.SelectedIndex)
                {
                    // New list selected, start over
                    ActiveListCollection.Clear();
                    _selectedTaskList     = TaskListsView.SelectedIndex;
                    _selectedTaskListGuid = TaskListCollection[_selectedTaskList].Guid;
                    // Show loading ring
                    LoadingTasksRing.IsActive = true;

                    if (Settings.TrackExecution)
                    {
                        EnsureSelectedIndexVisible(TaskListsView, TaskListsScrollView);
                    }
                }

                // Keep indicies in sync
                TaskListsResultsAndButtonsView.SelectedIndex = _selectedTaskList;

                var    item   = TaskListsResultsAndButtonsView.ContainerFromIndex(TaskListsResultsAndButtonsView.SelectedIndex) as FrameworkElement;
                string status = ((TaskListSummary)TaskListsResultsAndButtonsView.SelectedItem).Status.ToString();
                AutomationProperties.SetName(item, status);

                // Create new poller
                if (_activeListPoller != null)
                {
                    _activeListPoller.StopPolling();
                }
                _activeListPoller = new ServerPoller(selectedTaskListGuid, typeof(TaskList), 1000);
                _activeListPoller.OnUpdatedObject += OnUpdatedTaskListAsync;
                _activeListPoller.OnException     += ((App)Application.Current).OnServerPollerException;
                _activeListPoller.StartPolling(Client);

                // Show Tests
                ActiveTestsView.Visibility = Visibility.Visible;
            }
            else
            {
                // Stop polling, hide tasks
                if (_activeListPoller != null)
                {
                    _activeListPoller.StopPolling();
                    _activeListPoller = null;
                }
                ActiveTestsView.Visibility = Visibility.Collapsed;
            }
        }
Example #3
0
        private async Task TrackTaskExecution(TaskBase latestTask, bool settingChanged = false)
        {
            var item = ActiveListCollection.Where(x => x.Task.Guid == latestTask.Guid).First();

            ActiveTestsResultsView.SelectedItem = item;
            ActiveTestsView.SelectedItem        = item;
            FollowOutput = true;

            // Ensure the running task has changed before updating UI
            if (settingChanged || (_selectedTaskGuid != latestTask.Guid))
            {
                // Prepare result preview
                _selectedTaskGuid = latestTask.Guid;
                await ResultsPageEmbedded.SetupForTask(latestTask).ConfigureAwait(true);

                // Make result preview visible
                ResultsPreviewScrollView.Visibility = Visibility.Visible;
                ResultsPreviewTaskName.Visibility   = Visibility.Visible;
                ResultsPreviewTaskName.Text         = latestTask.Name;
                LayoutRoot.RowDefinitions.Last().Height = new GridLength(1, GridUnitType.Star);
                LayoutRoot.RowDefinitions[2].Height = GridLength.Auto;
                EnsureSelectedIndexVisible(ActiveTestsView, TestsScrollView);
            }
        }
Example #4
0
        private async void OnUpdatedTaskListGuidAndStatusAsync(object source, ServerPollerEventArgs e)
        {
            var newSummaries = (List <TaskListSummary>)e.Result;

            // Get the new TaskLists
            if (newSummaries != null)
            {
                int newCount = newSummaries.Count;

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    try
                    {
                        if (newSummaries.Any(x => x.IsRunningOrPending))
                        {
                            RunAllButton.Content = resourceLoader.GetString("AbortAllButton/Content");
                            ToolTipService.SetToolTip(RunAllButton, resourceLoader.GetString("AbortAllButton/ToolTipService/ToolTip"));
                            AutomationProperties.SetName(RunAllButton, resourceLoader.GetString("AbortAllButton/ToolTipService/ToolTip"));
                        }
                        else
                        {
                            RunAllButton.Content = resourceLoader.GetString("RunAllButton/Content");
                            ToolTipService.SetToolTip(RunAllButton, resourceLoader.GetString("RunAllButton/ToolTipService/ToolTip"));
                            AutomationProperties.SetName(RunAllButton, resourceLoader.GetString("RunAllButton/ToolTipService/ToolTip"));
                        }

                        if (newCount == 0)
                        {
                            // No TaskLists exist, clear everything
                            LoadingTasksRing.IsActive = false;
                            TaskListCollection.Clear();
                            ActiveListCollection.Clear();
                            return;
                        }

                        if (_trackExecution)
                        {
                            // Find the latest running list. If none are running find the first run pending list.
                            var latestList = newSummaries.Where(x => x.Status == TaskStatus.Running).DefaultIfEmpty(new TaskListSummary()).LastOrDefault();
                            if (latestList.Guid == Guid.Empty)
                            {
                                latestList = newSummaries.Where(x => x.Status == TaskStatus.RunPending).DefaultIfEmpty(new TaskListSummary()).FirstOrDefault();
                            }

                            if (latestList.Guid != Guid.Empty)
                            {
                                _selectedTaskListGuid = latestList.Guid;
                            }
                        }

                        bool selectedListFound = false;
                        for (int i = 0; i < newSummaries.Count; i++)
                        {
                            var newSummary = newSummaries[i];

                            if (newSummary.Guid == _selectedTaskListGuid)
                            {
                                selectedListFound = true;
                            }

                            // Update the TaskListCollection
                            if (i == TaskListCollection.Count)
                            {
                                TaskListCollection.Insert(i, newSummary);
                            }
                            else if (!TaskListCollection[i].Equals(newSummary))
                            {
                                // Template reselected automatically
                                TaskListCollection[i] = newSummary;
                            }

                            // Ensure correct list is selected
                            if ((_selectedTaskListGuid == newSummary.Guid) && (TaskListsView.SelectedIndex != i))
                            {
                                TaskListsView.SelectedIndex = i;
                            }
                        }

                        // Prune non-existent Lists
                        int j = newSummaries.Count;
                        while (TaskListCollection.Count > newSummaries.Count)
                        {
                            TaskListCollection.RemoveAt(j);
                        }

                        if (!selectedListFound && _selectedTaskList != -1)
                        {
                            // The selected list was deleted
                            _selectedTaskList     = -1;
                            _selectedTaskListGuid = Guid.Empty;

                            TaskListsView.SelectedIndex = -1;
                            ActiveListCollection.Clear();
                            LoadingTasksRing.IsActive = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.AllExceptionsToString());
                    }
                });
            }
            else
            {
                // No TaskLists exist, clear everything
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    LoadingTasksRing.IsActive = false;
                    TaskListCollection.Clear();
                    ActiveListCollection.Clear();
                    EndTrackExecution();
                });
            }
        }
Example #5
0
        private async void OnUpdatedTaskListAsync(object source, ServerPollerEventArgs e)
        {
            if (e.Result != null)
            {
                TaskList list      = (TaskList)e.Result;
                var      taskArray = list.Tasks.ToArray();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        LoadingTasksRing.IsActive = false;

                        if (taskArray.Length == 0)
                        {
                            // No Tasks exist, clear everything
                            ActiveListCollection.Clear();
                            return;
                        }

                        for (int i = 0; i < taskArray.Length; i++)
                        {
                            // Determine the template to use. Do here since it depends on the status of the list, not only the Task
                            var newTask     = taskArray[i];
                            var newTemplate = (((list.TaskListStatus != TaskStatus.Running) &&
                                                (list.TaskListStatus != TaskStatus.RunPending)) &&
                                               (newTask.LatestTaskRunPassed != null) &&
                                               (newTask.LatestTaskRunPassed == false)) ? TaskViewTemplate.WithRetryButton : TaskViewTemplate.Normal;

                            // Update the ActiveListCollection
                            try
                            {
                                if (i == ActiveListCollection.Count)
                                {
                                    ActiveListCollection.Insert(i, new TaskBaseWithTemplate(newTask, newTemplate));
                                }
                                else if (!ActiveListCollection[i].Task.Equals(newTask))
                                {
                                    // force template reselection
                                    ActiveListCollection[i] = new TaskBaseWithTemplate(newTask, newTemplate);
                                }
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                Debug.WriteLine(ex.AllExceptionsToString());
                            }
                        }

                        if (_trackExecution)
                        {
                            // Show mini window with latest output
                            var latestTask = taskArray.Where(x => x.LatestTaskRunStatus == TaskStatus.Running).DefaultIfEmpty(null).LastOrDefault();
                            if (latestTask == null)
                            {
                                latestTask = taskArray.Where(x => x.LatestTaskRunStatus == TaskStatus.RunPending).DefaultIfEmpty(null).FirstOrDefault();
                            }

                            if (latestTask != null)
                            {
                                // Select the running task
                                var item = ActiveListCollection.Where(x => x.Task.Guid == latestTask.Guid).First();
                                ActiveTestsResultsView.SelectedItem = item;
                                ActiveTestsView.SelectedItem        = item;
                                FollowOutput = true;

                                // Ensure the running task has changed before updating UI
                                if (_selectedTaskGuid != latestTask.Guid)
                                {
                                    // Prepare result preview
                                    _selectedTaskGuid = latestTask.Guid;
                                    await ResultsPageEmbedded.SetupForTask(latestTask);
                                    // Make result preview visible
                                    ResultsPreviewScrollView.Visibility     = Visibility.Visible;
                                    ResultsPreviewTaskName.Visibility       = Visibility.Visible;
                                    ResultsPreviewTaskName.Text             = latestTask.Name;
                                    LayoutRoot.RowDefinitions.Last().Height = new GridLength(1, GridUnitType.Star);
                                    LayoutRoot.RowDefinitions[2].Height     = GridLength.Auto;
                                    EnsureSelectedIndexVisible(ActiveTestsView, TestsScrollView);
                                }
                            }
                            else if (!TaskListCollection.Any(x => (x.Guid != _selectedTaskListGuid) && (x.IsRunningOrPending)))
                            {
                                // No more tasks are queued to run. Hide preview.
                                _selectedTaskGuid = Guid.Empty;
                                EndTrackExecution();
                            }
                        }

                        // Prune non-existent Tasks
                        int j = taskArray.Length;
                        while (ActiveListCollection.Count > taskArray.Length)
                        {
                            ActiveListCollection.RemoveAt(j);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.AllExceptionsToString());
                    }
                });
            }
            else
            {
                // No Tasks exist, clear everything
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    LoadingTasksRing.IsActive = false;
                    ActiveListCollection.Clear();
                });
            }
        }
Example #6
0
        private async void OnUpdatedTaskListAsync(object source, ServerPollerEventArgs e)
        {
            if (e.Result != null)
            {
                TaskList list      = (TaskList)e.Result;
                var      taskArray = list.Tasks.ToArray();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        LoadingTasksRing.IsActive = false;

                        if (taskArray.Length == 0)
                        {
                            // No Tasks exist, clear everything
                            ActiveListCollection.Clear();
                            return;
                        }

                        for (int i = 0; i < taskArray.Length; i++)
                        {
                            // Determine the template to use. Do here since it depends on the status of the list, not only the Task
                            var newTask     = taskArray[i];
                            var newTemplate = (((list.TaskListStatus != TaskStatus.Running) &&
                                                (list.TaskListStatus != TaskStatus.RunPending)) &&
                                               (newTask.LatestTaskRunPassed != null) &&
                                               (newTask.LatestTaskRunPassed == false)) ? TaskViewTemplate.WithRetryButton : TaskViewTemplate.Normal;

                            // Update the ActiveListCollection
                            try
                            {
                                if (i == ActiveListCollection.Count)
                                {
                                    ActiveListCollection.Insert(i, new TaskBaseWithTemplate(newTask, newTemplate));
                                }
                                else if (!ActiveListCollection[i].Task.Equals(newTask))
                                {
                                    // force template reselection
                                    ActiveListCollection[i] = new TaskBaseWithTemplate(newTask, newTemplate);
                                }
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                Debug.WriteLine(ex.AllExceptionsToString());
                            }
                        }

                        if (Settings.TrackExecution)
                        {
                            // Show mini window with latest output
                            var latestTask = taskArray.Where(x => x.LatestTaskRunStatus == TaskStatus.Running).DefaultIfEmpty(null).LastOrDefault();
                            if (latestTask == null)
                            {
                                latestTask = taskArray.Where(x => x.LatestTaskRunStatus == TaskStatus.RunPending).DefaultIfEmpty(null).FirstOrDefault();
                            }

                            if (latestTask != null)
                            {
                                // Select the running task
                                await TrackTaskExecution(latestTask);
                            }
                            else if (!TaskListCollection.Any(x => (x.Guid != _selectedTaskListGuid) && (x.IsRunningOrPending)))
                            {
                                // No more tasks are queued to run. Hide preview.
                                _selectedTaskGuid = Guid.Empty;
                                EndTrackExecution();
                            }
                        }

                        // Prune non-existent Tasks
                        int j = taskArray.Length;
                        while (ActiveListCollection.Count > taskArray.Length)
                        {
                            ActiveListCollection.RemoveAt(j);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.AllExceptionsToString());
                    }
                });
            }
            else
            {
                // No Tasks exist, clear everything
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    LoadingTasksRing.IsActive = false;
                    ActiveListCollection.Clear();
                });
            }
        }