private string GetTargetFileFullPath(RulesDto rulesDto, GeneralOptionsDto generalOptionsDto) { var actualProjectPath = GetProjectPath(rulesDto.ProjectName); if (!string.IsNullOrEmpty(actualProjectPath)) { var actualFilePath = GetFilePathWithinProjectDirectory(rulesDto.FileName, actualProjectPath); if (!string.IsNullOrEmpty(actualFilePath)) { var targetFileIsUnderSourceControl = dte.SourceControl.IsItemUnderSCC(actualFilePath); if (FileIsEligibleToBeChanged(rulesDto, generalOptionsDto, actualFilePath, targetFileIsUnderSourceControl)) { if (File.Exists(actualFilePath)) { return(actualFilePath); } else { failureMessages.Add("File " + actualFilePath + " does not exist"); return(string.Empty); } } } } return(string.Empty); }
private void SolutionOpenPopUpDotTxtHandler(GeneralOptionsDto generalOptionsDto) { if (generalOptionsDto.ShowSolutionOpenPopUpDotTxt) { var textFile = Path.Combine(solutionFolder, CommonConstants.SolutionOpenPopUpDotTxt); textFileDtos.Add(new TextFileDto { FileName = textFile }); } }
private GeneralOptionsDto GetGeneralOptionsDtoFromStorage() { var generalOptions = (GeneralOptions)GetDialogPage(typeof(GeneralOptions)); var generalOptionsDto = new GeneralOptionsDto { UnderSourceControlOnly = generalOptions.UnderSourceControlOnly, KeepFileOpenAfterSave = generalOptions.KeepFileOpenAfterSave, HideResultsDialogIfNoModifications = generalOptions.HideResultsDialogIfNoModifications, }; return(generalOptionsDto); }
private bool ShowPopUpMessage(GeneralOptionsDto generalOptionsDto) { var showPopUpMessage = false; if (matchingSolutionOpened && (anyRulesProcessed || failureMessages.Count > 0)) { showPopUpMessage = true; if (generalOptionsDto.HideResultsDialogIfNoModifications && changesCount == 0) { showPopUpMessage = false; } } return(showPopUpMessage); }
private IEnumerable <string> PerformFindReplace(RulesDto rulesDto, GeneralOptionsDto generalOptionsDto, string targetFileFullPath) { var findReplaceMessages = new List <string>(); dte.ItemOperations.OpenFile(targetFileFullPath); var textDocument = dte.ActiveDocument.Object("TextDocument") as TextDocument; if (textDocument == null) { failureMessages.Add("File " + rulesDto.FileName + " is not an editable text file"); } else { var find = textDocument.DTE.Find; vsFindOptions vsFindOptions; if (rulesDto.CaseSensitive) { vsFindOptions = vsFindOptions.vsFindOptionsMatchCase; } else { vsFindOptions = vsFindOptions.vsFindOptionsFromStart; } var result = find.FindReplace(vsFindAction.vsFindActionReplaceAll, rulesDto.FindWhat, (int)vsFindOptions, rulesDto.ReplaceWith, vsFindTarget.vsFindTargetCurrentDocument); if (result == vsFindResult.vsFindResultReplaced) { changesCount++; findReplaceMessages.Add(rulesDto.FileName.ToLower() + " in " + rulesDto.ProjectName.ToLower()); dte.ActiveDocument.Save(); } } if (!generalOptionsDto.KeepFileOpenAfterSave) { dte.ActiveDocument.Close(); } return(findReplaceMessages); }
private bool FileIsEligibleToBeChanged(RulesDto rulesDto, GeneralOptionsDto generalOptionsDto, string actualFilePath, bool targetFileIsUnderSourceControl) { bool fileIsEligibleToBeChanged; if (!string.IsNullOrEmpty(actualFilePath)) { if (generalOptionsDto.UnderSourceControlOnly && !targetFileIsUnderSourceControl) { failureMessages.Add("File " + rulesDto.FileName + " is not under source-control"); fileIsEligibleToBeChanged = false; } else { fileIsEligibleToBeChanged = true; } } else { fileIsEligibleToBeChanged = false; } return(fileIsEligibleToBeChanged); }
private IEnumerable <string> ApplyChangesToSourceCode(IEnumerable <RulesDto> rulesDtos, GeneralOptionsDto generalOptionsDto, string dteSolutionFullName) { var applyChangesMessages = new List <string>(); var dteSolutionName = Path.GetFileName(dteSolutionFullName).ToLower(); projectPaths = new Dictionary <string, string>(); foreach (var rulesDto in rulesDtos.Where( x => x.Enabled && x.SolutionName.ToLower() == dteSolutionName && !string.IsNullOrEmpty(x.FindWhat) && !string.IsNullOrEmpty(x.FileName) && !string.IsNullOrEmpty(x.ProjectName))) { matchingSolutionOpened = true; try { SetProjectPaths(); anyRulesProcessed = true; rulesEnabledForThisSolutionCount++; var targetFileFullPath = GetTargetFileFullPath(rulesDto, generalOptionsDto); if (!string.IsNullOrEmpty(targetFileFullPath)) { var findReplaceMessages = PerformFindReplace(rulesDto, generalOptionsDto, targetFileFullPath); applyChangesMessages.AddRange(findReplaceMessages); } rulesProcesssedSuccessfullyCount++; } catch (Exception ex) { failureMessages.Add(ex.Message); } } rulesProcesssedUnsuccessfullyCount = rulesEnabledForThisSolutionCount - rulesProcesssedSuccessfullyCount; return(applyChangesMessages); }
private async Task <string> GetPopUpBodyAsync(IEnumerable <TextFileDto> textFileDtos, GeneralOptionsDto generalOptionsDto) { var popUpBody = string.Empty; foreach (var textFileDto in textFileDtos) { await ReadAllLinesAsync(textFileDto); textFileDto.AllLines = PackageHelper.GetTruncatedIndividualLines(textFileDto.AllLines, generalOptionsDto.LineLengthTruncationLimit); } PackageHelper.CalculateOverallLinesToShow(textFileDtos, generalOptionsDto.OverallLinesLimit); foreach (var textFileDto in textFileDtos) { popUpBody += GetPopUpMessage(textFileDto); } return(popUpBody); }