Пример #1
0
        private void ButtonClear_Click(object sender, RoutedEventArgs e)
        {
            SyncMlSessions.Clear();

            TextEditorMessages.Clear();
            TextEditorStream.Clear();
        }
Пример #2
0
        private void MenuItemBackgroundLogging_Unchecked(object sender, RoutedEventArgs e)
        {
            if (!((MenuItem)sender).IsChecked)
            {
                Trace.Close();
                Trace.Listeners.Remove("listenerSyncMLStream");

                TextEditorStream.Clear();
                TextEditorStream.IsEnabled = true;
            }
        }
Пример #3
0
        private void MenuItemBackgroundLogging_Checked(object sender, RoutedEventArgs e)
        {
            if (((MenuItem)sender).IsChecked)
            {
                Trace.Listeners.Add(new TextWriterTraceListener($"SyncMLStream-BackgroundLogging-{Environment.MachineName}-{DateTime.Now:MM-dd-yy_H-mm-ss}.xml", "listenerSyncMLStream"));
                Trace.AutoFlush = true;

                SyncMlSessions.Clear();
                ListBoxMessages.ItemsSource = null;

                TextEditorStream.Clear();
                TextEditorMessages.Clear();

                TextEditorStream.IsEnabled = false;
                TextEditorStream.AppendText(Environment.NewLine + "\t'Background Logging Mode' enabled.");
            }
        }
Пример #4
0
 private void ButtonClear_Click(object sender, RoutedEventArgs e)
 {
     TextEditorStream.Clear();
 }
