Browse Source

Remove Elementype from Reportingfactora and CollectionDataSource

Cleanup
reports
Peter Forstmeier 12 years ago
parent
commit
f67a2b8920
  1. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj
  2. 96
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs
  3. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs
  4. 27
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs
  5. 8
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs
  6. 10
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs
  7. 12
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs
  8. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs
  9. 7
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj

@ -132,7 +132,7 @@ @@ -132,7 +132,7 @@
<Compile Include="Src\Globals\StandardFormatter.cs" />
<Compile Include="Src\Globals\StringHelper.cs" />
<Compile Include="Src\Globals\TypeHelper.cs" />
<Compile Include="Src\Interfaces\Data\IDataViewHandling.cs" />
<Compile Include="Src\Interfaces\Data\IDataSource.cs" />
<Compile Include="Src\Interfaces\Export\IExportColumn.cs" />
<Compile Include="Src\Interfaces\Export\IExportContainer.cs" />
<Compile Include="Src\Interfaces\Export\IPage.cs" />

96
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
Sorted,
Grouped
}
public class CollectionDataSource:IDataViewHandling
public class CollectionDataSource:IDataSource
{
@ -36,7 +36,22 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -36,7 +36,22 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
readonly PropertyDescriptorCollection listProperties;
OrderGroup orderGroup;
public CollectionDataSource(IEnumerable list, ReportSettings reportSettings)
{
if (list == null)
throw new ArgumentNullException("list");
if (reportSettings == null)
throw new ArgumentNullException("reportSettings");
baseList = CreateBaseList(list);
CurrentList = baseList;
this.reportSettings = reportSettings;
this.listProperties = this.baseList.GetItemProperties(null);
orderGroup = OrderGroup.AsIs;
}
[Obsolete("use public CollectionDataSource(IEnumerable list, ReportSettings reportSettings")]
public CollectionDataSource(IEnumerable list, Type elementType, ReportSettings reportSettings)
{
if (list == null)
@ -44,8 +59,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -44,8 +59,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
if (reportSettings == null)
throw new ArgumentNullException("reportSettings");
baseList = CreateBaseList(list, elementType);
//test
baseList = CreateBaseList(list);
CurrentList = baseList;
this.elementType = elementType;
@ -57,13 +72,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -57,13 +72,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
public IndexList IndexList {
get {
throw new NotImplementedException();
}
}
public Collection<AbstractColumn> AvailableFields {
get {
var availableFields = new Collection<AbstractColumn>();
@ -73,23 +81,23 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -73,23 +81,23 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return availableFields;
}
}
//test
public IList <object> CurrentList {get;private set;}
public int Count {
get {
return baseList.Count;
}
}
public int CurrentPosition {get;set;}
public object Current {get; private set;}
public object Current {get; set;}
#region Sort
public void Sort()
void Sort()
{
if (reportSettings.SortColumnsCollection.Count > 0) {
var sorted = SortInternal();
@ -97,15 +105,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -97,15 +105,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = sorted.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("sort CurrentPosition {0}",CurrentPosition);
} else {
orderGroup = OrderGroup.AsIs;
listEnumerator = baseList.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("asis CurrentPosition {0}",CurrentPosition);
}
}
@ -125,7 +129,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -125,7 +129,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
#region Grouping
public void Group()
void Group()
{
orderGroup = OrderGroup.Grouped;
groupedList = GroupInternal();
@ -134,8 +138,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -134,8 +138,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = groupEnumerator.Current.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("group CurrentPosition {0}",CurrentPosition);
}
@ -198,32 +200,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -198,32 +200,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return p.PropertyType;
}
/*
public bool MoveNext()
{
if (orderGroup == OrderGroup.Grouped) {
var canMove = listEnumerator.MoveNext();
if (! canMove) {
var groupCanMove = groupEnumerator.MoveNext();
if (groupCanMove) {
listEnumerator = groupEnumerator.Current.GetEnumerator();
canMove = listEnumerator.MoveNext();
Current = listEnumerator.Current;
} else {
Console.WriteLine("end");
}
} else {
Current = listEnumerator.Current;
}
return canMove;
} else {
var b = listEnumerator.MoveNext();
Current = listEnumerator.Current;
return b;
}
}
*/
public bool MoveNext()
{
@ -245,38 +221,18 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -245,38 +221,18 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
}
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("CurrentPosition {0}",CurrentPosition);
return canMove;
}
#endregion
public void Reset()
{
throw new NotImplementedException();
}
static DataCollection<object> CreateBaseList(IEnumerable source, Type elementType)
static DataCollection<object> CreateBaseList(IEnumerable source)
{
var list = new DataCollection<object>(elementType);
Type et = source.AsQueryable().ElementType;
var list = new DataCollection<object>(et);
list.AddRange(source);
return list;
}
/*
PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){
if (listAccessors != null && listAccessors.Length > 0){
var t = this.elementType;
t = listAccessors.Aggregate(t,
(current, pd) => (Type) PropertyTypeHash.Instance[current, pd.Name]);
// if t is null an empty list will be generated
return ExtendedTypeDescriptor.GetProperties(t);
}
return ExtendedTypeDescriptor.GetProperties(elementType);
}
*/
}
}

