Beispiel #1
0
        public void BackupFileSettings_SerializationAndDeserialization()
        {
            var backupSettings = new DummyBackupProjectSettings(
                Path.Combine(DirectoryFinder.FwSourceDirectory, "FDO/FDOTests/BackupRestore"),
                "FieldWorksLanguageProject", null, FDOBackendProviderType.kXML)
            {
                Comment = "Test comment",
                IncludeSupportingFiles     = true,
                IncludeSpellCheckAdditions = true,
                LinkedFilesPath            = Path.Combine("%proj%", "LinkedFiles")
            };

            using (var stream = new MemoryStream())
            {
                BackupFileSettings.SaveToStream(backupSettings, stream);

                stream.Seek(0, SeekOrigin.Begin);

                BackupFileSettings restoredSettings = BackupFileSettings.CreateFromStream(stream);

                Assert.AreEqual(backupSettings.Comment, restoredSettings.Comment);
                Assert.AreEqual(backupSettings.IncludeConfigurationSettings, restoredSettings.IncludeConfigurationSettings);
                Assert.AreEqual(backupSettings.IncludeSupportingFiles, restoredSettings.IncludeSupportingFiles);
                Assert.AreEqual(backupSettings.IncludeSpellCheckAdditions, restoredSettings.IncludeSpellCheckAdditions);
                Assert.AreEqual(backupSettings.IncludeLinkedFiles, restoredSettings.IncludeLinkedFiles);
                Assert.AreEqual(backupSettings.ProjectName, restoredSettings.ProjectName);
                Assert.AreEqual(backupSettings.BackupTime, restoredSettings.BackupTime);
                Assert.AreEqual(backupSettings.LinkedFilesPath, restoredSettings.LinkedFilesPathRelativePersisted);
                Assert.AreEqual(backupSettings.LinkedFilesPath, restoredSettings.LinkedFilesPathActualPersisted);
            }
        }
Beispiel #2
0
 private bool SetupRestore()
 {
     try
     {
         var backupSettings = new BackupFileSettings(m_restoreFileFullPath);
         m_restoreSettings = new RestoreProjectSettings(ParatextLexiconPluginDirectoryFinder.ProjectsDirectory)
         {
             Backup = backupSettings,
             IncludeConfigurationSettings     = backupSettings.IncludeConfigurationSettings,
             IncludeLinkedFiles               = backupSettings.IncludeLinkedFiles,
             IncludeSupportingFiles           = backupSettings.IncludeSupportingFiles,
             IncludeSpellCheckAdditions       = backupSettings.IncludeSpellCheckAdditions,
             BackupOfExistingProjectRequested = false
         };
     }
     catch (InvalidBackupFileException ibfe)
     {
         MessageBox.Show(ibfe.Message, Strings.ksBackupFileProblemCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(false);
     }
     catch
     {
         MessageBox.Show(Strings.ksBackupFileProblemText, Strings.ksBackupFileProblemCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the SelectedIndexChanged event of the m_cboProjects control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        /// ------------------------------------------------------------------------------------
        private void m_cboProjects_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedProject = (string)m_cboProjects.SelectedItem;

            if (selectedProject == null)
            {
                return;                 // Hopefully this is just temporary from clearing out the list.
            }
            m_lstVersions.BeginUpdate();
            m_lstVersions.Items.Clear();
            foreach (DateTime backupDate in m_presenter.BackupRepository.GetAvailableVersions(selectedProject))
            {
                // We have to ensure that at least the first one is valid because we're going to make it
                // the default
                BackupFileSettings backupFile = m_presenter.BackupRepository.GetBackupFile(selectedProject,
                                                                                           backupDate, (m_lstVersions.Items.Count == 0));
                if (backupFile != null)
                {
                    ListViewItem newItem = new ListViewItem(new[] { backupDate.ToString(), backupFile.Comment });
                    newItem.Tag = backupFile;
                    m_lstVersions.Items.Add(newItem);
                }
            }

            m_lstVersions.EndUpdate();

            // ENHANCE: If there are no available versions for the selected project, we should
            // probably say so.
            if (m_lstVersions.Items.Count > 0)
            {
                m_lstVersions.SelectedIndices.Add(0);
            }
        }
        public void VerifyStringForBackupPropertiesLabel()
        {
            var restoreProjectPresenter       = new RestoreProjectPresenter(null, string.Empty);
            BackupFileSettings backupSettings = new BackupFileSettings(
                Path.ChangeExtension("dummy", FwFileExtensions.ksFwBackupFileExtension), false);

            // This is needed to thwart BackupFileSettings's normal logic to populate the flags
            // from the backup zip file
            ReflectionHelper.SetField(backupSettings, "m_projectName", "dummy");

            ReflectionHelper.SetField(backupSettings, "m_configurationSettings", true);
            String resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);

            Assert.AreEqual("Configuration settings", resultStr);

            ReflectionHelper.SetField(backupSettings, "m_supportingFiles", true);
            resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);
            Assert.AreEqual("Configuration settings and Supporting Files.", resultStr);

            ReflectionHelper.SetField(backupSettings, "m_configurationSettings", false);
            resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);
            Assert.AreEqual("Supporting Files", resultStr);

            ReflectionHelper.SetField(backupSettings, "m_linkedFiles", true);
            resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);
            Assert.AreEqual("Linked files and Supporting Files.", resultStr);

            ReflectionHelper.SetField(backupSettings, "m_configurationSettings", true);
            resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);
            Assert.AreEqual("Configuration settings, Linked files and Supporting Files.", resultStr);

            ReflectionHelper.SetField(backupSettings, "m_spellCheckAdditions", true);
            resultStr = restoreProjectPresenter.IncludesFiles(backupSettings);
            Assert.AreEqual("Configuration settings, Linked files, Supporting Files and Spelling dictionary.", resultStr);
        }
Beispiel #5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Sets the dialog controls from backup settings.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="suggestedNewProjectName">Name of the suggested new project.</param>
 /// ------------------------------------------------------------------------------------
 private void SetDialogControlsFromBackupSettings(BackupFileSettings settings, String suggestedNewProjectName)
 {
     EnableDisableDlgControlsForRestore(true);
     TargetProjectName = suggestedNewProjectName;
     m_configurationSettings.Checked = settings.IncludeConfigurationSettings;
     m_configurationSettings.Enabled = settings.IncludeConfigurationSettings;
     // If the settings file does not contain enough information for restoring the
     // linked files, then just disable the option. (FWR-2245)
     m_linkedFiles.Checked         = settings.LinkedFilesAvailable;
     m_linkedFiles.Enabled         = settings.LinkedFilesAvailable;
     m_supportingFiles.Checked     = settings.IncludeSupportingFiles;
     m_supportingFiles.Enabled     = settings.IncludeSupportingFiles;
     m_spellCheckAdditions.Checked = settings.IncludeSpellCheckAdditions;
     m_spellCheckAdditions.Enabled = settings.IncludeSpellCheckAdditions;
     if (m_rdoDefaultFolder.Checked)
     {
         m_lblDefaultBackupIncludes.Text = m_presenter.IncludesFiles(settings);
     }
     else
     {
         m_lblBackupProjectName.Text   = settings.ProjectName;
         m_lblBackupDate.Text          = settings.BackupTime.ToString();
         m_lblBackupComment.Text       = settings.Comment;
         m_lblOtherBackupIncludes.Text = m_presenter.IncludesFiles(settings);
     }
     SetOriginalNameFromSettings();
 }
        public void InavlidBackupFile()
        {
            DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
                                                                                       "Floozy", null, FDOBackendProviderType.kXML);
            string backupFileName1 = backupSettings.ZipFileName;

            m_fileOs.AddExistingFile(backupFileName1);
            // Force the second backup to appear to be older
            backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3);
            string backupFileName2 = backupSettings.ZipFileName;

            m_fileOs.AddExistingFile(backupFileName2);

            BackupFileRepository repo = new BackupFileRepository();
            BackupFileSettings   invalidFileSettings = repo.GetMostRecentBackup("Floozy");
            BackupFileSettings   validFileSettings   = repo.GetBackupFile("Floozy", backupSettings.BackupTime, false);

            ReflectionHelper.SetProperty(validFileSettings, "ProjectName", "Floozy");             // Force it to think it's already loaded and happy.

            Assert.AreEqual(2, repo.GetAvailableVersions("Floozy").Count());
            Assert.IsNull(repo.GetBackupFile("Floozy", invalidFileSettings.BackupTime, true));
            Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count());
            Assert.AreEqual(validFileSettings, repo.GetBackupFile("Floozy", validFileSettings.BackupTime, true));
            Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count());
        }
