Skip to content

Commit

Permalink
Make ReportCellProperty and ReportTableProperty interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dimabarbul committed Aug 9, 2023
1 parent 84d3e64 commit 68e77a5
Show file tree
Hide file tree
Showing 96 changed files with 348 additions and 362 deletions.
128 changes: 64 additions & 64 deletions ChangeLog.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions benchmarks/XReports.Benchmarks/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Task VerticalFromEntitiesHtmlEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildVerticalReportFromEntities();
IReportTable<HtmlReportCell> htmlReportTable = this.ConvertToHtml(reportTable);

foreach (ReportTableProperty _ in htmlReportTable.Properties)
foreach (IReportTableProperty _ in htmlReportTable.Properties)
{
}

Expand All @@ -81,7 +81,7 @@ public Task VerticalFromEntitiesExcelEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildVerticalReportFromEntities();
IReportTable<ExcelReportCell> excelReportTable = this.ConvertToExcel(reportTable);

foreach (ReportTableProperty _ in excelReportTable.Properties)
foreach (IReportTableProperty _ in excelReportTable.Properties)
{
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public Task VerticalFromDataReaderHtmlEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildVerticalReportFromDataReader();
IReportTable<HtmlReportCell> htmlReportTable = this.ConvertToHtml(reportTable);

foreach (ReportTableProperty _ in htmlReportTable.Properties)
foreach (IReportTableProperty _ in htmlReportTable.Properties)
{
}

Expand All @@ -168,7 +168,7 @@ public Task VerticalFromDataReaderExcelEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildVerticalReportFromDataReader();
IReportTable<ExcelReportCell> excelReportTable = this.ConvertToExcel(reportTable);

foreach (ReportTableProperty _ in excelReportTable.Properties)
foreach (IReportTableProperty _ in excelReportTable.Properties)
{
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public Task HorizontalHtmlEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildHorizontalReport();
IReportTable<HtmlReportCell> htmlReportTable = this.ConvertToHtml(reportTable);

foreach (ReportTableProperty _ in htmlReportTable.Properties)
foreach (IReportTableProperty _ in htmlReportTable.Properties)
{
}

Expand All @@ -255,7 +255,7 @@ public Task HorizontalExcelEnumAsync()
IReportTable<ReportCell> reportTable = this.BuildHorizontalReport();
IReportTable<ExcelReportCell> excelReportTable = this.ConvertToExcel(reportTable);

foreach (ReportTableProperty _ in excelReportTable.Properties)
foreach (IReportTableProperty _ in excelReportTable.Properties)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ namespace XReports.Benchmarks.ReportStructure.Models;

public abstract class ReportCellsSource<TSourceEntity>
{
protected ReportCellsSource(string title, params ReportCellProperty[] properties)
protected ReportCellsSource(string title, params IReportCellProperty[] properties)
{
this.Title = title;
this.Properties = properties;
}

public string Title { get; }

public ReportCellProperty[] Properties { get; }
public IReportCellProperty[] Properties { get; }

public abstract Type ValueType { get; }
public abstract Func<TSourceEntity, TValue> ConvertValueSelector<TValue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace XReports.Benchmarks.ReportStructure.Models;

public class TypedReportCellsSource<TSourceEntity, TValue> : ReportCellsSource<TSourceEntity>
{
public TypedReportCellsSource(string title, Func<TSourceEntity, TValue> valueSelector, params ReportCellProperty[] properties)
public TypedReportCellsSource(string title, Func<TSourceEntity, TValue> valueSelector, params IReportCellProperty[] properties)
: base(title, properties)
{
this.ValueSelector = valueSelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public static IEnumerable<ReportCellsSource<IDataReader>> GetDataReaderCellsSour
yield return new TypedReportCellsSource<IDataReader, string>("Type", e => e.GetString(35));
}

public static ReportCellProperty[] GetGlobalProperties()
public static IReportCellProperty[] GetGlobalProperties()
{
return new ReportCellProperty[]
return new IReportCellProperty[]
{
new SameColumnFormatProperty(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace XReports.Benchmarks.XReportsProperties;

public class CustomFormatProperty : ReportCellProperty
public class CustomFormatProperty : IReportCellProperty
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private class Entity
public decimal Score { get; set; }
}

private class CustomFormatProperty : ReportCellProperty
private class CustomFormatProperty : IReportCellProperty
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private class Entity
public decimal Score { get; set; }
}

private class HeatmapProperty : ReportCellProperty
private class HeatmapProperty : IReportCellProperty
{
private readonly decimal minimumValue;
private readonly Color minimumColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private class Entity
public int? Score { get; set; }
}

private class ReplaceEmptyProperty : ReportCellProperty
private class ReplaceEmptyProperty : IReportCellProperty
{
public ReplaceEmptyProperty(string text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private class Entity
public decimal Score { get; set; }
}

private class ThreeColorHeatmapProperty : ReportCellProperty
private class ThreeColorHeatmapProperty : IReportCellProperty
{
private readonly decimal minimumValue;
private readonly Color minimumColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private class Entity
public decimal Score { get; set; }
}

private class ThreeColorHeatmapProperty : ReportCellProperty
private class ThreeColorHeatmapProperty : IReportCellProperty
{
public ThreeColorHeatmapProperty(decimal minimumValue, Color minimumColor, decimal middleValue, Color middleColor, decimal maximumValue, Color maximumColor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IActionResult Download()

private IReportTable<ReportCell> BuildReport()
{
ReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
AlignmentProperty centerAlignment = new(Alignment.Center);
BoldProperty bold = new();
IndentationProperty indentation = new();

Expand Down Expand Up @@ -137,7 +137,7 @@ private class Entity
public string Email { get; set; }
}

private class IndentationProperty : ReportCellProperty
private class IndentationProperty : IReportCellProperty
{
public IndentationProperty(int indentLevel = 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IActionResult Download()

private IReportTable<ReportCell> BuildReport()
{
ReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
IReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
BoldProperty bold = new();

ReportSchemaBuilder<Entity> reportBuilder = new();
Expand Down
4 changes: 2 additions & 2 deletions demos/XReports.Demos/Views/BasicHorizontalReport/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@section Code
{
class IndentationProperty : ReportCellProperty
class IndentationProperty : IReportCellProperty
{
public IndentationProperty(int indentLevel = 1)
{
Expand All @@ -46,7 +46,7 @@
}
}

ReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
AlignmentProperty centerAlignment = new(Alignment.Center);
BoldProperty bold = new BoldProperty();
IndentationProperty indentation = new IndentationProperty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@section Code
{
ReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
IReportCellProperty centerAlignment = new AlignmentProperty(Alignment.Center);
BoldProperty bold = new BoldProperty();

ReportSchemaBuilder&lt;Entity&gt; reportBuilder = new ReportSchemaBuilder&lt;Entity&gt;();
Expand Down
2 changes: 1 addition & 1 deletion demos/XReports.Demos/Views/CustomFormat/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@section Code
{
// Property is used to mark cells.
class CustomFormatProperty : ReportCellProperty { }
class CustomFormatProperty : IReportCellProperty { }

// The property handler processes cells during conversion to Html having custom property added.
class CustomFormatPropertyHtmlHandler : PropertyHandler&lt;CustomFormatProperty, HtmlReportCell&gt;
Expand Down
2 changes: 1 addition & 1 deletion demos/XReports.Demos/Views/Heatmap/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@section Code
{
class HeatmapProperty : ReportCellProperty
class HeatmapProperty : IReportCellProperty
{
private readonly decimal minimumValue;
private readonly Color minimumColor;
Expand Down
2 changes: 1 addition & 1 deletion demos/XReports.Demos/Views/ReplaceEmpty/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@section Code
{
class ReplaceEmptyProperty : ReportCellProperty
class ReplaceEmptyProperty : IReportCellProperty
{
public ReplaceEmptyProperty(string text)
{
Expand Down
2 changes: 1 addition & 1 deletion demos/XReports.Demos/Views/ThreeColorHeatmap/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@section Code
{
class ThreeColorHeatmapProperty : ReportCellProperty
class ThreeColorHeatmapProperty : IReportCellProperty
{
private readonly decimal minimumValue;
private readonly Color minimumColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@section Code
{
class ThreeColorHeatmapProperty : ReportCellProperty
class ThreeColorHeatmapProperty : IReportCellProperty
{
public ThreeColorHeatmapProperty(decimal minimumValue, Color minimumColor, decimal middleValue, Color middleColor, decimal maximumValue, Color maximumColor)
{
Expand Down
2 changes: 1 addition & 1 deletion docs/xreports.core/cell-processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class StripedProcessor : IReportCellProcessor<UserInfo>
}

// Cell property to mark cells alignment.
class AlignmentProperty : ReportCellProperty
class AlignmentProperty : IReportCellProperty
{
public AlignmentProperty(bool isLeftAligned)
{
Expand Down
28 changes: 9 additions & 19 deletions docs/xreports.core/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,14 @@ Another way of handling properties is to use [property handlers](./using-report-

Let's create some properties to see how they can be used. Imagine that we want report where some cells are emphasised by converting their text to upper case. Also we'd like to have some cells protected by hiding their text using some mask symbol.

From programming stand point property is a class inherited from ReportCellProperty.
From programming stand point property is a class, record or struct implementing IReportCellProperty.

```c#
class UpperCaseProperty : ReportCellProperty
class UpperCaseProperty : IReportCellProperty
{
}

class ProtectedProperty : ReportCellProperty
{
public char Symbol { get; }

public ProtectedProperty(char symbol)
{
this.Symbol = symbol;
}
}
record ProtectedProperty(char Symbol) : IReportCellProperty;
```

Assign properties to columns you want during building schema.
Expand Down Expand Up @@ -89,8 +81,7 @@ class MyConsoleWriter : ConsoleWriter
}

// For ProtectedProperty it's not enough to know that it's assigned as we need to know symbol to mask the value.
ProtectedProperty protectedProperty = reportCell.GetProperty<ProtectedProperty>();
if (protectedProperty != null)
if (reportCell.TryGetProperty(out ProtectedProperty protectedProperty))
{
text = new string(protectedProperty.Symbol, text.Length);
}
Expand All @@ -100,10 +91,8 @@ class MyConsoleWriter : ConsoleWriter
}

/*
EXAMPLE OUTPUT:
| Username | Password |
-----------------------------------------------
|----------------------|----------------------|
| GUEST | ***** |
| ADMIN | ******** |
*/
Expand Down Expand Up @@ -229,10 +218,12 @@ builder.AddGlobalProperties(new UpperCaseProperty());

## Table Properties

[Working example](samples/properties/XReports.DocsSamples.Properties.CellProperties/Program.cs)

Sometimes you may need to add properties to table itself, for example, it may be report title or author information.

```c#
class TitleProperty : ReportTableProperty
class TitleProperty : IReportTableProperty
{
public TitleProperty(string title)
{
Expand All @@ -246,8 +237,7 @@ class MyConsoleWriter : ConsoleWriter
{
public override void Write(IReportTable<ReportCell> reportTable)
{
TitleProperty titleProperty = reportTable.GetProperty<TitleProperty>();
if (titleProperty != null)
if (reportTable.TryGetProperty(out TitleProperty titleProperty))
{
Console.WriteLine($"*** {titleProperty.Title} ***");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override void WriteCell(ReportCell reportCell, int cellWidth)
}

// Cell property to mark cells alignment.
internal class AlignmentProperty : ReportCellProperty
internal class AlignmentProperty : IReportCellProperty
{
public AlignmentProperty(bool isLeftAligned)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
HtmlWriter writer = new HtmlWriter();
writer.Write(htmlReportTable);

internal class BoldProperty : ReportCellProperty
internal class BoldProperty : IReportCellProperty
{
}

Expand All @@ -42,7 +42,7 @@ protected override void HandleProperty(BoldProperty property, HtmlReportCell cel
}
}

internal class ItalicProperty : ReportCellProperty
internal class ItalicProperty : IReportCellProperty
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
Console.WriteLine("Email");
new HtmlWriter().Write(emailConverter.Convert(reportTable));

internal class BoldProperty : ReportCellProperty
internal class BoldProperty : IReportCellProperty
{
}

internal class ItalicProperty : ReportCellProperty
internal class ItalicProperty : IReportCellProperty
{
}

Expand Down
Loading

0 comments on commit 68e77a5

Please sign in to comment.