Skip to content

Commit

Permalink
Update code style in exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiy Korzh authored and korzh committed Mar 24, 2021
1 parent 1c869a4 commit 5e197bf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor

// filling cols
if (settings.ShowColumnNames) {

var colCellLetter = startLetter;
for (int i = 0; i < data.Cols.Count; i++) {
if (ignoredCols.Contains(i))
Expand All @@ -134,9 +133,7 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
Task WriteRowAsync(EasyDataRow row, bool isExtra = false)
{
var rowCellLetter = startLetter;
for (int i = 0; i < row.Count; i++)
{

for (int i = 0; i < row.Count; i++) {
if (ignoredCols.Contains(i))
continue;

Expand Down Expand Up @@ -229,8 +226,7 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false)

ws.Columns(2, 2 + (int)(endCellLetter - startLetter)).AdjustToContents();

using (MemoryStream memoryStream = new MemoryStream())
{
using (MemoryStream memoryStream = new MemoryStream()) {
wb.SaveAs(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

Expand All @@ -254,8 +250,7 @@ private static XLAlignmentHorizontalValues MapAlignment(ColumnAlignment alignmen

private static XLDataType MapDataType(DataType type)
{
switch (type)
{
switch (type) {
case DataType.Bool:
return XLDataType.Boolean;
case DataType.Date:
Expand All @@ -276,8 +271,9 @@ private static XLDataType MapDataType(DataType type)

private ExcelDataExportSettings MapSettings(IDataExportSettings settings)
{
if (settings is ExcelDataExportSettings)
if (settings is ExcelDataExportSettings) {
return settings as ExcelDataExportSettings;
}

var result = ExcelDataExportSettings.Default;
result.Title = settings.Title;
Expand Down
20 changes: 9 additions & 11 deletions easydata.net/src/EasyData.Exporters.Default/Csv/CsvDataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void Export(IEasyDataResultSet data, Stream stream)
/// <param name="stream">The stream.</param>
/// <param name="settings">The settings.</param>
public void Export(IEasyDataResultSet data, Stream stream, IDataExportSettings settings)
{

{
ExportAsync(data, stream, settings).GetAwaiter().GetResult();
}

Expand Down Expand Up @@ -91,12 +90,10 @@ private async Task ExportAsync(IEasyDataResultSet data, TextWriter writer, IData
var ignoredCols = GetIgnoredColumns(data, settings);

//creating header
if (mappedSettings.ShowColumnNames)
{
if (mappedSettings.ShowColumnNames) {
var val = new StringBuilder();

for (int i = 0; i < data.Cols.Count; i++)
{
for (int i = 0; i < data.Cols.Count; i++) {
if (ignoredCols.Contains(i))
continue;

Expand All @@ -110,7 +107,8 @@ private async Task ExportAsync(IEasyDataResultSet data, TextWriter writer, IData
}


async Task WriteRowAsync(EasyDataRow row, bool isExtra = false) {
async Task WriteRowAsync(EasyDataRow row, bool isExtra = false)
{
var rowContent = new StringBuilder();

for (int i = 0; i < row.Count; i++)
Expand All @@ -132,7 +130,6 @@ async Task WriteRowAsync(EasyDataRow row, bool isExtra = false) {


foreach (var row in data.Rows) {

var add = settings?.RowFilter?.Invoke(row);
if (add.HasValue && !add.Value)
continue;
Expand All @@ -144,11 +141,11 @@ async Task WriteRowAsync(EasyDataRow row, bool isExtra = false) {

}

if (mappedSettings.BeforeRowAdded != null)
if (mappedSettings.BeforeRowAdded != null) {
await mappedSettings.BeforeRowAdded(null, WriteExtraRowAsync);
}

await writer.FlushAsync().ConfigureAwait(false);

}

/// <summary>
Expand Down Expand Up @@ -190,8 +187,9 @@ protected string GetFormattedValue(object val, DataType dataType, CsvDataExportS

private CsvDataExportSettings MapSettings(IDataExportSettings settings)
{
if (settings is CsvDataExportSettings)
if (settings is CsvDataExportSettings) {
return settings as CsvDataExportSettings;
}

var result = CsvDataExportSettings.Default;
result.Title = settings.Title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ async Task RenderRowAsync(EasyDataRow row, bool isExtra = false)
{
await writer.WriteLineAsync($"<tr {(isExtra ? "class=\"eq-extra-row\"" : "")}>").ConfigureAwait(false);

for (int i = 0; i < row.Count; i++)
{

for (int i = 0; i < row.Count; i++) {
if (ignoredCols.Contains(i))
continue;

Expand All @@ -178,7 +176,6 @@ async Task RenderRowAsync(EasyDataRow row, bool isExtra = false)


foreach (var row in data.Rows) {

var add = settings?.RowFilter?.Invoke(row);
if (add.HasValue && !add.Value)
continue;
Expand All @@ -189,11 +186,11 @@ async Task RenderRowAsync(EasyDataRow row, bool isExtra = false)
await RenderRowAsync(row);

a++;

}

if (mappedSettings.BeforeRowAdded != null)
if (mappedSettings.BeforeRowAdded != null) {
await mappedSettings.BeforeRowAdded(null, RenderExtraRowAsync);
}

await writer.WriteLineAsync("</tbody>").ConfigureAwait(false);
await writer.WriteLineAsync("</table>").ConfigureAwait(false);
Expand Down Expand Up @@ -248,8 +245,9 @@ private static string FixHtmlTags(string s)

private static HtmlDataExportSettings MapSettings(IDataExportSettings settings)
{
if (settings is HtmlDataExportSettings)
if (settings is HtmlDataExportSettings) {
return settings as HtmlDataExportSettings;
}

var result = HtmlDataExportSettings.Default;
result.Title = settings.Title;
Expand Down
33 changes: 12 additions & 21 deletions easydata.net/src/EasyData.Exporters.PdfSharp/Pdf/PdfDataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor

var section = document.AddSection();

if (settings.ShowDatasetInfo)
{
// TO DO: render paragrap with info here
if (settings.ShowDatasetInfo) {
// TODO: render paragrap with info here
if (!string.IsNullOrWhiteSpace(mappedSettings.Title)) {
var p = section.AddParagraph();
p.Format.Alignment = ParagraphAlignment.Center;
Expand Down Expand Up @@ -126,8 +125,7 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
//ignored columns
var ignoredCols = GetIgnoredColumns(data, settings);
int colsCount = 0;
for (int i = 0; i < data.Cols.Count; i++)
{
for (int i = 0; i < data.Cols.Count; i++) {
if (ignoredCols.Contains(i))
continue;

Expand All @@ -137,9 +135,7 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
}

// filling rows
if (settings.ShowColumnNames)
{

if (settings.ShowColumnNames) {
var row = table.AddRow();
row.HeadingFormat = true;
row.Format.Alignment = ParagraphAlignment.Center;
Expand All @@ -162,9 +158,7 @@ public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExpor
}

// filling rows
var rows = data.Rows.Where(row =>
{

var rows = data.Rows.Where(row => {
var add = settings?.RowFilter?.Invoke(row);
if (add.HasValue && !add.Value)
return false;
Expand All @@ -178,11 +172,8 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false)
var pdfRow = table.AddRow();
pdfRow.TopPadding = 1.5;

for (int i = 0; i < row.Count; i++)
{

if (ignoredCols.Contains(i))
continue;
for (int i = 0; i < row.Count; i++) {
if (ignoredCols.Contains(i)) continue;

var col = data.Cols[i];
var dfmt = col.DisplayFormat;
Expand All @@ -206,23 +197,22 @@ Task WriteRowAsync(EasyDataRow row, bool isExtra = false)
Func<EasyDataRow, Task> WriteExtraRowAsync = (extraRow) => WriteRowAsync(extraRow, true);

foreach (var row in rows) {

if (mappedSettings.BeforeRowAdded != null)
await mappedSettings.BeforeRowAdded(row, WriteExtraRowAsync);

await WriteRowAsync(row);
}

if (mappedSettings.BeforeRowAdded != null)
if (mappedSettings.BeforeRowAdded != null) {
await mappedSettings.BeforeRowAdded(null, WriteExtraRowAsync);
}

// rendering pdf
var pdfRenderer = new PdfDocumentRenderer(true);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();

using (MemoryStream memoryStream = new MemoryStream())
{
using (MemoryStream memoryStream = new MemoryStream()) {
pdfRenderer.PdfDocument.Save(memoryStream, false);
memoryStream.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -280,8 +270,9 @@ protected void ApplyStyles(Document document, PdfDataExportSettings settings)

private static PdfDataExportSettings MapSettings(IDataExportSettings settings)
{
if (settings is PdfDataExportSettings)
if (settings is PdfDataExportSettings) {
return settings as PdfDataExportSettings;
}

var result = PdfDataExportSettings.Default;
result.Title = settings.Title;
Expand Down

0 comments on commit 5e197bf

Please sign in to comment.