/// <summary> /// Initializes a new instance of the <see cref="SrcMLRuntimeException"/> class. /// </summary> /// <param name="pathToExecutable">The path to executable.</param> /// <param name="arguments">The arguments.</param> /// <param name="returnValue">The return value.</param> public SrcMLRuntimeException(string pathToExecutable, string arguments, ExecutableReturnValue returnValue) : base(FormatMessage(pathToExecutable, arguments, returnValue)) { this._pathToExecutable = pathToExecutable; this._argumentString = arguments; this._returnValue = returnValue; }
/// <summary> /// Initializes a new instance of the <see cref="SrcMLRuntimeException"/> class. /// </summary> /// <param name="pathToExecutable">The path to executable.</param> /// <param name="arguments">The arguments.</param> /// <param name="returnValue">The return value.</param> public SrcMLRuntimeException(string pathToExecutable, string arguments, ExecutableReturnValue returnValue) : base(FormatMessage(pathToExecutable, arguments, returnValue)) { this._pathToExecutable = pathToExecutable; this._argumentString = arguments; this._returnValue = returnValue; }
internal static string GetErrorMessageFromReturnCode(ExecutableReturnValue value) { switch (value) { case ExecutableReturnValue.Normal: return("Normal"); case ExecutableReturnValue.Error: return("Unspecified Error"); case ExecutableReturnValue.ProblemWithInputFile: return("Problem with input file"); case ExecutableReturnValue.UnknownOption: return("Unknown option"); case ExecutableReturnValue.UnknownEncoding: return("Unknown encoding"); case ExecutableReturnValue.InvalidLanguage: return("Invalid languageFilter"); case ExecutableReturnValue.LanguageOptionSpecifiedButValueMissing: return("Language option specified, but value missing"); case ExecutableReturnValue.FilenameOptionSpecifiedButValueMissing: return("Filename option specified, but value missing"); case ExecutableReturnValue.DirectoryOptionSpecifiedButValueMissing: return("Directory option specified, but value missing"); case ExecutableReturnValue.VersionOptionSpecifiedButValueMissing: return("Version option specified, but value missing"); case ExecutableReturnValue.TextEncodingOptionSpecifiedButValueMissing: return("Text encoding option specified, but value missing"); case ExecutableReturnValue.XmlEncodingOptionSpecifiedButValueMissing: return("XML encoding option specified, but value missing"); case ExecutableReturnValue.UnitOptionSpecifiedButValueMissing: return("Unit option specified, but value missing"); case ExecutableReturnValue.UnitOptionValueIsNotValid: return("Unit option value is not valid"); case ExecutableReturnValue.InvalidCombinationOfOptions: return("Invalid combination of options"); case ExecutableReturnValue.IncompleteOutputDueToTermination: return("Incomplete output due to termination"); default: return("Unknown error code. Please report."); } }
internal static string FormatMessage(string pathToExecutable, string arguments, ExecutableReturnValue returnValue) { string executableName = Path.GetFileName(pathToExecutable); string message = KsuAdapter.GetErrorMessageFromReturnCode(returnValue); return(String.Format(CultureInfo.CurrentCulture, "{0} failed: {1}\n\t{2} {3}", executableName, message, pathToExecutable, arguments)); }
internal static void RaiseExceptionOnError(string pathToExecutable, string arguments, ExecutableReturnValue value) { if (ExecutableReturnValue.Normal != value) { throw new SrcMLRuntimeException(pathToExecutable, arguments, value); } }
internal static string FormatMessage(string pathToExecutable, string arguments, ExecutableReturnValue returnValue) { string executableName = Path.GetFileName(pathToExecutable); string message = KsuAdapter.GetErrorMessageFromReturnCode(returnValue); return String.Format(CultureInfo.CurrentCulture, "{0} failed: {1}\n\t{2} {3}", executableName, message, pathToExecutable, arguments); }
internal static string GetErrorMessageFromReturnCode(ExecutableReturnValue value) { switch (value) { case ExecutableReturnValue.Normal: return "Normal"; case ExecutableReturnValue.Error: return "Unspecified Error"; case ExecutableReturnValue.ProblemWithInputFile: return "Problem with input file"; case ExecutableReturnValue.UnknownOption: return "Unknown option"; case ExecutableReturnValue.UnknownEncoding: return "Unknown encoding"; case ExecutableReturnValue.InvalidLanguage: return "Invalid languageFilter"; case ExecutableReturnValue.LanguageOptionSpecifiedButValueMissing: return "Language option specified, but value missing"; case ExecutableReturnValue.FilenameOptionSpecifiedButValueMissing: return "Filename option specified, but value missing"; case ExecutableReturnValue.DirectoryOptionSpecifiedButValueMissing: return "Directory option specified, but value missing"; case ExecutableReturnValue.VersionOptionSpecifiedButValueMissing: return "Version option specified, but value missing"; case ExecutableReturnValue.TextEncodingOptionSpecifiedButValueMissing: return "Text encoding option specified, but value missing"; case ExecutableReturnValue.XmlEncodingOptionSpecifiedButValueMissing: return "XML encoding option specified, but value missing"; case ExecutableReturnValue.UnitOptionSpecifiedButValueMissing: return "Unit option specified, but value missing"; case ExecutableReturnValue.UnitOptionValueIsNotValid: return "Unit option value is not valid"; case ExecutableReturnValue.InvalidCombinationOfOptions: return "Invalid combination of options"; case ExecutableReturnValue.IncompleteOutputDueToTermination: return "Incomplete output due to termination"; default: return "Unknown error code. Please report."; } }
internal static void RaiseExceptionOnError(string pathToExecutable, string arguments, ExecutableReturnValue value) { if (ExecutableReturnValue.Normal != value) throw new SrcMLRuntimeException(pathToExecutable, arguments, value); }