Пример #5
0
        private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {
                if (!(e.UserState is TraceEvent userState))
                {
                    throw new ArgumentException("No TraceEvent received.");
                }

                // show all events
                if (CheckBoxShowTraceEvents.IsChecked == true)
                {
                    // filter a bit otherwise too much noise...
                    if (!string.Equals(userState.EventName, "FunctionEntry",
                                       StringComparison.CurrentCultureIgnoreCase) &&
                        !string.Equals(userState.EventName, "FunctionExit",
                                       StringComparison.CurrentCultureIgnoreCase) &&
                        !string.Equals(userState.EventName, "GenericLogEvent",
                                       StringComparison.CurrentCultureIgnoreCase))
                    {
                        TextEditorStream.AppendText(userState.EventName + " ");
                    }
                }

                // we are interested in just a few events with relevant data
                if (string.Equals(userState.EventName, "OmaDmClientExeStart",
                                  StringComparison.CurrentCultureIgnoreCase) ||
                    string.Equals(userState.EventName, "OmaDmSyncmlVerboseTrace",
                                  StringComparison.CurrentCultureIgnoreCase))
                {
                    SyncMlProgress.NotInProgress = false;
                    LabelStatus.Visibility       = Visibility.Visible;

                    string eventDataText = null;
                    try
                    {
                        eventDataText = Encoding.UTF8.GetString(userState.EventData());
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    if (eventDataText == null)
                    {
                        return;
                    }

                    var startIndex = eventDataText.IndexOf("<SyncML", StringComparison.CurrentCultureIgnoreCase);
                    if (startIndex == -1)
                    {
                        return;
                    }

                    var valueSyncMl =
                        TryFormatXml(eventDataText.Substring(startIndex, eventDataText.Length - startIndex - 1));

                    if (TextEditorStream.Text.Length == 0)
                    {
                        TextEditorStream.AppendText(valueSyncMl + Environment.NewLine);
                    }
                    else
                    {
                        TextEditorStream.AppendText(Environment.NewLine + valueSyncMl + Environment.NewLine);
                    }

                    TextEditorMessages.Text = valueSyncMl;
                    _foldingStrategy.UpdateFoldings(_foldingManager, TextEditorMessages.Document);

                    var valueSessionId = "0";
                    var matchSessionId = new Regex("<SessionID>([0-9a-zA-Z]+)</SessionID>").Match(valueSyncMl);
                    if (matchSessionId.Success)
                    {
                        valueSessionId = matchSessionId.Groups[1].Value;
                    }

                    if (!SyncMlSessions.Any(item => item.SessionId == valueSessionId))
                    {
                        var syncMlSession = new SyncMlSession(valueSessionId);
                        SyncMlSessions.Add(syncMlSession);
                        SyncMlMlMessages.Clear();
                    }

                    var valueMsgId = "0";
                    var matchMsgId = new Regex("<MsgID>([0-9]+)</MsgID>").Match(valueSyncMl);
                    if (matchMsgId.Success)
                    {
                        valueMsgId = matchMsgId.Groups[1].Value;
                    }

                    var syncMlMessage = new SyncMlMessage(valueSessionId, valueMsgId, valueSyncMl);
                    SyncMlSessions.FirstOrDefault(item => item.SessionId == valueSessionId)?.Messages
                    .Add(syncMlMessage);
                    SyncMlMlMessages.Add(syncMlMessage);
                }
                else if (string.Equals(userState.EventName, "OmaDmSessionStart",
                                       StringComparison.CurrentCultureIgnoreCase))
                {
                    TextEditorStream.AppendText("<!--- OmaDmSessionStart --->" + Environment.NewLine);
                }
                else if (string.Equals(userState.EventName, "OmaDmSessionComplete",
                                       StringComparison.CurrentCultureIgnoreCase))
                {
                    TextEditorStream.AppendText(Environment.NewLine + "<!--- OmaDmSessionComplete --->" +
                                                Environment.NewLine);
                    SyncMlProgress.NotInProgress = true;
                    LabelStatus.Visibility       = Visibility.Hidden;
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
Пример #6
0
        private void MenuItemOpen_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                Filter           = "Xml files|*.xml|All files|*.*",
                FilterIndex      = 0,
                RestoreDirectory = true,
                Title            = "Open SyncML stream",
            };

            if (openFileDialog.ShowDialog() == true)
            {
                TextEditorStream.Clear();
                TextEditorMessages.Clear();

                SyncMlSessions.Clear();

                var fileStream = openFileDialog.OpenFile();
                using (StreamReader reader = new StreamReader(fileStream))
                {
                    TextEditorStream.Text = reader.ReadToEnd();
                }

                if (TextEditorStream.Text.Length > 0)
                {
                    var syncMlMessages = Regex.Matches(TextEditorStream.Text, @"<SyncML[\s\S]*?</SyncML>", RegexOptions.IgnoreCase);
                    foreach (Match message in syncMlMessages)
                    {
                        var valueSyncMl = TryFormatXml(message.Value);

                        TextEditorMessages.Text = valueSyncMl;
                        _foldingStrategy.UpdateFoldings(_foldingManager, TextEditorMessages.Document);

                        var valueSessionId = "0";
                        var matchSessionId = new Regex("<SessionID>([0-9a-zA-Z]+)</SessionID>", RegexOptions.IgnoreCase).Match(valueSyncMl);
                        if (matchSessionId.Success)
                        {
                            valueSessionId = matchSessionId.Groups[1].Value;
                        }

                        if (!SyncMlSessions.Any(item => item.SessionId == valueSessionId))
                        {
                            var syncMlSession = new SyncMlSession(valueSessionId);
                            SyncMlSessions.Add(syncMlSession);
                        }

                        var valueMsgId = "0";
                        var matchMsgId = new Regex("<MsgID>([0-9]+)</MsgID>", RegexOptions.IgnoreCase).Match(valueSyncMl);
                        if (matchMsgId.Success)
                        {
                            valueMsgId = matchMsgId.Groups[1].Value;
                        }

                        var syncMlMessage = new SyncMlMessage(valueSessionId, valueMsgId, valueSyncMl);
                        SyncMlSessions.FirstOrDefault(item => item.SessionId == valueSessionId)?.Messages
                        .Add(syncMlMessage);
                    }
                }
            }
        }