public void MatchesSavedSuccessfully()
        {
            XmlDocument doc = new XmlDocument();
            Controller controller = new CSharpController();
            controller.Reorder = true;

            CodeRootMap map = new CodeRootMap();
            CodeRoot userCR = new CodeRoot(controller);
            CodeRoot newgenCR = new CodeRoot(controller);
            CodeRoot prevgenCR = new CodeRoot(controller);

            Class clazz = new Class(controller, "Class1");
            clazz.AddChild(new Class(controller, "InnerClass"));
            userCR.AddChild(clazz);

            clazz = new Class(controller, "Class2");
            clazz.AddChild(new Class(controller, "InnerClass"));
            newgenCR.AddChild(clazz);

            clazz = new Class(controller, "Class3");
            clazz.AddChild(new Class(controller, "InnerClass"));
            prevgenCR.AddChild(clazz);

            map.AddCodeRoot(userCR,		Version.User);
            map.AddCodeRoot(newgenCR,	Version.NewGen);
            map.AddCodeRoot(prevgenCR,	Version.PrevGen);

            Assert.That(map.MatchConstructs("Class1", "Class2", "Class3"), "Matching constructs", Is.True);

            CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();
            processor.SaveCustomMappings(doc, map, "Test.cs");
            XmlNodeList nodes = doc.SelectNodes("Manifest/Mappings/CodeRootMappings/CodeRootMap");
            Assert.IsNotNull(nodes, "Couldn't find the CodeRootMap nodes");
            Assert.That(nodes.Count, Is.EqualTo(1));

            Assert.That(nodes.Item(0).Attributes["filename"].Value, Is.EqualTo("Test.cs"));

            XmlNode mappingElement = nodes.Item(0);

            XmlNode userNode = mappingElement.SelectSingleNode(ManifestConstants.UserObjectElement);
            XmlNode newgNode = mappingElement.SelectSingleNode(ManifestConstants.NewGenObjectElement);
            XmlNode prevNode = mappingElement.SelectSingleNode(ManifestConstants.PrevGenObjectElement);

            Assert.That(userNode, Is.Not.Null);
            Assert.That(newgNode, Is.Not.Null);
            Assert.That(prevNode, Is.Not.Null);

            Assert.That(userNode.InnerText, Is.EqualTo("Class1"));
            Assert.That(newgNode.InnerText, Is.EqualTo("Class2"));
            Assert.That(prevNode.InnerText, Is.EqualTo("Class3"));
        }
示例#2
0
        /// <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();
        }