public void AutomatedAnalyse() { using (_cycloneEntities = new cycloneEntities()) { List <source> sourceList = _cycloneEntities.sources.Where(a => a.time_intervals_id != null && a.time_intervals_id != "").ToList(); foreach (source source in sourceList) { source_analyzer lastAnalyse = _cycloneEntities.source_analyzer.OrderByDescending(a => a.processed_time) .Where(a => a.source_id == source.source_id).FirstOrDefault(); if (lastAnalyse != null) { DateTime lastAnalyseTime = Convert.ToDateTime(lastAnalyse.processed_time); double intervalInHours = Convert.ToDouble(_cycloneEntities.time_intervals.Where(a => a.time_intervals_id == source.time_intervals_id) .FirstOrDefault().hours_value); if (lastAnalyseTime.AddHours(intervalInHours) <= DateTime.Now) { CloneAnalyzer cloneAnalyzer = new CloneAnalyzer(); Boolean status = cloneAnalyzer.TimeToTimeAnalyse(source); } } } } }
private void getAnalysisResult() { dataGridView1.DataSource = dataTable; _cloneAnalyzer = new CloneAnalyzer(""); source_analyzer anlyzer = _cloneAnalyzer.GetAnalyzeDetailsByID(_sourceAnalyzeId); cycloneEntities _cycloneEntities = new cycloneEntities(); if (anlyzer != null) { DataRow dr = dataTable.NewRow(); dataGridView1.AllowUserToAddRows = false; dr["Source ID"] = anlyzer.source_id; _sourceId = anlyzer.source_id; dr["Analyzer ID"] = _sourceAnalyzeId; dr["Processed Time"] = anlyzer.processed_time; dr["Source File Count"] = anlyzer.source_file_count; dr["Line of Code Count"] = anlyzer.line_of_code_count; dr["Clone Class Count"] = anlyzer.clone_classes_count; dr["Clones Count"] = anlyzer.clones_count; dataTable.Rows.Add(dr); } dataGridView1.Refresh(); }
private void TimelyAnalyzeSource(string DestinationPath, string projectREF, source source) { workingDirectory = ConfigurationSettings.AppSettings["DefaultSourceLocation"]; String DefaultOutputLocation = ConfigurationSettings.AppSettings["DefaultOutputLocation"]; String batchFileLocation = ConfigurationSettings.AppSettings["CONQATEngineBATPath"]; if (Directory.Exists(workingDirectory)) { grantAccess(workingDirectory); if (Directory.Exists(workingDirectory + "\\" + projectREF)) { grantAccess(workingDirectory + "\\" + projectREF); if (File.Exists(workingDirectory + "\\" + projectREF + "\\" + projectREF + ".cqb")) { if (File.Exists(workingDirectory + "\\" + projectREF + "\\" + projectREF + ".cqr")) { var batchFile = workingDirectory + "\\" + projectREF + "\\" + projectREF + ".bat"; if (File.Exists(batchFile)) { try { Process p; ProcessStartInfo psi = new ProcessStartInfo(); psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.FileName = batchFile; psi.Arguments = " /k start /wait"; p = System.Diagnostics.Process.Start(psi); do { if (!p.HasExited) { Thread.Sleep(1000); } } while (!p.WaitForExit(1000)); p.WaitForExit(); p.Close(); //read the xml and update the database if (!File.Exists(workingDirectory + "\\" + projectREF + "\\" + "clones.xml")) { //strStatus = "Clones not found!"; } else { XmlReader xmlReader = new XmlReader(); source_analyzer sourceAnalyzer = new source_analyzer(); List <source_file> sourceFileList = new List <source_file>(); List <clone_class> cloneClassList = new List <clone_class>(); List <clone_fragment> cloneFragmentList = new List <clone_fragment>(); sourceAnalyzer = xmlReader.ReadCloneXml(workingDirectory + "\\" + projectREF + "\\" + "clones.xml", projectREF, out sourceFileList, out cloneClassList, out cloneFragmentList); sourceAnalyzer.source_path = DestinationPath; //source source = new source(); //source.create_date = DateTime.Now; //source.location = LocalFilePath; //source.source_id = projectREF; //source.source_name = ProjectName; //source.git_url = GitHubUrl; using (var _cycloneEntities = new cycloneEntities()) { //_cycloneEntities.sources.Add(source); _cycloneEntities.SaveChanges(); foreach (source_file sourceFile in sourceFileList) { sourceFile.source_id = source.source_id; _cycloneEntities.source_file.Add(sourceFile); } _cycloneEntities.SaveChanges(); _cycloneEntities.source_analyzer.Add(sourceAnalyzer); _cycloneEntities.SaveChanges(); foreach (clone_class cloneClass in cloneClassList) { _cycloneEntities.clone_class.Add(cloneClass); } _cycloneEntities.SaveChanges(); foreach (clone_fragment cloneFragment in cloneFragmentList) { _cycloneEntities.clone_fragment.Add(cloneFragment); } _cycloneEntities.SaveChanges(); TypeDetector _typeDetector = new TypeDetector(); _typeDetector.getTypes(DestinationPath); SetUpFilesForVisualizaton(sourceAnalyzer.analyzer_id); } } } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } else { string cqrFile = workingDirectory + projectREF + @"\" + projectREF + ".cqr"; var command = @batchFileLocation + "conqat.bat" + @" -f " + @"""" + cqrFile + @""""; File.WriteAllText(workingDirectory + "\\" + projectREF + "\\" + projectREF + ".bat", command); TimelyAnalyzeSource(DestinationPath, projectREF, source); } } else { //creating cqr using (StreamReader sr = new StreamReader("Templates\\CQR\\template.cqr")) { String cqrText = sr.ReadToEnd(); cqrText = cqrText.Replace("{blockSpecname}", projectREF); File.WriteAllText(workingDirectory + "\\" + projectREF + "\\" + projectREF + ".cqr", cqrText); TimelyAnalyzeSource(DestinationPath, projectREF, source); } } } else { //creating cqb using (StreamReader sr = new StreamReader("Templates\\CQB\\template.cqb")) { String cqbText = sr.ReadToEnd(); cqbText = cqbText.Replace("{blockSpecname}", projectREF) .Replace("{rootDir}", DestinationPath) .Replace("{xmlOutput}", @DefaultOutputLocation + projectREF + @"\") .Replace("{htmlPresentationOutput}", @DefaultOutputLocation + projectREF + @"\"); File.WriteAllText(workingDirectory + "\\" + projectREF + "\\" + projectREF + ".cqb", cqbText); TimelyAnalyzeSource(DestinationPath, projectREF, source); } } } else { Directory.CreateDirectory(workingDirectory + "\\" + projectREF); TimelyAnalyzeSource(DestinationPath, projectREF, source); } } }
internal source_analyzer ReadCloneXml(String _xmlpath, String sourceId, out List <source_file> _sourceFileList, out List <clone_class> _cloneClassList, out List <clone_fragment> _cloneFragmentList) { source_analyzer sourceAnalyzer = new source_analyzer(); List <source_file> sourceFileList = new List <source_file>(); List <clone_class> cloneClassList = new List <clone_class>(); List <clone_fragment> cloneFragmentList = new List <clone_fragment>(); sourceAnalyzer.analyzer_id = Guid.NewGuid().ToString(); XmlDocument xml = new XmlDocument(); XmlNamespaceManager manager = new XmlNamespaceManager(xml.NameTable); manager.AddNamespace("ns", "http://conqat.cs.tum.edu/ns/clonereport"); xml.Load(_xmlpath); XmlNodeList sourceFileXMLList = xml.SelectNodes("/ns:cloneReport/ns:sourceFile", manager); XmlNodeList cloneClassXMLList = xml.SelectNodes("/ns:cloneReport/ns:cloneClass", manager); int totalLOC = 0; foreach (XmlNode xmlNode in sourceFileXMLList) { string id = xmlNode.Attributes["id"].Value; string path = xmlNode.Attributes["path"].Value; string location = xmlNode.Attributes["location"].Value; string length = xmlNode.Attributes["length"].Value; string fingerprint = xmlNode.Attributes["fingerprint"].Value; source_file source = new source_file(); source.file_id = id; source.file_path = location; source.line_of_code = Convert.ToInt32(length); source.source_id = sourceId; source.analyzer_id = sourceAnalyzer.analyzer_id; totalLOC += Convert.ToInt32(length); sourceFileList.Add(source); } foreach (XmlNode xmlNode in cloneClassXMLList) { // XmlNodeList cloneNodeList = xmlNode.ChildNodes.SelectNodes("/ns:clone", manager); clone_class cloneClass = new clone_class(); cloneClass.cloneclass_id = xmlNode.Attributes["id"].Value; cloneClass.clone_fragments_count = xmlNode.ChildNodes.Count; cloneClass.clone_lines_count = Convert.ToInt32(xmlNode.Attributes["normalizedLength"].Value); cloneClass.analyzer_id = sourceAnalyzer.analyzer_id; cloneClass.source_id = sourceId; // cloneClass.source_analyzer_analyzer_id = sourceAnalyzer.analyzer_id; cloneClassList.Add(cloneClass); foreach (XmlNode _xmlNode in xmlNode.ChildNodes) { clone_fragment cloneFragment = new clone_fragment(); cloneFragment.clone_fragment_id = _xmlNode.Attributes["id"].Value; cloneFragment.clone_lines_count = Convert.ToInt32(_xmlNode.Attributes["lengthInUnits"].Value); cloneFragment.start_line = Convert.ToInt32(_xmlNode.Attributes["startLine"].Value); cloneFragment.end_line = Convert.ToInt32(_xmlNode.Attributes["endLine"].Value); cloneFragment.clone_class_id = cloneClass.cloneclass_id; cloneFragment.source_file_id = _xmlNode.Attributes["sourceFileId"].Value; cloneFragment.analyzer_id = sourceAnalyzer.analyzer_id; cloneFragment.source_path = sourceFileList.Where(a => a.file_id == cloneFragment.source_file_id).FirstOrDefault().file_path; cloneFragmentList.Add(cloneFragment); } } sourceAnalyzer.source_file_count = sourceFileXMLList.Count; sourceAnalyzer.clone_classes_count = cloneClassXMLList.Count; sourceAnalyzer.source_id = sourceId; sourceAnalyzer.processed_time = DateTime.Now; sourceAnalyzer.clones_count = cloneFragmentList.Count; sourceAnalyzer.line_of_code_count = totalLOC; _cloneClassList = cloneClassList; _cloneFragmentList = cloneFragmentList; _sourceFileList = sourceFileList; return(sourceAnalyzer); }