private IReadOnlyList <ProjectRuleSetConflict> FindConflicts(RuleSetInformation[] aggregatedRuleSet) { List <ProjectRuleSetConflict> conflicts = new List <ProjectRuleSetConflict>(); IRuleSetInspector inspector = this.serviceProvider.GetService <IRuleSetInspector>(); inspector.AssertLocalServiceIsNotNull(); // At the moment single threaded, if needed this could be done in parallel foreach (RuleSetInformation aggregate in aggregatedRuleSet) { try { RuleConflictInfo conflict = inspector.FindConflictingRules(aggregate.BaselineFilePath, aggregate.RuleSetFilePath, aggregate.RuleSetDirectories); Debug.Assert(conflict != null); if (conflict?.HasConflicts ?? false) { conflicts.Add(new ProjectRuleSetConflict(conflict, aggregate)); } } catch (Exception ex) { if (ErrorHandler.IsCriticalException(ex)) { throw; } this.WriteWarning(Strings.ConflictsManagerFailedInFindConflicts, aggregate.RuleSetFilePath, aggregate.BaselineFilePath, ex.Message); Debug.Fail("Failed to resolve conflict for " + aggregate.RuleSetFilePath, ex.ToString()); } } return(conflicts); }
private void OnFixConflicts(IEnumerable <ProjectRuleSetConflict> conflicts) { if (this.OnFixConflictsStatus(conflicts)) { var componentModel = host.GetService <SComponentModel, IComponentModel>(); TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.FixConflictsCommandCalled); IRuleSetInspector inspector = this.host.GetService <IRuleSetInspector>(); inspector.AssertLocalServiceIsNotNull(); ISourceControlledFileSystem sccFileSystem = this.host.GetService <ISourceControlledFileSystem>(); sccFileSystem.AssertLocalServiceIsNotNull(); IRuleSetSerializer ruleSetSerializer = this.host.GetService <IRuleSetSerializer>(); ruleSetSerializer.AssertLocalServiceIsNotNull(); var fixedConflictsMap = new Dictionary <RuleSetInformation, FixedRuleSetInfo>(); foreach (RuleSetInformation ruleSetInfo in conflicts.Select(c => c.RuleSetInfo)) { FixedRuleSetInfo fixInfo = inspector.FixConflictingRules(ruleSetInfo.BaselineFilePath, ruleSetInfo.RuleSetFilePath, ruleSetInfo.RuleSetDirectories); Debug.Assert(fixInfo != null); fixedConflictsMap[ruleSetInfo] = fixInfo; sccFileSystem.QueueFileWrite(fixInfo.FixedRuleSet.FilePath, () => { ruleSetSerializer.WriteRuleSetFile(fixInfo.FixedRuleSet, fixInfo.FixedRuleSet.FilePath); return(true); }); } this.WriteFixSummaryToOutputWindow(fixedConflictsMap); if (sccFileSystem.WriteQueuedFiles()) { this.Clear(); } else { Debug.Fail("Failed to write one or more of the queued files"); } } }