Beispiel #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="RestoreProjectDlg"/> class.
 /// </summary>
 /// <param name="backupFileSettings">Specific backup file settings to use (dialog
 /// controls to select a backup file will be disabled)</param>
 /// <param name="helpTopicProvider">The help topic provider.</param>
 /// ------------------------------------------------------------------------------------
 public RestoreProjectDlg(BackupFileSettings backupFileSettings,
                          IHelpTopicProvider helpTopicProvider) : this(helpTopicProvider)
 {
     m_lblBackupZipFile.Text      = backupFileSettings.File;
     m_presenter                  = new RestoreProjectPresenter(this);
     BackupFileSettings           = backupFileSettings;
     m_rdoDefaultFolder.Enabled   = m_btnBrowse.Enabled = false;
     m_rdoAnotherLocation.Checked = true;
     SetOriginalNameFromSettings();
 }
Beispiel #8
0
        public void BackupFileSettings_InitializeFromZipfileMetadata()
        {
            string zipFilePath = Path.Combine(Path.Combine(DirectoryFinder.FwSourceDirectory, "FDO/FDOTests/BackupRestore/RestoreProjectPresenterTests"),
                                              Path.ChangeExtension("RestoreProjectPresenterTests", FwFileExtensions.ksFwBackupFileExtension));

            BackupFileSettings backupSettings = new BackupFileSettings(zipFilePath);

            Assert.AreEqual("BackupOnlyCoreFiles", backupSettings.Comment);
            Assert.AreEqual("RestoreProjectPresenterTests", backupSettings.ProjectName);
            //We should test the following booleans to be true since they are false by default. This means
            //the BackupSettings.xml file needs to have these values set to true.
            Assert.AreEqual(true, backupSettings.IncludeConfigurationSettings);
            Assert.AreEqual(true, backupSettings.IncludeLinkedFiles);
            Assert.AreEqual(true, backupSettings.IncludeSupportingFiles);
            Assert.AreEqual(true, backupSettings.IncludeSpellCheckAdditions);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Return a string indicating which sets of files were included in the backup.
        /// This is internal for testing purposes.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// ------------------------------------------------------------------------------------
        internal String IncludesFiles(BackupFileSettings settings)
        {
            List <string> itemsBackedUp = new List <string>();

            if (settings.IncludeConfigurationSettings)
            {
                itemsBackedUp.Add(FwCoreDlgs.ksConfigurationSettingsRestoreDlg);
            }
            if (settings.IncludeLinkedFiles)
            {
                itemsBackedUp.Add(FwCoreDlgs.ksMediaFilesRestoreDlg);
            }
            if (settings.IncludeSupportingFiles)
            {
                itemsBackedUp.Add(FwCoreDlgs.ksSupportingFilesRestoreDlg);
            }
            if (settings.IncludeSpellCheckAdditions)
            {
                itemsBackedUp.Add(FwCoreDlgs.ksSpellingFilesRestoreDlg);
            }

            int numberOfFileSetsBackedUp = itemsBackedUp.Count;

            if (numberOfFileSetsBackedUp == 0)
            {
                return(string.Empty);
            }

            StringBuilder strbldr = new StringBuilder();

            strbldr.Append(itemsBackedUp[0]);
            for (int i = 1; i < numberOfFileSetsBackedUp - 1; i++)
            {
                strbldr.AppendFormat(", {0}", itemsBackedUp[i]);
            }
            if (numberOfFileSetsBackedUp > 1)
            {
                strbldr.AppendFormat(FwCoreDlgs.ksIncludesAndRestoreDlg, itemsBackedUp[numberOfFileSetsBackedUp - 1]);
            }
            return(strbldr.ToString());
        }
Beispiel #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when a backup version is chosen either by browsing to a zip file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void OnBackupVersionChosen()
        {
            m_rdoUseOriginalName.Text  = String.Format(m_fmtUseOriginalName, String.Empty);
            m_txtOtherProjectName.Text = String.Empty;
            Settings.Backup            = null;
            if (String.IsNullOrEmpty(BackupZipFile))
            {
                EnableDisableDlgControlsForRestore(false);
                return;
            }

            if (HandleRestoreFileErrors(this, BackupZipFile,
                                        () => BackupFileSettings = new BackupFileSettings(BackupZipFile, true)))
            {
                SetOriginalNameFromSettings();
            }
            else
            {
                EnableDisableDlgControlsForRestore(false);
            }
        }
        public void BackupsForMultipleProjects()
        {
            DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
                                                                                       "AAA", null, FDOBackendProviderType.kXML);

            backupSettings.Comment = "thing1";
            string backupFileName1 = backupSettings.ZipFileName;

            m_fileOs.AddExistingFile(backupFileName1);
            backupSettings.ProjectName = "ZZZ";
            backupSettings.Comment     = "thing2";
            string backupFileName2 = backupSettings.ZipFileName;

            m_fileOs.AddExistingFile(backupFileName2);
            // Add another backup for "AAA" that appears to be older
            backupSettings.ProjectName = "AAA";
            backupSettings.Comment     = null;
            backupSettings.BackupTime  = backupSettings.BackupTime.AddHours(-3);
            string backupFileName3 = backupSettings.ZipFileName;

            m_fileOs.AddExistingFile(backupFileName3);

            BackupFileRepository repo = new BackupFileRepository();

            Assert.AreEqual(2, repo.AvailableProjectNames.Count());
            Assert.AreEqual(2, repo.GetAvailableVersions("AAA").Count());
            Assert.AreEqual(1, repo.GetAvailableVersions("ZZZ").Count());
            BackupFileSettings fileSettings = repo.GetBackupFile("AAA", backupSettings.BackupTime, false);

            Assert.AreEqual(backupFileName3, fileSettings.File);
            Assert.AreEqual(string.Empty, fileSettings.Comment);
            fileSettings = repo.GetMostRecentBackup("AAA");
            Assert.AreEqual(backupFileName1, fileSettings.File);
            Assert.AreEqual("thing1", fileSettings.Comment);
            fileSettings = repo.GetMostRecentBackup("ZZZ");
            Assert.AreEqual(backupFileName2, fileSettings.File);
            Assert.AreEqual("thing2", fileSettings.Comment);
        }
