Browse Source

Expressions - Aggregates (Sum)

reports
Peter Forstmeier 12 years ago
parent
commit
e592a63fd4
  1. 7
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj
  2. 35
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/FieldMemberAccessor.cs
  3. 42
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/PropertyMemberAccessore.cs
  4. 88
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/PropertyPath.cs
  5. 53
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs
  6. 8
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs
  7. 58
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs
  8. 14
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageGrammer.cs
  9. 10
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs
  10. 106
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/TypeNormalizer.cs
  11. 14
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj
  12. 46
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/AggregateFuctionHelper.cs
  13. 72
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs
  14. 0
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs
  15. 0
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs
  16. 0
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs
  17. 0
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs
  18. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs
  19. 118
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs

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

@ -95,7 +95,11 @@
<Compile Include="Src\DataSource\DataCollection.cs" /> <Compile Include="Src\DataSource\DataCollection.cs" />
<Compile Include="Src\DataSource\ExtendedPropertyDescriptor.cs" /> <Compile Include="Src\DataSource\ExtendedPropertyDescriptor.cs" />
<Compile Include="Src\DataSource\ExtendedTypeDescriptor.cs" /> <Compile Include="Src\DataSource\ExtendedTypeDescriptor.cs" />
<Compile Include="Src\DataSource\FieldMemberAccessor.cs" />
<Compile Include="Src\DataSource\PropertyMemberAccessore.cs" />
<Compile Include="Src\DataSource\PropertyPath.cs" />
<Compile Include="Src\DataSource\PropertyTypeHash.cs" /> <Compile Include="Src\DataSource\PropertyTypeHash.cs" />
<Compile Include="Src\DataSource\ReflectionExtension.cs" />
<Compile Include="Src\Exporter\BaseExporter.cs" /> <Compile Include="Src\Exporter\BaseExporter.cs" />
<Compile Include="Src\Exporter\DebugExporter.cs" /> <Compile Include="Src\Exporter\DebugExporter.cs" />
<Compile Include="Src\Exporter\Visitors\CanvasExtension.cs" /> <Compile Include="Src\Exporter\Visitors\CanvasExtension.cs" />
@ -115,8 +119,10 @@
<Compile Include="Src\Expressions\Irony\Ast\GlobalsNode.cs" /> <Compile Include="Src\Expressions\Irony\Ast\GlobalsNode.cs" />
<Compile Include="Src\Expressions\Irony\Ast\ParametersCallNode.cs" /> <Compile Include="Src\Expressions\Irony\Ast\ParametersCallNode.cs" />
<Compile Include="Src\Expressions\Irony\ExpressionEvaluator.cs" /> <Compile Include="Src\Expressions\Irony\ExpressionEvaluator.cs" />
<Compile Include="Src\Expressions\Irony\Imports\ImportAggregates.cs" />
<Compile Include="Src\Expressions\Irony\ReportingLanguageGrammer.cs" /> <Compile Include="Src\Expressions\Irony\ReportingLanguageGrammer.cs" />
<Compile Include="Src\Expressions\Irony\ReportingLanguageRuntime.cs" /> <Compile Include="Src\Expressions\Irony\ReportingLanguageRuntime.cs" />
<Compile Include="Src\Expressions\TypeNormalizer.cs" />
<Compile Include="Src\Factories\ExportColumnFactory.cs" /> <Compile Include="Src\Factories\ExportColumnFactory.cs" />
<Compile Include="Src\Factories\ReportCreatorFactory.cs" /> <Compile Include="Src\Factories\ReportCreatorFactory.cs" />
<Compile Include="Src\Globals\CreateGraphics.cs" /> <Compile Include="Src\Globals\CreateGraphics.cs" />
@ -166,6 +172,7 @@
<Folder Include="Src\Exporter\Visitors" /> <Folder Include="Src\Exporter\Visitors" />
<Folder Include="Src\Expressions\Irony" /> <Folder Include="Src\Expressions\Irony" />
<Folder Include="Src\Expressions\Irony\Ast" /> <Folder Include="Src\Expressions\Irony\Ast" />
<Folder Include="Src\Expressions\Irony\Imports" />
<Folder Include="Src\Interfaces" /> <Folder Include="Src\Interfaces" />
<Folder Include="Src\Globals" /> <Folder Include="Src\Globals" />
<Folder Include="Src" /> <Folder Include="Src" />

35
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/FieldMemberAccessor.cs

