public async Task SetupForTask(TaskBase task)
        {
            if (((App)Application.Current).IsServiceExecutingBootTasks)
            {
                _isBootTask = true;
            }
            else
            {
                _isBootTask = false;
            }

            Client = ((App)Application.Current).Client;
            StopPolling();
            await ClearOutput();

            _taskRunPoller = null;
            _test          = task;
            FollowOutput   = true;

            if (task != null)
            {
                _taskPoller = new ServerPoller(_test.Guid, typeof(TaskBase), 5000);
                _taskPoller.OnUpdatedObject += OnUpdatedTestAsync;
                _taskPoller.OnException     += OnPollingException;
                _taskPoller.StartPolling(Client);
            }

            UpdateTaskRunNav(null);
        }
Exemple #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;
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e != null)
            {
                mainPage = (Frame)e.Parameter;
            }
            if (_taskListGuidPoller == null)
            {
                _taskListGuidPoller = new ServerPoller(null, typeof(TaskList), 2000);
                _taskListGuidPoller.OnUpdatedObject += OnUpdatedTaskListGuidsAsync;
                _taskListGuidPoller.OnException     += ((App)Application.Current).OnServerPollerException;
            }

            _taskListGuidPoller.StartPolling(Client);
        }
Exemple #4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Client = ((App)Application.Current).Client;
            if (e != null)
            {
                mainPage = (Frame)e.Parameter;
            }
            EndTrackExecution();

            if (((App)Application.Current).IsServiceExecutingBootTasks)
            {
                UpdateHeaders(false);
            }
            else
            {
                UpdateHeaders(true);
            }

            if (_activeListPoller != null)
            {
                _activeListPoller.StartPolling(Client);
            }

            if (_taskListGuidPoller == null)
            {
                _taskListGuidPoller = new ServerPoller(null, typeof(TaskList), 1000, true, 2);
                _taskListGuidPoller.OnUpdatedObject += OnUpdatedTaskListGuidAndStatusAsync;
                _taskListGuidPoller.OnException     += ((App)Application.Current).OnServerPollerException;
            }

            _taskListGuidPoller.StartPolling(Client);

            if (_selectedTaskList != -1)
            {
                TaskListsView.SelectedIndex = _selectedTaskList;
                if (_trackExecution)
                {
                    EnsureSelectedIndexVisible(TaskListsView, TaskListsScrollView);
                }
            }
        }
        /// <summary>
        /// Runs a command using cmd.exe
        /// </summary>
        private async Task ExecuteCommand(string command)
        {
            // Update UI
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                RunButtonIcon.Symbol = Symbol.Stop;
                CommandBox.IsEnabled = false;

                // Log command to console output
                var textBlock = new TextBlock()
                {
                    Text                   = $"{Environment.NewLine}>{command}{Environment.NewLine}",
                    FontWeight             = Windows.UI.Text.FontWeights.Bold,
                    IsTextSelectionEnabled = true
                };
                OutputStack.Children.Add(textBlock);
            });

            // Execute command
            _newCmd = true;
            if (_taskRunPoller != null)
            {
                _taskRunPoller.StopPolling();
            }

            try
            {
                _activeRunSem.Wait();
                _activeCmdTaskRun = await Client.RunExecutable(@"cmd.exe", $"/C \"{command}\"", null, (bool)ContainerCheckBox.IsChecked);
            }
            finally
            {
                _activeRunSem.Release();
            }

            // Watch for new output
            _taskRunPoller = new ServerPoller((Guid)_activeCmdTaskRun.Guid, typeof(TaskRun), 1000);
            _taskRunPoller.OnUpdatedObject += OnUpdatedCmdStatusAsync;
            _taskRunPoller.OnException     += ((App)Application.Current).OnServerPollerException;
            _taskRunPoller.StartPolling(Client);
        }