Beispiel #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="BackupProjectDlg"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// ------------------------------------------------------------------------------------
        public BackupProjectDlg(LcmCache cache,
                                IHelpTopicProvider helpTopicProvider) : this()
        {
            m_cache             = cache;
            m_helpTopicProvider = helpTopicProvider;

            m_presenter = new BackupProjectPresenter(this, m_cache);

            //It should only be displayed if the SupportingFiles folder has content.
            if (!m_presenter.SupportingFilesFolderContainsFiles)
            {
                m_supportingFiles.Enabled = false;
            }

            DestinationFolder = FwDirectoryFinder.DefaultBackupDirectory;
            if (File.Exists(m_presenter.PersistanceFilePath))
            {
                // If something bad happens when loading the previous dialog settings (probably just a
                // pre-7.0 version), just log the error and use the defaults.
                ExceptionHelper.LogAndIgnoreErrors(() =>
                {
                    //If the dialog settings file does exist then read it in and set the dialog to match
                    //the last values set.
                    using (FileStream fs = new FileStream(m_presenter.PersistanceFilePath, FileMode.Open))
                    {
                        IBackupSettings backupSettings = BackupFileSettings.CreateFromStream(fs);
                        // Per FWR-2748, we do NOT want to copy a previous comment into the dialog.
                        //Comment = backupSettings.Comment;
                        //Show SupportingFiles, unchecked by default
                        //SupportingFiles = backupSettings.IncludeSupportingFiles;
                        IncludeConfigurationSettings = backupSettings.IncludeConfigurationSettings;
                        IncludeLinkedFiles           = backupSettings.IncludeLinkedFiles;
                    }
                });
            }
        }