/// <summary>Converts a tool log file 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> /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception> /// <param name="toolFormat">The tool format of the input file.</param> /// <param name="inputFileName">The input log file name.</param> /// <param name="outputFileName">The name of the file to which the resulting SARIF log shall be /// written. This cannot be a directory.</param> /// <param name="conversionOptions">Options for controlling the conversion.</param> /// <param name="pluginAssemblyPath">Path to plugin assembly containing converter types.</param> public void ConvertToStandardFormat( string toolFormat, string inputFileName, string outputFileName, LoggingOptions loggingOptions = LoggingOptions.None, OptionallyEmittedData dataToInsert = OptionallyEmittedData.None, string pluginAssemblyPath = null) { if (inputFileName == null) { throw new ArgumentNullException(nameof(inputFileName)); } if (outputFileName == null) { throw new ArgumentNullException(nameof(outputFileName)); } // FileMode settings here will results in an exception being raised if the input // file does not exist, and that an existing output file will be overwritten using (var input = File.OpenRead(inputFileName)) using (var outputTextStream = File.Create(outputFileName)) using (var outputTextWriter = new StreamWriter(outputTextStream)) using (var outputJson = new JsonTextWriter(outputTextWriter)) { if (loggingOptions.HasFlag(LoggingOptions.PrettyPrint)) { outputJson.Formatting = Formatting.Indented; } using (var output = new ResultLogJsonWriter(outputJson)) { ConvertToStandardFormat(toolFormat, input, output, dataToInsert, pluginAssemblyPath); } } }
/// <summary> /// Осуществляет перечисление сборок в папке <see cref="LibraryDirectory"/>. /// </summary> /// <param name="callbackAfterLoad">Если задано, то вызывается для сборки, если callbackBeforeLoad не задано или возвратило true.</param> /// <param name="callbackBeforeLoad">Если задано, то вызывается для каждой найденной сборки. Если возвращает false, то обработка этоЙ сборки прекращается.</param> /// <param name="enumerateAttrs">Указывает, какие библиотеки следует включить в перечисление.</param> /// <param name="nameForLogging"></param> /// <param name="tasksAllowed"></param> public static IEnumerable <TResult> Enumerate <TResult>(Func <Assembly, TResult> callbackAfterLoad, Func <string, bool> callbackBeforeLoad = null, EnumerateAttrs enumerateAttrs = EnumerateAttrs.ExcludeMicrosoft | EnumerateAttrs.ExcludeSystem, string nameForLogging = null, bool tasksAllowed = false) { var results = new HashSet <TResult>(); var measure = new MeasureTime(); try { Action <Assembly> action = (a) => { var result = callbackAfterLoad(a); if (result != null) { results.Add(result); } }; var dddddd = new Reflection.LibraryEnumerator(action, callbackBeforeLoad, enumerateAttrs, GlobalAssemblyFilter, LoggingOptions, nameForLogging, tasksAllowed); dddddd.Enumerate(); } catch (Exception) { } finally { if (!_isFirstFullEnumeration) { _isFirstFullEnumeration = true; if (LoggingOptions.HasFlag(eLoggingOptions.EnumerationSummaryFirstRun)) { Debug.WriteLine("LibraryEnumeratorFactory.Enumerate: First enumeration ends with {0}ms", measure.Calculate().TotalMilliseconds); } } } return(results); }
/// <summary> /// Осуществляет перечисление сборок в папке <see cref="LibraryDirectory"/>. /// </summary> /// <param name="callbackAfterLoad">Если задано, то вызывается для сборки, если callbackBeforeLoad не задано или возвратило true.</param> /// <param name="callbackBeforeLoad">Если задано, то вызывается для каждой найденной сборки. Если возвращает false, то обработка этоЙ сборки прекращается.</param> /// <param name="enumerateAttrs">Указывает, какие библиотеки следует включить в перечисление.</param> /// <param name="nameForLogging"></param> /// <param name="tasksAllowed"></param> public static void Enumerate(Action <Assembly> callbackAfterLoad, Func <string, bool> callbackBeforeLoad = null, EnumerateAttrs enumerateAttrs = EnumerateAttrs.ExcludeMicrosoft | EnumerateAttrs.ExcludeSystem, string nameForLogging = null, bool tasksAllowed = false) { var measure = new MeasureTime(); try { var dddddd = new Reflection.LibraryEnumerator(callbackAfterLoad, callbackBeforeLoad, enumerateAttrs, GlobalAssemblyFilter, LoggingOptions, nameForLogging, tasksAllowed); dddddd.Enumerate(); } catch (Exception) { } finally { if (!_isFirstFullEnumeration) { _isFirstFullEnumeration = true; if (LoggingOptions.HasFlag(eLoggingOptions.EnumerationSummaryFirstRun)) { Debug.WriteLine("LibraryEnumeratorFactory.Enumerate: First enumeration ends with {0}ms", measure.Calculate().TotalMilliseconds); } } } }