Exemple #6
0
        /// <summary>
        /// Runs a command using cmd.exe
        /// </summary>
        private async Task ExecuteCommand(string command)
        {
            // Update history & reset index
            if ((_cmdHistory.Count == 0) || (!_cmdHistory[_cmdHistory.Count - 1].Equals(command, StringComparison.CurrentCulture)))
            {
                _cmdHistory.Add(command);
                if (_cmdHistory.Count > MaxCmdHistory)
                {
                    // TODO: this is O(n) - not super efficient. Using a cicular list would be ideal.
                    // However it is unlikely to occur, and with MaxCmdHistory set to 100 it still only took a few hundred ticks, not even a millisecond.
                    _cmdHistory.RemoveAt(0);
                }

                _cmdHistory.Add(command);
            }

            _cmdHistoryIndex = _cmdHistory.Count;

            // Update UI
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                RunButtonIcon.Symbol = Symbol.Stop;
                CommandBox.IsEnabled = false;

                // Log command to console output
                var textBlock = new TextBlock()
                {
                    Text                   = $"{Environment.NewLine}>{command}{Environment.NewLine}",
                    FontWeight             = Windows.UI.Text.FontWeights.Bold,
                    IsTextSelectionEnabled = true
                };
                OutputStack.Text = textBlock.Text;
            });

            // Execute command
            _newCmd = true;
            if (_taskRunPoller != null)
            {
                _taskRunPoller.StopPolling();
            }

            try
            {
                _activeRunSem.Wait();
                if (_isWindows)
                {
                    _activeCmdTaskRun = await Client.RunExecutable(@"cmd.exe", $"/C \"{command}\"", null, (bool)ContainerCheckBox.IsChecked);
                }
                else
                {
                    // Unlike Windows, every command is a file in $PATH, so we need to split the given string into the program & arguments
                    var    spaceIndex = command.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase);
                    string program;
                    string args = null;
                    if (spaceIndex == -1)
                    {
                        program = command;
                    }
                    else
                    {
                        program = command.Substring(0, spaceIndex);
                        args    = command.Substring(spaceIndex);
                    }

                    _activeCmdTaskRun = await Client.RunExecutable(program, args, null, (bool)ContainerCheckBox.IsChecked);
                }
            }
            finally
            {
                _activeRunSem.Release();
            }

            // Watch for new output
            _taskRunPoller = new ServerPoller((Guid)_activeCmdTaskRun.Guid, typeof(TaskRun), 1000);
            _taskRunPoller.OnUpdatedObject += OnUpdatedCmdStatusAsync;
            _taskRunPoller.OnException     += ((App)Application.Current).OnServerPollerException;
            _taskRunPoller.StartPolling(Client);
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Client = ((App)Application.Current).Client;

            // Get TaskRun we are reporting results for
            taskRun = ((App)Application.Current).RunWaitingForResult;

            taskRunPoller = new ServerPoller(taskRun.Guid, typeof(TaskRun), 1000);
            taskRunPoller.OnUpdatedObject += OnUpdatedRun;
            taskRunPoller.OnException     += TaskRunPoller_OnException;
            taskRunPoller.StartPolling(Client);

            // Append task details to UI
            string taskRunText = taskRun.TaskName;

            if (!String.IsNullOrEmpty(taskRunText))
            {
                TestText.Text       = taskRunText;
                TestText.Visibility = Visibility.Visible;
            }

            if (taskRun.TaskPath != taskRun.TaskName)
            {
                string taskRunPath = taskRun.TaskPath;
                if (!String.IsNullOrEmpty(taskRunPath))
                {
                    PathText.Text            = taskRunPath;
                    PathText.Visibility      = Visibility.Visible;
                    PathTextLabel.Visibility = Visibility.Visible;
                }
            }

            string argsString    = taskRun.Arguments;
            string taskRunString = taskRun.Guid.ToString();

            if (!String.IsNullOrEmpty(argsString))
            {
                ArgsText.Text            = argsString;
                ArgsText.Visibility      = Visibility.Visible;
                ArgsTextLabel.Visibility = Visibility.Visible;
            }

            if (!String.IsNullOrEmpty(taskRunString))
            {
                TaskRunText.Text            = taskRunString;
                TaskRunText.Visibility      = Visibility.Visible;
                TaskRunTextLabel.Visibility = Visibility.Visible;
            }

            string    mediaPath = taskRun.TaskPath;
            MediaType mediaType = GetInstructionalMediaType(mediaPath);

            if (mediaType == MediaType.Image)
            {
                AddSourceToImage(mediaPath, InstructionalImage, MediaProblems);
            }
            else if (mediaType == MediaType.Video)
            {
                AddSourceToVideoAndDisplay(mediaPath, InstructionalVideo, MediaProblems);
            }

            base.OnNavigatedTo(e);
        }