コード例 #1
0
        /// ------------------------------------------------------------------------------------
        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);
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        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();
        }
コード例 #3
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));
            }
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        /// <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);
                }
            }
        }
コード例 #5
0
        /// <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));
            }
        }
コード例 #6
0
 public void TestSetup()
 {
     _prj.PhoneCache.Clear();
     _prj.RecordCache.Clear();
     _recCache    = _prj.RecordCache;
     _cache       = new WordListCache();
     _query       = new SearchQuery();
     _sortOptions = new SortOptions(true, _prj);
 }
コード例 #7
0
        public ActionResult LoadPercentage()
        {
            if (string.IsNullOrWhiteSpace(Request["recordGuid"]))
            {
                return(null);
            }

            var recordGuid = long.Parse(Request["recordGuid"]);
            var percentage = RecordCache.LoadPercetage(recordGuid);

            return(Json(new { percentage }, JsonRequestBehavior.AllowGet));
        }
コード例 #8
0
        /// ------------------------------------------------------------------------------------
        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);
        }
コード例 #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Build the PaWordListGrid for searching.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void Initialize(string eticWrds, string cvWrds, string glossWrds)
        {
            m_recCache = _prj.RecordCache;
            m_cache    = new WordListCache();

            AddWords(eticWrds, cvWrds, glossWrds);

            // Create grid
            m_grid = new PaWordListGrid(m_cache, GetType(), false);

            // Make all the grid's rows & columns visible and thus searchable
            for (int row = 0; row < m_grid.Rows.Count; row++)
            {
                m_grid.Rows[row].Visible = true;
                for (int col = 0; col < m_grid.Columns.Count; col++)
                {
                    m_grid.Columns[col].Visible = true;
                }
            }

            // Get rid of columns we don't care about for the tests.
            for (int i = m_grid.ColumnCount - 1; i >= 0; i--)
            {
                if (!"Phonetic CVPattern Gloss".Contains(m_grid.Columns[i].Name))
                {
                    m_grid.Columns.Remove(m_grid.Columns[i]);
                }
            }

            // Set the CVPattern & Gloss column Display Indexes to the correct order
            // based on the columnsToSearch below.
            m_grid.Columns["Phonetic"].DisplayIndex  = 0;
            m_grid.Columns["CVPattern"].DisplayIndex = 1;
            m_grid.Columns["Gloss"].DisplayIndex     = 2;

            SetField(typeof(FindInfo), "s_reverseFind", false);
            FindInfo.Grid = m_grid;

            // Add columns to search
            var columnsToSearch = new List <FindDlgColItem>();

            columnsToSearch.Add(new FindDlgColItem(m_grid.Columns["Phonetic"].Index, 0, "Phonetic", "Phonetic"));
            columnsToSearch.Add(new FindDlgColItem(m_grid.Columns["CVPattern"].Index, 1, "CV Pattern", "CVPattern"));
            columnsToSearch.Add(new FindDlgColItem(m_grid.Columns["Gloss"].Index, 2, "Gloss", "Gloss"));
            FindInfo.ColumnsToSearch = columnsToSearch.ToArray();

            m_findDlg = new FindDlg(m_grid);
            ResetStartCell();
        }
コード例 #10
0
        public void RecordCache_Test1()
        {
            RecordCache cache   = new RecordCache(Connection);
            MarcRecord  record1 = cache.Get(1);

            Debug.Assert(record1 == null);
            record1 = cache.GetOrRequest(1);
            Debug.Assert(record1 != null);
            Debug.Assert(cache.RequestCount == 1);

            MarcRecord record2 = cache.Get(1);

            Debug.Assert(record2 != null);
            Debug.Assert(cache.RequestCount == 1);
        }
コード例 #11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make sure custom fields stored in the PaXML file are added to the project's field
        /// list.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void AddCustomFieldsFromPaXML(RecordCache cache)
        {
            // TODO: Fix
            //if (cache.DeserializedCustomFields != null &&
            //    cache.DeserializedCustomFields.Count > 0)
            //{
            //    foreach (PaFieldInfo customField in cache.DeserializedCustomFields)
            //    {
            //        PaFieldInfo fieldInfo = m_project.FieldInfo[customField.FieldName];
            //        if (fieldInfo == null)
            //            m_project.FieldInfo.Add(customField);
            //    }

            //    cache.DeserializedCustomFields = null;
            //}
        }
コード例 #12
0
ファイル: ServiceCache.cs プロジェクト: HLFrye/ZeroconfDotNet
        public void AddPacket(Packet p)
        {
            foreach (var ans in p.Answers)
            {
                var key = ans.Record.Name;
                if (!_cache.ContainsKey(key))
                {
                    _cache[key] = new RecordCache();
                }
                _cache[key].AddRecord(ans);

                if ((!nextCheck.HasValue) || (nextCheck > ans.TTL))
                {
                    _timer.FireNext((int)ans.TTL);
                    nextCheck = (int)ans.TTL;
                }
            }
        }
コード例 #13
0
        /// ------------------------------------------------------------------------------------
        public void Read(RecordCache recCache)
        {
            m_worker.ReportProgress(0);

            if (m_dataSource.FwDataSourceInfo == null)
            {
                return;
            }

            m_recCache = recCache;

            // Get the lexical data from the FW database.
            m_dataSource.SkipLoadingBecauseOfProblem = !GetData();
            m_dataSource.FwDataSourceInfo.IsMissing  = m_dataSource.SkipLoadingBecauseOfProblem;

            if (!m_dataSource.SkipLoadingBecauseOfProblem && !m_dataSource.FwDataSourceInfo.IsMissing)
            {
                m_dataSource.UpdateLastModifiedTime();
            }
        }
コード例 #14
0
        /// ------------------------------------------------------------------------------------
        public RecordCache Read()
        {
            TempRecordCache.Dispose();
            m_recCache = new RecordCache(m_project);
            App.IPASymbolCache.ClearUndefinedCharacterCollection();

            var worker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            worker.DoWork          += HandleBackgroundProcessStart;
            worker.ProgressChanged += HandleBackgroundProcessProgressChanged;
            worker.RunWorkerAsync();

            while (worker.IsBusy)
            {
                Application.DoEvents();
            }

            return(m_recCache);
        }
コード例 #15
0
 public void TestSetup()
 {
     _prj.PhoneCache.Clear();
     _prj.RecordCache.Clear();
     _recCache = _prj.RecordCache;
 }