internal RunVersionOne CreateRunVersionOne(Run v2Run)
        {
            RunVersionOne run = null;

            if (v2Run != null)
            {
                if (v2Run.TryGetProperty("sarifv1/run", out run))
                {
                    return(run);
                }
                else
                {
                    _currentV2Run = v2Run;

                    // We need to create the run before we start working on children
                    // because some of them will need to refer to _currentRun
                    run         = new RunVersionOne();
                    _currentRun = run;

                    CreateFileKeyIndexMappings(v2Run.Artifacts, out _v1FileKeyToV2IndexMap, out _v2FileIndexToV1KeyMap);
                    _v2RuleIndexToV1KeyMap = CreateV2RuleIndexToV1KeyMapping(v2Run.Tool.Driver.RuleDescriptors);

                    run.BaselineId   = v2Run.BaselineInstanceGuid;
                    run.Files        = CreateFileDataVersionOneDictionary();
                    run.Id           = v2Run.Id?.InstanceGuid;
                    run.AutomationId = v2Run.AggregateIds?.FirstOrDefault()?.InstanceId;

                    run.StableId = v2Run.Id?.InstanceIdLogicalComponent();

                    run.Invocation       = CreateInvocationVersionOne(v2Run.Invocations?[0]);
                    run.LogicalLocations = CreateLogicalLocationVersionOneDictionary(v2Run.LogicalLocations);
                    run.Properties       = v2Run.Properties;
                    run.Results          = new List <ResultVersionOne>();

                    run.Rules = ConvertRulesArrayToDictionary(_currentV2Run.Tool.Driver.RuleDescriptors, _v2RuleIndexToV1KeyMap);
                    run.Tool  = CreateToolVersionOne(v2Run.Tool);

                    foreach (Result v2Result in v2Run.Results)
                    {
                        run.Results.Add(CreateResultVersionOne(v2Result));
                    }

                    // Stash the entire v2 run in this v1 run's property bag
                    if (EmbedVersionTwoContentInPropertyBag)
                    {
                        run.SetProperty($"{FromPropertyBagPrefix}/run", v2Run);
                    }
                }
            }

            return(run);
        }
示例#2
0
        internal RunVersionOne CreateRun(Run v2Run)
        {
            RunVersionOne run = null;

            if (v2Run != null)
            {
                if (v2Run.TryGetProperty("sarifv1/run", out run))
                {
                    return(run);
                }
                else
                {
                    _currentV2Run = v2Run;

                    // We need to create the run before we start working on children
                    // because some of them will need to refer to _currentRun
                    run         = new RunVersionOne();
                    _currentRun = run;

                    run.Architecture     = v2Run.Architecture;
                    run.AutomationId     = v2Run.AutomationLogicalId;
                    run.BaselineId       = v2Run.BaselineInstanceGuid;
                    run.Files            = v2Run.Files?.ToDictionary(v => v.Key, v => CreateFileData(v.Value));
                    run.Id               = v2Run.InstanceGuid;
                    run.Invocation       = CreateInvocation(v2Run.Invocations?[0]);
                    run.LogicalLocations = v2Run.LogicalLocations?.ToDictionary(v => v.Key, v => CreateLogicalLocation(v.Value));
                    run.Properties       = v2Run.Properties;
                    run.Results          = new List <ResultVersionOne>();
                    run.Rules            = v2Run.Resources?.Rules?.ToDictionary(v => v.Key, v => CreateRule(v.Value));
                    run.StableId         = v2Run.LogicalId;
                    run.Tool             = CreateTool(v2Run.Tool);

                    foreach (Result v2Result in v2Run.Results)
                    {
                        run.Results.Add(CreateResult(v2Result));
                    }

                    // Stash the entire v2 run in this v1 run's property bag
                    run.SetProperty($"{FromPropertyBagPrefix}/run", v2Run);
                }
            }

            return(run);
        }