/// ------------------------------------------------------------------------------------ public FwDataSourcePropertiesDlg(PaProject project, PaDataSource ds) : this() { Utils.WaitCursors(true); m_dataSource = ds; lblProjectValue.Text = ds.FwDataSourceInfo.ToString(); lblProject.Font = FontHelper.UIFont; lblProjectValue.Font = FontHelper.MakeFont(FontHelper.UIFont, FontStyle.Bold); grpWritingSystems.Font = FontHelper.UIFont; grpPhoneticDataStoreType.Font = FontHelper.UIFont; rbLexForm.Font = FontHelper.UIFont; rbPronunField.Font = FontHelper.UIFont; rbLexForm.Checked = (ds.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.LexemeForm); rbPronunField.Checked = (ds.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.PronunciationField); m_grid = new Fw6FieldMappingGrid(ds, project.Fields); m_grid.Dock = DockStyle.Fill; pnlGrid.Controls.Add(m_grid); m_dirty = false; m_grid.IsDirty = false; Utils.WaitCursors(false); }
/// ------------------------------------------------------------------------------------ private void ShowFw7DataSourcePropertiesDialog(PaDataSource ds) { if (ds.FwDataSourceInfo.IsMissing) { ds.FwDataSourceInfo.ShowMissingMessage(); return; } Utils.WaitCursors(true); using (var dlg = new Fw7DataSourcePropertiesDlg(ds, Project.Fields)) { Utils.WaitCursors(false); if (dlg.ShowDialog(this) != DialogResult.OK || !dlg.ChangesWereMade) { return; } } m_grid.Refresh(); // Go through the new mappings and mark those that should be parsed. foreach (var mapping in ds.FieldMappings .Where(m => Properties.Settings.Default.ParsedFw7Fields.Contains(m.NameInDataSource))) { mapping.IsParsed = true; } Project.SynchronizeProjectFieldMappingsWithDataSourceFieldMappings(); m_dirty = true; }
/// ------------------------------------------------------------------------------------ public void Dispose() { m_worker?.Dispose(); m_project = null; m_dataSource = null; m_fwDsInfo = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Because deserialization cannot deserialize a dictionary, moving field values from /// the deserialized values list to a dictionary has to be done in a separate process. /// </summary> /// ------------------------------------------------------------------------------------ public void PostDeserializeProcess(PaDataSource dataSource, PaProject project) { DataSource = dataSource; Project = project; if (m_fieldValuesList != null && m_fieldValuesList.Count() > 0) { m_fieldValues = m_fieldValuesList.ToDictionary(fv => fv.Name, fv => fv); m_fieldValuesList = null; } if (WordEntries == null) { return; } int i = 0; foreach (var entry in WordEntries) { if (entry.RecordEntry == null) { entry.RecordEntry = this; } entry.PostDeserializeProcess(); entry.WordIndex = i++; } }
/// ------------------------------------------------------------------------------------ public Fw7DataSourcePropertiesDlg(PaDataSource ds, IEnumerable <PaField> projectFields) : this() { if (App.DesignMode) { return; } m_datasource = ds; // Save the phonetic and audio file mappings because we need to remove them from the // mappings list so the user won't see them. They're mapped for free and the user // can't control that. These will get added back in when the dialog is closed. m_phoneticMapping = ds.FieldMappings.Single(m => m.Field.Type == FieldType.Phonetic && m.NameInDataSource == "Phonetic"); m_vernacularMapping = ds.FieldMappings.FirstOrDefault( m => m.Field.Name == ds.FwDataSourceInfo.PhoneticSourceField && m.NameInDataSource != "Phonetic"); m_audioFileMapping = ds.FieldMappings.Single(m => m.Field.Type == FieldType.AudioFilePath); ds.FieldMappings.Remove(m_phoneticMapping); ds.FieldMappings.Remove(m_audioFileMapping); var potentialFieldNames = Properties.Settings.Default.DefaultFw7Fields.Cast <string>(); var customFields = new Fw7CustomField(ds); var cuslist = potentialFieldNames.ToList(); cuslist.AddRange(customFields.FieldNames()); potentialFieldNames = cuslist; //(IEnumerable<string>) m_potentialFields = projectFields.Where(f => potentialFieldNames.Contains(f.Name)); m_potentialVernacularFields = m_potentialFields.Where(f => f.FwWsType == FwDBUtils.FwWritingSystemType.Vernacular).ToList(); foreach (var field in customFields.FieldNames().Where(fieldName => customFields.FwWritingSystemType(fieldName) == FwDBUtils.FwWritingSystemType.Vernacular).Select(fieldName => new PaField(fieldName) { FwWsType = FwDBUtils.FwWritingSystemType.Vernacular })) { if (m_potentialVernacularFields.FirstOrDefault(f => f.Name == field.Name) == null) { m_potentialVernacularFields.Add(field); } } lblProjectValue.Text = ds.FwDataSourceInfo.ToString(); lblProject.Font = FontHelper.UIFont; lblProjectValue.Font = FontHelper.MakeFont(FontHelper.UIFont, FontStyle.Bold); grpFields.Font = FontHelper.UIFont; grpPhoneticField.Font = FontHelper.UIFont; rbVernForm.Font = FontHelper.UIFont; rbPronunField.Font = FontHelper.UIFont; cboPhoneticWritingSystem.Font = FontHelper.UIFont; lblPronunciationOptions.Font = FontHelper.UIFont; cboPronunciationOptions.Font = FontHelper.UIFont; InitializeGrid(); InitializePhoneticAndAudioFieldInfo(); m_dirty = false; LocalizeItemDlg <TMXDocument> .StringsLocalized += InitializePronunciationCombo; }
public override void FixtureSetup() { base.FixtureSetup(); _dataSource = new PaDataSource(); _dataSource.Type = DataSourceType.Toolbox; _dataSource.FieldMappings = new System.Collections.Generic.List <FieldMapping>(); _dataSource.FieldMappings.Add(new FieldMapping("\\ph", _prj.GetPhoneticField(), true)); }
public override void FixtureSetup() { base.FixtureSetup(); _dataSource = new PaDataSource(); _prj.DataSources = new List <PaDataSource>(new[] { _dataSource }); FindInfo.ShowMessages = false; FwDBAccessInfo.ShowMsgOnFileLoadFailure = false; FwQueries.ShowMsgOnFileLoadFailure = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private int ProcessDataSourceFromPap(PaDataSource dataSource) { string fileOnly = Path.GetFileName(dataSource.DataSourceFile); string pathInPap = Path.GetDirectoryName(dataSource.DataSourceFile); string pathInZip = pathInPap; // Strip off the root portion of the path (e.g. c:\) if (Path.IsPathRooted(pathInZip)) { string root = Path.GetPathRoot(pathInZip); pathInZip = pathInZip.Substring(root.Length); } // Make sure the data source file can be found among those whose // entries were found in the backup file. If not (which should // never happen), skip the data source and go to the next one. int i = m_origPaths.IndexOf(Path.Combine(pathInZip, fileOnly)); if (i < 0) { return(-1); } // Remove the path and file name from the list found in the zip file. m_origPaths.RemoveAt(i); // Make sure the file was extracted from the zip file. if (!File.Exists(Path.Combine(m_tmpFolder, fileOnly))) { return(-1); } // Add a row in the data source grid containing the data source file name // and the propsed location where the data source file will be restored // (i.e. the path specified in the pap file). string path = Path.Combine(m_restoreRoot, pathInPap); grid.Rows.Add(new string[] { fileOnly, path, path, string.Empty }); DataGridViewRow row = grid.Rows[grid.RowCount - 1]; // If the data source is an SA audio file, then make sure to include // the audio file's companion transcriptions file. if (dataSource.DataSourceType == DataSourceType.SA) { string saxmlFile = Path.ChangeExtension(fileOnly, "saxml"); if (File.Exists(Path.Combine(m_tmpFolder, saxmlFile))) { row.Cells[3].Value = saxmlFile; m_origPaths.Remove(Path.Combine(pathInZip, saxmlFile)); } } return(row.Index); }
public Fw7CustomField(PaDataSource ds) { if (ds == null || ds.FwDataSourceInfo == null || !File.Exists(ds.FwDataSourceInfo.Name)) { CustomFields = new List <CustomField>(); CustomValues = new List <rt>(); return; } _extractCustomFieldsXsl.Load(XmlReader.Create(Path.Combine(new [] { App.AssemblyPath, "DataSourceClasses", "FieldWorks", "ExtractCustomFields.xsl" }))); Deserialize(ds.FwDataSourceInfo.Name); CreateIndex(); }
/// ------------------------------------------------------------------------------------ public Fw6FieldMappingGrid(PaDataSource ds, IEnumerable <PaField> projectFields) : this(ds) { var mappableFields = Properties.Settings.Default.Fw6FieldsMappableInPropsDlg.Cast <string>(); m_potentialFields = projectFields.Where(f => mappableFields.Contains(f.Name)); m_mappings = (from fname in mappableFields let mapping = ds.FieldMappings.SingleOrDefault(m => m.Field.Name == fname) select(mapping != null ? mapping.Copy() : new FieldMapping(m_potentialFields.Single(f => f.Name == fname), false))).ToList(); LockTargetFieldColumn(); RowCount = m_mappings.Count; }
/// ------------------------------------------------------------------------------------ public Fw7FieldMappingGrid(PaDataSource ds, IEnumerable <PaField> potentialFields) : base(ds) { m_potentialFields = potentialFields.OrderBy(f => f.DisplayName); // We don't want to show the phonetic and audio file mappings in this grid. m_mappings = (from m in ds.FieldMappings where m.Field.Type != FieldType.Phonetic && m.Field.Type != FieldType.AudioFilePath select m.Copy()).ToList(); CustomizeGrid(); AllowUserToAddRows = true; RowCount = m_mappings.Count + 1; }
public override void FixtureSetup() { base.FixtureSetup(); _dataSource = new PaDataSource(); _dataSource.Type = DataSourceType.Toolbox; _phoneticField = _prj.Fields.Single(f => f.Type == FieldType.Phonetic); _cvField = _prj.Fields.Single(f => f.Name == PaField.kCVPatternFieldName); _dataSource.FieldMappings = new System.Collections.Generic.List <FieldMapping>(); _dataSource.FieldMappings.Add(new FieldMapping("\\ph", _phoneticField, true)); _dataSource.FieldMappings.Add(new FieldMapping("\\cv", _cvField, true)); }
/// ------------------------------------------------------------------------------------ /// <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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// This message (i.e. BeforeLoadingDataSources) gets called right before PA loads all /// the data sources in the current project. This specific version of the message /// handler will do is find all data sources that match the ones this add-on saves /// in the DataSourceLoadInfo list (saved in a file in the project folder) and remove /// them from the project's data source list. The data sources that are removed are /// stored in a temporary list so that they can be re-added to the project's list /// after the data sources are read. /// </summary> /// <remarks> /// Concerning the reason for setting the last modification date on each skipped /// data source to tomorrow (i.e. DateTime.Now.AddDays(1)), is so that every time /// PA gains focus and it determines if any of the data sources have been updated /// since it lost focus, PA will determine that all skipped data sources have not /// been updated. Normally, the last modification date on a data source is set when /// the data source is read. But if the data source is skipped, then the last /// modification date will not get set properly and will cause PA to keep re-reading /// data sources each time the program becomes active. Hence setting the data to /// tomorrow. /// </remarks> /// ------------------------------------------------------------------------------------ protected bool OnBeforeLoadingDataSources(object args) { PaProject project = args as PaProject; if (project == null) { return(false); } m_skippedDataSources = null; // Get the list of data sources that were marked for not loading. SkippedDataSourceList sdsl = SkippedDataSourceList.Load(project); if (sdsl == null || sdsl.Count == 0) { return(false); } // Create our list to temporarily store the skipped data sources. Make it // a sorted list so we can insert them back in the list in the same place // they were when we removed them. This is so they will appear in the // project settings dialog in the same order in which the user added them. m_skippedDataSources = new SortedDictionary <int, PaDataSource>(); // Go through the project's data sources and remove any that are to be skipped. for (int i = project.DataSources.Count - 1; i >= 0; i--) { PaDataSource ds = project.DataSources[i]; if (sdsl.SkipDataSource(ds.ToString(true))) { // Set the skipped data sources date to tomorrow (see comment in // header of this method), save it to our temp. list and remove // it from the project's list of data sources. ds.LastModification = DateTime.Now.AddDays(1); m_skippedDataSources[i] = ds; project.DataSources.RemoveAt(i); } } if (m_skippedDataSources.Count == 0) { m_skippedDataSources = null; } return(false); }
public override void FixtureSetup() { base.FixtureSetup(); m_dataSource = new PaDataSource(); m_dataSource.Type = DataSourceType.Toolbox; m_dataSource.ParseType = DataSourceParseType.Interlinear; m_dataSource.FieldMappings = new List <FieldMapping>(); m_dataSource.FieldMappings.Add(new FieldMapping("\\ph", _prj.GetPhoneticField(), true)); m_dataSource.FieldMappings.Add(new FieldMapping("\\cv", _prj.Fields.Single(f => f.Name == "CVPattern"), true)); m_dataSource.FieldMappings.Add(new FieldMapping("\\gl", _prj.Fields.Single(f => f.Name == "Gloss"), true)); _prj.DataSources = new List <PaDataSource>(new[] { m_dataSource }); FindInfo.ShowMessages = false; FwDBAccessInfo.ShowMsgOnFileLoadFailure = false; FwQueries.ShowMsgOnFileLoadFailure = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show properties dialog for FW data sources of types where the data is being read /// directly from an FW database as opposed to a PAXML data source with some FW /// information in it. /// </summary> /// ------------------------------------------------------------------------------------ private void ShowFwDataSourcePropertiesDialog(PaDataSource ds) { if (ds.FwDataSourceInfo.IsMissing) { ds.FwDataSourceInfo.ShowMissingMessage(); return; } using (var dlg = new FwDataSourcePropertiesDlg(Project, ds)) { if (dlg.ShowDialog(this) == DialogResult.OK && dlg.ChangesWereMade) { m_dirty = true; Project.SynchronizeProjectFieldMappingsWithDataSourceFieldMappings(); } } }
/// ------------------------------------------------------------------------------------ public SFDataSourcePropertiesDlg(PaDataSource ds, IEnumerable <PaField> projectFields) { InitializeComponent(); // If the grid is not null, we've already been here. if (App.DesignMode) { return; } m_datasource = ds; var possibleSfmFieldNames = Properties.Settings.Default.DefaultSfmFields.Cast <string>(); // Merge the project's mapped sfm fields with the default set. var mappedSfmFields = m_datasource.FieldMappings.Select(m => m.Field).ToList(); mappedSfmFields.AddRange(projectFields.Where(f => possibleSfmFieldNames.Contains(f.Name))); m_potentialFields = mappedSfmFields.Distinct(new FieldNameComparer()); m_filename = m_datasource.SourceFile; m_tooltip.SetToolTip(pnlSrcFileHdg, m_filename); InitializeSomeUIStuff(); ReadSfmFile(); InitializeBottomPanel(); InitializeToolboxSortFieldControls(); InitializeFieldMappingsGrid(); InitializeFirstInterlinearCombo(); cboRecordMarkers.Items.AddRange(m_markersInFile.ToArray()); var marker = m_markersInFile.SingleOrDefault(m => m == m_datasource.SfmRecordMarker); cboRecordMarkers.SelectedItem = (marker ?? m_markersInFile[0]); if (marker != null) { cboRecordMarkers.SelectedItem = marker; } else if (m_markersInFile.Count > 0) { cboRecordMarkers.SelectedItem = m_markersInFile[0]; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the mappings dialog for SFM and Toolbox data source types. /// </summary> /// ------------------------------------------------------------------------------------ private void ShowSfmMappingsDialog(PaDataSource ds) { // Make sure the file exists before going to the mappings dialog. if (!File.Exists(ds.SourceFile)) { var msg = LocalizationManager.GetString("DialogBoxes.ProjectSettingsDlg.DataSourceFileMissingMsg", "The data source file '{0}' is missing."); msg = string.Format(msg, Utils.PrepFilePathForMsgBox(ds.SourceFile)); Utils.MsgBox(msg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } using (var dlg = new SFDataSourcePropertiesDlg(ds, Project.Fields)) { if (dlg.ShowDialog(this) == DialogResult.OK && dlg.ChangesWereMade) { m_dirty = true; Project.SynchronizeProjectFieldMappingsWithDataSourceFieldMappings(); } } }
/// ------------------------------------------------------------------------------------ public static SaDataSourceReader Create(BackgroundWorker worker, PaProject project, PaDataSource ds) { if (!ds.FieldMappings.Any(m => m.Field.Type == FieldType.Phonetic)) { return(null); } var reader = new SaDataSourceReader(); reader.m_worker = worker; reader.m_project = project; reader.m_dataSource = ds; return(reader); }
/// ------------------------------------------------------------------------------------ public static Fw6DataSourceReader Create(BackgroundWorker worker, PaProject project, PaDataSource ds) { var eticMapping = ds.FieldMappings.Single(m => m.Field.Type == FieldType.Phonetic); if (eticMapping == null) { return(null); } var reader = new Fw6DataSourceReader(); reader.m_worker = worker; reader.m_project = project; reader.m_dataSource = ds; reader.m_fwDsInfo = ds.FwDataSourceInfo; return(reader); }
/// ------------------------------------------------------------------------------------ public static Fw7DataSourceReader Create(BackgroundWorker worker, PaProject project, PaDataSource ds) { var eticMapping = ds.FieldMappings.Single(m => m.Field.Type == FieldType.Phonetic && m.NameInDataSource == "Phonetic"); if (eticMapping == null) { return(null); } var audioMapping = ds.FieldMappings.Single(m => m.Field.Type == FieldType.AudioFilePath); var reader = new Fw7DataSourceReader(); reader.m_worker = worker; reader.m_project = project; reader.m_dataSource = ds; reader.m_fwDsInfo = ds.FwDataSourceInfo; reader.m_phoneticFieldName = eticMapping.NameInDataSource; reader.m_phoneticWsId = eticMapping.FwWsId; reader.m_audioWsId = audioMapping != null ? audioMapping.FwWsId : null; if (reader.m_dataSource != null) { reader.m_customfield = new Fw7CustomField(reader.m_dataSource); } reader.m_vernPhonetic = null; if (ds.FwDataSourceInfo == null || ds.FwDataSourceInfo.PhoneticSourceField == null) { return(reader); } reader.m_vernPhonetic = new PaField(ds.FwDataSourceInfo.PhoneticSourceField); reader.m_vernCustom = reader.m_customfield.FieldNames().Contains(reader.m_vernPhonetic.Name); return(reader); }
/// ------------------------------------------------------------------------------------ public Fw6FieldMappingGrid(PaDataSource ds) { m_writingSystems = ds.FwDataSourceInfo.GetWritingSystems(); AddWritingSystemColumn(); ShowFontColumn(false); }
/// ------------------------------------------------------------------------------------ public void Dispose() { m_worker = null; m_project = null; m_dataSource = null; }