public Container(string name, string folder, Data.Repository repository) { Name = name; Folder = folder; Repository = repository; }
private void Control(PerformContext hangfireContext, Probe probe, Data.Repository repo, string temp1, string temp2, string language) { switch (probe.ProbeType) { case ProbeType.CodeChanges: hangfireContext?.WriteLine(ConsoleTextColor.Green, "CodeChanges probe is activated."); // load file1, and file2 for comparison var file1 = File.ReadAllText(temp1); var file2 = File.ReadAllText(temp2); hangfireContext?.WriteLine(ConsoleTextColor.Gray, "Old version"); hangfireContext?.WriteLine(file1); hangfireContext?.WriteLine(ConsoleTextColor.Gray, "New version"); hangfireContext?.WriteLine(file2); if (!file1.Equals(file2)) { hangfireContext?.WriteLine(ConsoleTextColor.Red, $"{probe.Object.Name} is changed."); foreach (var act in probe.Actuators) { var service = _messageFactory.GetMessageService(act.Type); service.Send(repo, act, $"{probe.Object.Name} is changed."); ActuatorPrint(hangfireContext, act); } } else { hangfireContext?.WriteLine(ConsoleTextColor.Red, $"{probe.Object.Name} isn't changed."); } break; case ProbeType.StaticAnalysis: hangfireContext?.WriteLine(ConsoleTextColor.Green, "StaticAnalysis probe is activated."); hangfireContext?.WriteLine($"Strategy of the probe is {probe.Metrics.Strategy}..."); // collect the parameters List <string> parameters = new List <string>(); // for test var tex = File.ReadAllText(temp2); hangfireContext?.WriteLine(tex); // add file path parameters.Add(temp1); // transform all parameters from a to 'a' parameters.AddRange(probe.Metrics.Arguments.Select(i => $"'{i}'")); // execute static analysis script var result1 = _scriptExecutor.Execute(probe.ProbeType, language, parameters.ToArray()); // change the file path of parameters parameters[0] = temp2; // execute second static analysis script var result2 = _scriptExecutor.Execute(probe.ProbeType, language, parameters.ToArray()); if (result1.Contains(temp1)) { result1 = result1.Replace(temp1, probe.Object.Path); } if (result2.Contains(temp2)) { result2 = result2.Replace(temp2, probe.Object.Path); } // report the results upon strategy if (probe.Metrics.Strategy == ReportType.Always) { if (string.IsNullOrEmpty(result2) || result2.Equals("-1")) { hangfireContext?.WriteLine(ConsoleTextColor.Red, "No result."); } else { foreach (var act in probe.Actuators) { var service = _messageFactory.GetMessageService(act.Type); service.Send(repo, act, $"{probe.Object.Name} static analysis results. {result2}"); ActuatorPrint(hangfireContext, act); } hangfireContext?.WriteLine(result2); } } else if (probe.Metrics.Strategy == ReportType.Diff) { if (!result1.Equals(result2)) { hangfireContext?.WriteLine("There is a difference between results"); hangfireContext?.WriteLine(result1); foreach (var act in probe.Actuators) { var service = _messageFactory.GetMessageService(act.Type); service.Send(repo, act, $"{probe.Object.Name} has different static analysis results between two commits. " + "Old" + Environment.NewLine + result1 + Environment.NewLine + "**************" + Environment.NewLine + result2); ActuatorPrint(hangfireContext, act); } } else { hangfireContext?.WriteLine(ConsoleTextColor.Red, "No difference."); } } break; } // delete temporary files File.Delete(temp1); File.Delete(temp2); }