コード例 #1
0
 public void GetLinkedFilesRelativePathFromFullPath()
 {
     Assert.AreEqual(String.Format("%proj%{0}LinkedFiles", Path.DirectorySeparatorChar),
                     DirectoryFinderRelativePaths.GetLinkedFilesRelativePathFromFullPath(String.Format("%proj%{0}LinkedFiles", Path.DirectorySeparatorChar),
                                                                                         Path.Combine(DirectoryFinder.FwSourceDirectory, "FDO/FDOTests/BackupRestore/Project"),
                                                                                         "Project"));
 }
コード例 #2
0
        public void GetLinkedFilesFullPathFromRelativePath()
        {
            var projectPath        = Path.Combine(DirectoryFinder.ProjectsDirectory, "TestProject");
            var linkedFilesRootDir = Path.Combine(projectPath, "LinkedFiles");
            var linkedFilesPath    =
                DirectoryFinderRelativePaths.GetLinkedFilesFullPathFromRelativePath(String.Format("%proj%{0}LinkedFiles", Path.DirectorySeparatorChar), projectPath);

            Assert.AreEqual(linkedFilesRootDir, linkedFilesPath);
        }
コード例 #3
0
        private List <string> ProcessExternalLinksRelativePaths(IDomainObjectDTORepository dtoRepos, String linkedFilesRootDir)
        {
            var filePathsInTsStrings = new List <string>();

            foreach (var dto in dtoRepos.AllInstancesWithValidClasses())              //Get the Elements for all CmObjects
            {
                if (dto.XmlBytes.IndexOfSubArray(externalLinkTag) < 0)
                {
                    continue;
                }
                var dtoXML = XElement.Parse(dto.Xml);
                foreach (var runXMLElement in dtoXML.XPathSelectElements("//Run"))
                {
                    var externalLinkAttributeForThisRun = runXMLElement.Attribute("externalLink");
                    if (externalLinkAttributeForThisRun != null)
                    {
                        try
                        {
                            //Convert the file paths which should be stored as relative paths
                            if (Path.IsPathRooted(FileUtils.ChangeWindowsPathIfLinux(externalLinkAttributeForThisRun.Value)))
                            {
                                var filePath = FileUtils.ChangeWindowsPathIfLinux(externalLinkAttributeForThisRun.Value);
                                //Check the path and if it is a rooted path which is relative to the LinkedFilesRootDir
                                //then we will have to confirm that is was changed to a relative path after the migration.
                                var fileAsRelativePath = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(filePath,
                                                                                                                 linkedFilesRootDir);
                                //Save the file paths so they can be turned into CmFiles
                                filePathsInTsStrings.Add(fileAsRelativePath);
                                //If these two strings do not match then a full path was converted to a LinkedFiles relative path
                                //so replace the path in the CmFile object.
                                if (!String.Equals(fileAsRelativePath, filePath))
                                {
                                    runXMLElement.Attribute("externalLink").Value = fileAsRelativePath;
                                    UpdateDto(dtoRepos, dto, dtoXML);
                                }
                            }
                            else
                            {
                                //if the file path was already relative we want to save it and turn it into a CmFiles
                                if (FileUtils.IsFileUriOrPath(externalLinkAttributeForThisRun.Value) && FileUtils.IsFilePathValid(externalLinkAttributeForThisRun.Value))
                                {
                                    filePathsInTsStrings.Add(externalLinkAttributeForThisRun.Value);
                                }
                            }
                        }
                        catch (ArgumentException)
                        {
                            Logger.WriteEvent("Invalid path for external link - no CmFile created: " + externalLinkAttributeForThisRun);
                        }
                    }
                }
            }
            return(filePathsInTsStrings);
        }
コード例 #4
0
        public void GetFullPathFromRelativeLFPath()
        {
            var linkedFilesRootDir = Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, "TestProject"), "LinkedFiles");
            var fullLFPath         = DirectoryFinderRelativePaths.GetFullPathFromRelativeLFPath(String.Format("AudioVisual{0}StarWars.mvi", Path.DirectorySeparatorChar), linkedFilesRootDir);
            var audioVisualFile    = Path.Combine(Path.Combine(linkedFilesRootDir, "AudioVisual"), "StarWars.mvi");

            Assert.AreEqual(audioVisualFile, fullLFPath);

            //if a fully rooted path is passed in the return value should be the path that was passed in.
            var fileUnderProjectRootDir = String.Format("{1}{0}AudioVisual{0}StarWars.mvi", Path.DirectorySeparatorChar, DirectoryFinder.FWDataDirectory);

            fullLFPath = DirectoryFinderRelativePaths.GetFullPathFromRelativeLFPath(fileUnderProjectRootDir, linkedFilesRootDir);
            Assert.AreEqual(fullLFPath, fileUnderProjectRootDir);
        }
