Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        public void Save()
        {
            var project = new XElement("Project");

            project.Add(new XElement("Iso639Code", Iso639Code.NullTrim()));

            project.Add(!TranscriptionFont.Equals(Program.DialogFont)
                                ? new XElement("transcriptionFont", FontHelper.FontToString(TranscriptionFont))
                                : new XElement("transcriptionFont", null));

            project.Add(!FreeTranslationFont.Equals(Program.DialogFont)
                                ? new XElement("freeTranslationFont", FontHelper.FontToString(FreeTranslationFont))
                                : new XElement("freeTranslationFont", null));

            var autoSegmenterSettings = new XElement("AutoSegmentersettings");

            project.Add(autoSegmenterSettings);

            if (AutoSegmenterMinimumSegmentLengthInMilliseconds != Settings.Default.DefaultAutoSegmenterMinimumSegmentLengthInMilliseconds ||
                AutoSegmenterMaximumSegmentLengthInMilliseconds != Settings.Default.DefaultAutoSegmenterMaximumSegmentLengthInMilliseconds ||
                AutoSegmenterPreferrerdPauseLengthInMilliseconds != Settings.Default.DefaultAutoSegmenterPreferrerdPauseLengthInMilliseconds ||
                !AutoSegmenterOptimumLengthClampingFactor.Equals(Settings.Default.DefaultAutoSegmenterOptimumLengthClampingFactor))
            {
                autoSegmenterSettings.Add(new XAttribute("minSegmentLength", AutoSegmenterMinimumSegmentLengthInMilliseconds));
                autoSegmenterSettings.Add(new XAttribute("maxSegmentLength", AutoSegmenterMaximumSegmentLengthInMilliseconds));
                autoSegmenterSettings.Add(new XAttribute("preferrerdPauseLength", AutoSegmenterPreferrerdPauseLengthInMilliseconds));
                autoSegmenterSettings.Add(new XAttribute("optimumLengthClampingFactor", AutoSegmenterOptimumLengthClampingFactor));
            }
            else
            {
                autoSegmenterSettings.Add(new XAttribute("minSegmentLength", "0"));
                autoSegmenterSettings.Add(new XAttribute("maxSegmentLength", "0"));
                autoSegmenterSettings.Add(new XAttribute("preferrerdPauseLength", "0"));
                autoSegmenterSettings.Add(new XAttribute("optimumLengthClampingFactor", "0"));
            }

            // metadata for archiving
            project.Add(new XElement("Title", Title.NullTrim()));
            project.Add(new XElement("FundingProjectTitle", FundingProjectTitle.NullTrim()));
            project.Add(new XElement("ProjectDescription", ProjectDescription.NullTrim()));
            project.Add(new XElement("VernacularISO3CodeAndName", VernacularISO3CodeAndName.NullTrim()));
            project.Add(new XElement("Location", Location.NullTrim()));
            project.Add(new XElement("Region", Region.NullTrim()));
            project.Add(new XElement("Country", Country.NullTrim() ?? "Unspecified"));
            project.Add(new XElement("Continent", Continent.NullTrim() ?? "Unspecified"));
            project.Add(new XElement("ContactPerson", ContactPerson.NullTrim()));
            project.Add(new XElement("AccessProtocol", AccessProtocol.NullTrim()));
            project.Add(new XElement("DateAvailable", DateAvailable.NullTrim()));
            project.Add(new XElement("RightsHolder", RightsHolder.NullTrim()));
            project.Add(new XElement("Depositor", Depositor.NullTrim()));
            project.Add(new XElement("IMDIOutputDirectory", IMDIOutputDirectory.NullTrim()));

            int       retryCount = 1;
            Exception error;

            do
            {
                try
                {
                    error = null;
                    project.Save(SettingsFilePath);
                    break;
                }
                catch (Exception e)
                {
                    error = e;
                    if (retryCount-- == 0)
                    {
                        break;
                    }
                    Thread.Sleep(250);
                }
            } while (true);

            if (error != null)
            {
                ErrorReport.NotifyUserOfProblem(error,
                                                LocalizationManager.GetString("MainWindow.ProblemSavingSayMoreProject",
                                                                              "There was a problem saving the SayMore project:\r\n\r\n{0}"), SettingsFilePath);
            }

            if (_accessProtocolChanged)
            {
                foreach (var editor in Program.GetControlsOfType <SessionBasicEditor>(Program.ProjectWindow))
                {
                    editor.SetAccessProtocol();
                }

                _accessProtocolChanged = false;
            }
        }