/// <summary> /// Do comparison. /// </summary> public override void Execute() { Project project = App.Instance.SalesForceApp.CurrentProject; ISourceFileEditorDocument currentDocument = CurrentDocument; if (project != null && currentDocument != null) { SourceFileContent content = null; using (App.Wait("Comparing files")) content = project.Client.Meta.GetSourceFileContent(currentDocument.File); if (currentDocument.Content == content.ContentValue) { App.MessageUser("The version on the server is identical to your current version.", "Compare", System.Windows.MessageBoxImage.Information, new string[] { "OK" }); } else { string diff = DiffUtility.Diff(content.ContentValue, currentDocument.Content); TextViewDocument document = new TextViewDocument( project, diff, currentDocument.File.Name, "Compare.png", true); App.Instance.Content.OpenDocument(document); } } }
// set plagiarism result in percentage private void SetPlagiarismPercentage() { try { double percentage = 0; var sourceFileList = SourceFileContent.Distinct().ToList(); var compareResultsList = CompareResultBag.GroupBy(item => item.matchText) .Select(grp => grp.OrderBy(item => item.matchText).First()) .ToList(); if (sourceFileList.Count > 0 && compareResultsList.Count > 0) { percentage = Convert.ToDouble((double)compareResultsList.Count / (double)sourceFileList.Count) * 100; } labelPalagrismPer.Visible = true; labelPalagrismResult.Visible = true; labelPalagrismResult.Text = Math.Round(percentage, 2).ToString() + "%"; } catch (Exception ex) { throw ex; } }
// compare directory file content with browsed file content private void CompareFile(int i, string[] filesList) { try { string fileContent = GetFileText(filesList[i]); if (!string.IsNullOrEmpty(fileContent.Trim())) { foreach (string text in SourceFileContent) { if (fileContent.Replace(" ", "").ToLower().Trim().Contains(text.Replace(" ", "").ToLower().Trim())) { CompareResult compareResult = new CompareResult(); compareResult.matchText = text; compareResult.filePath = filesList[i]; // set value of chracter tracing compareResult.charTracing = SetCharTracingText(fileContent, text); CompareResultBag.Add(compareResult); } else { // for testing only CompareResult compareResult = new CompareResult(); compareResult.matchText = text; compareResult.filePath = filesList[i]; UnMatchResultBag.Add(compareResult); } } var fileMatchWords = CompareResultBag.Where(x => x.filePath == filesList[i]); if (fileMatchWords != null && fileMatchWords.ToList().Count > 0) { var compareResultsList = fileMatchWords.GroupBy(item => item.matchText) .Select(grp => grp.OrderBy(item => item.matchText).First()) .ToList(); double totalMatchWords = (double)compareResultsList.Count; double fileWordsWithCombination = SourceFileContent.Distinct().ToList().Count; double percentage = Convert.ToDouble(totalMatchWords / fileWordsWithCombination) * 100; fileMatchWords.FirstOrDefault().filePercentage = Math.Round(percentage, 2).ToString() + "%"; } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Reload the document. /// </summary> /// <returns>true if the document was reloaded.</returns> public override bool Reload() { try { _suspendAutoCheckout = true; bool canReload = true; if (IsDirty) { canReload = (App.MessageUser( "You have unsaved changes which will be lost. Do you want to proceed?", "Data Loss", System.Windows.MessageBoxImage.Warning, new string[] { "Yes", "No" }) == "Yes"); } if (canReload) { using (App.Wait("Refreshing document.")) { _serverContent = Project.Client.Meta.GetSourceFileContent(File); View.Text = _serverContent.ContentValue; View.IsReadOnly = _serverContent.IsGenerated; View.SetErrors(null); IsDirty = false; // update search index if (!Project.IsDownloadingSymbols) { using (SearchIndex searchIndex = new SearchIndex(Project.SearchFolder, true)) { searchIndex.Add( File.Id, File.FileName, File.FileType.Name, File.Name, _serverContent.ContentValue); } } } } return(canReload); } finally { _suspendAutoCheckout = false; } }
/// <summary> /// Do comparison. /// </summary> public override void Execute() { Project project = App.Instance.SalesForceApp.CurrentProject; ISourceFileEditorDocument currentDocument = CurrentDocument; if (project != null && currentDocument != null) { string otherText = null; // get the project to compare with List <string> projectNames = new List <string>(Project.Projects); projectNames.Remove(project.ProjectName); SelectProjectWindow dlg = new SelectProjectWindow(); dlg.ProjectNames = projectNames.ToArray(); dlg.SelectLabel = "Select"; if (App.ShowDialog(dlg)) { // get the other text from the selected project using (App.Wait("Getting file for comparison")) { using (Project otherProject = Project.OpenProject(dlg.SelectedProjectName)) { SourceFile[] otherFiles = otherProject.Client.Meta.GetSourceFiles( new SourceFileType[] { currentDocument.File.FileType }, false); foreach (SourceFile otherFile in otherFiles) { if (otherFile.Name == currentDocument.File.Name) { SourceFileContent otherContent = otherProject.Client.Meta.GetSourceFileContent(otherFile); otherText = otherContent.ContentValue; break; } } if (otherText == null) { otherText = String.Empty; } } } } // do comparison if (otherText != null) { if (currentDocument.Content == otherText) { App.MessageUser("The version in the other project is identical to your current version.", "Compare", System.Windows.MessageBoxImage.Information, new string[] { "OK" }); } else { string diff = DiffUtility.Diff(otherText, currentDocument.Content); TextViewDocument document = new TextViewDocument( project, diff, currentDocument.File.Name, "Compare.png", true); App.Instance.Content.OpenDocument(document); } } } }
/// <summary> /// Save changes made to the content. /// </summary> public override void Save() { if (!IsDirty) { return; } try { // check for conflict first string currentTimeStamp = null; using (App.Wait("Checking for conflicts...")) currentTimeStamp = Project.Client.Meta.GetSourceFileContentLastModifiedTimeStamp(File); if (currentTimeStamp != _serverContent.LastModifiedTimeStamp) { if (App.MessageUser( "This file has been modified since you opened it. If you continue you will overwrite the current file on the server which may result in the loss of someone else's changes. Do you want to proceed?", "Conflict", System.Windows.MessageBoxImage.Warning, new string[] { "Yes", "No" }) != "Yes") { return; } } using (App.Wait("Saving...")) { // save changes SalesForceError[] errors = Project.Client.Meta.SaveSourceFileContent( File, View.Text, _serverContent.MetadataValue); // display errors List <string> errorMessages = new List <string>(); foreach (SalesForceError error in errors) { errorMessages.Add(error.ToString()); } View.SetErrors(errorMessages); // update content if (errors.Length == 0) { currentTimeStamp = Project.Client.Meta.GetSourceFileContentLastModifiedTimeStamp(File); _serverContent = new SourceFileContent( File.FileType.Name, View.Text, currentTimeStamp); IsDirty = false; } // update search index if (!Project.IsDownloadingSymbols) { using (SearchIndex searchIndex = new SearchIndex(Project.SearchFolder, true)) { searchIndex.Add( File.Id, File.FileName, File.FileType.Name, File.Name, _serverContent.ContentValue); } } } } catch (Exception err) { App.HandleException(err); } }