private void getAllItems() { OldAnalysisGrid.DataSource = tblItems; _cloneAnalyzer = new CloneAnalyzer(""); List <source> sourceList = _cloneAnalyzer.GetAllOldAnalyzeDetails(); cycloneEntities _cycloneEntities = new cycloneEntities(); foreach (source i in sourceList) { DataRow dr = tblItems.NewRow(); dr["Source ID"] = i.source_id; dr["Source Name"] = i.source_name; dr["Source Location"] = i.location; dr["Last Analysed Time"] = i.create_date; dr["Line of Code in Last Analysis"] = _cycloneEntities.source_analyzer .Where(a => a.source_id == i.source_id) .OrderByDescending(a => a.processed_time).FirstOrDefault().line_of_code_count; dr["Clone Count in Last Analysis"] = _cycloneEntities.source_analyzer .Where(a => a.source_id == i.source_id) .OrderByDescending(a => a.processed_time).FirstOrDefault().clones_count; DataGridViewButtonColumn visualizeButtonColumn = new DataGridViewButtonColumn(); visualizeButtonColumn.Name = "Analysis History"; visualizeButtonColumn.Text = "View"; visualizeButtonColumn.UseColumnTextForButtonValue = true; int columnIndex = 6; if (OldAnalysisGrid.Columns["Analysis History"] == null) { OldAnalysisGrid.Columns.Insert(columnIndex, visualizeButtonColumn); } tblItems.Rows.Add(dr); } OldAnalysisGrid.Refresh(); }
private void getPreviousData() { dataGridView.DataSource = dataTable; _cloneAnalyzer = new CloneAnalyzer(""); List <source_analyzer> anlyzerList = _cloneAnalyzer.GetAllDetailsByID(sourceId); cycloneEntities _cycloneEntities = new cycloneEntities(); foreach (source_analyzer i in anlyzerList) { DataRow dr = dataTable.NewRow(); dataGridView.AllowUserToAddRows = false; dr["Source ID"] = sourceId; dr["Analyzer ID"] = i.analyzer_id.PadLeft(4, '0'); dr["Processed Time"] = i.processed_time; dr["Source File Count"] = i.source_file_count; dr["Line of Code Count"] = i.line_of_code_count; dr["Clone Class Count"] = i.clone_classes_count; dr["Clones Count"] = i.clones_count; DataGridViewButtonColumn visualizeButtonColumn = new DataGridViewButtonColumn(); visualizeButtonColumn.Name = "Visualize Statistics"; visualizeButtonColumn.Text = "Visualize"; visualizeButtonColumn.UseColumnTextForButtonValue = true; int columnIndex = 7; if (dataGridView.Columns["Visualize Statistics"] == null) { dataGridView.Columns.Insert(columnIndex, visualizeButtonColumn); } dataTable.Rows.Add(dr); } dataGridView.Refresh(); }
public source_analyzer GetAnalyzeDetailsByID(string _sourceAnalyzeId) { using (var _cycloneEntities = new cycloneEntities()) { return(_cycloneEntities.source_analyzer.Where(a => a.analyzer_id == _sourceAnalyzeId).FirstOrDefault()); } }
public List <source_analyzer> GetAllDetailsByID(String id) { using (var _cycloneEntities = new cycloneEntities()) { return(_cycloneEntities.source_analyzer.Where(a => a.source_id == id).OrderByDescending(a => a.processed_time).ToList()); } }
public List <source> GetAllOldAnalyzeDetails() { using (var _cycloneEntities = new cycloneEntities()) { return(_cycloneEntities.sources.ToList()); } }
public void getTypes(String LocalFilePath) { var ext = new List <string> { ".java" }; //TODO: Project path eka UI eken aragen danda var myFiles = Directory.GetFiles(@LocalFilePath, "*.*", SearchOption.AllDirectories) .Where(s => ext.Any(e => s.EndsWith(e))); using (var _cycloneEntities = new cycloneEntities()) { string analyzerid = _cycloneEntities.source_analyzer.OrderByDescending(a => a.processed_time).FirstOrDefault().analyzer_id; var filesList = _cycloneEntities.clone_class.Where(a => a.analyzer_id == analyzerid).ToList(); foreach (clone_class cloneclass in filesList) { var fragmentList = _cycloneEntities.clone_fragment.Where(a => a.analyzer_id == analyzerid && a.clone_class_id == cloneclass.cloneclass_id).ToList(); foreach (clone_fragment cf in fragmentList) { int i = 0; if (i > 0) { break; } String CodeBlockI = getCodeByStartAndEnd(cf.source_path, cf.start_line, cf.end_line); bool isTypeII = false; for (int j = 0; j < fragmentList.Count; j++) { if (i < j) { String CodeBlockII = getCodeByStartAndEnd(fragmentList[j].source_path, fragmentList[j].start_line, fragmentList[j].end_line); Boolean status = CompareCodeBlocks(CodeBlockI, CodeBlockII); if (!status) { isTypeII = true; break; } } } clone_class cloneClass = _cycloneEntities.clone_class.Where(a => a.cloneclass_id == cloneclass.cloneclass_id && a.analyzer_id == cloneclass.analyzer_id).FirstOrDefault(); if (isTypeII) { cloneClass.clone_class_type = "Type2"; } else { cloneClass.clone_class_type = "Type1"; } _cycloneEntities.clone_class.Attach(cloneClass); var entry = _cycloneEntities.Entry(cloneClass); entry.Property(e => e.clone_class_type).IsModified = true; _cycloneEntities.SaveChanges(); i++; } } } }
private void LoadTimeIntervalsDB() { using (var _cycloneEntities = new cycloneEntities()) { cmbInterval.DataSource = _cycloneEntities.time_intervals .Select(a => new { a.time_intervals_id, a.display_value }).ToList(); cmbInterval.ValueMember = "time_intervals_id"; cmbInterval.DisplayMember = "display_value"; } }
private string GetSourceIdByUrl(string url) { string sourceId; using (_cycloneEntities = new cycloneEntities()) { try { sourceId = _cycloneEntities.sources.Where(a => a.git_url.Contains(url)) .OrderByDescending(a => a.create_date).FirstOrDefault().source_id; } catch (Exception) { sourceId = null; } return(sourceId); } }
private void SetUpFilesForVisualizaton(string analyzeId) { WAMPVisualizationPath = ConfigurationSettings.AppSettings["WAMPVisualizationPath"]; String LocalFilePathFromCopy = ""; using (var _cycloneEntities = new cycloneEntities()) { LocalFilePathFromCopy = _cycloneEntities.source_analyzer.Where(a => a.analyzer_id == analyzeId) .FirstOrDefault().source_path; } if (LocalFilePathFromCopy != "") { if (!Directory.Exists(WAMPVisualizationPath + "\\sources")) { Directory.CreateDirectory(WAMPVisualizationPath + "\\sources"); SetUpFilesForVisualizaton(analyzeId); } else { if (!Directory.Exists(WAMPVisualizationPath + "\\sources\\" + analyzeId)) { Directory.CreateDirectory(WAMPVisualizationPath + "\\sources\\" + analyzeId); SetUpFilesForVisualizaton(analyzeId); } else { //Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(LocalFilePathFromCopy, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(LocalFilePathFromCopy, WAMPVisualizationPath + "\\sources\\" + analyzeId)); } //Copy all the files & Replaces any files with the same name foreach (string newPath in Directory.GetFiles(LocalFilePathFromCopy, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(LocalFilePathFromCopy, WAMPVisualizationPath + "\\sources\\" + analyzeId), true); } } } } }
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); } } }
public Boolean TimeToTimeAnalyse(source _source) { try { workingDirectory = ConfigurationSettings.AppSettings["DefaultSourceLocation"]; using (_cycloneEntities = new cycloneEntities()) { String SourcePath = ""; List <source_analyzer> sourceAnalyzerList = _cycloneEntities.source_analyzer.Where(a => a.source_id == _source.source_id).ToList(); if (sourceAnalyzerList.Count > 0) { var LastSourcePath = sourceAnalyzerList.OrderByDescending(a => a.processed_time) .FirstOrDefault().source_path; if (LastSourcePath != null && LastSourcePath != "") { SourcePath = LastSourcePath; } else { SourcePath = _source.location; } } else { SourcePath = _source.location; } if (SourcePath != "") { var uniqueId = Guid.NewGuid().ToString(); var DestinationPath = workingDirectory + "\\GitSources\\" + uniqueId; if (!Directory.Exists(DestinationPath)) { Directory.CreateDirectory(DestinationPath); grantAccess(DestinationPath); } //Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath)); } //Copy all the files & Replaces any files with the same name foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true); } TimelyAnalyzeSource(DestinationPath, _source.source_id, _source); } else { return(false); } } return(true); } catch (Exception) { return(false); } }
public void RetriveFromHook() { using (_onlineDBEntities = new onlineDBEntities()) { //using (TransactionScope dbContextTransaction = new TransactionScope()) //{ try { List <webHook> webHookList = _onlineDBEntities.webHooks .Where(a => a.isSync != true).ToList(); List <CodeCloneAnalysis_DB.webhook> webHookListForMYSQL = new List <webhook>(); List <CodeCloneAnalysis_DB.webhook_commits> webHookCommitsForMYSQL = new List <webhook_commits>(); List <CodeCloneAnalysis_DB.webhook_files> webHookFilesForMYSQL = new List <webhook_files>(); String source_id = ""; foreach (webHook _webhook in webHookList) { CodeCloneAnalysis_DB.webhook wh = new CodeCloneAnalysis_DB.webhook(); wh.after_id = _webhook.after; wh.before_id = _webhook.before; wh.entry_time = _webhook.entryTime; wh.head_commit_added = _webhook.headCommitAdded; wh.head_commit_id = _webhook.headCommitId; wh.head_commit_message = _webhook.headCommitMessage; wh.head_commit_modified = _webhook.headCommitModified; wh.head_commit_removed = _webhook.headCommitRemoved; wh.head_commit_url = _webhook.headCommitUrl; wh.repository_id = _webhook.repositoryId; wh.repository_url = _webhook.repositoryUrl; wh.webhook_ref_id = _webhook.webHookRefId; wh.source_id = GetSourceIdByUrl(_webhook.repositoryUrl); source_id = wh.source_id; webHookListForMYSQL.Add(wh); foreach (webHookFile _webHookfile in _webhook.webHookFiles) { CodeCloneAnalysis_DB.webhook_files whf = new webhook_files(); whf.additions = _webHookfile.additions; whf.changes = _webHookfile.changes; whf.deletions = _webHookfile.deletions; whf.file_id = _webHookfile.fileId; whf.file_name = _webHookfile.fileName; whf.patch = _webHookfile.patch; whf.status = _webHookfile.Status; whf.webhook_ref_id = _webhook.webHookRefId; webHookFilesForMYSQL.Add(whf); } foreach (webHookCommit _webHookCommit in _webhook.webHookCommits) { CodeCloneAnalysis_DB.webhook_commits whc = new webhook_commits(); whc.added = _webHookCommit.added; whc.author_name = _webHookCommit.authorName; whc.author_user_name = _webHookCommit.authorUserName; whc.committer_name = _webHookCommit.committerName; whc.committer_user_name = _webHookCommit.committerUserName; whc.git_commit_id = _webHookCommit.gitCommitId; whc.icommit_id = _webHookCommit.icommitId; whc.message = _webHookCommit.message; whc.modified = _webHookCommit.modified; whc.removed = _webHookCommit.removed; whc.timestamp = _webHookCommit.timestamp; whc.url = _webHookCommit.url; whc.webhook_ref_id = _webhook.webHookRefId; webHookCommitsForMYSQL.Add(whc); } } using (_cycloneEntities = new cycloneEntities()) { foreach (webhook wh in webHookListForMYSQL) { _cycloneEntities.webhooks.Add(wh); } _cycloneEntities.SaveChanges(); foreach (webhook_commits whc in webHookCommitsForMYSQL) { _cycloneEntities.webhook_commits.Add(whc); } foreach (webhook_files whf in webHookFilesForMYSQL) { _cycloneEntities.webhook_files.Add(whf); } _cycloneEntities.SaveChanges(); foreach (webHook webHook in webHookList) { webHook.isSync = true; webHook.TimeSync = DateTime.Now; _onlineDBEntities.webHooks.Attach(webHook); var entry = _onlineDBEntities.Entry(webHook); entry.Property(e => e.isSync).IsModified = true; entry.Property(e => e.TimeSync).IsModified = true; } UpdateModifiedUsers(webHookList, source_id); } _onlineDBEntities.SaveChanges(); // dbContextTransaction.Complete(); } catch (Exception ex) { // dbContextTransaction.Dispose(); } finally { // dbContextTransaction.Dispose(); } //} } }
private void UpdateModifiedUsers(List <webHook> webHook, string source_id) { using (_cycloneEntities = new cycloneEntities()) { if (webHook.Count > 0) { string lastAnalysisId = _cycloneEntities.source_analyzer.Where(a => a.source_id == source_id) .OrderByDescending(a => a.processed_time).FirstOrDefault().analyzer_id; List <clone_fragment> cloneFragments = _cycloneEntities.clone_fragment .Where(a => a.analyzer_id == lastAnalysisId).ToList(); foreach (webHook wh in webHook) { foreach (webHookFile whf in wh.webHookFiles) { if (whf.patch == null) { continue; } String[] changes = whf.patch.Split(new[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); List <String> StartLines = new List <string>(); for (int i = 0; i < changes.Length; i++) { if (changes[i].Trim().StartsWith("-")) { StartLines.Add(changes[i].ToString()); } } for (int i = 0; i < cloneFragments.Count(); i++) { if (cloneFragments[i].source_path.ToString().Split('\\').Last() == whf.fileName.Split('/').Last()) { bool changed = false; foreach (String str in StartLines) { int startingLine = Convert.ToInt32(str.Replace("-", "").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).First()); if (startingLine >= cloneFragments[i].start_line && startingLine <= cloneFragments[i].end_line) { changed = true; } } if (!changed) { continue; } clones_modified_users cmu = new clones_modified_users(); cmu.analyzer_id = lastAnalysisId; cmu.file_name = whf.fileName; cmu.modified_line_number = Convert.ToInt32(cloneFragments[i].start_line); cmu.modification_id = Guid.NewGuid().ToString(); cmu.source_id = source_id; cmu.status = whf.Status; cmu.timestamp = wh.entryTime; cmu.user_name = _cycloneEntities.webhook_commits.Where(a => a.webhook_ref_id == wh.webHookRefId).OrderBy(a => a.icommit_id).FirstOrDefault().committer_name; _cycloneEntities.clones_modified_users.Add(cmu); _cycloneEntities.SaveChanges(); break; } } } } } } }