Exemplo n.º 1
0
        /// <summary>
        /// Logs a message to the console.
        /// </summary>
        /// <param name="style"> A style which influences the icon and text color. </param>
        /// <param name="objects"> The objects to output to the console. These can be strings or
        /// ObjectInstances. </param>
        public void Log(SilverlightMessageStyle style, object[] objects)
        {
            // Trigger BeforeLog event.
            if (this.BeforeLog != null)
            {
                BeforeLog(this, EventArgs.Empty);
            }

            // Determine the color and icon.
            Color     color = Colors.Black;
            UIElement icon  = null;

            switch (style)
            {
            case SilverlightMessageStyle.Information:
                break;

            case SilverlightMessageStyle.Warning:
                break;

            case SilverlightMessageStyle.Error:
                color = Colors.Red;
                icon  = new ErrorIcon();
                break;

            case SilverlightMessageStyle.Command:
                color = Color.FromArgb(255, 0, 128, 255);
                icon  = new CommandIcon()
                {
                    Foreground = new SolidColorBrush(Colors.Gray)
                };
                break;

            case SilverlightMessageStyle.Result:
                if (objects.Length == 1 && objects[0] == Undefined.Value)
                {
                    color = Colors.Gray;
                }
                else
                {
                    color = Color.FromArgb(255, 0, 0, 210);
                }
                icon = new ResultIcon();
                break;
            }

            // Output the message to the console.
            var paragraph = new Paragraph();

            if (icon != null)
            {
                var canvas = new Canvas()
                {
                    Width = 0, Height = 12
                };
                canvas.Children.Add(icon);
                Canvas.SetLeft(icon, -17);
                Canvas.SetTop(icon, 1);
                paragraph.Inlines.Add(new InlineUIContainer()
                {
                    Child = canvas
                });
            }

            // Add the messages to the paragraph.
            for (int i = 0; i < objects.Length; i++)
            {
                if (i > 0)
                {
                    paragraph.Inlines.Add(new Run()
                    {
                        Text = " "
                    });
                }
                if (objects[i] is ObjectInstance)
                {
                    var expandableObject = new ExpandableObjectControl(TypeConverter.ToString(objects[i]), objects[i], EnumerateProperties);
                    paragraph.Inlines.Add(new InlineUIContainer()
                    {
                        Child = expandableObject, Foreground = new SolidColorBrush(color)
                    });
                }
                else
                {
                    paragraph.Inlines.Add(new Run()
                    {
                        Text = TypeConverter.ToString(objects[i]), Foreground = new SolidColorBrush(color)
                    });
                }
            }
            this.richTextBox.Blocks.Add(paragraph);

            // Trigger AfterLog event.
            if (this.AfterLog != null)
            {
                AfterLog(this, EventArgs.Empty);
            }
        }
        /// <summary>
        /// Logs a message to the console.
        /// </summary>
        /// <param name="style"> A style which influences the icon and text color. </param>
        /// <param name="objects"> The objects to output to the console. These can be strings or
        /// ObjectInstances. </param>
        public void Log(SilverlightMessageStyle style, object[] objects)
        {
            // Trigger BeforeLog event.
            if (this.BeforeLog != null)
                BeforeLog(this, EventArgs.Empty);

            // Determine the color and icon.
            Color color = Colors.Black;
            UIElement icon = null;
            switch (style)
            {
                case SilverlightMessageStyle.Information:
                    break;
                case SilverlightMessageStyle.Warning:
                    break;
                case SilverlightMessageStyle.Error:
                    color = Colors.Red;
                    icon = new ErrorIcon();
                    break;
                case SilverlightMessageStyle.Command:
                    color = Color.FromArgb(255, 0, 128, 255);
                    icon = new CommandIcon() { Foreground = new SolidColorBrush(Colors.Gray) };
                    break;
                case SilverlightMessageStyle.Result:
                    if (objects.Length == 1 && objects[0] == Undefined.Value)
                        color = Colors.Gray;
                    else
                        color = Color.FromArgb(255, 0, 0, 210);
                    icon = new ResultIcon();
                    break;
            }

            // Output the message to the console.
            var paragraph = new Paragraph();
            if (icon != null)
            {
                var canvas = new Canvas() { Width = 0, Height = 12 };
                canvas.Children.Add(icon);
                Canvas.SetLeft(icon, -17);
                Canvas.SetTop(icon, 1);
                paragraph.Inlines.Add(new InlineUIContainer() { Child = canvas });
            }

            // Add the messages to the paragraph.
            for (int i = 0; i < objects.Length; i++)
            {
                if (i > 0)
                    paragraph.Inlines.Add(new Run() { Text = " " });
                if (objects[i] is ObjectInstance)
                {
                    var expandableObject = new ExpandableObjectControl(TypeConverter.ToString(objects[i]), objects[i], EnumerateProperties);
                    paragraph.Inlines.Add(new InlineUIContainer() { Child = expandableObject, Foreground = new SolidColorBrush(color) });
                }
                else
                {
                    paragraph.Inlines.Add(new Run() { Text = TypeConverter.ToString(objects[i]), Foreground = new SolidColorBrush(color) });
                }
            }
            this.richTextBox.Blocks.Add(paragraph);

            // Trigger AfterLog event.
            if (this.AfterLog != null)
                AfterLog(this, EventArgs.Empty);
        }