Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the list of search classes for the specified project. If the project is
        /// null, then the default list is loaded.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static SearchClassList InternalLoad(PaProject project, string filename)
        {
            SearchClassList srchClasses = null;

            if (File.Exists(filename))
            {
                srchClasses = XmlSerializationHelper.DeserializeFromFile <SearchClassList>(filename);
            }

            if (srchClasses == null)
            {
                return(new SearchClassList(project));
            }

            srchClasses.m_project = project;
            bool upgradeMade = false;

            // Run through this for the sake of classes created before 26-Jul-07
            // that used the enumeration PhoneticChars instead of Phones.
            foreach (var srchClass in srchClasses.Where(c => c.Type == SearchClassType.PhoneticChars))
            {
                srchClass.Type = SearchClassType.Phones;
                upgradeMade    = true;
            }

            if (upgradeMade)
            {
                srchClasses.Save();
            }

            return(srchClasses);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Person object by deserializing the specified file. The file can be just
        /// the name of the file, without the path, or the full path specification. If that
        /// fails, null is returned or, when there's an exception, it is thrown.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static Person Load(SpongeProject prj, string pathName)
        {
            var fileName = Path.GetFileName(pathName);
            var folder   = fileName;

            if (folder.EndsWith("." + Sponge.PersonFileExtension))
            {
                folder = fileName.Remove(folder.Length - (Sponge.PersonFileExtension.Length + 1));
            }
            else
            {
                fileName += ("." + Sponge.PersonFileExtension);
            }

            folder   = Path.Combine(prj.PeopleFolder, folder);
            fileName = Path.Combine(folder, fileName);

            Exception e;
            var       person = XmlSerializationHelper.DeserializeFromFile <Person>(fileName, out e);

            if (e != null)
            {
                var msg = ExceptionHelper.GetAllExceptionMessages(e);
                Utils.MsgBox(msg);
            }

            person.Project = prj;
            return(person);
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        public static FieldDisplayPropsCache LoadProjectFieldDisplayProps(PaProject project)
        {
            var path = PaFieldDisplayProperties.GetFileForProject(project.ProjectPathFilePrefix);

            if (!File.Exists(path))
            {
                return(GetDefaultCache());
            }

            Exception e;
            var       cache = XmlSerializationHelper.DeserializeFromFile <FieldDisplayPropsCache>(path, "FieldDisplayProps", out e);

            if (e == null)
            {
                return(cache);
            }

            var msg = LocalizationManager.GetString(
                "ProjectFields.ErrorReadingFieldDisplayPropertiesFileMsg",
                "The following error occurred when reading the file\n\n'{0}'\n\n{1}");

            while (e.InnerException != null)
            {
                e = e.InnerException;
            }

            Utils.MsgBox(string.Format(msg, path, e.Message));

            return(null);
        }
Example #4
0
        public static ApplicationMetadata Load(out Exception exception)
        {
            exception = null;

            ApplicationMetadata metadata;

            if (!File.Exists(FilePath))
            {
                metadata = new ApplicationMetadata();
                if (!Directory.Exists(GlyssenInfo.BaseDataFolder))
                {
                    // In production, Installer is responsible for creating the base data folder.
                    // The version number will be initially set to 0, but since their won't be any
                    // projects to migrate, the migrator won't do anything but set the version number.
                    // However, on a developer machine (or in the event that a user has blown away or
                    // renamed the folder), we need to force its creation now.
                    Directory.CreateDirectory(GlyssenInfo.BaseDataFolder);
                    metadata.DataVersion = Settings.Default.DataFormatVersion;
                    metadata.Save();
                }
            }
            else
            {
                metadata = XmlSerializationHelper.DeserializeFromFile <ApplicationMetadata>(FilePath, out exception);
            }
            return(metadata);
        }
Example #5
0
        /// ------------------------------------------------------------------------------------
        private static FwQueries Load(string filename)
        {
            // Find the file that contains the queries.
            var queryFile = FileLocator.GetFileDistributedWithApplication(App.ConfigFolderName, filename);
            var fwqueries = XmlSerializationHelper.DeserializeFromFile <FwQueries>(queryFile);

            if (fwqueries != null)
            {
                fwqueries.QueryFile = queryFile;
            }
            else if (ShowMsgOnFileLoadFailure)
            {
                string filePath = Utils.PrepFilePathForMsgBox(queryFile);

                var msg = LocalizationManager.GetString("Miscellaneous.Messages.DataSourceReading.LoadingSQLQueriesErrorMsg",
                                                        "The file that contains FieldWorks queries '{0}' is either missing or corrupt. " +
                                                        "Until this problem is corrected, FieldWorks data sources cannot be accessed or " +
                                                        "added as data sources.");

                App.NotifyUserOfProblem(msg, filePath);
                fwqueries = new FwQueries(true);
            }

            return(fwqueries);
        }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines whether or not the specified data source file is an xml file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool GetIsXmlFile(string filename)
        {
            XmlDocument xmldoc = new XmlDocument();

            try
            {
                xmldoc.Load(filename);
            }
            catch
            {
                return(false);
            }

            // At this point, we know we have a valid XML file. Now check if it's PAXML.
            var paxmlContent = XmlSerializationHelper.DeserializeFromFile <PaXMLContent>(filename);

            if (paxmlContent == null)
            {
                Type = DataSourceType.XML;
            }
            else
            {
                // We know we have a PAXML file. Now check if it was written by FieldWorks.
                string fwServer;
                string fwDBName;
                Type             = GetPaXmlType(filename, out fwServer, out fwDBName);
                TotalLinesInFile = paxmlContent.Cache.Count;
                paxmlContent.Cache.Clear();
            }

            return(true);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the default and project-specific ambiguous sequences.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static AmbiguousSequences Load(string projectPathPrefix)
        {
            string filename = GetFileForProject(projectPathPrefix);
            var    list     = XmlSerializationHelper.DeserializeFromFile <AmbiguousSequences>(filename);

            return(list ?? new AmbiguousSequences());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Combines the specified path with the PapFile path to point to a pap file. That
        /// pap file is deserialized and each data source path in the pap file is modified
        /// to use that combined path. Then the pap file is rewritten and added to the
        /// program's list of recent projects.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Modify(string path, string dataSourcePath, bool addToRecentlyUsedProjectsList)
        {
            var papFilePath = Path.Combine(path, PapFile);

            if (!File.Exists(papFilePath))
            {
                return;
            }

            var prj = XmlSerializationHelper.DeserializeFromFile <PaProject>(papFilePath);

            if (prj == null)
            {
                return;
            }

            foreach (var dataSource in prj.DataSources.Where(ds => ds.SourceFile != null))
            {
                var newPath  = dataSourcePath ?? Path.GetDirectoryName(papFilePath);
                var filename = Path.GetFileName(dataSource.SourceFile);
                dataSource.SourceFile = Path.Combine(newPath, filename);
            }

            XmlSerializationHelper.SerializeToFile(papFilePath, prj);

            if (addToRecentlyUsedProjectsList)
            {
                App.AddProjectToRecentlyUsedProjectsList(papFilePath, true);
            }
        }
Example #9
0
        public static string GetRevisionOrChangesetId(string filename)
        {
            Exception exception;
            var       metadata = XmlSerializationHelper.DeserializeFromFile <GlyssenDblTextMetadata>(filename, out exception);

            return(metadata != null ? metadata.RevisionOrChangesetId : null);
        }
Example #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the specified XML file.
        /// </summary>
        /// <param name="filename">The name of the XML file.</param>
        /// <returns>information from the stylesheet needed for checking</returns>
        /// ------------------------------------------------------------------------------------
        public static StyleMarkupInfo Load(string filename)
        {
            StyleMarkupInfo smi = XmlSerializationHelper.DeserializeFromFile <StyleMarkupInfo>(filename);

            smi.m_stylePropInfo = new StylePropsInfo(smi);
            return(smi ?? new StyleMarkupInfo());
        }
Example #11
0
        private TM LoadMetadataInternal(string metadataPath)
        {
            var dblMetadata = DblMetadataBase <TL> .Load <TM>(metadataPath, out var exception);

            if (exception != null)
            {
                DblMetadata metadata = XmlSerializationHelper.DeserializeFromFile <DblMetadata>(metadataPath,
                                                                                                out var metadataBaseDeserializationError);
                if (metadataBaseDeserializationError != null)
                {
                    throw new ApplicationException(Localizer.GetString("DblBundle.MetadataInvalid",
                                                                       "Unable to read metadata. File is not a valid Text Release Bundle:") +
                                                   Environment.NewLine + _pathToZippedBundle, metadataBaseDeserializationError);
                }

                throw new ApplicationException(
                          String.Format(Localizer.GetString("DblBundle.MetadataInvalidVersion",
                                                            "Unable to read metadata. Type: {0}. Version: {1}. File is not a valid Text Release Bundle:"),
                                        metadata.Type, metadata.TypeVersion) +
                          Environment.NewLine + _pathToZippedBundle);
            }

            if (!dblMetadata.IsTextReleaseBundle)
            {
                throw new ApplicationException(
                          String.Format(Localizer.GetString("DblBundle.NotTextReleaseBundle",
                                                            "This metadata in this bundle indicates that it is of type \"{0}\". Only Text Release Bundles are currently supported."),
                                        dblMetadata.Type));
            }

            return(dblMetadata);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="MasterQuestionParser"/> class.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public MasterQuestionParser(string filename, IEnumerable <string> questionWords,
                             IEnumerable <IKeyTerm> keyTerms, KeyTermRules keyTermRules,
                             IEnumerable <PhraseCustomization> customizations,
                             IEnumerable <Substitution> phraseSubstitutions) :
     this(XmlSerializationHelper.DeserializeFromFile <QuestionSections>(filename),
          questionWords, keyTerms, keyTermRules, customizations, phraseSubstitutions)
 {
 }
Example #13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads all FDO classes.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void LoadAllLCMClasses()
        {
            LoadFDOClassNames();

            if (File.Exists(s_settingFileName))
            {
                s_allFDOClasses =
                    XmlSerializationHelper.DeserializeFromFile <List <LCMClass> >(s_settingFileName);

                if (s_allFDOClasses != null)
                {
                    // Go through the list of deserialized classes and make sure there aren't
                    // any that used to be in the meta data cache but are no longer there.
                    for (int i = s_allFDOClasses.Count - 1; i >= 0; i--)
                    {
                        if (!s_allLCMClassNames.Contains(s_allFDOClasses[i].ClassName))
                        {
                            s_allFDOClasses.RemoveAt(i);
                        }
                    }

                    // Go through the FDO class names from the meta data cache and
                    // make sure all of them are found in the list just deserialized.
                    foreach (string name in s_allLCMClassNames)
                    {
                        // Search the deserialized list for the class name.
                        var query = from cls in s_allFDOClasses
                                    where cls.ClassName == name
                                    select cls;

                        // If the class was not found in the deserialized list,
                        // then add it to the list.
                        if (query.Count() == 0)
                        {
                            s_allFDOClasses.Add(new LCMClass(GetLCMClassType(name)));
                        }
                    }
                }
            }

            if (s_allFDOClasses == null)
            {
                s_allFDOClasses = new List <LCMClass>();
                foreach (string name in AllLcmClassNames)
                {
                    s_allFDOClasses.Add(GetLCMClassProperties(name));
                }

                s_allFDOClasses.Sort((c1, c2) => c1.ClassName.CompareTo(c2.ClassName));
            }

            // Store the classes in a list accessible by the class' type.
            s_FDOClassesByType = new Dictionary <Type, LCMClass>();
            foreach (LCMClass cls in s_allFDOClasses)
            {
                s_FDOClassesByType[cls.ClassType] = cls;
            }
        }
        public void GenerateOrUpdateFromMasterQuestions(string masterQuestionsFilename, string existingTxlTranslationsFilename = null, bool retainOnlyTranslatedStrings = false)
        {
            var questions = XmlSerializationHelper.DeserializeFromFile <QuestionSections>(masterQuestionsFilename);
            var existingTxlTranslations = (existingTxlTranslationsFilename == null) ? null :
                                          XmlSerializationHelper.DeserializeFromFile <List <XmlTranslation> >(existingTxlTranslationsFilename);

            GenerateOrUpdateFromMasterQuestions(questions, existingTxlTranslations, retainOnlyTranslatedStrings);
            Save();
        }
Example #15
0
        public static CharacterGroupList LoadCharacterGroupListFromFile(string filename, Project project)
        {
            var list = XmlSerializationHelper.DeserializeFromFile <CharacterGroupList>(filename);

            foreach (var characterGroup in list.CharacterGroups)
            {
                characterGroup.Initialize(project);
            }
            return(list);
        }
Example #16
0
        private TM LoadMetadata()
        {
            const string filename     = "metadata.xml";
            string       metadataPath = Path.Combine(m_pathToUnzippedDirectory, filename);

            if (!File.Exists(metadataPath))
            {
                bool sourceBundle = filename.Contains("source") || Directory.Exists(Path.Combine(m_pathToUnzippedDirectory, "gather"));
                if (sourceBundle)
                {
                    throw new ApplicationException(
                              string.Format(LocalizationManager.GetString("DblBundle.SourceReleaseBundle",
                                                                          "This bundle appears to be a source bundle. Only Text Release Bundles are currently supported."), filename) +
                              Environment.NewLine + m_pathToZippedBundle);
                }
                throw new ApplicationException(
                          string.Format(LocalizationManager.GetString("DblBundle.FileMissingFromBundle",
                                                                      "Required {0} file not found. File is not a valid Text Release Bundle:"), filename) +
                          Environment.NewLine + m_pathToZippedBundle);
            }

            Exception exception;
            var       dblMetadata = DblMetadataBase <TL> .Load <TM>(metadataPath, out exception);

            if (exception != null)
            {
                Exception   metadataBaseDeserializationError;
                DblMetadata metadata = XmlSerializationHelper.DeserializeFromFile <DblMetadata>(metadataPath,
                                                                                                out metadataBaseDeserializationError);
                if (metadataBaseDeserializationError != null)
                {
                    throw new ApplicationException(
                              LocalizationManager.GetString("DblBundle.MetadataInvalid",
                                                            "Unable to read metadata. File is not a valid Text Release Bundle:") +
                              Environment.NewLine + m_pathToZippedBundle, metadataBaseDeserializationError);
                }

                throw new ApplicationException(
                          String.Format(LocalizationManager.GetString("DblBundle.MetadataInvalidVersion",
                                                                      "Unable to read metadata. Type: {0}. Version: {1}. File is not a valid Text Release Bundle:"),
                                        metadata.Type, metadata.TypeVersion) +
                          Environment.NewLine + m_pathToZippedBundle);
            }

            if (!dblMetadata.IsTextReleaseBundle)
            {
                throw new ApplicationException(
                          String.Format(LocalizationManager.GetString("DblBundle.NotTextReleaseBundle",
                                                                      "This metadata in this bundle indicates that it is of type \"{0}\". Only Text Release Bundles are currently supported."),
                                        dblMetadata.Type));
            }

            return(dblMetadata);
        }
        public static CharacterGroupList LoadCharacterGroupListFromFile(string filename, Project project)
        {
            var comparer = new CharacterByKeyStrokeComparer(project.GetKeyStrokesByCharacterId());
            var list     = XmlSerializationHelper.DeserializeFromFile <CharacterGroupList>(filename);

            foreach (var characterGroup in list.CharacterGroups)
            {
                characterGroup.Initialize(project, comparer);
            }
            return(list);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the specified file.
        /// </summary>
        /// <param name="filename">The name of the OXEKT file.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="ResolveConflict">The delegate to call to resolve a conflict when a
        /// different rendering already exists.</param>
        /// <param name="e">Exception that was encountered or null</param>
        /// <returns>A loaded XmlTermRenderingsList</returns>
        /// ------------------------------------------------------------------------------------
        public static XmlTermRenderingsList LoadFromFile(string filename, FdoCache cache,
                                                         Func <IChkRef, string, string, bool> ResolveConflict, out Exception e)
        {
            XmlTermRenderingsList list =
                XmlSerializationHelper.DeserializeFromFile <XmlTermRenderingsList>(filename, true, out e);

            if (cache != null && list != null)
            {
                list.WriteToCache(cache, ResolveConflict ?? ((occ, existing, imported) => { return(false); }));
            }

            return(list ?? new XmlTermRenderingsList());
        }
Example #19
0
        /// ------------------------------------------------------------------------------------
        private static void Load()
        {
            s_loadAttempted = true;

            try
            {
                var filename = FileLocator.GetFileDistributedWithApplication(App.ConfigFolderName,
                                                                             "NormalizationExceptions.xml");

                s_exceptionsList = XmlSerializationHelper.DeserializeFromFile <List <NormalizationException> >(filename);
            }
            catch { }
        }
Example #20
0
        public PhotoProductXmlRepository(string xmlDataFilePath)
        {
            if (String.IsNullOrEmpty(xmlDataFilePath))
            {
                throw new ArgumentNullException(nameof(xmlDataFilePath));
            }

            var data = XmlSerializationHelper.DeserializeFromFile <PhotoProduct[]>(xmlDataFilePath);

            foreach (var products in data)
            {
                Add(products);
            }
        }
        /// ------------------------------------------------------------------------------------
        internal static TrainingProjectSetupInfo Load()
        {
            var path = Path.Combine(Application.StartupPath, App.kTrainingSubFolder);

            path = Path.Combine(path, "TrainingProjectsSetup.xml");

            try
            {
                return(XmlSerializationHelper.DeserializeFromFile <TrainingProjectSetupInfo>(path));
            }
            catch { }

            return(null);
        }
Example #22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deserializes a PAXML file to a RecordCache instance.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static RecordCache Load(PaDataSource dataSource, PaProject project)
        {
            if (dataSource == null)
            {
                return(null);
            }

            string filename = dataSource.SourceFile;

            try
            {
                var paxmlcontent = XmlSerializationHelper.DeserializeFromFile <PaXMLContent>(filename);
                var cache        = (paxmlcontent == null ? null : paxmlcontent.Cache);

                if (cache == null)
                {
                    return(null);
                }

                cache._project           = project;
                cache._phoneticFieldName = project.GetPhoneticField().Name;
                string fwServer;
                string fwDBName;
                PaDataSource.GetPaXmlType(filename, out fwServer, out fwDBName);

                foreach (var entry in cache)
                {
                    entry.PostDeserializeProcess(dataSource, project);

                    if (entry.FieldValues.Count > 0 &&
                        (entry.WordEntries == null || entry.WordEntries.Count == 0))
                    {
                        entry.NeedsParsing = true;
                    }
                }

                return(cache);
            }
            catch (Exception e)
            {
                var msg = LocalizationManager.GetString("Miscellaneous.Messages.DataSourceReading.LoadingRecordCacheErrorMsg",
                                                        "The following error occurred while loading '{0}'",
                                                        "Message displayed when failing to load a PaXml file.");

                App.NotifyUserOfProblem(e, msg, filename);
                return(null);
            }
        }
Example #23
0
        private static List <Tu> ProcessLanguage(string modifiedLangAbbr, Action <TmxFormat, Tu, string> addTerm)
        {
            string outputFileName = Path.Combine(kLocalizationFolder, "Glyssen." + modifiedLangAbbr + ".tmx");

            TmxFormat newTmx;

            if (File.Exists(outputFileName))
            {
                newTmx = XmlSerializationHelper.DeserializeFromFile <TmxFormat>(outputFileName);

                var tus = newTmx.Body.Tus;

                // If this is not a language that has been worked on by a localizer, we can safely blow
                // away everything and start from scratch. Otherwise, we only want to remove translation units
                // which no longer exist in English.
                if (s_languagesWithCustomizedTranslations.Contains(modifiedLangAbbr))
                {
                    tus.RemoveAll(lt => lt.Tuid.StartsWith("CharacterName.") && !s_englishTranslationUnits.Any(ent => ent.Tuid == lt.Tuid));
                }
                else
                {
                    tus.RemoveAll(t => t.Tuid.StartsWith("CharacterName."));
                }
            }
            else
            {
                newTmx = new TmxFormat();
                newTmx.Header.SrcLang  = modifiedLangAbbr;
                newTmx.Header.Props    = new Prop[2];
                newTmx.Header.Props[0] = new Prop("x-appversion", "0.17.0.0");
                newTmx.Header.Props[1] = new Prop("x-hardlinebreakreplacement", "\\n");
            }

            foreach (string name in s_names)
            {
                Tu tmxTermEntry = new Tu("CharacterName." + name)
                {
                    Prop = new Prop("x-dynamic", "true")
                };
                tmxTermEntry.Tuvs.Add(new Tuv("en", name));

                addTerm(newTmx, tmxTermEntry, name);
            }

            XmlSerializationHelper.SerializeToFile(outputFileName, newTmx);

            return(newTmx.Body.Tus);
        }
Example #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies that the templates list has been loaded.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void VerifyListLoaded()
        {
            if (s_list == null)
            {
                string path = FileLocationUtilities.GetFileDistributedWithApplication("FieldTemplatesTemplates.xml");

                // TODO: Do something when there's an exception returned.
                Exception e;
                s_list = XmlSerializationHelper.DeserializeFromFile <FieldTemplateList>(path, out e);

                if (e != null)
                {
                    ErrorReport.ReportNonFatalException(e);
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies that the templates list has been loaded.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void VerifyListLoaded()
        {
            if (s_list == null)
            {
                string path = FileLocator.GetFileDistributedWithApplication("SessionFileInfoTemplates.xml");

                // TODO: Do something when there's an exception returned.
                Exception e;
                s_list = XmlSerializationHelper.DeserializeFromFile <SessionFileInfoTemplateList>(path, out e);

                if (e != null)
                {
                    throw e;
                }
            }
        }
Example #26
0
        /// ------------------------------------------------------------------------------------
        public static List <PaField> LoadFields(string path, string rootElementName)
        {
            Exception e;
            var       list = XmlSerializationHelper.DeserializeFromFile <List <PaField> >(path, rootElementName, out e);

            if (e == null)
            {
                return(EnsureListContainsCalculatedFields(list).ToList());
            }

            App.NotifyUserOfProblem(e, LocalizationManager.GetString(
                                        "ProjectFields.ReadingFieldsFileErrorMsg",
                                        "There was an error reading field information from the file '{0}'."), path);

            return(null);
        }
        public static void Generate(string sourceQuestionsFilename, string alternativesFilename, string destFilename)
        {
            Dictionary <string, string[]> alternatives = null;

            if (alternativesFilename != null)
            {
                QuestionAlternativeOverrides qAlts = XmlSerializationHelper.DeserializeFromFile <QuestionAlternativeOverrides>(alternativesFilename);
                //alternatives = new Dictionary<string, string[]>();
                //foreach (Alternative a in qAlts.Items)
                //{
                //    Debug.Assert(!alternatives.ContainsKey(a.Text));
                //    alternatives[a.Text] = a.AlternateForms;
                //}
                alternatives = qAlts.Items.ToDictionary(a => a.Text, a => a.AlternateForms);
            }
            XmlSerializationHelper.SerializeToFile(destFilename, Generate(SourceLines(sourceQuestionsFilename), alternatives));
        }
        /// ------------------------------------------------------------------------------------
        public static GridLayoutInfo Load(PaProject project)
        {
            var filename = project.ProjectPathFilePrefix + kFiltersFilePrefix;

            var info = XmlSerializationHelper.DeserializeFromFile <GridLayoutInfo>(filename);

            if (info == null)
            {
                info = new GridLayoutInfo(project);
            }
            else
            {
                info._project = project;
            }

            return(info);
        }
Example #29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the transcription file for the specified audio file path.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SaAudioDocument Load(string audioFilePath, bool isForTmpOperation,
                                           bool returnNullIfNoExist)
        {
            // Make sure the wave file exists.
            if (!File.Exists(audioFilePath))
            {
                SaAudioDocumentReader.ShowWaveFileNotFoundMsg(audioFilePath);
                return(null);
            }

            // Get what the file name should be for the transcription file.
            string transcriptionFile = GetTranscriptionFile(audioFilePath, isForTmpOperation);

            SaAudioDocument doc;

            // If it doesn't exist, it means the audio file doesn't have any transcriptions.
            if (!File.Exists(transcriptionFile))
            {
                if (returnNullIfNoExist)
                {
                    return(null);
                }

                doc = new SaAudioDocument(audioFilePath);
            }
            else
            {
                // Get the transcription data from the companion transcription file.
                Exception e;
                s_audioFileLoading = audioFilePath;
                doc = XmlSerializationHelper.DeserializeFromFile <SaAudioDocument>(transcriptionFile, out e);

                if (e != null)
                {
                    ErrorReport.ReportNonFatalException(e);
                    return(null);
                }

                s_audioFileLoading = null;
                doc.AudioFile      = audioFilePath;
            }

            doc.m_docVer            = kCurrSaDocVersion;
            doc.m_isForTmpOperation = isForTmpOperation;
            return(doc);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Loads the specified phonetic inventory file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static InventoryHelper Load()
        {
            Exception exception;
            var       ih = XmlSerializationHelper.DeserializeFromFile <InventoryHelper>(
                App.PhoneticInventoryFilePath, out exception);

            if (ih == null)
            {
                App.CloseSplashScreen();
                ErrorReport.ReportFatalException(exception);
            }

            IPASymbolCache = new IPASymbolCache();
            IPASymbolCache.LoadFromList(ih.IPASymbols);
            ih.IPASymbols = null;

            return(ih);
        }