Ejemplo n.º 1
0
        /// <summary>
        /// Take a TextFileInformation object, diff it if it hasn't been diffed, and create a VisualDiffOutput object that
        /// represents the output of the diff in a form that can be displayed to the user.
        /// </summary>
        /// <remarks>
        /// If the Prevgen file does not exist, it will perform a diff, then copy the NewGen file into the PrevGen temporarily,
        /// so that all changes will show as User changes.
        /// </remarks>
        /// <param name="fileInfo">The TextFileInformation object that has the information on the diffed files.</param>
        /// <returns>A VisualDiffOutput object containing all of the information needed to show the output of the diff to the user.</returns>
        private VisualDiffOutput ProcessDiff(FileInformation<string> fileInfo)
        {
            if (fileInfo == null) throw new ArgumentNullException("fileInfo");

            VisualDiffOutput output = new VisualDiffOutput();

            bool virtualPrevGen = false;
            string oldPrevGenFilePath = null;

            if (fileInfo.CurrentDiffResult.DiffPerformedSuccessfully == false)
                fileInfo.PerformDiff();

            if (fileInfo.PrevGenFile.HasContents == false)
            {
                virtualPrevGen = true;
                oldPrevGenFilePath = fileInfo.PrevGenFile.FilePath;
                fileInfo.PrevGenFile.ReplaceContents(fileInfo.NewGenFile.GetContents(), true);
            }

            output.DiffType = fileInfo.CurrentDiffResult.DiffType;

            switch (fileInfo.CurrentDiffResult.DiffType)
            {
                case TypeOfDiff.ExactCopy:
                    ProcessExactCopy(fileInfo, output);
                    break;
                case TypeOfDiff.TemplateChangeOnly:
                    ProcessTemplateChange(fileInfo, output);
                    break;
                case TypeOfDiff.UserChangeOnly:
                    ProcessUserChange(fileInfo, output);
                    break;
                case TypeOfDiff.UserAndTemplateChange:
                    ProcessUserAndTemplateChange(fileInfo, output);
                    break;
                case TypeOfDiff.Conflict:
                case TypeOfDiff.Warning:
                    ProcessUserAndTemplateChange(fileInfo, output);
                    break;
            }

            if (virtualPrevGen)
            {
                fileInfo.PrevGenFile.FilePath = oldPrevGenFilePath;
                if (oldPrevGenFilePath != null)
                {
                    fileInfo.PrevGenFile.ReplaceContents("", false);
                }
            }

            return output;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Take a TextFileInformation object, diff it if it hasn't been diffed, and create a VisualDiffOutput object that
        /// represents the output of the diff in a form that can be displayed to the user.
        /// </summary>
        /// <remarks>
        /// If the Prevgen file does not exist, it will perform a diff, then copy the NewGen file into the PrevGen temporarily,
        /// so that all changes will show as User changes.
        /// </remarks>
        /// <param name="fileInfo">The TextFileInformation object that has the information on the diffed files.</param>
        /// <returns>A VisualDiffOutput object containing all of the information needed to show the output of the diff to the user.</returns>
        private VisualDiffOutput ProcessDiff(FileInformation<string> fileInfo)
        {
            if (fileInfo == null) throw new ArgumentNullException("fileInfo");

            VisualDiffOutput output = new VisualDiffOutput();

            bool virtualPrevGen = false;
            string oldPrevGenFilePath = null;

            if (fileInfo.CurrentDiffResult.DiffPerformedSuccessfully == false)
                fileInfo.PerformDiff();

            if (fileInfo.PrevGenFile.HasContents == false)
            {
                virtualPrevGen = true;
                oldPrevGenFilePath = fileInfo.PrevGenFile.FilePath;
                fileInfo.PrevGenFile.ReplaceContents(fileInfo.NewGenFile.GetContents(), true);
            }

            output.DiffType = fileInfo.CurrentDiffResult.DiffType;

            switch (fileInfo.CurrentDiffResult.DiffType)
            {
                case TypeOfDiff.ExactCopy:
                    ProcessExactCopy(fileInfo, output);
                    break;
                case TypeOfDiff.TemplateChangeOnly:
                    ProcessTemplateChange(fileInfo, output);
                    break;
                case TypeOfDiff.UserChangeOnly:
                    ProcessUserChange(fileInfo, output);
                    break;
                case TypeOfDiff.UserAndTemplateChange:
                    ProcessUserAndTemplateChange(fileInfo, output);
                    break;
                case TypeOfDiff.Conflict:
                case TypeOfDiff.Warning:
                    ProcessUserAndTemplateChange(fileInfo, output);
                    break;
            }

            if (virtualPrevGen)
            {
                fileInfo.PrevGenFile.FilePath = oldPrevGenFilePath;
                if (oldPrevGenFilePath != null)
                {
                    fileInfo.PrevGenFile.ReplaceContents("", false);
                }
            }

            return output;
        }