private IReadOnlyList <BaselineCommandData> WriteBaselineComparisonsForInvocationUnit(InvocationUnit unit, string reportDir, string newCommand)
        {
            if (!_unitNameAndCommandToDataPathMap.TryGetValue(unit.Name, out IReadOnlyDictionary <string, string> commandToDataRelativePathMap))
            {
                throw new Exception($"Invocation unit {unit.Name} didn't have a command-path map");
            }

            if (!_unitNameAndCommandToReportFileMap.TryGetValue(unit.Name, out IReadOnlyDictionary <string, string> commandToReportFileMap))
            {
                throw new Exception($"Invocation unit {unit.Name} didn't have a report file map");
            }

            IReadOnlyDictionary <string, DirectoryDifference> comparisonsForUnit = CreateComparisonsForInvocationUnit(commandToDataRelativePathMap);
            List <BaselineCommandData> commandInfoList = new List <BaselineCommandData>();

            foreach (KeyValuePair <string, DirectoryDifference> commandComparison in comparisonsForUnit)
            {
                string command = commandComparison.Key;
                if (!commandToDataRelativePathMap.TryGetValue(command, out string relativePath))
                {
                    throw new Exception($"Unit '{unit.Name}' data map didnt have a data path for command: '{command}'");
                }

                CommandBaseline baselineForCommand = new CommandBaseline()
                {
                    InvocationName = unit.Name,
                    Command        = command,
                    NewCommand     = newCommand,
                    FileResults    = commandComparison.Value
                };

                if (!commandToReportFileMap.TryGetValue(command, out string reportFilename))
                {
                    throw new Exception($"Unit '{unit.Name}' report map didnt have a report file for command: '{command}'");
                }

                string  reportFileFullPath = Path.Combine(reportDir, reportFilename);
                JObject serialized         = JObject.FromObject(baselineForCommand);

                File.WriteAllText(reportFileFullPath, serialized.ToString());

                BaselineCommandData dataForCommand = new BaselineCommandData()
                {
                    Command        = command,
                    RelativePath   = relativePath,
                    ReportFileName = reportFilename
                };
                commandInfoList.Add(dataForCommand);
            }

            return(commandInfoList);
        }
Beispiel #2
0
        public static InvocationBaselineUnit FromJObject(JObject source)
        {
            string name = source.GetValue(nameof(Name)).ToString();

            List <string> installRequirementList = new List <string>();
            JToken        installToken           = source.GetValue(nameof(InstallRequirements));

            foreach (string installItem in installToken.Values <string>())
            {
                installRequirementList.Add(installItem);
            }

            List <BaselineCommandData> invocationData = new List <BaselineCommandData>();

            foreach (JToken invocationJObject in source.GetValue(nameof(Invocations)))
            {
                invocationData.Add(BaselineCommandData.FromJObject((JObject)invocationJObject));
            }

            return(new InvocationBaselineUnit(name, installRequirementList, invocationData));
        }