Base class for tool file converters. Encapsulates the common logic for populating the logicalLocations dictionary.
예제 #1
0
        /// <summary>Converts a tool log file represented as a stream into the SARIF format.</summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <exception cref="ArgumentException">Thrown when one or more arguments have unsupported or
        /// illegal values.</exception>
        /// <param name="toolFormat">The tool format of the input file.</param>
        /// <param name="inputStream">A stream that contains tool log contents.</param>
        /// <param name="outputStream">A stream to which the converted output should be written.</param>
        /// <param name="pluginAssemblyPath">Path to plugin assembly containing converter types.</param>
        public void ConvertToStandardFormat(
            string toolFormat,
            Stream inputStream,
            IResultLogWriter outputStream,
            LoggingOptions loggingOptions = LoggingOptions.None,
            string pluginAssemblyPath     = null)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException(nameof(inputStream));
            }
            if (outputStream == null)
            {
                throw new ArgumentNullException(nameof(outputStream));
            }

            ConverterFactory factory = CreateConverterFactory(pluginAssemblyPath);

            ToolFileConverterBase converter = factory.CreateConverter(toolFormat);

            if (converter != null)
            {
                converter.Convert(inputStream, outputStream, loggingOptions);
            }
            else
            {
                throw new ArgumentException("Unrecognized tool specified: " + toolFormat, nameof(toolFormat));
            }
        }
예제 #2
0
        public static ResultLogObjectWriter GetConverterObjects(ToolFileConverterBase converter, byte[] inputData)
        {
            var result = new ResultLogObjectWriter();
            using (var input = new MemoryStream(inputData))
            {
                converter.Convert(input, result);
            }

            return result;
        }
예제 #3
0
        public static string GetConverterJson(ToolFileConverterBase converter, byte[] inputData)
        {
            using (var input = new MemoryStream(inputData))
            {
                using (var output = new StringWriter())
                {
                    var json = new JsonTextWriter(output);
                    json.Formatting = Newtonsoft.Json.Formatting.Indented;
                    json.CloseOutput = false;
                    using (var outputWriter = new ResultLogJsonWriter(json))
                    {
                        converter.Convert(input, outputWriter);
                    }

                    return output.ToString();
                }
            }
        }
예제 #4
0
 public static ResultLogObjectWriter GetConverterObjects(ToolFileConverterBase converter, string inputData)
 {
     return GetConverterObjects(converter, Encoding.UTF8.GetBytes(inputData));
 }
예제 #5
0
 public static string GetConverterJson(ToolFileConverterBase converter, string inputData)
 {
     return GetConverterJson(converter, Encoding.UTF8.GetBytes(inputData));
 }