diff --git a/Tools/VECTOStart/StarterHelper.cs b/Tools/VECTOStart/StarterHelper.cs index 80bf7a926fa9bab39fee74f07ec6d1ff7385acee..71b70ddfd53e3f732833fe9e5d41f38b1de5d0cd 100644 --- a/Tools/VECTOStart/StarterHelper.cs +++ b/Tools/VECTOStart/StarterHelper.cs @@ -33,7 +33,7 @@ namespace TUGraz.VECTO string argumentsString = ""; if (cmdArguments.Length > 0) { foreach (var cmdArgument in cmdArguments) { - argumentsString += "\"" + cmdArgument + "\" "; + argumentsString += "\"" + SanitizeInput(cmdArgument) + "\" "; } } @@ -59,7 +59,19 @@ namespace TUGraz.VECTO } } - private static void ValidateVersion(string version, params string[] validVersions) + public static string SanitizeInput(string input) + { + var disallowedChars = new char[] { '&', ';', '|', '$' }; + + foreach (var c in disallowedChars) + { + input = input.Replace(c.ToString(), string.Empty); + } + + return input; + } + + private static void ValidateVersion(string version, params string[] validVersions) { if (!((IList)validVersions).Contains(version)) throw new Exception($"Invalid .NET Version supplied. Only the following values are valid: {string.Join(", ", validVersions)}"); diff --git a/VECTO3GUI2020/Helper/ProcessHelper.cs b/VECTO3GUI2020/Helper/ProcessHelper.cs index e8de544054341c7ab934f26908eb1833ab154c11..467d2c620a2e2cc1e5f85124db43de0f348860d4 100644 --- a/VECTO3GUI2020/Helper/ProcessHelper.cs +++ b/VECTO3GUI2020/Helper/ProcessHelper.cs @@ -55,7 +55,7 @@ namespace VECTO3GUI2020.Helper } } - argumentsString = argumentsStrBuilder.ToString(); + argumentsString = SanitizeInput(argumentsStrBuilder.ToString()); Debug.WriteLine(argumentsString); } @@ -69,5 +69,17 @@ namespace VECTO3GUI2020.Helper } } - } + public static string SanitizeInput(string input) + { + var disallowedChars = new char[] { '&', ';', '|', '$' }; + + foreach (var c in disallowedChars) + { + input = input.Replace(c.ToString(), string.Empty); + } + + return input; + } + + } } diff --git a/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs b/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs index 725d24157b2643680f26704af197cef722c91c27..77af5aef45c80c1863b9ad4f2532d1a1c5df9b27 100644 --- a/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs +++ b/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs @@ -66,7 +66,8 @@ namespace TUGraz.VectoCommon.Exceptions } } - public class VectoXMLException : VectoException + [Serializable] + public class VectoXMLException : VectoException { protected VectoXMLException(SerializationInfo info, StreamingContext context) : base(info, context) { } public VectoXMLException(string message) : base(message) { } diff --git a/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleAlternator.cs b/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleAlternator.cs index 02052660cf0f23d3f08fc30bb0f70448009c575d..c6cc436829a2f93250ec2fdf4aa0c04d194a6dd7 100644 --- a/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleAlternator.cs +++ b/VectoCore/VectoCore/Models/BusAuxiliaries/DownstreamModules/Impl/Electrics/SimpleAlternator.cs @@ -26,6 +26,13 @@ namespace TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.Electric public string Source => null; - #endregion - } + #endregion + + public override bool Equals(object obj) + { + var other = obj as SimpleAlternator; + return (other != null) && (other._efficiency == _efficiency); + } + + } } diff --git a/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs b/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs index 6db81775f88abda0fd05deb6f1efaf4f7f609227..35b27396e3570514ee7eecb3423be7aee4ba954a 100644 --- a/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs +++ b/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs @@ -209,17 +209,15 @@ namespace TUGraz.VectoCore.OutputData.FileIO public virtual void WriteReport(ReportType type, Stream data) { - Stream stream = null; - switch (type) { - case ReportType.DeclarationReportPdf: - stream = new FileStream(PDFReportName, FileMode.Create); - break; - default: + if (type != ReportType.DeclarationReportPdf) + { + throw new ArgumentOutOfRangeException($"ReportType is {type}, but {ReportType.DeclarationReportPdf} is expected."); + } - throw new ArgumentOutOfRangeException("type"); - } - data.CopyToAsync(stream); - //stream.Write(data); + using (Stream stream = new FileStream(PDFReportName, FileMode.Create)) + { + data.CopyToAsync(stream); + } } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Utils/IterationStatistics.cs b/VectoCore/VectoCore/Utils/IterationStatistics.cs index 84fe22268042b74e903f2f575c18792fbe57e258..9d21f7cdddf37ea16dff37d67ca7590f39bb6072 100644 --- a/VectoCore/VectoCore/Utils/IterationStatistics.cs +++ b/VectoCore/VectoCore/Utils/IterationStatistics.cs @@ -127,8 +127,11 @@ namespace TUGraz.VectoCore.Utils } table.Rows.Add(row); } - var writer = new StreamWriter("statistics_" + runName + ".csv"); - VectoCSVFile.Write(writer, table); + + using (var writer = new StreamWriter("statistics_" + runName + ".csv")) + { + VectoCSVFile.Write(writer, table); + } } public sealed class DataEntry