@ -0,0 +1,35 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Reflection;
namespace ICSharpCode.Reporting.DataSource
{
/// <summary>
/// Description of FieldMemberAccessor.
/// </summary>
public class FieldMemberAccessor : IMemberAccessor
{
private readonly FieldInfo _field;
public FieldMemberAccessor(FieldInfo field)
{
_field = field;
}
public object GetValue(object target)
{
return _field.GetValue(target);
}
public bool IsStatic
{
get { return _field.IsStatic; }
}
public Type MemberType
{
get { return _field.FieldType;}
}
}
}

42
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/PropertyMemberAccessore.cs

@ -0,0 +1,42 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Reflection;
namespace ICSharpCode.Reporting.DataSource
{
/// <summary>
/// Description of PropertyMemberAccessore.
/// </summary>
public interface IMemberAccessor
{
object GetValue(object target);
bool IsStatic { get; }
Type MemberType { get; }
}
public class PropertyMemberAccessor : IMemberAccessor
{
private readonly PropertyInfo _prop;
public PropertyMemberAccessor(PropertyInfo prop)
{
_prop = prop;
}
public object GetValue(object target)
{
return _prop.GetValue(target, null);
}
public bool IsStatic
{
get { return _prop.GetGetMethod().IsStatic; }
}
public Type MemberType
{
get { return _prop.PropertyType;}
}
}
}

88
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/PropertyPath.cs

@ -0,0 +1,88 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Text;
namespace ICSharpCode.Reporting.DataSource
{
public class PropertyPath
{
private readonly Type _rootType;
private readonly IMemberAccessor[] _properties;
private readonly bool _rootIsStatic;
private PropertyPath(Type rootType,IMemberAccessor[] props)
{
_properties = props;
_rootType = rootType;
if (_properties[0].IsStatic)
_rootIsStatic = true;
}
public object Evaluate(object target)
{
if (target == null && _rootIsStatic == false)
return null;
// Type s = target.GetType();
if (target != null && _rootType.IsAssignableFrom(target.GetType()) == false)
return null;
object current = target;
foreach (IMemberAccessor prop in _properties)
{
current = prop.GetValue(current);
if (current == null)
return null;
}
return current;
}
public static PropertyPath Parse(Type targetType,string propPath)
{
if (String.IsNullOrEmpty(propPath))
return null;
string[] parts = propPath.Split('.');
return Compile(targetType, parts);
}
public static PropertyPath Compile(Type targetType,string[] pathParts)
{
var accessors = new IMemberAccessor[pathParts.Length];
Type currentType = targetType;
for (int i = 0; i < pathParts.Length; i++)
{
string part = pathParts[i];
IMemberAccessor accessor = currentType.FindAccessor(part);
if (accessor == null)
return null;
accessors[i] = accessor;
currentType = accessor.MemberType;
}
return new PropertyPath(targetType, accessors);
}
public static string GetCacheKey(Type targetType,string[] name)
{
var key = new StringBuilder();
key.Append(targetType.FullName);
foreach (string namePart in name)
key.Append(namePart);
return key.ToString();
}
}
}

53
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs

@ -0,0 +1,53 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Reflection;
namespace ICSharpCode.Reporting.DataSource
{
/// <summary>
/// Description of ReflectionExtension.
/// </summary>
///
public static class ReflectionExtensions
{
public static PropertyPath ParsePropertyPath(this object target,string propertyPath)
{
if (target == null || String.IsNullOrEmpty(propertyPath))
return null;
return PropertyPath.Parse(target.GetType(), propertyPath);
}
public static object EvaluatePropertyPath(this object target,string propertyPath)
{
PropertyPath path = ParsePropertyPath(target, propertyPath);
if (path != null)
return path.Evaluate(target);
return null;
}
public static IMemberAccessor FindAccessor(this Type type, string accessorName)
{
PropertyInfo prop = type.GetProperty(accessorName,
BindingFlags.IgnoreCase | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if (prop != null)
return new PropertyMemberAccessor(prop);
FieldInfo field = type.GetField(accessorName,
BindingFlags.IgnoreCase | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if (field != null)
return new FieldMemberAccessor(field);
return null;
}
}
}

8
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
readonly ReportingLanguageGrammer grammar; readonly ReportingLanguageGrammer grammar;
readonly ReportingExpressionEvaluator evaluator; readonly ReportingExpressionEvaluator evaluator;
public ExpressionVisitor(Collection<ExportPage> pages,ReportSettings reportSettings):this(reportSettings) public ExpressionVisitor(Collection<ExportPage> pages,ReportSettings reportSettings):this(reportSettings)
{ {
this.pages = pages; this.pages = pages;
@ -59,7 +60,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
object result = Evaluate(exportColumn); object result = Evaluate(exportColumn);
exportColumn.Text = result.ToString(); exportColumn.Text = result.ToString();
} catch (Exception e) { } catch (Exception e) {
var s = String.Format("SharpReport.Exprssions -> {0} for {1}",e.Message,exportColumn.Text); var s = String.Format("SharpReport.Expressions -> {0} for {1}",e.Message,exportColumn.Text);
Console.WriteLine(s); Console.WriteLine(s);
} }
} }
@ -72,5 +73,10 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
var result = evaluator.Evaluate(str); var result = evaluator.Evaluate(str);
return result; return result;
} }
public ReportingExpressionEvaluator Evaluator {
get { return evaluator; }
}
} }
} }

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

