/// ------------------------------------------------------------------------------------ public bool Read(RecordCache recCache) { var recMarker = m_dataSource.SfmRecordMarker; if (string.IsNullOrEmpty(recMarker)) { // TODO: report error. return(false); } recMarker += " "; m_interlinearFields = m_dataSource.FieldMappings .Where(m => m.IsInterlinear).Select(m => m.Field.Name); m_markerMappings = m_dataSource.FieldMappings .ToDictionary(m => m.NameInDataSource, m => m); var recordLines = new Dictionary <string, string>(); bool foundFirstRecord = false; foreach (var line in File.ReadAllLines(m_dataSource.SourceFile)) { m_worker.ReportProgress(0); var currLine = line.Trim(); // Toss out lines that don't begin with a backslash or that precede // the first line in the file that begins with our record marker. if (!currLine.StartsWith("\\") || (!foundFirstRecord && !currLine.StartsWith(recMarker, StringComparison.Ordinal))) { continue; } foundFirstRecord = true; // If we've stored up a record and we've come to a new record, then write // the data of the stored one before beginning to store the new one. if (currLine.StartsWith(recMarker, StringComparison.Ordinal) && recordLines.Count > 0) { recCache.Add(SaveSingleRecord(recordLines)); recordLines.Clear(); } // Split the line between its marker and its data. var split = currLine.Split(" ".ToCharArray(), 2); if (split.Length >= 2) { recordLines[split[0]] = split[1].TrimStart(); } } // Save last record, if there is one. if (recordLines.Count > 0) { recCache.Add(SaveSingleRecord(recordLines)); } return(true); }
/// ------------------------------------------------------------------------------------ public void Read(RecordCache recCache) { var allLexEntries = FwDBUtils.GetLexEntriesFromFw7Project(m_fwDsInfo).ToArray(); if (allLexEntries == null) { return; } m_worker.ReportProgress(allLexEntries.Length, m_dataSource.DisplayTextWhenReading); var customnames = m_customfield.FieldNames(); foreach (var lxEntry in allLexEntries) { m_worker.ReportProgress(0); var entry = ReadSingleLexEntry(lxEntry); if (entry != null) { var customvalues = m_customfield.CustomValues.FindAll(m => m.Guid == lxEntry.Guid.ToString()); SetCustomFieldsforEntry(customnames, customvalues, entry); if (m_dataSource.FwDataSourceInfo != null && m_dataSource.FwDataSourceInfo.PhoneticSourceField != null) { var vernacularMapping = new PaField(m_dataSource.FwDataSourceInfo.PhoneticSourceField); entry.SetValue(PaField.kPhoneticSourceFieldName.ToString(CultureInfo.InvariantCulture), m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.PronunciationField && m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.AllPronunciationFields ? vernacularMapping.Name : m_fwDsInfo.PhoneticStorageMethod.ToString()); } recCache.Add(entry); } } m_dataSource.UpdateLastModifiedTime(); }
/// ------------------------------------------------------------------------------------ /// <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> /// Returns a list containing the available signals in the specified record. /// </summary> /// <param name="record">Record to be read.</param> /// <returns>List of available signals in the specified record.</returns> internal static IEnumerable <Signal> GetSignals(Record record) { var signalsCount = GetSignalsCount(record); if (signalsCount == -1)// no input file { throw new ArgumentNullException("record", "The specified input file does not exist"); } else if (signalsCount == -2) { throw new ArgumentException("Invalid header file.", "record"); } else { var signals = new Signal[signalsCount]; PInvoke.isigopen(record, signals, signals.Length); foreach (var signal in signals) { if (!RecordCache.ContainsKey(signal)) { RecordCache.Add(signal, record); } } return(new List <Signal>(signals)); } }
/// <summary> /// Gets the available signals in the specified record. /// </summary> /// <param name="record">The record name.</param> /// <returns>A list containing the signals of the specified record.</returns> public static List <Signal> GetSignals(string record) { var signalsCount = GetSignalsCount(record); if (signalsCount == -1)// no input file { throw new ArgumentNullException("record", "The specified input file does not exist."); } else if (signalsCount == -2) { throw new ArgumentException("Invalid header file.", "record"); } else { var signals = new Signal[signalsCount]; PInvoke.isigopen(record, signals, signals.Length); var objRecord = new Record(record); foreach (var signal in signals) { objRecord.Signals.Add(signal); if (!RecordCache.ContainsKey(signal)) { RecordCache.Add(signal, objRecord); } } return(new List <Signal>(signals)); } }
/// ------------------------------------------------------------------------------------ public bool Read(RecordCache recCache) { var reader = new SaAudioDocumentReader(m_worker); if (!reader.Initialize(m_dataSource.SourceFile) || reader.Words == null) { return(false); } // Make only a single record entry for the entire wave file. var recCacheEntry = new RecordCacheEntry(false, m_project) { DataSource = m_dataSource, NeedsParsing = false, Channels = reader.Channels, BitsPerSample = reader.BitsPerSample, SamplesPerSecond = reader.SamplesPerSecond, }; var audioField = m_project.GetAudioFileField(); recCacheEntry.SetValue(audioField.Name, m_dataSource.SourceFile); m_worker.ReportProgress(0); // Get all the record level fields. foreach (var fname in m_dataSource.FieldMappings.Where(m => !m.IsParsed).Select(m => m.Field.Name)) { SetFieldValueFromObject(typeof(SaAudioDocumentReader), fname, reader, recCacheEntry.SetValue); } int wordIndex = 0; recCacheEntry.WordEntries = new List <WordCacheEntry>(); foreach (var kvp in reader.Words) { var wentry = new WordCacheEntry(recCacheEntry, wordIndex++); foreach (var fname in m_dataSource.FieldMappings.Where(m => m.IsParsed).Select(m => m.Field.Name)) { SetFieldValueFromObject(typeof(AudioDocWords), fname, kvp.Value, wentry.SetValue); } wentry.AudioOffset = kvp.Key; wentry.AudioLength = kvp.Value.AudioLength; recCacheEntry.WordEntries.Add(wentry); } recCache.Add(recCacheEntry); return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add records to the m_cache. /// </summary> /// ------------------------------------------------------------------------------------ private void AddWords(string words, string pattern, string gloss) { m_recCache.Clear(); var entry = new RecordCacheEntry(_prj); entry.SetValue(kPhonetic, words); entry.SetValue(kCVPattern, pattern); entry.SetValue(kGloss, gloss); entry.NeedsParsing = true; entry.DataSource = m_dataSource; m_recCache.Add(entry); m_recCache.BuildWordCache(null); m_cache.Clear(); foreach (var wcEntry in m_recCache.WordCache) { m_cache.Add(wcEntry); } }
/// ------------------------------------------------------------------------------------ private void AddWords(string words, string pattern) { var entry = new RecordCacheEntry(_prj); entry.NeedsParsing = true; entry.SetValue("Phonetic", words); entry.SetValue("CVPattern", pattern); _dataSource.ParseType = DataSourceParseType.OneToOne; entry.DataSource = _dataSource; _recCache.Add(entry); _recCache.BuildWordCache(null); BuildPhoneSortKeysForTests(); _cache.Clear(); foreach (var wcEntry in _recCache.WordCache) { _cache.Add(wcEntry); } }
/// ------------------------------------------------------------------------------------ private void AddWords(string words) { var entry = new RecordCacheEntry(_prj); entry.SetValue("Phonetic", words); entry.NeedsParsing = true; entry.DataSource = _dataSource; _recCache.Add(entry); _recCache.BuildWordCache(null); BuildPhoneSortKeysForTests(); var query = new SearchQuery(); query.IgnoreDiacritics = false; query.IgnoredCharacters = null; query.Pattern = "[V]/*_*"; _cache = App.Search(query); _cache.SearchQuery = query; }
/// ------------------------------------------------------------------------------------ private void HandleReadingFwData(SqlDataReader reader) { if (reader == null || reader.IsClosed) { return; } // First, get a list of the fields returned from the query // and translate those to their corresponding PA fields. var fieldNames = new Dictionary <int, string>(); for (int i = 0; i < reader.FieldCount; i++) { if (m_dataSource.FieldMappings.Any(m => m.Field.Name == reader.GetName(i))) { fieldNames[i] = reader.GetName(i); } } var eticField = m_dataSource.FieldMappings.FirstOrDefault(m => m.Field.Type == FieldType.Phonetic); var eticFieldName = (eticField != null ? eticField.PaFieldName : null); while (reader.Read()) { // Make a new record entry for each row returned from the query. var recCacheEntry = new RecordCacheEntry(false, m_project) { DataSource = m_dataSource, NeedsParsing = false, WordEntries = new List <WordCacheEntry>(), }; var wentry = new WordCacheEntry(recCacheEntry); // Read the data for all columns having a mapped field. foreach (var kvp in fieldNames) { var dbValue = reader[kvp.Key]; if (dbValue is DBNull) { continue; } // Put the phonetic field in a word entry and all the other data in the // record entry. if (kvp.Value != eticFieldName) { recCacheEntry.SetValue(kvp.Value, dbValue.ToString()); } else { wentry.SetValue(kvp.Value, dbValue.ToString()); } } var guid = reader["Guid"]; if (!(guid is DBNull)) { recCacheEntry.Guid = new Guid(guid.ToString()); } // Add the entries to the caches. recCacheEntry.WordEntries.Add(wentry); m_recCache.Add(recCacheEntry); } }