Exemple #1
0
        private void AppendDmlOutput(string content)
        {
            var paragraph = new Paragraph();

            ContentTextBox.Document.Blocks.Add(paragraph);

            var matches = Regex.Matches(content, @"<exec cmd=\""(?<command>.+?)\"">(?<label>.+?)</exec>");

            int index = 0;

            foreach (Match match in matches)
            {
                paragraph.Inlines.Add(new Run(System.Net.WebUtility.HtmlDecode(content.Substring(index, match.Index - index))));

                var hyperLink = new Hyperlink(new Run(match.Groups["label"].Value));

                var command = match.Groups["command"].Value;

                hyperLink.Command = new DmlCommand(() => _ = ExecuteCommand(command));

                paragraph.Inlines.Add(hyperLink);

                index = match.Index + match.Length;
            }

            if (index < content.Length)
            {
                paragraph.Inlines.Add(new Run(System.Net.WebUtility.HtmlDecode(content.Substring(index))));
            }

            Dispatcher.InvokeAsync(() => ContentTextBox.ScrollToEnd(), DispatcherPriority.ApplicationIdle);
        }
Exemple #2
0
        private async Task ExecuteCommand(string command)
        {
            ContentTextBox.Document.Blocks.Add(new Paragraph(new Run(command)));
            ContentTextBox.ScrollToEnd();

            var result = await _console.ExecuteCommandAndCaptureOutputAsync(command);

            _historyManager.LogCommand(command, result);

            AppendDmlOutput(result);
        }
        public void AddLine(string line, SolidColorBrush colorBrush)
        {
            var tp = ContentTextBox.Document.ContentEnd;

            var tr = new TextRange(tp, tp)
            {
                Text = line + '\r'
            };

            tr.ApplyPropertyValue(TextElement.ForegroundProperty, colorBrush);

            if (!VM.ScrollLock)
            {
                ContentTextBox.ScrollToEnd();
            }
        }