Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0f109aa9 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

read/write files with UTF8, replace invalid characters in filenames

parent 3e800e43
No related branches found
No related tags found
No related merge requests found
......@@ -140,9 +140,9 @@ namespace TUGraz.VectoCore.OutputData
string cycleFileName)
{
var row = _table.NewRow();
row[JOB] = jobName;
row[INPUTFILE] = jobFileName;
row[CYCLE] = cycleFileName;
row[JOB] = ReplaceNotAllowedCharacters(jobName);
row[INPUTFILE] = ReplaceNotAllowedCharacters(jobFileName);
row[CYCLE] = ReplaceNotAllowedCharacters(cycleFileName);
row[STATUS] = data.RunStatus;
row[TIME] = data.Duration();
row[PPOS] = data.EnginePowerPositiveAverage().ConvertTo().Kilo.Watt;
......@@ -163,9 +163,9 @@ namespace TUGraz.VectoCore.OutputData
var row = _table.NewRow();
_table.Rows.Add(row);
row[JOB] = jobName;
row[INPUTFILE] = jobFileName;
row[CYCLE] = cycleFileName;
row[JOB] = ReplaceNotAllowedCharacters(jobName);
row[INPUTFILE] = ReplaceNotAllowedCharacters(jobFileName);
row[CYCLE] = ReplaceNotAllowedCharacters(cycleFileName);
row[STATUS] = data.RunStatus;
row[TIME] = data.Duration();
......@@ -243,6 +243,11 @@ namespace TUGraz.VectoCore.OutputData
row[PSTOP] = data.PercentStopTime();
}
private static string ReplaceNotAllowedCharacters(string text)
{
return text.Replace('#', '_').Replace(',', '_').Replace('\n', '_').Replace('\r', '_');
}
[MethodImpl(MethodImplOptions.Synchronized)]
private void WriteAuxiliaries(IModalDataContainer data, DataRow row)
{
......
......@@ -32,10 +32,12 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models;
......@@ -71,7 +73,7 @@ namespace TUGraz.VectoCore.Utils
public static DataTable Read(string fileName, bool ignoreEmptyColumns = false, bool fullHeader = false)
{
try {
return ReadData(File.ReadAllLines(fileName), ignoreEmptyColumns, fullHeader);
return ReadData(File.ReadAllLines(fileName, Encoding.UTF8), ignoreEmptyColumns, fullHeader);
} catch (Exception e) {
Logger<VectoCSVFile>().Error(e);
throw new VectoException("File {0}: {1}", fileName, e.Message);
......@@ -160,7 +162,7 @@ namespace TUGraz.VectoCore.Utils
private static string[] RemoveComments(string[] lines)
{
Contract.Requires(lines != null);
Debug.Assert(lines != null);
lines = lines.
Select(line => line.Contains('#') ? line.Substring(0, line.IndexOf(Comment)) : line).
......@@ -177,7 +179,7 @@ namespace TUGraz.VectoCore.Utils
/// <param name="table">The Datatable.</param>
public static void Write(string fileName, DataTable table)
{
var stream = new StreamWriter(fileName);
var stream = new StreamWriter(new FileStream(fileName, FileMode.Create), Encoding.UTF8);
Write(stream, table);
stream.Close();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment