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 @@
<Compile Include="Src\Globals\StandardFormatter.cs" /> <Compile Include="Src\Globals\StandardFormatter.cs" />
<Compile Include="Src\Globals\StringHelper.cs" /> <Compile Include="Src\Globals\StringHelper.cs" />
<Compile Include="Src\Globals\TypeHelper.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\IExportColumn.cs" />
<Compile Include="Src\Interfaces\Export\IExportContainer.cs" /> <Compile Include="Src\Interfaces\Export\IExportContainer.cs" />
<Compile Include="Src\Interfaces\Export\IPage.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
Sorted, Sorted,
Grouped Grouped
} }
public class CollectionDataSource:IDataViewHandling public class CollectionDataSource:IDataSource
{ {
@ -36,7 +36,22 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
readonly PropertyDescriptorCollection listProperties; readonly PropertyDescriptorCollection listProperties;
OrderGroup orderGroup; 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) public CollectionDataSource(IEnumerable list, Type elementType, ReportSettings reportSettings)
{ {
if (list == null) if (list == null)
@ -44,8 +59,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
if (reportSettings == null) if (reportSettings == null)
throw new ArgumentNullException("reportSettings"); throw new ArgumentNullException("reportSettings");
baseList = CreateBaseList(list, elementType); baseList = CreateBaseList(list);
//test
CurrentList = baseList; CurrentList = baseList;
this.elementType = elementType; this.elementType = elementType;
@ -57,13 +72,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
public IndexList IndexList {
get {
throw new NotImplementedException();
}
}
public Collection<AbstractColumn> AvailableFields { public Collection<AbstractColumn> AvailableFields {
get { get {
var availableFields = new Collection<AbstractColumn>(); var availableFields = new Collection<AbstractColumn>();
@ -73,23 +81,23 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return availableFields; return availableFields;
} }
} }
//test
public IList <object> CurrentList {get;private set;} public IList <object> CurrentList {get;private set;}
public int Count { public int Count {
get { get {
return baseList.Count; return baseList.Count;
} }
} }
public int CurrentPosition {get;set;}
public object Current {get; private set;}
public object Current {get; set;}
#region Sort #region Sort
public void Sort() void Sort()
{ {
if (reportSettings.SortColumnsCollection.Count > 0) { if (reportSettings.SortColumnsCollection.Count > 0) {
var sorted = SortInternal(); var sorted = SortInternal();
@ -97,15 +105,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = sorted.GetEnumerator(); listEnumerator = sorted.GetEnumerator();
listEnumerator.MoveNext(); listEnumerator.MoveNext();
Current = listEnumerator.Current; Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("sort CurrentPosition {0}",CurrentPosition);
} else { } else {
orderGroup = OrderGroup.AsIs; orderGroup = OrderGroup.AsIs;
listEnumerator = baseList.GetEnumerator(); listEnumerator = baseList.GetEnumerator();
listEnumerator.MoveNext(); listEnumerator.MoveNext();
Current = listEnumerator.Current; Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("asis CurrentPosition {0}",CurrentPosition);
} }
} }
@ -125,7 +129,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
#region Grouping #region Grouping
public void Group() void Group()
{ {
orderGroup = OrderGroup.Grouped; orderGroup = OrderGroup.Grouped;
groupedList = GroupInternal(); groupedList = GroupInternal();
@ -134,8 +138,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = groupEnumerator.Current.GetEnumerator(); listEnumerator = groupEnumerator.Current.GetEnumerator();
listEnumerator.MoveNext(); listEnumerator.MoveNext();
Current = listEnumerator.Current; Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("group CurrentPosition {0}",CurrentPosition);
} }
@ -198,32 +200,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return p.PropertyType; 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() public bool MoveNext()
{ {
@ -245,38 +221,18 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
} }
Current = listEnumerator.Current; Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("CurrentPosition {0}",CurrentPosition);
return canMove; return canMove;
} }
#endregion #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); list.AddRange(source);
return list; 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;
using System.Linq; using System.Linq;
using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.DataSource; using ICSharpCode.Reporting.DataSource;
using ICSharpCode.Reporting.Interfaces.Data;
using Irony.Interpreter; using Irony.Interpreter;
using Irony.Interpreter.Ast; using Irony.Interpreter.Ast;
@ -14,8 +15,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
/// </summary> /// </summary>
public static class ImportExtensions public static class ImportExtensions
{ {
public static CollectionDataSource GetDataSource (this ScriptThread thread){ public static IDataSource GetDataSource (this ScriptThread thread){
return (CollectionDataSource)thread.App.Globals["DataSource"]; 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
/// <summary> /// <summary>
/// Description of IDataViewHandling. /// Description of IDataViewHandling.
/// </summary> /// </summary>
public interface IDataViewHandling:IEnumerator{ public interface IDataSource{
void Sort ();
void Group();
void Bind(); void Bind();
// void Fill (int position,ReportItemCollection collection);
//rausnehmen
// void Fill (List<IDataItem> items);
void Fill(List<IPrintableObject> collection); 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;} Collection<AbstractColumn> AvailableFields {get;}
IList <object> CurrentList {get;}
int Count {get;} int Count {get;}
int CurrentPosition {get;set;} object Current {get;}
// IExpressionEvaluatorFacade ExpressionEvaluator {get;}
} }
} }

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

@ -27,10 +27,9 @@ namespace ICSharpCode.Reporting.PageBuilder
public class DataPageBuilder:BasePageBuilder public class DataPageBuilder:BasePageBuilder
{ {
public DataPageBuilder(IReportModel reportModel, Type elementType,IEnumerable list):base(reportModel) public DataPageBuilder(IReportModel reportModel,IEnumerable list):base(reportModel)
{ {
List = list; List = list;
ElementType = elementType;
} }
@ -101,14 +100,16 @@ namespace ICSharpCode.Reporting.PageBuilder
} }
} }
void CreateDataSource() void CreateDataSource()
{ {
DataSource = new CollectionDataSource(List, ElementType, ReportModel.ReportSettings); DataSource = new CollectionDataSource(List, ReportModel.ReportSettings);
if (DataSourceContainsData()) { if (DataSourceContainsData()) {
DataSource.Bind(); DataSource.Bind();
} }
} }
bool DataSourceContainsData () { bool DataSourceContainsData () {
if (DataSource.Count > 0) { if (DataSource.Count > 0) {
return true; return true;
@ -154,6 +155,5 @@ namespace ICSharpCode.Reporting.PageBuilder
protected IReportContainer CurrentSection { get; private set; } 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
public class ReportingFactory 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) public IReportCreator ReportCreator (Stream stream,Type listType,IEnumerable list)
{ {
ReportModel = LoadReportModel (stream); ReportModel = LoadReportModel (stream);
IReportCreator builder = null; IReportCreator builder = null;
builder = new DataPageBuilder(ReportModel,listType,list ); builder = new DataPageBuilder(ReportModel,list );
return builder; 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
[Test] [Test]
public void CollectionCountIsEqualToListCount() { 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)); Assert.That(collectionSource.Count,Is.EqualTo(list.Count));
} }
[Test] [Test]
public void AvailableFieldsEqualContibutorsPropertyCount() { 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)); Assert.That(collectionSource.AvailableFields.Count,Is.EqualTo(6));
} }
@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
public void GroupbyOneColumn () { public void GroupbyOneColumn () {
var rs = new ReportSettings(); var rs = new ReportSettings();
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); 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(); collectionSource.Bind();
} }
@ -50,7 +50,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
ColumnName = "Firstname" ColumnName = "Firstname"
} }
}; };
var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings()); var collectionSource = new CollectionDataSource (list,new ReportSettings());
collectionSource.Bind(); collectionSource.Bind();
collectionSource.Fill(ric); collectionSource.Fill(ric);
foreach (BaseDataItem element in ric) { foreach (BaseDataItem element in ric) {
@ -75,7 +75,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
var rs = new ReportSettings(); var rs = new ReportSettings();
rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending)); rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs); var collectionSource = new CollectionDataSource (list,rs);
collectionSource.Bind(); collectionSource.Bind();
string compare = String.Empty; string compare = String.Empty;
int i = 0; int i = 0;
@ -117,7 +117,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
rs.GroupColumnCollection.Add( new GroupColumn("RandomInt",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(); collectionSource.Bind();
int i = 0; int i = 0;
do { 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
helper = new AggregateFuctionHelper(); helper = new AggregateFuctionHelper();
aggregateCollection = helper.AggregateCollection; aggregateCollection = helper.AggregateCollection;
dataSource = new CollectionDataSource(aggregateCollection,typeof(Aggregate),new ReportSettings()); dataSource = new CollectionDataSource(aggregateCollection,new ReportSettings());
dataSource.Bind(); 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
[Test] [Test]
public void DataSourceIsSet() { 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); Assert.That(dataPageBuilder.List,Is.Not.Null);
} }
@ -41,7 +41,6 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
public void CanInitDataPageBuilder() public void CanInitDataPageBuilder()
{ {
var dpb = new DataPageBuilder (new ReportModel(), var dpb = new DataPageBuilder (new ReportModel(),
typeof(string),
new System.Collections.Generic.List<string>()); new System.Collections.Generic.List<string>());
Assert.That(dpb,Is.Not.Null); Assert.That(dpb,Is.Not.Null);
} }
@ -158,7 +157,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
var reportingFactory = new ReportingFactory(); var reportingFactory = new ReportingFactory();
var model = reportingFactory.LoadReportModel (stream); var model = reportingFactory.LoadReportModel (stream);
reportCreator = new DataPageBuilder(model,typeof(string),new List<string>()); reportCreator = new DataPageBuilder(model,new List<string>());
reportCreator.BuildExportList(); reportCreator.BuildExportList();
Assert.That(reportCreator.Pages[0].ExportedItems.Count,Is.EqualTo(4)); Assert.That(reportCreator.Pages[0].ExportedItems.Count,Is.EqualTo(4));
} }
@ -175,7 +174,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
var reportingFactory = new ReportingFactory(); var reportingFactory = new ReportingFactory();
var model = reportingFactory.LoadReportModel (stream); var model = reportingFactory.LoadReportModel (stream);
reportCreator = new DataPageBuilder(model,typeof(Contributor),list); reportCreator = new DataPageBuilder(model,list);
} }
} }
} }

Loading…
Cancel
Save