コード例 #5
0
        public void GetRelativeLFPathFromFullFilePath()
        {
            var linkedFilesRootDir = Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, "TestProject"), "LinkedFiles");
            var audioVisualFile    = Path.Combine(Path.Combine(linkedFilesRootDir, "AudioVisual"), "StarWars.mvi");
            var relativeLFPath     = DirectoryFinderRelativePaths.GetRelativeLFPathFromFullFilePath(audioVisualFile, linkedFilesRootDir);

            Assert.AreEqual(String.Format("%lf%{0}AudioVisual{0}StarWars.mvi", Path.DirectorySeparatorChar), relativeLFPath);

            //Ensure empty string is returned when the path is not relative to the LinkedFiles directory.
            var pathNotUnderLinkedFiles = Path.Combine(DirectoryFinder.FWDataDirectory, "LordOfTheRings.mvi");

            relativeLFPath = DirectoryFinderRelativePaths.GetRelativeLFPathFromFullFilePath(pathNotUnderLinkedFiles, linkedFilesRootDir);
            Assert.True(string.IsNullOrEmpty(relativeLFPath));
        }
コード例 #6
0
        public void GetFullFilePathFromRelativeLFPath()
        {
            var linkedFilesRootDir = Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, "TestProject"), "LinkedFiles");
            var fullLFPath         = DirectoryFinderRelativePaths.GetFullFilePathFromRelativeLFPath(String.Format("%lf%{0}AudioVisual{0}StarWars.mvi", Path.DirectorySeparatorChar), linkedFilesRootDir);
            var audioVisualFile    = Path.Combine(Path.Combine(linkedFilesRootDir, "AudioVisual"), "StarWars.mvi");

            Assert.AreEqual(audioVisualFile, fullLFPath);

            //if a fully rooted path is passed in the return value should be null.
            var projectRootDir = DirectoryFinder.FWDataDirectory;

            fullLFPath = DirectoryFinderRelativePaths.GetFullFilePathFromRelativeLFPath(projectRootDir, linkedFilesRootDir);
            Assert.True(string.IsNullOrEmpty(fullLFPath));
        }
コード例 #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Marks the indicated text in the given string builder as a hyperlink.
        /// </summary>
        /// <param name="strBldr">The string builder.</param>
        /// <param name="ichStart">The index of the first character in the string builder which
        /// should be marked as hyperlink text.</param>
        /// <param name="ichLim">The "limit" index in the string builder indicating the end of
        /// the hyperlink text.</param>
        /// <param name="url">The URL that is the target of the hyperlink.</param>
        /// <param name="linkStyle">The style to use to mark the hyperlink.</param>
        /// <param name="linkedFilesRootDir">The project's LinkedFilesRootDir</param>
        /// <returns>The value returned is used to create a CmFile if it represents a file path.</returns>
        /// ------------------------------------------------------------------------------------
        public static string MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart,
                                                       int ichLim, string url, IStStyle linkStyle, string linkedFilesRootDir)
        {
            var relativeUrl = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(url, linkedFilesRootDir);

            if (string.IsNullOrEmpty(relativeUrl))
            {
                MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, url, linkStyle);
                return(url);
            }
            else
            {
                MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, relativeUrl, linkStyle);
                return(relativeUrl);
            }
        }
コード例 #8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="BackupFileSettings"/> class from an
 /// existing BackupProjectSettings object
 /// </summary>
 /// <param name="settings">The BackupProjectSettings.</param>
 /// ------------------------------------------------------------------------------------
 private BackupFileSettings(BackupProjectSettings settings)
 {
     m_backupTime              = settings.BackupTime;
     m_comment                 = settings.Comment;
     m_configurationSettings   = settings.IncludeConfigurationSettings;
     m_supportingFiles         = settings.IncludeSupportingFiles;
     m_linkedFiles             = settings.IncludeLinkedFiles;
     m_projectName             = settings.ProjectName;
     m_projectPathPersisted    = DirectoryFinder.GetPathWithoutRoot(settings.ProjectPath);
     m_spellCheckAdditions     = settings.IncludeSpellCheckAdditions;
     m_dbVersion               = settings.DbVersion;
     m_fwVersion               = settings.FwVersion;
     m_linkedFilesPathRelative = DirectoryFinderRelativePaths.GetLinkedFilesRelativePathFromFullPath(settings.LinkedFilesPath, settings.ProjectPath, settings.ProjectName);
     m_linkedFilesPathActual   = settings.LinkedFilesPath;
     m_appAbbrev               = settings.AppAbbrev;
 }