5
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs

@ -4,6 +4,7 @@ using System; @@ -4,6 +4,7 @@ using System;
using System.Linq;
using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.DataSource;
using ICSharpCode.Reporting.Interfaces.Data;
using Irony.Interpreter;
using Irony.Interpreter.Ast;
@ -14,8 +15,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports @@ -14,8 +15,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
/// </summary>
public static class ImportExtensions
{
public static CollectionDataSource GetDataSource (this ScriptThread thread){
return (CollectionDataSource)thread.App.Globals["DataSource"];
public static IDataSource GetDataSource (this ScriptThread thread){
return (IDataSource)thread.App.Globals["DataSource"];
}
}

27
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataViewHandling.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs

@ -19,35 +19,16 @@ namespace ICSharpCode.Reporting.Interfaces.Data @@ -19,35 +19,16 @@ namespace ICSharpCode.Reporting.Interfaces.Data
/// <summary>
/// Description of IDataViewHandling.
/// </summary>
public interface IDataViewHandling:IEnumerator{
void Sort ();
void Group();
public interface IDataSource{
void Bind();
// void Fill (int position,ReportItemCollection collection);
//rausnehmen
// void Fill (List<IDataItem> items);
void Fill(List<IPrintableObject> collection);
// void Fill(ReportItemCollection collection);
IndexList IndexList {get;}
// object CurrentFromPosition(int pos);
// CurrentItemsCollection FillDataRow();
// CurrentItemsCollection FillDataRow(int pos);
//
Collection<AbstractColumn> AvailableFields {get;}
IList <object> CurrentList {get;}
int Count {get;}
int CurrentPosition {get;set;}
// IExpressionEvaluatorFacade ExpressionEvaluator {get;}
object Current {get;}
}
}

8
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs

@ -27,10 +27,9 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -27,10 +27,9 @@ namespace ICSharpCode.Reporting.PageBuilder
public class DataPageBuilder:BasePageBuilder
{
public DataPageBuilder(IReportModel reportModel, Type elementType,IEnumerable list):base(reportModel)
public DataPageBuilder(IReportModel reportModel,IEnumerable list):base(reportModel)
{
List = list;
ElementType = elementType;
}
@ -101,14 +100,16 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -101,14 +100,16 @@ namespace ICSharpCode.Reporting.PageBuilder
}
}
void CreateDataSource()
{
DataSource = new CollectionDataSource(List, ElementType, ReportModel.ReportSettings);
DataSource = new CollectionDataSource(List, ReportModel.ReportSettings);
if (DataSourceContainsData()) {
DataSource.Bind();
}
}
bool DataSourceContainsData () {
if (DataSource.Count > 0) {
return true;
@ -154,6 +155,5 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -154,6 +155,5 @@ namespace ICSharpCode.Reporting.PageBuilder
protected IReportContainer CurrentSection { get; private set; }
protected Type ElementType {get;private set;}
}
}

10
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs

@ -24,12 +24,20 @@ namespace ICSharpCode.Reporting @@ -24,12 +24,20 @@ namespace ICSharpCode.Reporting
public class ReportingFactory
{
public IReportCreator ReportCreator (Stream stream,IEnumerable list)
{
ReportModel = LoadReportModel (stream);
IReportCreator builder = null;
builder = new DataPageBuilder(ReportModel,list );
return builder;
}
[Obsolete("Use public IReportCreator ReportCreator (Stream stream,IEnumerable list")]
public IReportCreator ReportCreator (Stream stream,Type listType,IEnumerable list)
{
ReportModel = LoadReportModel (stream);
IReportCreator builder = null;
builder = new DataPageBuilder(ReportModel,listType,list );
builder = new DataPageBuilder(ReportModel,list );
return builder;
}

12
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs

@ -17,14 +17,14 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -17,14 +17,14 @@ namespace ICSharpCode.Reporting.Test.DataSource
[Test]
public void CollectionCountIsEqualToListCount() {
var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings());
var collectionSource = new CollectionDataSource (list,new ReportSettings());
Assert.That(collectionSource.Count,Is.EqualTo(list.Count));
}
[Test]
public void AvailableFieldsEqualContibutorsPropertyCount() {
var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings());
var collectionSource = new CollectionDataSource (list,new ReportSettings());
Assert.That(collectionSource.AvailableFields.Count,Is.EqualTo(6));
}
@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
public void GroupbyOneColumn () {
var rs = new ReportSettings();
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
var collectionSource = new CollectionDataSource (list,rs);
collectionSource.Bind();
}
@ -50,7 +50,7 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -50,7 +50,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
ColumnName = "Firstname"
}
};
var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings());
var collectionSource = new CollectionDataSource (list,new ReportSettings());
collectionSource.Bind();
collectionSource.Fill(ric);
foreach (BaseDataItem element in ric) {
@ -75,7 +75,7 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -75,7 +75,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
var rs = new ReportSettings();
rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
var collectionSource = new CollectionDataSource (list,rs);
collectionSource.Bind();
string compare = String.Empty;
int i = 0;
@ -117,7 +117,7 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -117,7 +117,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
rs.GroupColumnCollection.Add( new GroupColumn("RandomInt",1,ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
var collectionSource = new CollectionDataSource (list,rs);
collectionSource.Bind();
int i = 0;
do {

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates @@ -57,7 +57,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
helper = new AggregateFuctionHelper();
aggregateCollection = helper.AggregateCollection;
dataSource = new CollectionDataSource(aggregateCollection,typeof(Aggregate),new ReportSettings());
dataSource = new CollectionDataSource(aggregateCollection,new ReportSettings());
dataSource.Bind();
}

7
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory @@ -32,7 +32,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
[Test]
public void DataSourceIsSet() {
var dataPageBuilder = new DataPageBuilder (new ReportModel(),typeof(string),new System.Collections.Generic.List<string>());
var dataPageBuilder = new DataPageBuilder (new ReportModel(),new System.Collections.Generic.List<string>());
Assert.That(dataPageBuilder.List,Is.Not.Null);
}
@ -41,7 +41,6 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory @@ -41,7 +41,6 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
public void CanInitDataPageBuilder()
{
var dpb = new DataPageBuilder (new ReportModel(),
typeof(string),
new System.Collections.Generic.List<string>());
Assert.That(dpb,Is.Not.Null);
}
@ -158,7 +157,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory @@ -158,7 +157,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
var reportingFactory = new ReportingFactory();
var model = reportingFactory.LoadReportModel (stream);
reportCreator = new DataPageBuilder(model,typeof(string),new List<string>());
reportCreator = new DataPageBuilder(model,new List<string>());
reportCreator.BuildExportList();
Assert.That(reportCreator.Pages[0].ExportedItems.Count,Is.EqualTo(4));
}
@ -175,7 +174,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory @@ -175,7 +174,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
var reportingFactory = new ReportingFactory();
var model = reportingFactory.LoadReportModel (stream);
reportCreator = new DataPageBuilder(model,typeof(Contributor),list);
reportCreator = new DataPageBuilder(model,list);
}
}
}

Loading…
Cancel
Save