@ -0,0 +1,58 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.DataSource;
using Irony.Interpreter;
using Irony.Interpreter.Ast;
namespace ICSharpCode.Reporting.Expressions.Irony.Imports
{
/// <summary>
/// Description of ImportAggregates.
/// </summary>
public static class ImportAggregates
{
public static object Sum(ScriptThread thread, AstNode[] childNodes) {
double sum = 0;
var fieldName = childNodes[0].Evaluate(thread).ToString();
var dataSource = (CollectionSource)thread.App.Globals["Current"];
var curpos = dataSource.CurrentPosition;
dataSource.CurrentPosition = 0;
if (FieldExist(dataSource.Current,fieldName)) {
do {
var current = dataSource.Current;
var property = current.ParsePropertyPath(fieldName);
var val = property.Evaluate(current);
var nextVal = TypeNormalizer.EnsureType<double>(val);
sum = sum + nextVal;
}
while (dataSource.MoveNext());
}
dataSource.CurrentPosition = curpos;
return sum;
}
static bool FieldExist (object current,string fieldName) {
var property1 = current.ParsePropertyPath(fieldName);
if (property1 == null) {
Console.WriteLine(String.Format("Aggregate <Sum> Field '{0}' not found",fieldName));
return false;
}
return true;
}
}
}

14
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageGrammer.cs

@ -48,7 +48,7 @@ bool operations &,&&, |, ||; ternary '?:' operator." ;
// 2. Non-terminals // 2. Non-terminals
var Term = new NonTerminal("Term"); var Term = new NonTerminal("Term");
var BinExpr = new NonTerminal("BinExpr", typeof(BinaryOperationNode)); var BinExpr = new NonTerminal("BinExpr", typeof(BinaryOperationNode));
var ParExpr = new NonTerminal("ParExpr"); var ParExpr = new NonTerminal("ParExsumpr");
var UnExpr = new NonTerminal("UnExpr", typeof(UnaryOperationNode)); var UnExpr = new NonTerminal("UnExpr", typeof(UnaryOperationNode));
var TernaryIfExpr = new NonTerminal("TernaryIf", typeof(IfNode)); var TernaryIfExpr = new NonTerminal("TernaryIf", typeof(IfNode));
var ArgList = new NonTerminal("ArgList", typeof(ExpressionListNode)); var ArgList = new NonTerminal("ArgList", typeof(ExpressionListNode));
@ -105,18 +105,10 @@ bool operations &,&&, |, ||; ternary '?:' operator." ;
ParametersSection.Rule = ToTerm("Parameters") + exclamationMark + identifier; ParametersSection.Rule = ToTerm("Parameters") + exclamationMark + identifier;
FieldsSection.Rule = ToTerm("Fields") + exclamationMark + identifier; FieldsSection.Rule = ToTerm("Fields") + exclamationMark + identifier;
GlobalSection.Rule = ToTerm("Globals") + exclamationMark + identifier; GlobalSection.Rule = ToTerm("Globals") + exclamationMark + identifier;
// GlobalSection.Rule = ToTerm("Globals") + exclamationMark + ToTerm("PageNumber");
/*
GlobalSection.Rule = GlobalSection + exclamationMark + Symbol("PageNumber")
| GlobalSection + exclamationMark + Symbol("TotalPages")
| GlobalSection + exclamationMark + Symbol("ExecutionTime")
| GlobalSection + exclamationMark + Symbol("ReportFolder")
| GlobalSection + exclamationMark + Symbol("ReportName");
*/
// end of SharpReporting // end of SharpReporting
FunctionCall.NodeCaptionTemplate = "call #{0}(...)"; FunctionCall.NodeCaptionTemplate = "call #{0}(...)";
ObjectRef.Rule = identifier | MemberAccess | IndexedAccess; ObjectRef.Rule = identifier | MemberAccess | IndexedAccess;

