Example #1
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 #2
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();
                });
            }
        }