Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Perform a restore of the project specified in the settings.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <exception cref="IOException">File does not exist, or some such problem</exception>
        /// <exception cref="InvalidBackupFileException">XML deserialization problem or required
        /// files not found in zip file</exception>
        /// ------------------------------------------------------------------------------------
        public void RestoreProject(IThreadedProgress progressDlg)
        {
            BackupFileSettings fileSettings = m_restoreSettings.Backup;

            fileSettings.Validate();             // Normally, this will already have been done, so this will do nothing.

            bool suppressConversion = false;

            //First of all, if the project exists and we are overwriting it, then make a copy of the project.  That way
            //if the restoration fails part way through, we can put it back the way it was.
            if (Directory.Exists(m_restoreSettings.ProjectPath))
            {
                // If the project already exists using the fwdata extension, either we're not sharing,
                // or it is a project for which sharing is suppressed. In any case we don't want to
                // convert the new project.
                suppressConversion = File.Exists(m_restoreSettings.FullProjectPath);
                CreateACopyOfTheProject();
            }

            //When restoring a project, ensure all the normal folders are there even if some
            //of those folders had nothing from them in the backup.
            Directory.CreateDirectory(m_restoreSettings.ProjectPath);
            FdoCache.CreateProjectSubfolders(m_restoreSettings.ProjectPath);

            try
            {
                //Import from FW version 6.0 based on the file extension.
                string extension = Path.GetExtension(fileSettings.File).ToLowerInvariant();
                if (extension == FwFileExtensions.ksFw60BackupFileExtension || extension == ".xml")
                {
                    ImportFrom6_0Backup(fileSettings, progressDlg);
                }
                else                     //Restore from FW version 7.0 and newer backup.
                {
                    RestoreFrom7_0AndNewerBackup(fileSettings);
                }
            }
            catch (Exception error)
            {
                if (error is IOException || error is InvalidBackupFileException ||
                    error is UnauthorizedAccessException)
                {
                    CleanupAfterRestore(false);
                    // ENHANCE: If/when we have the restore process using a progress dialog so that this code
                    // runs in the progress dialog thread instead of the main thread, all message boxes should
                    // be replaced with the ThreadHelper.ShowMessageBox() method so that they will be thread-safe.
                    MessageBoxUtils.Show(null, error.Message, AppStrings.ksRestoreDidNotSucceed,
                                         MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                throw;
            }

            // switch to the desired backend (if it's in the projects directory...anything else stays XML for now).
            if (DirectoryFinder.IsSubFolderOfProjectsDirectory(m_restoreSettings.ProjectPath) && !suppressConversion)
            {
                ClientServerServices.Current.Local.ConvertToDb4oBackendIfNeeded(progressDlg, m_restoreSettings.FullProjectPath);
            }

            CleanupAfterRestore(true);
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Perform a restore of the project specified in the settings.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <exception cref="IOException">File does not exist, or some such problem</exception>
        /// <exception cref="InvalidBackupFileException">XML deserialization problem or required
        /// files not found in zip file</exception>
        /// ------------------------------------------------------------------------------------
        public void RestoreProject(IThreadedProgress progressDlg)
        {
            BackupFileSettings fileSettings = m_restoreSettings.Backup;

            fileSettings.Validate();             // Normally, this will already have been done, so this will do nothing.

            bool suppressConversion = false;

            //First of all, if the project exists and we are overwriting it, then make a copy of the project.  That way
            //if the restoration fails part way through, we can put it back the way it was.
            if (Directory.Exists(m_restoreSettings.ProjectPath))
            {
                // If the project already exists using the fwdata extension, either we're not sharing,
                // or it is a project for which sharing is suppressed. In any case we don't want to
                // convert the new project.
                suppressConversion = File.Exists(m_restoreSettings.FullProjectPath);
                CreateACopyOfTheProject();
            }

            //When restoring a project, ensure all the normal folders are there even if some
            //of those folders had nothing from them in the backup.
            Directory.CreateDirectory(m_restoreSettings.ProjectPath);
            FdoCache.CreateProjectSubfolders(m_restoreSettings.ProjectPath);

            try
            {
                //Import from FW version 6.0 based on the file extension.
                var extension = Path.GetExtension(fileSettings.File).ToLowerInvariant();
                if (extension == FdoFileHelper.ksFw60BackupFileExtension || extension == ".xml")
                {
                    ImportFrom6_0Backup(fileSettings, progressDlg);
                }
                else                     //Restore from FW version 7.0 and newer backup.
                {
                    RestoreFrom7_0AndNewerBackup(fileSettings);
                }
            }
            catch (Exception error)
            {
                if (error is IOException || error is InvalidBackupFileException ||
                    error is UnauthorizedAccessException)
                {
                    CleanupAfterRestore(false);
                }
                throw;
            }

            // switch to the desired backend (if it's in the projects directory...anything else stays XML for now).
            if (Path.GetDirectoryName(m_restoreSettings.ProjectPath) == m_restoreSettings.ProjectsRootFolder && !suppressConversion)
            {
                ClientServerServices.Current.Local.ConvertToDb4oBackendIfNeeded(progressDlg, m_restoreSettings.FullProjectPath);
            }

            CleanupAfterRestore(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Import from a 6.0 XML file.
        /// </summary>
        public bool ImportFrom6_0Xml(string pathname, string folderName, string projectFile)
        {
            bool   retval        = true;
            bool   fCreateFolder = !Directory.Exists(folderName);
            string replacedProj  = null;

            if (fCreateFolder)
            {
                Directory.CreateDirectory(folderName);
            }
            else if (File.Exists(projectFile))
            {
                replacedProj = projectFile + "-replaced";
                if (File.Exists(replacedProj))
                {
                    File.Delete(replacedProj);
                }
                File.Move(projectFile, replacedProj);
            }
            using (var process = CreateAndInitProcess(
                       Path.Combine(DirectoryFinder.FWCodeDirectory, "ConverterConsole.exe"),
                       '"' + pathname + "\" \"" + projectFile + '"'))
            {
                m_progressDlg.ProgressBarStyle = ProgressBarStyle.Marquee;                 // Can't get actual progress from external program
                m_progressDlg.Title            = Strings.ksConverting;
                string message = String.Format(Strings.ksConvertingFile, Path.GetFileNameWithoutExtension(projectFile));
                if (!(bool)m_progressDlg.RunTask(true, ProcessFile, process, message))
                {
                    // user canceled
                    retval = false;
                }
                else if (process.ExitCode != 0 || !String.IsNullOrEmpty(m_errorMessages))
                {
                    message = String.Format(Strings.ksConversionProcessFailed, process.ExitCode, m_errorMessages);
                    // ENHANCE (TimS): We should not be showing a message box at this level. If we
                    // really need to show it here, we should pass in the owning form instead of relying on
                    // Form.ActiveForm since it can return null if no .Net forms have focus.
                    MessageBoxUtils.Show(Form.ActiveForm, message, Strings.ksCannotConvert);
                    retval = false;
                }
                if (retval == false)
                {
                    File.Delete(projectFile);
                    if (fCreateFolder)
                    {
                        Directory.Delete(folderName);
                    }
                    else if (replacedProj != null)
                    {
                        File.Move(replacedProj, projectFile);
                    }
                }
                else
                {
                    try
                    {
                        string srcDir  = Path.GetDirectoryName(pathname);
                        string destDir = Path.GetDirectoryName(projectFile);
                        if (srcDir == destDir)
                        {
                            File.Delete(pathname);
                            string logfile = pathname.Replace(".xml", "-Export.log");
                            File.Delete(logfile);
                        }
                        FdoCache.CreateProjectSubfolders(folderName);
                    }
                    catch (Exception)
                    {
                        // ignore any exceptions thrown when trying to create the subdirectories.
                    }
                }
                return(retval);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Import from a 6.0 XML file.
        /// </summary>
        public bool ImportFrom6_0Xml(string pathname, string folderName, string projectFile)
        {
            bool   retval        = true;
            bool   fCreateFolder = !Directory.Exists(folderName);
            string replacedProj  = null;

            if (fCreateFolder)
            {
                Directory.CreateDirectory(folderName);
            }
            else if (File.Exists(projectFile))
            {
                replacedProj = projectFile + "-replaced";
                if (File.Exists(replacedProj))
                {
                    File.Delete(replacedProj);
                }
                File.Move(projectFile, replacedProj);
            }
            using (var process = CreateAndInitProcess(m_converterConsolePath, '"' + pathname + "\" \"" + projectFile + '"'))
            {
                m_progressDlg.IsIndeterminate = true;                 // Can't get actual progress from external program
                m_progressDlg.Title           = Strings.ksConverting;
                string message = String.Format(Strings.ksConvertingFile, Path.GetFileNameWithoutExtension(projectFile));
                if (!(bool)m_progressDlg.RunTask(true, ProcessFile, process, message))
                {
                    // user canceled
                    retval = false;
                }
                else if (process.ExitCode != 0 || !String.IsNullOrEmpty(m_errorMessages))
                {
                    message = String.Format(Strings.ksConversionProcessFailed, process.ExitCode, m_errorMessages);
                    BackOutCleanUp(projectFile, fCreateFolder, folderName, replacedProj);
                    throw new CannotConvertException(message);
                }
                if (retval == false)
                {
                    BackOutCleanUp(projectFile, fCreateFolder, folderName, replacedProj);
                }
                else
                {
                    try
                    {
                        string srcDir  = Path.GetDirectoryName(pathname);
                        string destDir = Path.GetDirectoryName(projectFile);
                        if (srcDir == destDir)
                        {
                            File.Delete(pathname);
                            string logfile = pathname.Replace(".xml", "-Export.log");
                            File.Delete(logfile);
                        }
                        FdoCache.CreateProjectSubfolders(folderName);
                    }
                    catch (Exception)
                    {
                        // ignore any exceptions thrown when trying to create the subdirectories.
                    }
                }
                return(retval);
            }
        }