public RowItem Pivot(TickCounter tickCounter, RowItem rowItem) { foreach (var pivotColumn in PivotColumns) { var parent = pivotColumn.Parent.CollectionAncestor(); IList <PivotKey> pivotKeys; if (null == parent) { pivotKeys = new PivotKey[] { null }; } else { pivotKeys = rowItem.PivotKeys.Where(key => key.Last.Key.Equals(parent.PropertyPath)).ToArray(); } foreach (var pivotKey in pivotKeys) { var parentValue = pivotColumn.Parent.GetPropertyValue(rowItem, pivotKey); if (null != parentValue) { var keys = pivotColumn.CollectionInfo.GetKeys(parentValue).Cast <object>().ToArray(); if (keys.Length > 0) { var newPivotKeys = rowItem.PivotKeys.Except(new[] { pivotKey }).ToList(); var pivotKeyLocal = pivotKey ?? PivotKey.EMPTY; var propertyPath = pivotColumn.PropertyPath; newPivotKeys.AddRange(keys.Select(key => pivotKeyLocal.AppendValue(propertyPath, key))); rowItem = rowItem.SetPivotKeys(new HashSet <PivotKey>(newPivotKeys)); } } } } return(rowItem); }
public GroupedPropertyDescriptor(string name, PivotKey outerPivotKey, DisplayColumn displayColumn, PivotKey innerPivotKey) : base(name, displayColumn.GetAttributes(MergePivotKeys(outerPivotKey, innerPivotKey)).ToArray()) { OuterPivotKey = outerPivotKey; InnerPivotKey = innerPivotKey; DisplayColumn = displayColumn; }
public ColumnPropertyDescriptor(DisplayColumn displayColumn, string name, PropertyPath propertyPath, PivotKey pivotKey) : base(name, displayColumn.GetAttributes(pivotKey).ToArray()) { DisplayColumn = displayColumn; PropertyPath = propertyPath; PivotKey = pivotKey; }
public object GetValue(RowItem rowItem, PivotKey pivotKey) { if (rowItem == null) { return null; } if (ColumnDescriptor == null) { return "#COLUMN " + PropertyPath + " NOT FOUND#"; // Not L10N } return ColumnDescriptor.GetPropertyValue(rowItem, pivotKey); }
public IEnumerable <DataPropertyDescriptor> GetItemProperties(IEnumerable <RowItem> rowItems) { var columnNames = new HashSet <string>(); var propertyDescriptors = new List <DataPropertyDescriptor>(); var pivotDisplayColumns = new Dictionary <PivotKey, List <DisplayColumn> >(); var rowItemsArray = rowItems as RowItem[] ?? rowItems.ToArray(); foreach (var displayColumn in ViewInfo.DisplayColumns) { if (displayColumn.ColumnSpec.Hidden) { continue; } var pivotColumn = PivotColumns.LastOrDefault(pc => displayColumn.PropertyPath.StartsWith(pc.PropertyPath)); ICollection <PivotKey> pivotKeys = null; if (pivotColumn != null) { pivotKeys = GetPivotKeys(pivotColumn.PropertyPath, rowItemsArray); } if (pivotKeys == null) { propertyDescriptors.Add(new ColumnPropertyDescriptor(displayColumn, MakeUniqueName(columnNames, displayColumn.PropertyPath))); continue; } foreach (var value in pivotKeys) { List <DisplayColumn> columns; if (!pivotDisplayColumns.TryGetValue(value, out columns)) { columns = new List <DisplayColumn>(); pivotDisplayColumns.Add(value, columns); } columns.Add(displayColumn); } } var allPivotKeys = pivotDisplayColumns.Keys.ToArray(); Array.Sort(allPivotKeys, PivotKey.GetComparer(ViewInfo.DataSchema)); foreach (var pivotKey in allPivotKeys) { foreach (var pivotColumn in pivotDisplayColumns[pivotKey]) { var qualifiedPropertyPath = PivotKey.QualifyPropertyPath(pivotKey, pivotColumn.PropertyPath); var columnName = MakeUniqueName(columnNames, qualifiedPropertyPath); propertyDescriptors.Add(new ColumnPropertyDescriptor(pivotColumn, columnName, qualifiedPropertyPath, pivotKey)); } } return(propertyDescriptors); }
public string GetColumnCaption(PivotKey pivotKey, ColumnCaptionType columnCaptionType) { string columnCaption; if (null != ColumnSpec.Caption) { columnCaption = ColumnSpec.Caption; } else if (null == ColumnDescriptor) { columnCaption = PropertyPath.ToString(); } else { columnCaption = DataSchema.GetColumnCaption(DataSchema.GetColumnCaption(ColumnDescriptor), columnCaptionType); } return QualifyColumnCaption(pivotKey, columnCaption); }
private static PivotKey MergePivotKeys(PivotKey outerPivotKey, PivotKey innerPivotKey) { if (outerPivotKey == null) { return(innerPivotKey); } else { if (innerPivotKey == null) { return(outerPivotKey); } else { return(outerPivotKey.Concat(innerPivotKey)); } } }
public static string QualifyColumnCaption(PivotKey pivotKey, string columnCaption) { if (null == pivotKey) { return columnCaption; } StringBuilder prefix = new StringBuilder(); foreach (var kvp in pivotKey.KeyPairs) { if (prefix.Length > 0) { prefix.Append(" "); // Not L10N } prefix.Append(kvp.Value ?? string.Empty); } if (prefix.Length == 0) { return columnCaption; } return prefix + " " + columnCaption; // Not L10N }
public override object GetPropertyValue(RowItem rowItem, PivotKey pivotKey) { var collection = Parent.GetPropertyValue(rowItem, pivotKey); if (null == collection) { return null; } object key = rowItem.RowKey.FindValue(PropertyPath); if (null == key && null != pivotKey) { key = pivotKey.FindValue(PropertyPath); } if (null == key) { return null; } return _collectionInfo.GetItemFromKey(collection, key); }
public GroupedPropertyDescriptor(string name, DisplayColumn displayColumn, PivotKey innerPivotKey) : this(name, null, displayColumn, innerPivotKey) { }
public bool TryGetInnerRow(PivotKey key, out RowItem row) { return(_innerRows.TryGetValue(key, out row)); }
public bool ContainsKey(PivotKey key) { return(_innerRows.ContainsKey(key)); }
public override void SetValue(RowItem rowItem, PivotKey pivotKey, object value) { var parentComponent = Parent.GetPropertyValue(rowItem, pivotKey); if (parentComponent == null) { return; } _propertyDescriptor.SetValue(parentComponent, value); }
public void AddInnerRow(PivotKey key, RowItem innerRow) { _innerRows.Add(key, innerRow); }
public override object GetPropertyValue(RowItem rowItem, PivotKey pivotKey) { if (null != pivotKey) { if (!rowItem.PivotKeys.Contains(pivotKey)) { return null; } } return rowItem.Value; }
public abstract object GetPropertyValue(RowItem rowItem, PivotKey pivotKey);
public IEnumerable<Attribute> GetAttributes(PivotKey pivotKey) { if (null == ColumnDescriptor) { return new Attribute[0]; } var overrideAttributes = new Attribute[] {new DisplayNameAttribute(GetColumnCaption(pivotKey, ColumnCaptionType.localized))}; var mergedAttributes = AttributeCollection.FromExisting(new AttributeCollection(ColumnDescriptor.GetAttributes().ToArray()), overrideAttributes); return mergedAttributes.Cast<Attribute>(); }
public void SetValue(RowItem rowItem, PivotKey pivotKey, object value) { if (IsReadOnly) { throw new InvalidOperationException(Resources.DisplayColumn_SetValue_Column_is_read_only); } ColumnDescriptor.SetValue(rowItem, pivotKey, value); }
public virtual void SetValue(RowItem rowItem, PivotKey pivotKey, object value) { }
private static PivotKey MergePivotKeys(PivotKey outerPivotKey, PivotKey innerPivotKey) { if (outerPivotKey == null) { return innerPivotKey; } else { if (innerPivotKey == null) { return outerPivotKey; } else { return outerPivotKey.Concat(innerPivotKey); } } }
public bool ContainsKey(PivotKey key) { return _innerRows.ContainsKey(key); }
public RowItem SetRowKey(PivotKey rowKey) { return new RowItem(this){RowKey = rowKey}; }
public RowItem(object value, PivotKey rowKey, IEnumerable<PivotKey> pivotKeys) { Value = value; RowKey = rowKey; PivotKeys = ImmutableList.ValueOf(pivotKeys); }
public bool TryGetInnerRow(PivotKey key, out RowItem row) { return _innerRows.TryGetValue(key, out row); }
public override object GetPropertyValue(RowItem rowItem, PivotKey pivotKey) { object parentValue = Parent.GetPropertyValue(rowItem, pivotKey); if (null == parentValue) { return null; } try { return _propertyDescriptor.GetValue(parentValue); } catch { return null; } }
public RowItem Pivot(TickCounter tickCounter, RowItem rowItem) { foreach (var pivotColumn in PivotColumns) { var parent = pivotColumn.Parent.CollectionAncestor(); IList<PivotKey> pivotKeys; if (null == parent) { pivotKeys = new PivotKey[] { null }; } else { pivotKeys = rowItem.PivotKeys.Where(key => key.Last.Key.Equals(parent.PropertyPath)).ToArray(); } foreach (var pivotKey in pivotKeys) { var parentValue = pivotColumn.Parent.GetPropertyValue(rowItem, pivotKey); if (null != parentValue) { var keys = pivotColumn.CollectionInfo.GetKeys(parentValue).Cast<object>().ToArray(); if (keys.Length > 0) { var newPivotKeys = rowItem.PivotKeys.Except(new[] {pivotKey}).ToList(); var pivotKeyLocal = pivotKey ?? PivotKey.EMPTY; var propertyPath = pivotColumn.PropertyPath; newPivotKeys.AddRange(keys.Select(key => pivotKeyLocal.AppendValue(propertyPath, key))); rowItem = rowItem.SetPivotKeys(new HashSet<PivotKey>(newPivotKeys)); } } } } return rowItem; }
public ReportResults GroupAndTotal(CancellationToken cancellationToken, ReportResults pivotedRows) { IDictionary <IList <Tuple <PropertyPath, PivotKey, object> >, List <GroupedRow> > allReportRows = new Dictionary <IList <Tuple <PropertyPath, PivotKey, object> >, List <GroupedRow> >(); var groupColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.GroupBy == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var pivotOnColumns = ViewInfo.DisplayColumns .Where(col => TotalOperation.PivotKey == col.ColumnSpec.TotalOperation) .Select(col => col.ColumnDescriptor) .ToArray(); var allInnerPivotKeys = new HashSet <PivotKey>(); var allPivotKeys = new Dictionary <PivotKey, PivotKey>(); foreach (var rowItem in pivotedRows.RowItems) { cancellationToken.ThrowIfCancellationRequested(); allInnerPivotKeys.UnionWith(rowItem.PivotKeys); IList <Tuple <PropertyPath, PivotKey, object> > groupKey = new List <Tuple <PropertyPath, PivotKey, object> >(); foreach (var column in groupColumns) { cancellationToken.ThrowIfCancellationRequested(); var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { groupKey.Add(new Tuple <PropertyPath, PivotKey, object>(column.PropertyPath, null, column.GetPropertyValue(rowItem, null))); } else { foreach (var pivotKey in GetPivotKeys(pivotColumn.PropertyPath, new [] { rowItem })) { cancellationToken.ThrowIfCancellationRequested(); if (!pivotKey.Contains(pivotColumn.PropertyPath)) { continue; } groupKey.Add(new Tuple <PropertyPath, PivotKey, object>(column.PropertyPath, pivotKey, column.GetPropertyValue(rowItem, pivotKey))); } } } groupKey = ImmutableList.ValueOf(groupKey); var pivotOnKeyValues = new List <KeyValuePair <PropertyPath, object> >(); foreach (var column in pivotOnColumns) { cancellationToken.ThrowIfCancellationRequested(); var pivotColumn = GetPivotColumn(column); if (null == pivotColumn) { pivotOnKeyValues.Add(new KeyValuePair <PropertyPath, object>(column.PropertyPath, column.GetPropertyValue(rowItem, null))); } else { Trace.TraceWarning(@"Unable to pivot on column {0} because it is already pivoted.", pivotColumn.PropertyPath); } } var pivotOnKey = PivotKey.GetPivotKey(allPivotKeys, pivotOnKeyValues); List <GroupedRow> rowGroups; if (!allReportRows.TryGetValue(groupKey, out rowGroups)) { rowGroups = new List <GroupedRow>(); allReportRows.Add(groupKey, rowGroups); } var rowGroup = rowGroups.FirstOrDefault(rg => !rg.ContainsKey(pivotOnKey)); if (null == rowGroup) { rowGroup = new GroupedRow(); rowGroups.Add(rowGroup); } rowGroup.AddInnerRow(pivotOnKey, rowItem); } var outerPivotKeys = allPivotKeys.Keys.Where(key => key.Length == pivotOnColumns.Length).ToArray(); var pivotKeyComparer = PivotKey.GetComparer(ViewInfo.DataSchema); Array.Sort(outerPivotKeys, pivotKeyComparer); var innerPivotKeys = allInnerPivotKeys.ToArray(); Array.Sort(innerPivotKeys, pivotKeyComparer); var reportItemProperties = new List <DataPropertyDescriptor>(); var propertyNames = new HashSet <string>(); foreach (var displayColumn in ViewInfo.DisplayColumns) { cancellationToken.ThrowIfCancellationRequested(); if (displayColumn.ColumnSpec.Hidden) { continue; } var totalOperation = displayColumn.ColumnSpec.TotalOperation; if (TotalOperation.GroupBy == totalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, null)); } else { foreach (var innerPivotKey in innerPivotKeys) { cancellationToken.ThrowIfCancellationRequested(); string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, displayColumn, innerPivotKey)); } } } } foreach (var outerPivotKey in outerPivotKeys) { foreach (var displayColumn in ViewInfo.DisplayColumns) { cancellationToken.ThrowIfCancellationRequested(); if (displayColumn.ColumnSpec.Hidden) { continue; } if (TotalOperation.PivotValue == displayColumn.ColumnSpec.TotalOperation || TotalOperation.PivotKey == displayColumn.ColumnSpec.TotalOperation) { var pivotColumn = GetPivotColumn(displayColumn.ColumnDescriptor); if (null == pivotColumn) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, null)); } else { foreach (var innerPivotKey in allInnerPivotKeys) { string propertyName = MakeUniqueName(propertyNames, displayColumn.PropertyPath); reportItemProperties.Add(new GroupedPropertyDescriptor(propertyName, outerPivotKey, displayColumn, innerPivotKey)); } } } } } return(new ReportResults(allReportRows.SelectMany(entry => entry.Value.Select( reportRow => new RowItem(reportRow))), reportItemProperties)); }