public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var atoms = value as IEnumerable <LogAtom>;

            if (atoms == null)
            {
                return(null);
            }

            // static columns: line, message
            int columns = matchers.Matchers.Count + 2;

            DataTable table    = new DataTable();
            Type      cellType = typeof(MetaValueVM);

            ObservableCollection <string> result = new ObservableCollection <string>();

            // Columns / Headers
            table.Columns.Add(new DataColumn("Line", cellType));

            int levelMeatValueIndex = -1;

            foreach (IMatcher <IComparable> matcher in matchers.Matchers)
            {
                if (matcher == matchers.LevelMatcherRef)
                {
                    levelMeatValueIndex = table.Columns.Count - 1;
                }
                table.Columns.Add(new DataColumn(matcher.Name, cellType));
            }
            table.Columns.Add(new DataColumn(matchers.RemainingLineMatcher.Name, cellType));

            // Rows / Data
            foreach (LogAtom logAtom in atoms)
            {
                // level settings
                RowSettings settings;
                if (levelMeatValueIndex != -1)
                {
                    IComparable levelValue = logAtom.MetaValues[levelMeatValueIndex];
                    settings = getRowSettings(levelValue);
                }
                else
                {
                    settings = new RowSettings();
                }

                if (settings.Show)
                {
                    string details;
                    if (logAtom.RawAdditionalLines != null)
                    {
                        details = String.Join("\n", logAtom.RawAdditionalLines);
                    }
                    else
                    {
                        details = "";
                    }
                    result.Add(details);
                }
            }
            return(table.DefaultView);
        }
Exemplo n.º 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var atoms = value as IEnumerable <LogAtom>;

            if (atoms == null)
            {
                return(null);
            }

            // static columns: line, message
            int columns = matchers.Matchers.Count + 2;

            DataTable table    = new DataTable();
            Type      cellType = typeof(MetaValueVM);

            // Columns / Headers
            table.Columns.Add(new DataColumn("Line", cellType));

            int levelMeatValueIndex = -1;

            foreach (IMatcher <IComparable> matcher in matchers.Matchers)
            {
                if (matcher == matchers.LevelMatcherRef)
                {
                    levelMeatValueIndex = table.Columns.Count - 1;
                }
                table.Columns.Add(new DataColumn(matcher.Name, cellType));
            }
            table.Columns.Add(new DataColumn(matchers.RemainingLineMatcher.Name, cellType));

            Console.WriteLine(levelMeatValueIndex);

            // Rows / Data
            foreach (LogAtom logAtom in atoms)
            {
                DataRow newRow = table.NewRow();

                // level settings
                RowSettings settings;
                if (levelMeatValueIndex != -1)
                {
                    IComparable levelValue = logAtom.MetaValues[levelMeatValueIndex];
                    settings = getRowSettings(levelValue);
                }
                else
                {
                    settings = new RowSettings();
                }

                if (settings.Show)
                {
                    // cells
                    newRow[0] = new MetaValueVM()
                    {
                        Brush = new SolidColorBrush(settings.Color),
                        Value = logAtom.LineNumber
                    };

                    for (int c = 0; c < columns - 1; c++)
                    {
                        IComparable atomValue;
                        if (c >= logAtom.MetaValues.Count)
                        {
                            atomValue = "Parse Error!";
                        }
                        else
                        {
                            atomValue = logAtom.MetaValues[c];
                        }
                        newRow[c + 1] = new MetaValueVM()
                        {
                            Value = atomValue,
                            Brush = new SolidColorBrush(settings.Color)
                        };
                    }

                    table.Rows.Add(newRow);
                }
            }
            return(table.DefaultView);
        }