Exemplo n.º 1
0
        /// <summary>
        /// Display a message, which is for information only
        /// </summary>
        public void Info(int level, string msg, params object[] args)
        {
            var p = new StoredPrint(StoredPrint.ColorBlack, String.Format(msg, args));

            if (level <= DebugLevel)
            {
                Append(p);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Display a message, which is for information only
        /// </summary>
        public void InfoWithHyperlink(int level, string msg, string linkTxt, string linkUri, params object[] args)
        {
            var p = new StoredPrint(
                StoredPrint.ColorBlack, String.Format(msg, args), linkTxt: linkTxt, linkUri: linkUri);

            if (level <= DebugLevel)
            {
                Append(p);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Directly append a stored print.
        /// </summary>
        public void Append(StoredPrint sp)
        {
            if (sp == null || StoredPrints == null)
            {
                return;
            }

            // in any case, add to stored prints
            lock (StoredPrints)
            {
                StoredPrints.Add(sp);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Display a message, which is for errors
        /// </summary>
        public void Error(Exception ex, string where)
        {
            if (ex == null)
            {
                return;
            }

            var s = AdminShellNS.Logging.FormatError(ex, where);

            var p = new StoredPrint(StoredPrint.Color.Red, s, isError: true);

            p.stackTrace = ex.StackTrace;
            NumberErrors++;
            Append(p);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Display a message, which is for errors
        /// </summary>
        public void Error(Exception ex, string where)
        {
            if (ex == null)
            {
                return;
            }

            var s = String.Format("Error {0}: {1} {2} at {3}.",
                                  where,
                                  ex.Message,
                                  ((ex.InnerException != null) ? ex.InnerException.Message : ""),
                                  AdminShellNS.AdminShellUtil.ShortLocation(ex));

            var p = new StoredPrint(StoredPrint.ColorRed, s, isError: true);

            p.stackTrace = ex.StackTrace;
            NumberErrors++;
            Append(p);
        }
        public static void StoredPrintToRichTextBox(
            RichTextBox rtb, StoredPrint sp, StoredPrintColors colors, bool isExternalError = false,
            RoutedEventHandler linkClickHandler = null)
        {
            // access
            if (rtb == null || sp == null)
            {
                return;
            }

            // append
            TextRange tr = new TextRange(rtb.Document.ContentEnd, rtb.Document.ContentEnd);

            tr.Text  = "" + sp.msg;
            tr.Text += Environment.NewLine;

            if (isExternalError || sp.isError)
            {
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushError);
                tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
            }
            else
            {
                if (sp.color == StoredPrint.ColorRed)
                {
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushRed);
                }

                if (sp.color == StoredPrint.ColorBlue)
                {
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushBlue);
                }
            }

            if (sp.linkTxt != null && sp.linkUri != null)
            {
                // see: https://stackoverflow.com/questions/762271/
                // clicking-hyperlinks-in-a-richtextbox-without-holding-down-ctrl-wpf
                // see: https://stackoverflow.com/questions/9279061/dynamically-adding-hyperlinks-to-a-richtextbox

                // try modify existing
                tr.Text = tr.Text.TrimEnd('\r', '\n') + " ";

                // make another append!
                var link = new Hyperlink(rtb.Document.ContentEnd, rtb.Document.ContentEnd);
                link.IsEnabled = true;

                // ReSharper disable EmptyGeneralCatchClause
                try
                {
                    link.Inlines.Add("" + sp.linkTxt + Environment.NewLine);
                    link.NavigateUri = new Uri(sp.linkUri);
                    if (linkClickHandler != null)
                    {
                        link.Click += linkClickHandler;
                    }
                }
                catch { }
                // ReSharper enable EmptyGeneralCatchClause
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Display a message, which is for information only
        /// </summary>
        public void Info(StoredPrint.Color color, string msg, params object[] args)
        {
            var p = new StoredPrint(color, String.Format(msg, args));

            Append(p);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Directly append a stored print.
 /// </summary>
 public void Append(StoredPrint sp)
 {
     shortTermStore?.Append(sp);
     longTermStore?.Append(sp);
 }
Exemplo n.º 9
0
        public static void StoredPrintToRichTextBox(
            RichTextBox rtb, StoredPrint sp, StoredPrintColors colors, bool isExternalError = false,
            RoutedEventHandler linkClickHandler = null)
        {
            // access
            if (rtb == null || sp == null)
            {
                return;
            }

            // append
            TextRange tr = new TextRange(rtb.Document.ContentEnd, rtb.Document.ContentEnd);

            tr.Text  = "" + sp.msg;
            tr.Text += Environment.NewLine;

            if (isExternalError || sp.isError)
            {
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushError);
                tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
            }
            else
            {
                switch (sp.color)
                {
                default:
                    throw ExhaustiveMatch.Failed(sp.color);

                case StoredPrint.Color.Red:
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushRed);
                    break;

                case StoredPrint.Color.Blue:
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, colors.BrushBlue);
                    break;

                case StoredPrint.Color.Black:
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Black));
                    break;
                }
            }

            if (sp.linkTxt != null && sp.linkUri != null)
            {
                // see: https://stackoverflow.com/questions/762271/
                // clicking-hyperlinks-in-a-richtextbox-without-holding-down-ctrl-wpf
                // see: https://stackoverflow.com/questions/9279061/dynamically-adding-hyperlinks-to-a-richtextbox

                // try modify existing
                tr.Text = tr.Text.TrimEnd('\r', '\n') + " ";

                // make another append!
                var link = new Hyperlink(rtb.Document.ContentEnd, rtb.Document.ContentEnd);
                link.IsEnabled = true;

                try
                {
                    link.Inlines.Add("" + sp.linkTxt + Environment.NewLine);
                    link.NavigateUri = new Uri(sp.linkUri);
                    if (linkClickHandler != null)
                    {
                        link.Click += linkClickHandler;
                    }
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Only append to longterm or to file, if file name is set
        /// </summary>
        public void Silent(string msg, params object[] args)
        {
            var p = new StoredPrint(StoredPrint.ColorNoDisplay, String.Format(msg, args));

            Append(p);
        }