/// <summary> /// Register events to MainWindow status textblock and Log file /// </summary> /// <param name="type">Log message type (INFO, WARNING, ERROR)</param> /// <param name="msg">Message to display</param> private void Log(string type, string msg) { var status = string.Empty; switch (type) { case "INFO": status += $"[INFO] {DateTime.Now.ToString(CultureInfo.CurrentCulture)} - {msg}"; break; case "ERROR": status += $"[ERROR] {DateTime.Now.ToString(CultureInfo.CurrentCulture)} - {msg}"; break; case "WARNING": status += $"[WARNING] {DateTime.Now.ToString(CultureInfo.CurrentCulture)} - {msg}"; break; } StatusTextBlock.Text += status + Environment.NewLine; StatusTextBlock.ScrollToEnd(); using (var writer = new StreamWriter("Log.txt", true)) { writer.Write(status + Environment.NewLine); } }
internal static IEnumerable <Inline> GenerateInlinesFromRawEntryText(string entryText) { int startIndex = 0; Match match = StatusTextBlock.UriMatchingRegex.Match(entryText); while (match.Success) { if (startIndex != match.Index) { yield return(new Run(StatusTextBlock.DecodeStatusEntryText(entryText.Substring(startIndex, match.Index - startIndex)))); } Hyperlink hyperLink = new Hyperlink(new Run(match.Value)); string uri = match.Value; if (match.Groups["emailAddress"].Success) { uri = "mailto:" + uri; } else if (match.Groups["toTwitterScreenName"].Success) { uri = "http://twitter.com/" + uri.Substring(1); } hyperLink.NavigateUri = new Uri(uri); yield return(hyperLink); startIndex = match.Index + match.Length; match = match.NextMatch(); } if (startIndex != entryText.Length) { yield return(new Run(StatusTextBlock.DecodeStatusEntryText(entryText.Substring(startIndex)))); } }
private static void StatusTextPropertyChangedCallback(DependencyObject target, DependencyPropertyChangedEventArgs eventArgs) { StatusTextBlock targetStatusEntryTextBlock = (StatusTextBlock)target; targetStatusEntryTextBlock.Inlines.Clear(); string newValue = eventArgs.NewValue as string; if (newValue != null) { targetStatusEntryTextBlock.Inlines.AddRange(StatusTextBlock.GenerateInlinesFromRawEntryText(newValue)); } }
private void _updateStatus(string message) { StatusTextBlock.Text = message; StatusTextBlock.Foreground = Brushes.Tomato; StatusTextBlock.UpdateLayout(); }