Example #1
0
        internal void Filter(TxReader reader)
        {
            var func = this.GetViewFilter(reader);

            int count = 0;

            if (func == null)
            {
                this.CurrenView.Filter = TrueFilter;
            }
            else
            {
                EventRecordProxy previous = null;
                this.CurrenView.Filter = (e) =>
                {
                    EventRecordProxy curr = (EventRecordProxy)e;
                    if (func(curr))
                    {
                        curr.Previous = previous;
                        previous      = curr;
                        count++;
                        return(true);
                    }

                    return(false);
                };
            }

            this.FilteredRowCount = count;
        }
Example #2
0
        IEnumerable<DataGridColumn> SearchRow(EventRecordProxy proxy, string pattern)
        {
            if (proxy.Id.ToString().IndexOf(pattern, 0, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                yield return GridColumns["Id"];
            }

            if (GuidToStringConverter.ToString(proxy.ActivityId).IndexOf(pattern, 0, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                yield return GridColumns["ActivityId"];
            }

            if (GuidToStringConverter.ToString(proxy.RelatedActivityId).IndexOf(pattern, 0, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                yield return GridColumns["RelatedActivityId"];
            }

            if (proxy.Symbol.IndexOf(pattern, 0, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                yield return GridColumns["Symbol"];
            }

            if (proxy.Message.IndexOf(pattern, 0, StringComparison.OrdinalIgnoreCase) >= 0)
            {
                yield return GridColumns["Message"];
            }
        }
Example #3
0
        private static bool GetSelectedInterval(out DateTime? max, out DateTime? min, DataGrid grid)
        {
            max = DateTime.MinValue;
            min = DateTime.MaxValue;
            int count = 0;
            foreach (var item in grid.SelectedCells)
            {
                var record = item.Item as EventRecordProxy;
                EventRecordProxy evt = record != null ? record : null;
                if (evt == null)
                {
                    continue;
                }
                if (evt.TimeStamp != null && evt.TimeStamp > max)
                {
                    max = evt.TimeStamp;
                }

                if (evt.TimeStamp != null && evt.TimeStamp < min)
                {
                    min = evt.TimeStamp;
                }
                count++;
            }

            if (count == 0)
            {
                max = DateTime.MinValue;
                min = DateTime.MaxValue;
            }

            return count != 0;
        }
Example #4
0
 internal void Select(EventRecordProxy eventRecordProxy)
 {
     if (eventRecordProxy != null)
     {
         this.CurrenView.MoveCurrentTo(eventRecordProxy);
         this.CurrentRow = this.CurrenView.CurrentPosition.ToString();
     }
 }
Example #5
0
 public static Resolver GetResolver(EventRecordProxy evt)
 {
     Resolver resolver;
     if (SymbolHelper.TryGetValue(evt.ProviderId, out resolver))
     {
         return resolver;
     }
     return SymbolHelper.Empty;
 }
Example #6
0
        public static Resolver GetResolver(EventRecordProxy evt)
        {
            Resolver resolver;

            if (SymbolHelper.TryGetValue(evt.ProviderId, out resolver))
            {
                return(resolver);
            }
            return(SymbolHelper.Empty);
        }
Example #7
0
        void gridEvents_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Guid activity = Guid.Empty;
            DateTime? max;
            DateTime? min;
            DataGrid grid = sender as DataGrid;
            if (grid == null)
            {
                return;
            }

            DependencyObject dep = e.OriginalSource as DependencyObject;
            DataGridCell cell;
            DataGridRow row;
            dep = GetCellRow(dep, out cell, out row);

            if (cell != null && row != null)
            {
                EventRecordProxy record = row.Item as EventRecordProxy;
                if (record == null)
                {
                    return;
                }

                if (cell.Column.Header.ToString() == "ActivityId")
                {
                    activity = record.ActivityId;
                }
                else if (cell.Column.Header.ToString() == "RelatedActivityId")
                {
                    activity = record.RelatedActivityId;
                }
            }

            if (this.gridEvents.SelectedCells.Count > 1)
            {
                if (GetSelectedInterval(out max, out min, grid))
                {
                    if (this.OnRangeSelected != null)
                    {
                        this.OnRangeSelected(new TimeSpan(min.Value.Ticks), new TimeSpan(max.Value.Ticks));
                    }
                    this.Model.SelectedTimeWindow = new TimeSpan(max.Value.Subtract(min.Value).Ticks);
                }
            }
            else
            {
                this.Model.SelectedTimeWindow = TimeSpan.MinValue;
            }

            if (activity != Guid.Empty)
            {
                this.Model.HighlightText = activity.ToString();
            }
        }
Example #8
0
            public bool MoveNext()
            {
                bool canmove = this.inner.MoveNext();

                if (canmove)
                {
                    this.current = (EventRecordProxy)this.inner.Current;
                    this.current.Previous = previous;
                    previous = this.current;
                }
                return canmove;
            }
Example #9
0
        void eventsGrid_OnCellCopy(string filter, EventRecordProxy arg2)
        {
            if (String.IsNullOrEmpty(this.FilterModel.FilterText))
            {
                this.FilterModel.FilterText = filter;
            }
            else
            {
                this.FilterModel.FilterText += " and " + filter;
            }

            //Ensure after you set the text to hide watermark;
            this.EnsureFindPanel();
        }
Example #10
0
 void gridEvents_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     object source = e.OriginalSource;
     DependencyObject dep = DataGridUtil.GetDataGridRow(source);
     DataGridRow row = dep as DataGridRow;
     if (row != null)
     {                
         EventRecordProxy item = row.Item as EventRecordProxy;
         if (item != null)
         {
             this.detailsWindow.Title = "EVENT DETAILS ROW " + row.Header;
             this.detailsWindow.DataContext = item.Details.ToString();
             if (!this.detailsWindow.IsVisible || !this.detailsWindow.IsActive)
             {
                 this.detailsWindow.Show();
                 this.detailsWindow.Activate();
             }
         }
     }
 }
Example #11
0
        public IEnumerable<int> FindTextInEventsTable(string pattern)
        {
            if (String.IsNullOrEmpty(pattern) || this.gridEvents.Items == null || this.gridEvents.Items.Count == 0)
            {
                this.Model.HighlightText = string.Empty;
                yield return -1;
            }

            int startIndex = 0;
            if (this.Model.CurrenView.CurrentPosition >= 0)
            {
                startIndex = this.Model.CurrenView.CurrentPosition;
            }

            this.Model.HighlightText = pattern;
            for (int i = startIndex; i < this.gridEvents.Items.Count; i++)
            {
                EventRecordProxy proxy = this.gridEvents.Items[i] as EventRecordProxy;

                foreach (var column in this.SearchRow(proxy, pattern))
                {
                    this.Model.CurrentRow = i.ToString();
                    this.gridEvents.SelectedCells.Clear();
                    DataGridCellInfo cellInfo = new DataGridCellInfo(proxy, column);
                    this.gridEvents.SelectedCells.Add(cellInfo);
                    this.gridEvents.ScrollIntoView(proxy);
                    this.Model.CurrenView.MoveCurrentTo(proxy);
                    yield return i;

                }
            }

            if (this.gridEvents.Items.Count > 0)
            {
                //this.gridEvents.SelectedItem = this.gridEvents.Items[0];
                //this.gridEvents.ScrollIntoView(this.gridEvents.Items[0]);
                //this.Model.CurrentRow = "0";
            }

            yield return -1;
        }
Example #12
0
        protected override bool TryGetProperty <T>(EventRecordProxy <EventLogRecord> .Field field, out T propertyValue)
        {
            if (this.DataItem == null)
            {
                propertyValue = default(T);
                return(false);
            }

            object val = null;

            switch (field)
            {
            case Field.Id:
                val = this.DataItem.Id;
                break;

            case Field.ProcessId:
                val = this.DataItem.ProcessId;
                break;

            case Field.ThreadId:
                val = this.DataItem.ThreadId;
                break;

            case Field.TimeCreated:
                val = this.DataItem.TimeCreated;
                break;

            case Field.ActivityId:
                val = this.DataItem.ActivityId ?? Guid.Empty;
                break;

            case Field.RelatedActivityId:
                val = this.DataItem.RelatedActivityId ?? Guid.Empty;
                break;

            case Field.Message:
                val = this.DataItem.FormatDescription();
                break;

            case Field.Symbol:
                if (this.DataItem.ProviderId == TraceHelper.WcfProviderId)
                {
                    val = this.resolver.GetSymbolName(this.DataItem.Id);
                }
                else
                {
                    val = string.Empty;
                }
                break;

            case Field.Task:
                if (this.DataItem.Task != null)
                {
                    if (TaskDictionary.ContainsKey(this.DataItem.Task.Value))
                    {
                        val = TaskDictionary[this.DataItem.Task.Value];
                    }
                    else
                    {
                        string name = this.DataItem.TaskDisplayName;
                        TaskDictionary.Add(this.DataItem.Task.Value, name);
                        val = name;
                    }
                }
                break;

            case Field.ProviderName:
                val = this.DataItem.ProviderName;
                break;

            case Field.Opcode:
                val = this.DataItem.OpcodeDisplayName ?? string.Empty;
                break;

            case Field.Keywords:
                val = (ulong)(this.DataItem.Keywords ?? 0);
                break;

            case Field.Level:
                val = (int)this.DataItem.Level;
                break;

            case Field.ProviderId:
                val = this.DataItem.ProviderId ?? Guid.Empty;
                break;
            }

            propertyValue = (T)val;

            return(val != null);
        }
Example #13
0
        void RefreshGrid()
        {
            Logger.Log("Refreshing grid.");
            TxReader reader = this.Model.Reader;
            IList <EventRecordProxy> events = null;
            int bufferCount = reader.IsRealtime ? 1 : 1000;
            IObservable <EventRecordProxy> observable = null;
            IDisposable subscriber = null;
            TaskCompletionSource <object> eventLoading = new TaskCompletionSource <object>();
            TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();

            Action <IList <EventRecordProxy>, IList <EventRecordProxy> > AddRange = (list, data) =>
            {
                lock (list)
                {
                    EventRecordProxy prev = list.Count > 0 ? list[list.Count - 1] : null;
                    foreach (var item in data)
                    {
                        item.Previous = prev;
                        list.Add(item);
                        prev = item;
                    }
                }
            };

            Action onComplete = () =>
            {
                if (!eventLoading.Task.IsCompleted &&
                    !eventLoading.Task.IsFaulted)
                {
                    eventLoading.SetResult(null);
                }
            };

            try
            {
                observable = this.Model.GetObservable();
                // Starting grid loading
                this.Model.StartActivity("Loading events ....");
                if (reader.IsRealtime)
                {
                    events = new ObservableCollection <EventRecordProxy>();
                    this.EventsModel.Items         = events;
                    this.loadingAdorner.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    events = new List <EventRecordProxy>();
                    this.loadingAdorner.Message    = "Event loading in progress.";
                    this.loadingAdorner.Visibility = System.Windows.Visibility.Visible;
                }

                subscriber = observable
                             .Buffer(bufferCount)
                             // TODO why posting on the UI thread doesn't work
                             // .SubscribeOn(SynchronizationContext.Current)
                             .Finally(onComplete)
                             .Subscribe(loadedData =>
                {
                    try
                    {
                        if (reader.IsRealtime)
                        {
                            this.Post(() => AddRange(events, loadedData));
                        }
                        else
                        {
                            AddRange(events, loadedData);
                        }

                        this.Post(() =>
                        {
                            this.Model.LogActivity(string.Format("Loaded {0} events ", events.Count));
                        });
                    }
                    catch (Exception ex)
                    {
                        eventLoading.SetException(ex);
                    }
                },
                                        (exception) =>
                {
                    eventLoading.SetException(exception);
                    Logger.Log(exception);
                    this.Post(() =>
                    {
                        this.Model.StopActivity(exception.Message);
                    });
                });

                reader.StartPublish(observable);
            }
            catch (Exception ex)
            {
                eventLoading.SetException(ex);
            }


            eventLoading.Task.ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    Logger.Log(t.Exception);
                    this.Model.StopReaderCommand.Execute(null);
                    this.Model.StopActivity("Could not load events");
                    this.FilterModel.FilterException = t.Exception;
                    this.loadingAdorner.Visibility   = System.Windows.Visibility.Hidden;
                    return;
                }

                if (reader.IsRealtime)
                {
                    return;
                }
                else
                {
                    //Finally set the item source to avoid adding on bound item collection.
                    this.EventsModel.Items         = events;
                    this.loadingAdorner.Visibility = System.Windows.Visibility.Hidden;
                    this.Model.StopActivity(string.Format(
                                                "Loaded {0} in {1} seconds",
                                                events.Count,
                                                this.Model.ActivityDuration.TotalSeconds));

                    // Switch to View mode after filtering source automatically.
                    this.FilterModel.Mode = FilterMode.View;
                }
            }, scheduler);
        }
Example #14
0
        void eventsGrid_OnCellCopy(string filter, EventRecordProxy arg2)
        {
            if (String.IsNullOrEmpty(this.FilterModel.FilterText))
            {
                this.FilterModel.FilterText = filter;
            }
            else
            {
                this.FilterModel.FilterText += " and " + filter;
            }

            //Ensure after you set the text to hide watermark;
            this.EnsureFindPanel();
        }
Example #15
0
 internal void Select(EventRecordProxy eventRecordProxy)
 {
     if (eventRecordProxy != null)
     {
         this.CurrenView.MoveCurrentTo(eventRecordProxy);
         this.CurrentRow = this.CurrenView.CurrentPosition.ToString();
     }
 }