public SarifWorkItemModel FileWorkItemInternal(SarifLog sarifLog, SarifWorkItemContext filingContext, FilingClient filingClient) { using (Logger.BeginScopeContext(nameof(FileWorkItemInternal))) { string logGuid = sarifLog.GetProperty <Guid>("guid").ToString(); // The helper below will initialize the sarif work item model with a copy // of the root pipeline filing context. This context will then be initialized // based on the current sarif log file that we're processing. // First intializes the contexts provider to the value in the current filing client. filingContext.CurrentProvider = filingClient.Provider; var sarifWorkItemModel = new SarifWorkItemModel(sarifLog, filingContext); try { // Populate the work item with the target organization/repository information. // In ADO, certain fields (such as the area path) will defaut to the // project name and so this information is used in at least that context. sarifWorkItemModel.OwnerOrAccount = filingClient.AccountOrOrganization; sarifWorkItemModel.RepositoryOrProject = filingClient.ProjectOrRepository; if (filingContext.SyncWorkItemMetadata) { Task <WorkItemModel> getMetadataTask = filingClient.GetWorkItemMetadata(sarifWorkItemModel); getMetadataTask.Wait(); sarifWorkItemModel = (SarifWorkItemModel)getMetadataTask.Result; } using (Logger.BeginScopeContext("RunTransformers")) { foreach (SarifWorkItemModelTransformer transformer in sarifWorkItemModel.Context.Transformers) { SarifWorkItemModel updatedSarifWorkItemModel = transformer.Transform(sarifWorkItemModel); // If a transformer has set the model to null, that indicates // it should be pulled from the work flow (i.e., not filed). if (updatedSarifWorkItemModel == null) { Dictionary <string, object> customDimentions = new Dictionary <string, object>(); customDimentions.Add("TransformerType", transformer.GetType().FullName); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.Canceled, customDimentions); return(null); } sarifWorkItemModel = updatedSarifWorkItemModel; } } Task <IEnumerable <WorkItemModel> > task = filingClient.FileWorkItems(new[] { sarifWorkItemModel }); task.Wait(); this.FiledWorkItems.AddRange(task.Result); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.Succeeded); } catch (Exception ex) { this.Logger.LogError(ex, "An exception was raised filing log '{logGuid}'.", logGuid); Dictionary <string, object> customDimentions = new Dictionary <string, object>(); customDimentions.Add("ExceptionType", ex.GetType().FullName); customDimentions.Add("ExceptionMessage", ex.Message); customDimentions.Add("ExceptionStackTrace", ex.ToString()); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.ExceptionRaised, customDimentions); } return(sarifWorkItemModel); } }
internal static void FileWorkItemsHelper(SarifLog sarifLog, SarifWorkItemContext filingContext, FilingClient filingClient) { // The helper below will initialize the sarif work item model with a copy // of the root pipeline filing context. This context will then be initialized // based on the current sarif log file that we're processing. SarifWorkItemModel workItemModel = new SarifWorkItemModel(sarifLog, filingContext); try { // Populate the work item with the target organization/repository information. // In ADO, certain fields (such as the area path) will defaut to the // project name and so this information is used in at least that context. workItemModel.RepositoryOrProject = filingClient.ProjectOrRepository; workItemModel.OwnerOrAccount = filingClient.AccountOrOrganization; foreach (SarifWorkItemModelTransformer transformer in workItemModel.Context.Transformers) { transformer.Transform(workItemModel); } filingClient.FileWorkItems(new[] { workItemModel }).Wait(); // TODO: We need to process updated work item models to persist filing // details back to the input SARIF file, if that was specified. // This code should either return or persist the updated models // via a property, so that the file work items command can do // this work. // // https://github.com/microsoft/sarif-sdk/issues/1774 } catch (Exception ex) { Console.Error.WriteLine(ex); } }
private void FileWorkItemsHelper(SarifLog sarifLog, SarifWorkItemContext filingContext, FilingClient filingClient) { string logGuid = sarifLog.GetProperty<Guid>("guid").ToString(); // The helper below will initialize the sarif work item model with a copy // of the root pipeline filing context. This context will then be initialized // based on the current sarif log file that we're processing. // First intializes the contexts provider to the value in the current filing client. filingContext.CurrentProvider = filingClient.Provider; var sarifWorkItemModel = new SarifWorkItemModel(sarifLog, filingContext); try { // Populate the work item with the target organization/repository information. // In ADO, certain fields (such as the area path) will defaut to the // project name and so this information is used in at least that context. sarifWorkItemModel.OwnerOrAccount = filingClient.AccountOrOrganization; sarifWorkItemModel.RepositoryOrProject = filingClient.ProjectOrRepository; foreach (SarifWorkItemModelTransformer transformer in sarifWorkItemModel.Context.Transformers) { SarifWorkItemModel updatedSarifWorkItemModel = transformer.Transform(sarifWorkItemModel); // If a transformer has set the model to null, that indicates // it should be pulled from the work flow (i.e., not filed). if (updatedSarifWorkItemModel == null) { Dictionary<string, object> customDimentions = new Dictionary<string, object>(); customDimentions.Add("TransformerType", transformer.GetType().FullName); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.Canceled, customDimentions); return; } sarifWorkItemModel = updatedSarifWorkItemModel; } Task<IEnumerable<WorkItemModel>> task = filingClient.FileWorkItems(new[] { sarifWorkItemModel }); task.Wait(); this.FiledWorkItems.AddRange(task.Result); // IMPORTANT: as we update our partitioned logs, we are actually modifying the input log file // as well. That's because our partitioning is configured to reuse references to existing // run and result objects, even though they are partitioned into a separate log file. // This approach also us to update the original log file with the filed work item details // without requiring us to build a map of results between the original log and its // partioned log files. // UpdateLogWithWorkItemDetails(sarifLog, sarifWorkItemModel.HtmlUri, sarifWorkItemModel.Uri); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.Succeeded); } catch (Exception ex) { this.Logger.LogError(ex, "An exception was raised filing log '{logGuid}'.", logGuid); Dictionary<string, object> customDimentions = new Dictionary<string, object>(); customDimentions.Add("ExceptionType", ex.GetType().FullName); customDimentions.Add("ExceptionMessage", ex.Message); customDimentions.Add("ExceptionStackTrace", ex.ToString()); LogMetricsForProcessedModel(sarifLog, sarifWorkItemModel, FilingResult.ExceptionRaised, customDimentions); } }