10
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/ReportingLanguageRuntime.cs

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.Reporting.Expressions.Irony.Imports;
using Irony.Interpreter; using Irony.Interpreter;
using Irony.Parsing; using Irony.Parsing;
@ -21,14 +22,15 @@ namespace ICSharpCode.Reporting.Expressions.Irony
base.Init(); base.Init();
//add built-in methods, special form IIF, import Math and Environment methods //add built-in methods, special form IIF, import Math and Environment methods
// BuiltIns.AddMethod(BuiltInPrintMethod, "print"); // BuiltIns.AddMethod(BuiltInPrintMethod, "print");
BuiltIns.AddMethod(BuiltInFormatMethod, "format"); // BuiltIns.AddMethod(BuiltInFormatMethod, "format");
BuiltIns.AddSpecialForm(SpecialFormsLibrary.Iif, "iif", 3, 3); BuiltIns.AddSpecialForm(SpecialFormsLibrary.Iif, "iif", 3, 3);
BuiltIns.ImportStaticMembers(typeof(System.Math)); BuiltIns.ImportStaticMembers(typeof(System.Math));
BuiltIns.ImportStaticMembers(typeof(Environment)); BuiltIns.ImportStaticMembers(typeof(Environment));
BuiltIns.AddSpecialForm(ImportAggregates.Sum,"sum",1,1);
} }
/*
private object BuiltInPrintMethod(ScriptThread thread, object[] args) { private object BuiltInPrintMethod(ScriptThread thread, object[] args) {
string text = string.Empty; string text = string.Empty;
switch(args.Length) { switch(args.Length) {
@ -44,7 +46,9 @@ namespace ICSharpCode.Reporting.Expressions.Irony
thread.App.WriteLine(text); thread.App.WriteLine(text);
return null; return null;
} }
*/
/*
private object BuiltInFormatMethod(ScriptThread thread, object[] args) { private object BuiltInFormatMethod(ScriptThread thread, object[] args) {
if (args == null || args.Length == 0) return null; if (args == null || args.Length == 0) return null;
var template = args[0] as string; var template = args[0] as string;
@ -57,6 +61,6 @@ namespace ICSharpCode.Reporting.Expressions.Irony
return text; return text;
} }
*/
} }
} }

106
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/TypeNormalizer.cs

@ -0,0 +1,106 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.Reporting.Expressions
{
/// <summary>
/// Description of TypeNormalizer.
/// </summary>
public class TypeNormalizer
{
public static void NormalizeTypes(ref object left,ref object right)
{
NormalizeTypes(ref left,ref right,0);
}
public static void NormalizeTypes(ref object left,ref object right,object nullValue)
{
if (left == null)
left = 0;
if (right == null)
right = 0;
if (left.GetType() == right.GetType())
return;
try
{
right = Convert.ChangeType(right,left.GetType());
}
catch
{
try
{
left = Convert.ChangeType(left, right.GetType());
}
catch
{
throw new Exception(String.Format("Error converting from {0} type to {1}", left.GetType().FullName, right.GetType().FullName));
}
}
}
public static void EnsureTypes(ref object[] values,Type targetType)
{
object nullValue = null;
if (targetType.IsValueType)
nullValue = Activator.CreateInstance(targetType);
EnsureTypes(ref values,targetType,nullValue);
}
public static void EnsureTypes(ref object[] values,Type targetType,object nullValue)
{
for (int i=0;i<values.Length;i++)
{
values[i] = EnsureType(values[i],targetType,nullValue);
}
}
public static T EnsureType<T>(object value)
{
return EnsureType<T>(value, default(T));
}
public static T EnsureType<T>(object value,object nullValue)
{
return (T) EnsureType(value, typeof (T), nullValue);
}
public static object EnsureType(object value, Type targetType)
{
if (value != null && value.GetType() == targetType)
return value;
object defaultValue = null;
if (targetType.IsValueType)
defaultValue = Activator.CreateInstance(targetType);
return EnsureType(value, targetType, defaultValue);
}
public static object EnsureType(object value,Type targetType,object nullValue)
{
if (value == null)
return nullValue;
if (targetType == typeof(object))
return value;
if (value.GetType() == targetType)
return value;
try {
return Convert.ChangeType(value, targetType);
} catch (Exception e) {
Console.WriteLine("TypeNormalizer {0} - {1}",value.ToString(),e.Message);
return value.ToString();
//throw new Exception()String.Format("TypeNormalizer for <{0}> - {1}",value.ToString(),e.Message));
}
}
}
}

