Beispiel #1
0
        /// <summary>
        /// Analyses the files in the given ProjectFileTree, reporting progress through the given ProgressHelper.
        /// </summary>
        /// <param name="progressHelper">The progress helper to use to report progress.</param>
        /// <param name="cont">The Controller to use.</param>
        /// <param name="tree">The project information to analyse.</param>
        public void StartAnalysis(IAnalysisProgressHelper progressHelper, IController cont, ProjectFileTree tree)
        {
            controller = cont;
            //output.BusyAnalysing = true;
            //output.ResetCounts();

            numConflicts = 0;
            numExactCopy = 0;
            numResolved  = 0;
            numNewFiles  = 0;

            log.Debug("Analysis started");

            if (progressHelper.IsCancellationPending())
            {
                progressHelper.Cancel();
                log.Debug("Analysis cancelled before it did anything.");
                return;
            }

            List <ProjectFileTreeNode> nodes = GetListOfNodesToProcess(tree.AllNodes, true);

            progressHelper.AddItemRangeToQueue(nodes);

            progressHelper.ReportProgress(0, progressHelper);
            progressHelper.ReportProgress(10, new AnalyseFilesProgress(nodes.Count, 0, 0, 0, 0, 0));

            log.Debug("Got all items to analyse, starting to process them.");

            while (progressHelper.HasItemsLeftToProcess())
            {
                if (progressHelper.IsCancellationPending())
                {
                    progressHelper.Cancel();
                    return;
                }

                ProjectFileTreeNode node = progressHelper.Dequeue();
                if (node == null)
                {
                    break;
                }
                AnalyseFile(progressHelper, node);
                progressHelper.ReportProgress(10, new AnalyseFilesProgress(progressHelper.Count, numExactCopy, numResolved, numConflicts, numAnalysisErrors + numGenerationErrors, numNewFiles, node.Path, node.Status));
                Application.DoEvents();
            }
        }
 internal ProjectFileTreeNode(ProjectFileTreeNode parentNode, ProjectFileTree parentTree)
 {
     this.parentNode = parentNode;
     this.parentTree = parentTree;
 }
        /// <summary>
        /// The write out process involves the following steps:
        /// 1. Back up the files currently in the user's project directory.
        /// 2. Write the template files that are being used to the temporary prevgen directory.
        /// 3. Write the merged files to the user's project directory.
        /// 4. Copy those temporary prevgen files over to the user's prevgen directory.
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="tempController"></param>
        /// <param name="files"></param>
        /// <param name="projectTree"></param>
        public void WriteAllFiles(TaskProgressHelper helper, IController tempController, List <IFileInformation> files, ProjectFileTree projectTree, bool overwriteExistingFiles)
        {
            controller = tempController;

            // Calculate which folders need backing up.
            List <string> directories = new List <string>();

            directories.Add("");             // The root folder.
            foreach (ProjectFileTreeNode node in projectTree.AllNodes)
            {
                if (node.IsFolder == false)
                {
                    continue;
                }
                string path = node.Path;
                if (directories.Contains(path) == false)
                {
                    directories.Add(path);
                }
            }

            //BackupUtility backupUtility = new BackupUtility();
            //string timeString = BackupUtility.GetTimeString();
            //foreach(string dir in directories)
            //{
            //    backupUtility.CreateBackup(
            //    Path.Combine(controller.CurrentProject.ProjectSettings.ProjectPath, dir),
            //    tempController.CurrentProject.ProjectSettings.ProjectGuid,
            //    Path.GetFileNameWithoutExtension(tempController.CurrentProject.ProjectSettings.TemplateFileName),
            //    Path.Combine(controller.CurrentProject.ProjectSettings.ProjectPath, dir),
            //    timeString);
            //}

            foreach (IFileInformation file in files)
            {
                if (file.CurrentDiffResult.DiffType == TypeOfDiff.Conflict)
                {
                    throw new WriteOutException(string.Format("Cannot write out files where a conflict exists! The file {0} has a conflict.", file.RelativeFilePath));
                }
            }

            foreach (IFileInformation file in files)
            {
                WriteSingleFile(file, overwriteExistingFiles);
                // Write the newly generated file to the temporary directory so we can copy it to the prevgen directory in the
                // user's project directory. We do this instead of copying the whole newgen directory so we avoid changing the
                // timestamps on the prevgen files.
                string prevgenPath = controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGeneratorOutput);
                file.WriteNewGenFile(prevgenPath);

                // TODO: Need to copy the Manifest file over from the temporary prevgen folder to the new one.
                //CopyAllManifestFiles(controller.GetTempFilePathForComponent(ComponentKey.SlyceMerge_PrevGen),
                //                     controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGeneratorOutput));

                if (file.CodeRootMap != null)
                {
                    CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();
                    string      manifestFilename        = Path.Combine(prevgenPath, ManifestConstants.MANIFEST_FILENAME);
                    XmlDocument doc = ManifestConstants.LoadManifestDocument(manifestFilename);
                    processor.SaveCustomMappings(doc, file.CodeRootMap, Path.GetFileName(file.RelativeFilePath));
                }
            }
            // Copy the temporary files we just created to the user's prevgen directory.
            CreatePrevGenFiles();
        }
 internal ProjectFileTreeNode(ProjectFileTreeNode parentNode, ProjectFileTree parentTree)
 {
     this.parentNode = parentNode;
     this.parentTree = parentTree;
 }