Skip to content

Commit

Permalink
#1549 refactor asccii writer and replace order von missing values and…
Browse files Browse the repository at this point in the history
… display pattern
  • Loading branch information
DavidBlaa committed Apr 10, 2024
1 parent 7f11d2a commit dae7614
Showing 1 changed file with 32 additions and 42 deletions.
74 changes: 32 additions & 42 deletions Components/IO/BExIS.Io.Transform.Output/AsciiWriter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BExIS.Dlm.Entities.Data;
using BExIS.Dlm.Entities.DataStructure;
using BExIS.IO.Transform.Validation.DSValidation;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Data;
Expand Down Expand Up @@ -250,19 +251,7 @@ protected override bool AddRow(AbstractTuple tuple, long rowIndex)

if (vv != null && vv.Value != null)
{
// checking for display pattern
string format = GetStringFormat(variable.DisplayPatternId);
if (!string.IsNullOrEmpty(format))
{
value = GetFormatedValue(vv.Value, dataType, format);
}
else value = vv.Value.ToString();

// check if the value is a missing value and should be replaced
if (variable.MissingValues.Any(mv => mv.Placeholder.Equals(value)))
{
value = variable.MissingValues.FirstOrDefault(mv => mv.Placeholder.Equals(value)).DisplayName;
}
value = formatValue(vv.Value, variable.DataType, variable.DisplayPatternId, GetStringFormat(variable.DisplayPatternId), variable.MissingValues);

// Add value to row
line[i] = escapeValue(value);
Expand Down Expand Up @@ -309,22 +298,7 @@ protected override bool AddRow(DataRow row, long rowIndex, bool internalId = fal

if (variable != null)
{
string originalValue = value; //prepare to check against the missing values
//checking for display pattern
Dlm.Entities.DataStructure.DataType dataType = variable.DataType;
string format = GetStringFormat(variable.DisplayPatternId);
if (!string.IsNullOrEmpty(format))
{
value = GetFormatedValue(value, dataType, format);
}
else value = value.ToString();

// checking for missing values against the original value
if (variable.MissingValues.Any(mv => mv.Placeholder.Equals(originalValue)))
{
value = variable.MissingValues.FirstOrDefault(mv => mv.Placeholder.Equals(originalValue)).DisplayName;
}

value = formatValue(value, variable.DataType, variable.DisplayPatternId, GetStringFormat(variable.DisplayPatternId), variable.MissingValues);
}
// add value to row
line[j] = escapeValue(value);
Expand All @@ -351,19 +325,7 @@ protected override bool AddRow(string[] row, long rowIndex)

if (variable != null)
{
//checking for display pattern
Dlm.Entities.DataStructure.DataType dataType = variable.DataType;
string format = GetStringFormat(variable.DisplayPatternId);
if (!string.IsNullOrEmpty(format))
{
value = GetFormatedValue(value, dataType, format);
}
else value = value.ToString();

if (variable.MissingValues.Any(mv => mv.Placeholder.Equals(value)))
{
value = variable.MissingValues.FirstOrDefault(mv => mv.Placeholder.Equals(value)).DisplayName;
}
value = formatValue(value, variable.DataType, variable.DisplayPatternId, GetStringFormat(variable.DisplayPatternId), variable.MissingValues);
}
newRow.Add(value);
}
Expand Down Expand Up @@ -407,6 +369,34 @@ private string escapeValue(string value)
return value;
}

/// <summary>
/// convert value to format or replace as missing value
/// </summary>
/// <param name="v"></param>
/// <param name="dataType"></param>
/// <param name="displayPatternId"></param>
/// <param name="format"></param>
/// <param name="missingValues"></param>
/// <returns></returns>
private string formatValue(object v, Dlm.Entities.DataStructure.DataType dataType, long displayPatternId, string format, ICollection<MissingValue> missingValues )
{
string originalValue = v.ToString(); //prepare to check against the missing values
//checking for display pattern
if (!string.IsNullOrEmpty(format))
{
v = GetFormatedValue(v, dataType, format);
}
else v = v.ToString();

// checking for missing values against the original value
if (missingValues.Any(mv => mv.Placeholder.Equals(originalValue)))
{
v = missingValues.FirstOrDefault(mv => mv.Placeholder.Equals(originalValue)).DisplayName;
}

return v.ToString();
}

#endregion helper

#region bexis internal usage
Expand Down

0 comments on commit dae7614

Please sign in to comment.