/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether or not the specified data source matches this data source. A /// match is determined by the data source types and their file names (or project /// name in the case of FW data sources). /// </summary> /// ------------------------------------------------------------------------------------ public bool Matches(PaDataSource ds, bool treatToolboxAsSFM) { bool typesMatch = (Type == ds.Type); if (!typesMatch && treatToolboxAsSFM) { // Determine if the TOOLBOX/SFM types match. typesMatch = ((Type == DataSourceType.Toolbox || Type == DataSourceType.SFM) && (ds.Type == DataSourceType.Toolbox || ds.Type == DataSourceType.SFM)); } if (!typesMatch) { return(false); } if (Type == DataSourceType.FW || Type == DataSourceType.FW7) { return(FwDataSourceInfo != null && ds.FwDataSourceInfo != null && FwDataSourceInfo.Name == ds.FwDataSourceInfo.Name && FwDataSourceInfo.Server == ds.FwDataSourceInfo.Server); } return(SourceFile.ToLower() == ds.SourceFile.ToLower()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reads a PA XML file into the record cache. /// </summary> /// ------------------------------------------------------------------------------------ private void ReadPaXmlFile(BackgroundWorker worker, PaDataSource ds) { var cache = RecordCache.Load(ds, m_project); if (cache == null) { return; } AddCustomFieldsFromPaXML(cache); // If the record cache member variable currently points to an empty cache, then // just set it to point to the cache into which we just read the specified PaXML // file. Otherwise move the records from the cache we just read into to the // member variable cache. if (m_recCache.Count == 0) { worker.ReportProgress(-1); m_recCache = cache; } else { while (cache.Count > 0) { worker.ReportProgress(0); m_recCache.Add(cache[0]); cache.RemoveAt(0); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the existence of the specified FW data source. /// </summary> /// ------------------------------------------------------------------------------------ private static void CheckExistenceOfFwDatabase(PaDataSource ds) { if (ds == null) { return; } if (!FwDBUtils.IsSQLServerStarted && !FwDBUtils.StartSQLServer(true)) { return; } if (ds.FwDataSourceInfo != null) { var fwDBInfoList = FwDBUtils.GetFwDataSourceInfoList(ds.FwDataSourceInfo.Server, false); if (fwDBInfoList.Any(fwinfo => ds.FwPrjName == fwinfo.Name)) { return; } ds.FwDataSourceInfo.IsMissing = true; } MissingFWDatabaseMsgBox.ShowDialog(ds.ToString(true)); ds.SkipLoadingBecauseOfProblem = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reads a single SFM file /// </summary> /// <returns>True indicates success</returns> /// ------------------------------------------------------------------------------------ protected bool ReadSfmDataSource(BackgroundWorker worker, PaDataSource ds) { var reader = SfmDataSourceReader.Create(worker, m_project, ds); if (reader == null) { App.NotifyUserOfProblem(GetPhoneticMappingErrorMsg(), ds.FwPrjName); return(false); } reader.Read(m_recCache); reader.Dispose(); return(true); }
/// ------------------------------------------------------------------------------------ private void ReadFw7DataSource(BackgroundWorker worker, PaDataSource ds) { var reader = Fw7DataSourceReader.Create(worker, m_project, ds); if (reader == null) { App.NotifyUserOfProblem(GetPhoneticMappingErrorMsg(), ds.FwPrjName); } else { reader.Read(m_recCache); reader.Dispose(); } }
/// ------------------------------------------------------------------------------------ public void Dispose() { m_worker = null; m_project = null; m_dataSource = null; }
/// ------------------------------------------------------------------------------------ public static SfmDataSourceReader Create(BackgroundWorker worker, PaProject project, PaDataSource ds) { if (!ds.FieldMappings.Any(m => m.Field.Type == FieldType.Phonetic)) { return(null); } var reader = new SfmDataSourceReader(); reader.m_worker = worker; reader.m_project = project; reader.m_dataSource = ds; return(reader); }
/// ------------------------------------------------------------------------------------ private void Initialize(PaDataSource ds) { if (ds.Type == DataSourceType.FW && ds.FwSourceDirectFromDB) { CheckExistenceOfFwDatabase(ds); } else if (ds.Type == DataSourceType.FW7) { if (File.Exists(ds.FwDataSourceInfo.Name)) { if (!File.Exists(ds.FwDataSourceInfo.Name)) { var oldProjectFolder = Path.GetDirectoryName(Path.GetDirectoryName(ds.FwDataSourceInfo.Name)); var newFwProjectFolder = Utils.FwProjectsPath; if (newFwProjectFolder != null) { if (oldProjectFolder != null) { ds.FwDataSourceInfo.Name = ds.FwDataSourceInfo.Name.Replace(oldProjectFolder, newFwProjectFolder).Replace(@"\\", @"\"); } } if (!File.Exists(ds.FwDataSourceInfo.Name)) { App.NotifyUserOfProblem(LocalizationManager.GetString( "Miscellaneous.Messages.DataSourceReading.FieldWorks7DataMissingMsg", "FieldWorks 7.0 (or later) data is missing. It must be acquired in order for Phonology Assistant to read the data source '{0}'. This data source will be skipped."), ds.FwDataSourceInfo.Name); ds.SkipLoadingBecauseOfProblem = true; return; } } } } else if (!File.Exists(ds.SourceFile)) { if (!Path.IsPathRooted(ds.SourceFile)) { ds.SourceFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ds.SourceFile); } if (!File.Exists(ds.SourceFile)) { string newPath = GetMissingDataSourceAction(ds.SourceFile); if (newPath == null) { ds.SkipLoadingBecauseOfProblem = true; return; } ds.SourceFile = newPath; } m_project.Save(); } if (ds.SkipLoadingBecauseOfProblem) { return; } if (ds.Type != DataSourceType.XML && ds.Type != DataSourceType.Unknown) { m_dataSources.Add(ds); } if (!ds.VerifyMappings()) { App.NotifyUserOfProblem(LocalizationManager.GetString( "Miscellaneous.Messages.DataSourceReading.MarkersMissingFromDataSourceMsg", "The data source file '{0}' is missing some standard format markers that were " + "assigned to Phonology Assistant fields. Those assignments have been removed. To verify the " + "assignment of markers to fields, go to the project settings dialog box, select " + "the data source and click 'Properties'."), ds.SourceFile); } }