示例#1
0
        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);
        }
示例#2
0
 private void SolutionOpenPopUpDotTxtHandler(GeneralOptionsDto generalOptionsDto)
 {
     if (generalOptionsDto.ShowSolutionOpenPopUpDotTxt)
     {
         var textFile = Path.Combine(solutionFolder, CommonConstants.SolutionOpenPopUpDotTxt);
         textFileDtos.Add(new TextFileDto {
             FileName = textFile
         });
     }
 }
示例#3
0
        private GeneralOptionsDto GetGeneralOptionsDtoFromStorage()
        {
            var generalOptions = (GeneralOptions)GetDialogPage(typeof(GeneralOptions));

            var generalOptionsDto = new GeneralOptionsDto
            {
                UnderSourceControlOnly             = generalOptions.UnderSourceControlOnly,
                KeepFileOpenAfterSave              = generalOptions.KeepFileOpenAfterSave,
                HideResultsDialogIfNoModifications = generalOptions.HideResultsDialogIfNoModifications,
            };

            return(generalOptionsDto);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }