private void CheckEnumerator(ICustomEnumerator enumerator, int count) { Assert.AreEqual(count, enumerator.RowCount); IList <object> result = new List <object>(); while (enumerator.MoveNext()) { result.Add(enumerator.Current); } Assert.AreEqual(count, result.Count); Assert.AreEqual(count, enumerator.RowCount); enumerator.Reset(); result.Clear(); Assert.AreEqual(count, enumerator.RowCount); while (enumerator.MoveNext()) { result.Add(enumerator.Current); } Assert.AreEqual(count, result.Count); Assert.AreEqual(count, enumerator.RowCount); }
public override void Render() { // Receive parent data item context HierarchicalDataItem parentDataItem = GetDataContext(); _data = _isDataReceivedDirectly ? _data : _templateProcessor.GetValue(_dataSourceTemplate, parentDataItem); bool isCanceled = CallBeforeRenderMethod(); if (isCanceled) { ResultRange = ExcelHelper.CloneRange(Range); return; } ICustomEnumerator enumerator = null; try { enumerator = EnumeratorFactory.Create(_data) ?? new EnumerableEnumerator(new object[] { }); IDictionary <IXLCell, IList <ParsedAggregationFunc> > totalCells = ParseTotalCells(); DoAggregation(enumerator, totalCells.SelectMany(t => t.Value).ToArray(), parentDataItem); IXLWorksheet ws = Range.Worksheet; dynamic dataSource = new ExpandoObject(); var dataSourceAsDict = (IDictionary <string, object>)dataSource; foreach (KeyValuePair <IXLCell, IList <ParsedAggregationFunc> > totalCell in totalCells) { IList <ParsedAggregationFunc> aggFuncs = totalCell.Value; foreach (ParsedAggregationFunc f in aggFuncs) { dataSourceAsDict[$"AggFunc_{f.UniqueName}"] = f.Result; } } string rangeName = $"AggFuncs_{Guid.NewGuid():N}"; Range.AddToNamed(rangeName, XLScope.Worksheet); var dataPanel = new ExcelDataSourcePanel(new[] { dataSource }, ws.NamedRange(rangeName), _report, _templateProcessor) { Parent = Parent }; dataPanel.Render(); ResultRange = ExcelHelper.MergeRanges(Range, dataPanel.ResultRange); } finally { (enumerator as IDisposable)?.Dispose(); } RemoveName(); CallAfterRenderMethod(); }
public override void Render() { // Receive parent data item context HierarchicalDataItem parentDataItem = GetDataContext(); _data = _isDataReceivedDirectly ? _data : _templateProcessor.GetValue(_dataSourceTemplate, parentDataItem); bool isCanceled = CallBeforeRenderMethod(); if (isCanceled) { ResultRange = ExcelHelper.CloneRange(Range); return; } ICustomEnumerator enumerator = null; try { enumerator = EnumeratorFactory.Create(_data); // Removing the template if there are no data if (enumerator == null || enumerator.RowCount == 0) { DeletePanel(this); return; } // Creating the panel template which will be replicated then ExcelDataItemPanel templatePanel = CreateTemplatePanel(); _templatePanelRowCount = templatePanel.Range.RowCount(); _templatePanelColumnCount = templatePanel.Range.ColumnCount(); // Allocating space for data if (enumerator.RowCount > 1) { AllocateSpaceForData(templatePanel, enumerator.RowCount); } int rowNum = 0; while (enumerator.MoveNext()) { object currentItem = enumerator.Current; ExcelDataItemPanel currentPanel; if (rowNum != enumerator.RowCount - 1) { IXLCell templateFirstCell = templatePanel.Range.FirstCell(); // The template itself is moved down or right, depending on the type of panel MoveTemplatePanel(templatePanel); // Copying the template on its previous place for the panel which the current data item will be rendered in currentPanel = (ExcelDataItemPanel)templatePanel.Copy(templateFirstCell); } else { // Rendering data directly in the template if there is the last data item currentPanel = templatePanel; } currentPanel.DataItem = new HierarchicalDataItem { Value = currentItem, Parent = parentDataItem }; // Fill template with data currentPanel.Render(); ResultRange = ExcelHelper.MergeRanges(ResultRange, currentPanel.ResultRange); RemoveAllNamesRecursive(currentPanel); rowNum++; } RemoveName(); } finally { (enumerator as IDisposable)?.Dispose(); } GroupResult(); CallAfterRenderMethod(); }