Beispiel #1
0
        /// <summary>
        /// Updates the UI when <see cref="SectionProperty"/> changes
        /// </summary>
        /// <param name="d">The source <see cref="DependencyObject"/> instance</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> info for the current update</param>
        private static void OnSectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Unpack the arguments
            Span @this = (Span)d;
            IdeResultWithSectionInfo value = (IdeResultWithSectionInfo)e.NewValue;

            @this.Inlines.Clear();

            if (value is null)
            {
                return;
            }

            switch (value.Section)
            {
            case IdeResultSection.ExceptionType:
                @this.Inlines.Add(new Run
                {
                    Text       = ExitCodeConverter.Convert(value.Result.ExitCode),
                    Foreground = new SolidColorBrush(Colors.DarkRed)
                });
                break;

            case IdeResultSection.Stdout:
                @this.Inlines.Add(new Run
                {
                    Text       = value.Result.Stdout,
                    Foreground = new SolidColorBrush(Colors.Cornsilk)
                });
                break;

            case IdeResultSection.FaultingOperator:
            case IdeResultSection.BreakpointReached:
                @this.Inlines.Add(new Run
                {
                    Text       = value.Result.HaltingInfo !.HaltingOperator.ToString(),
                    Foreground = SettingsService.GetValue <IdeTheme>(SettingsKeys.IdeTheme).AsBrainf_ckTheme().GetBrush(value.Result.HaltingInfo.HaltingOperator)
                });
                @this.Inlines.Add(new Run
                {
                    Text = $" {string.Format(AtPosition, value.Result.HaltingInfo.HaltingOffset)}"
                });
                break;
Beispiel #2
0
 /// <summary>
 /// Sets the value of <see cref="SectionProperty"/> for a given <see cref="Span"/>
 /// </summary>
 /// <param name="element">The input <see cref="Span"/> for which to set the property value</param>
 /// <param name="value">The value to set for the <see cref="SectionProperty"/> property</param>
 public static void SetSection(Span element, IdeResultWithSectionInfo value)
 {
     element.SetValue(SectionProperty, value);
 }
        private void LoadResults(InterpreterResult result)
        {
            Source.Clear();

            // A function used to quickly add a specific section to the current collection
            void AddToSource(IdeResultSection section)
            {
                var model = new IdeResultWithSectionInfo(section, result);

                Source.AddGroup(section, model);
            }

            // The order of items in the result view is as follows:
            // - (optional) Exception type
            // - (optional) Stdout buffer
            // - (optional) Error location
            // - (optional) Breakpoint location
            // - (optional) Stack trace
            // - Source code
            // - (optional) Function definitions
            // - Memory state
            // - Statistics
            //
            // Each group stores the type of section it represents, so that
            // a template selector can be used in the view. The value of each
            // group is the the whole session result, as it contains all the
            // available info for the current script execution.
            // Each template is responsible for extracting info from it
            // and display according to its own function and section type.
            if (!result.ExitCode.HasFlag(ExitCode.Success))
            {
                AddToSource(IdeResultSection.ExceptionType);
            }
            if (result.Stdout.Length > 0)
            {
                AddToSource(IdeResultSection.Stdout);
            }

            if (result.ExitCode.HasFlag(ExitCode.ExceptionThrown))
            {
                AddToSource(IdeResultSection.FaultingOperator);
            }
            else if (result.ExitCode.HasFlag(ExitCode.BreakpointReached))
            {
                AddToSource(IdeResultSection.BreakpointReached);
            }

            if (result.ExitCode.HasFlag(ExitCode.ExceptionThrown) ||
                result.ExitCode.HasFlag(ExitCode.ThresholdExceeded) ||
                result.ExitCode.HasFlag(ExitCode.BreakpointReached))
            {
                AddToSource(IdeResultSection.StackTrace);
            }

            AddToSource(IdeResultSection.SourceCode);

            if (result.Functions.Count > 0)
            {
                AddToSource(IdeResultSection.FunctionDefinitions);
            }

            AddToSource(IdeResultSection.MemoryState);
            AddToSource(IdeResultSection.Statistics);
        }