14
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj

@ -66,12 +66,13 @@
<ItemGroup> <ItemGroup>
<Compile Include="src\DataSource\ContributorsList.cs" /> <Compile Include="src\DataSource\ContributorsList.cs" />
<Compile Include="src\DataSource\CollectionHandlingFixture.cs" /> <Compile Include="src\DataSource\CollectionHandlingFixture.cs" />
<Compile Include="src\Expressions\InterationTests\FieldsFixture.cs" /> <Compile Include="src\Expressions\Aggregates\AggregateFuctionHelper.cs" />
<Compile Include="src\Expressions\InterationTests\GlobalsFixture.cs" /> <Compile Include="src\Expressions\Aggregates\SumAggregate.cs" />
<Compile Include="src\Expressions\InterationTests\StandardTests.cs" /> <Compile Include="src\Expressions\IntegrationTests\FieldsFixture.cs" />
<Compile Include="src\Expressions\InterationTests\ParametersFixture.cs" /> <Compile Include="src\Expressions\IntegrationTests\GlobalsFixture.cs" />
<Compile Include="src\Expressions\IntegrationTests\StandardTests.cs" />
<Compile Include="src\Expressions\IntegrationTests\ParametersFixture.cs" />
<Compile Include="src\Expressions\IronyGeneral.cs" /> <Compile Include="src\Expressions\IronyGeneral.cs" />
<Compile Include="src\Expressions\ParametersHandlingFixture.cs" />
<Compile Include="src\MeasureArrange\ContainerArrangeStrategyFixture.cs" /> <Compile Include="src\MeasureArrange\ContainerArrangeStrategyFixture.cs" />
<Compile Include="src\Model\ReportModelFixture.cs" /> <Compile Include="src\Model\ReportModelFixture.cs" />
<Compile Include="src\Model\ReportSettingsFixture.cs" /> <Compile Include="src\Model\ReportSettingsFixture.cs" />
@ -91,7 +92,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="src" /> <Folder Include="src" />
<Folder Include="src\Expressions\InterationTests" /> <Folder Include="src\Expressions\IntegrationTests" />
<Folder Include="src\Expressions\Aggregates" />
<Folder Include="src\Model" /> <Folder Include="src\Model" />
<Folder Include="src\DataSource" /> <Folder Include="src\DataSource" />
<Folder Include="src\MeasureArrange" /> <Folder Include="src\MeasureArrange" />

46
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/AggregateFuctionHelper.cs

@ -0,0 +1,46 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
{
/// <summary>
/// Description of AggregateFuctionHelper.
/// </summary>
internal class AggregateFuctionHelper
{
public AggregateFuctionHelper()
{
this.AggregateCollection = new AggregateCollection();
this.AggregateCollection.Add (new Aggregate("Value1",1,1.5));
this.AggregateCollection.Add (new Aggregate("Value2",2,2.5));
this.AggregateCollection.Add (new Aggregate("Value3",3,3.5));
this.AggregateCollection.Add (new Aggregate("Value400",400,400.75));
}
public AggregateCollection AggregateCollection {get; private set;}
}
class AggregateCollection: List<Aggregate>
{
}
class Aggregate {
public Aggregate (string name,int intValue, double amount)
{
this.Name = name;
this.IntValue = intValue;
this.DoubleValue = amount;
}
public string Name {get;set;}
public int IntValue {get;set;}
public double DoubleValue {get;set;}
}
}

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