コード例 #9
0
        public void GetRelativeLinkedFilesPath()
        {
            var linkedFilesRootDir = Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, "TestProject"), "LinkedFiles");
            var audioVisualFile    = Path.Combine(Path.Combine(linkedFilesRootDir, "AudioVisual"), "StarWars.mvi");
            var relativeLFPath     = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(audioVisualFile, linkedFilesRootDir);

            Assert.True(String.Equals(String.Format("AudioVisual{0}StarWars.mvi", Path.DirectorySeparatorChar), relativeLFPath));

            //Ensure ORIGINAL path is returned when the path is not relative to the LinkedFiles directory.
            var pathNotUnderLinkedFiles = Path.Combine(DirectoryFinder.FWDataDirectory, "LordOfTheRings.mvi");

            relativeLFPath = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(pathNotUnderLinkedFiles, linkedFilesRootDir);
            Assert.True(String.Equals(pathNotUnderLinkedFiles, relativeLFPath));
            Assert.That(DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(
                            "silfw:\\localhost\\link?app%3dflex%26database%3dc%3a%5cTestLangProj%5cTestLangProj.fwdata%26server%3d%26tool%3dnaturalClassedit%26guid%3d43c9ba97-2883-4f95-aa5d-ef9309e85025%26tag%3d",
                            relativeLFPath), Is.Null, "hyperlinks should be left well alone!!");
        }
コード例 #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// FWR-2461 Data Migration: for links to files in TsStrings
        ///--turn paths into relative paths to the LinkedFiledRootDir where possible
        ///--create a CmFile for each link found in a TsString owned by a CmFolder)
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of its work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000029);

            var    langProjDto               = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            var    langProjElement           = XElement.Parse(langProjDto.Xml);
            var    linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
            string persistedLinkedFilesRootDir;

            if (linkedFilesRootDirElement == null)
            {
                persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, DirectoryFinder.ksLinkedFilesDir);
            }
            else
            {
                persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
            }
            var linkedFilesRootDir = DirectoryFinderRelativePaths.GetLinkedFilesFullPathFromRelativePath(persistedLinkedFilesRootDir,
                                                                                                         domainObjectDtoRepository.ProjectFolder);

            //-------------------------------------------------
            var             langProjectGuid             = langProjElement.Attribute("guid").Value;
            var             filePathsInTsStringsElement = AddFilePathsInTsStringsElement(langProjElement);
            DomainObjectDTO cmFolderDto;
            var             cmFolderXElement = MakeCmFolder(domainObjectDtoRepository, langProjectGuid, filePathsInTsStringsElement, CmFolderTags.LocalFilePathsInTsStrings,
                                                            out cmFolderDto);

            UpdateDto(domainObjectDtoRepository, langProjDto, langProjElement);
            //--------------------------------------------------
            var cmFolderGuid = cmFolderXElement.Attribute("guid").Value;

            var filePathsInTsStrings = ProcessExternalLinksRelativePaths(domainObjectDtoRepository, linkedFilesRootDir);

            foreach (var filePath in filePathsInTsStrings)
            {
                MakeCmFile(domainObjectDtoRepository, cmFolderGuid, cmFolderXElement, filePath);
            }

            //Now that all the CmFile references have been added to the CmFolder update it in the repository.
            UpdateDto(domainObjectDtoRepository, cmFolderDto, cmFolderXElement);

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
コード例 #11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Change any CmFile filePaths to relative paths which are actually relative to the LinkedFilesRootDir
        /// </summary>
        /// <param name="domainObjectDtoRepository">
        /// Repository of all CmObject DTOs available for one migration step.
        /// </param>
        /// <remarks>
        /// The method must add/remove/update the DTOs to the repository,
        /// as it adds/removes objects as part of its work.
        ///
        /// Implementors of this interface should ensure the Repository's
        /// starting model version number is correct for the step.
        /// Implementors must also increment the Repository's model version number
        /// at the end of its migration work.
        ///
        /// The method also should normally modify the xml string(s)
        /// of relevant DTOs, since that string will be used by the main
        /// data migration calling client (ie. BEP).
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
        {
            DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000028);

            var    langProjDto               = domainObjectDtoRepository.AllInstancesSansSubclasses("LangProject").First();
            var    langProjElement           = XElement.Parse(langProjDto.Xml);
            var    linkedFilesRootDirElement = langProjElement.Element("LinkedFilesRootDir");
            string persistedLinkedFilesRootDir;

            if (linkedFilesRootDirElement == null)
            {
                persistedLinkedFilesRootDir = Path.Combine(domainObjectDtoRepository.ProjectFolder, DirectoryFinder.ksLinkedFilesDir);
            }
            else
            {
                persistedLinkedFilesRootDir = linkedFilesRootDirElement.Value;
            }
            var linkedFilesRootDir = DirectoryFinderRelativePaths.GetLinkedFilesFullPathFromRelativePath(persistedLinkedFilesRootDir,
                                                                                                         domainObjectDtoRepository.ProjectFolder);
            //Get the Elements  for class="CmFile"
            var CmFileDtosBeforeMigration = domainObjectDtoRepository.AllInstancesSansSubclasses("CmFile");

            foreach (var fileDto in CmFileDtosBeforeMigration)
            {
                XElement cmFileXML          = XElement.Parse(fileDto.Xml);
                var      filePath           = cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value;
                var      fileAsRelativePath = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(filePath,
                                                                                                      linkedFilesRootDir);
                //If these two strings do not match then a full path was converted to a LinkedFiles relative path
                //so replace the path in the CmFile object.
                // (If fileAsRelativePath is null, we could not make sense of the path at all; it may be corrupt.
                // Certainly we can't improve it!)
                if (fileAsRelativePath != null && !String.Equals(fileAsRelativePath, filePath))
                {
                    cmFileXML.XPathSelectElement("InternalPath").XPathSelectElement("Uni").Value = fileAsRelativePath;
                    UpdateDto(domainObjectDtoRepository, fileDto, cmFileXML);
                }
            }

            DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
        }