@ -0,0 +1,72 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.ObjectModel;
using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.Exporter.Visitors;
using ICSharpCode.Reporting.Items;
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
using NUnit.Framework;
namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
{
[TestFixture]
public class SumAggregate
{
Collection<ExportText> collection;
ExpressionVisitor expressionVisitor;
AggregateCollection agc;
AggregateFuctionHelper helper;
CollectionSource cs;
[Test]
public void CanSum_Int_WholeCollection()
{
var reportSettings = new ReportSettings();
var visitor = new ExpressionVisitor(reportSettings);
var script = "= sum('intValue')";
collection[0].Text = script;
visitor.Evaluator.Globals.Add("Current",cs);
visitor.Visit(collection[0]);
Assert.That (collection[0].Text,Is.EqualTo("406"));
Assert.That(Convert.ToInt32(collection[0].Text),Is.TypeOf(typeof(int)));
}
[Test]
public void CanSum_Double_WholeCollection()
{
var reportSettings = new ReportSettings();
var visitor = new ExpressionVisitor(reportSettings);
var script = "= sum('doubleValue')";
collection[0].Text = script;
visitor.Evaluator.Globals.Add("Current",cs);
visitor.Visit(collection[0]);
Assert.That (collection[0].Text,Is.EqualTo("408,25"));
Assert.That(Convert.ToDouble(collection[0].Text),Is.TypeOf(typeof(double)));
}
[SetUp]
public void CreateExportlist() {
collection = new Collection<ExportText>();
collection.Add(new ExportText()
{
Text = String.Empty
});
helper = new AggregateFuctionHelper();
agc = helper.AggregateCollection;
cs = new CollectionSource(agc,typeof(Aggregate),new ReportSettings());
cs.Bind();
}
[TestFixtureSetUp]
public void Setup() {
expressionVisitor = new ExpressionVisitor(new ReportSettings());
}
}
}

0
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/FieldsFixture.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs

0
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/GlobalsFixture.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs

0
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/ParametersFixture.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs

0
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/InterationTests/StandardTests.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs

1
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IronyGeneral.cs

@ -62,6 +62,7 @@ namespace ICSharpCode.Reporting.Test.Expressions
Assert.AreEqual(11.0, (double) result, 0.001, "Unexpected computation result"); Assert.AreEqual(11.0, (double) result, 0.001, "Unexpected computation result");
} }
#endregion #endregion
[SetUp] [SetUp]

118
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/ParametersHandlingFixture.cs

@ -1,118 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Reporting.BaseClasses;
using ICSharpCode.Reporting.Expressions.Irony;
using ICSharpCode.Reporting.Expressions.Irony.Ast;
using ICSharpCode.Reporting.Items;
using NUnit.Framework;
namespace ICSharpCode.Reporting.Test.Expressions
{
[TestFixture]
public class ParametersHandlingFixture
{
ReportingLanguageGrammer grammar;
ReportingExpressionEvaluator evaluator;
[Test]
public void CanEvaluateOneParameter()
{
var resultValue = "Hi from param1";
var parameters = new ParameterCollection();
parameters.Add(new BasicParameter() {
ParameterName = "param1",
ParameterValue = resultValue
}
);
AddToGlobals(parameters);
var script = "Parameters!param1";
var result = evaluator.Evaluate(script);
Assert.That (result,Is.EqualTo(resultValue));
}
[Test]
public void CanFindParameter () {
var resultValue = "Hi from param2";
var parameters = new ParameterCollection();
parameters.Add(new BasicParameter() {
ParameterName = "param1",
ParameterValue = "Value for parameter1"
}
);
parameters.Add(new BasicParameter() {
ParameterName = "param2",
ParameterValue = resultValue
}
);
parameters.Add(new BasicParameter() {
ParameterName = "param3",
ParameterValue = "Value for parameter2"
}
);
AddToGlobals(parameters);
var script = "Parameters!param2";
var result = evaluator.Evaluate(script);
Assert.That (result,Is.EqualTo(resultValue));
}
[Test]
public void CanConcatParameter () {
var parameters = new ParameterCollection();
parameters.Add(new BasicParameter() {
ParameterName = "param1",
ParameterValue = "SharpDevelop"
}
);
parameters.Add(new BasicParameter() {
ParameterName = "param2",
ParameterValue = " is "
}
);
parameters.Add(new BasicParameter() {
ParameterName = "param3",
ParameterValue = "great"
}
);
AddToGlobals(parameters);
var script = "Parameters!param1 + Parameters!param2 + Parameters!param3";
var result = evaluator.Evaluate(script);
Assert.That (result,Is.EqualTo("SharpDevelop is great"));
}
void AddToGlobals(ParameterCollection parameters)
{
var reportSettings = new ReportSettings();
reportSettings.ParameterCollection.AddRange(parameters);
evaluator.AddReportSettings(reportSettings);
}
[SetUp]
public void Initialize() {
grammar = new ReportingLanguageGrammer();
evaluator = new ReportingExpressionEvaluator(grammar);
}
[TestFixtureSetUp]
public void Init()
{
// TODO: Add Init code.
}
[TestFixtureTearDown]
public void Dispose()
{
// TODO: Add tear down code.
}
}
}
Loading…
Cancel
Save