コード例 #12
0
        private void RestoreLinkedFiles(BackupFileSettings fileSettings)
        {
            Debug.Assert(fileSettings.LinkedFilesAvailable,
                         "The option to include linked files should not be allowed if they aren't available in the backup settings");

            var proposedDestinationLinkedFilesPath =
                DirectoryFinderRelativePaths.GetLinkedFilesFullPathFromRelativePath(fileSettings.LinkedFilesPathRelativePersisted,
                                                                                    m_restoreSettings.ProjectPath);

            var linkedFilesPathInZip = fileSettings.LinkedFilesPathActualPersisted;

            if (fileSettings.LinkedFilesPathRelativePersisted.StartsWith(DirectoryFinderRelativePaths.ksProjectRelPath))
            {
                // We store any files inside the project folder as a relative path from the project's directory.
                // Make sure we don't attempt to search for the whole directory structure in the zip file. (FWR-2909)
                linkedFilesPathInZip = fileSettings.LinkedFilesPathRelativePersisted.Substring(
                    DirectoryFinderRelativePaths.ksProjectRelPath.Length + 1);
            }
            var filesContainedInLinkdFilesFolder = GetAllFilesUnderFolderInZipFileAndDateTimes(linkedFilesPathInZip);


            //If the proposed location is not in the default location under the project, then ask the user if they want
            //to restore the files to the default location instead. Otherwise just go ahead and restore the files.
            var defaultLinkedFilesPath = DirectoryFinder.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath);

            if (proposedDestinationLinkedFilesPath.Equals(defaultLinkedFilesPath))
            {
                if (!Directory.Exists(defaultLinkedFilesPath))
                {
                    Directory.CreateDirectory(proposedDestinationLinkedFilesPath);
                }
                ExternalLinksDirectoryExits(linkedFilesPathInZip, proposedDestinationLinkedFilesPath, filesContainedInLinkdFilesFolder);
            }
            else
            {
                //LinkedFiles folder does not exist which means it was not in the default location when the backup was made.
                //Therefore, ask the user if we can restore these files to the default location in the project's folder.
                using (var dlg = new RestoreLinkedFilesToProjectsFolder(m_helpTopicProvider))
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        if (dlg.fRestoreLinkedFilesToProjectFolder)
                        {
                            m_sLinkDirChangedTo = DirectoryFinder.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath);
                            //Restore the files to the project folder.
                            UncompressLinkedFiles(filesContainedInLinkdFilesFolder, m_sLinkDirChangedTo,
                                                  linkedFilesPathInZip);
                        }
                        else
                        {
                            if (!Directory.Exists(proposedDestinationLinkedFilesPath))
                            {
                                try
                                {
                                    Directory.CreateDirectory(proposedDestinationLinkedFilesPath);
                                }
                                catch (Exception error)
                                {
                                    CouldNotRestoreLinkedFilesToOriginalLocation(linkedFilesPathInZip, filesContainedInLinkdFilesFolder);
                                    return;
                                }
                            }
                            UncompressLinkedFiles(filesContainedInLinkdFilesFolder, proposedDestinationLinkedFilesPath,
                                                  linkedFilesPathInZip);
                        }
                    }
                }
            }
        }