Exemple #1
0
        /// <summary>
        /// The reversal should not be checking the writing system when testing for sorter compatibility since
        /// that writing system is changed in the Clerk through events and the bulkedit and browse view share the same clerk.
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <remarks>This method is only valid because there are no multi-lingual columns in the reversal views</remarks>
        /// <returns></returns>
        public override bool AreSortersCompatible(RecordSorter first, RecordSorter second)
        {
            if (first == null || second == null)
            {
                return(false);
            }

            var secondSorter = second as GenRecordSorter;
            var firstSorter  = first as GenRecordSorter;

            if (secondSorter == null || firstSorter == null)
            {
                return(first.CompatibleSorter(second));
            }

            var sfcThis  = firstSorter.Comparer as StringFinderCompare;
            var sfcOther = secondSorter.Comparer as StringFinderCompare;

            if (sfcThis == null || sfcOther == null)
            {
                return(false);
            }
            if (!sfcThis.Finder.SameFinder(sfcOther.Finder))
            {
                return(false);
            }
            return(true);
        }
        public override void ResetSearch(FdoCache cache, int currentID,
                                         bool wantExactMatch,
                                         int vernWs, string cf, string uf, string af,
                                         int analWs, string gl, List <ExtantEntryInfo> filters)
        {
            CheckDisposed();

            m_cacheSearch            = cache;
            m_currentID              = currentID;
            m_wantExactMatch         = wantExactMatch;
            m_vernWs                 = vernWs;
            m_cf                     = cf;
            m_uf                     = uf;
            m_af                     = af;
            m_analWs                 = analWs;
            m_gl                     = gl;
            m_filters                = filters;
            m_fResetSearchInProgress = true;
            RecordSorter sorter = null;

            if (!String.IsNullOrEmpty(cf) || !String.IsNullOrEmpty(uf) || !String.IsNullOrEmpty(af))
            {
                sorter = m_bvMatches.CreateSorterForFirstColumn(true, vernWs);
            }
            else if (!String.IsNullOrEmpty(gl))
            {
                sorter = m_bvMatches.CreateSorterForFirstColumn(false, analWs);
            }
            (Clerk as MatchingItemsRecordClerk).SetSorter(sorter);
            DoResetSearch();
        }
Exemple #3
0
        public void SortRecords_NoData()
        {
            var recordSorter  = new RecordSorter();
            var emptyList     = new List <Record>();
            var sortedRecords = recordSorter.SortRecords(emptyList, SortCriteria.GenderAscLastNameAsc).ToList <Record>();

            // Checking to make sure exception is not thrown and that sorted list is empty
            Assert.IsTrue(sortedRecords.Count == 0);
        }
Exemple #4
0
        public void SortRecords_LastNameDesc()
        {
            var recordSorter  = new RecordSorter();
            var sortedRecords = recordSorter.SortRecords(_records, SortCriteria.LastNameDesc).ToList <Record>();

            // Check the sort order
            //
            Assert.AreEqual(sortedRecords[0].LastName, "Sanders");
            Assert.AreEqual(sortedRecords[1].LastName, "Murphy");
            Assert.AreEqual(sortedRecords[2].LastName, "Doe");
        }
Exemple #5
0
        public void Setup()
        {
            // Would normally create some mock objects. In this case
            // the record repository pretty much already is a mock
            // implementation of a repository anyway, i.e.,
            // it doesn't really access a database.
            //
            var recordParser     = new RecordParser();
            var recordSorter     = new RecordSorter();
            var recordRepository = new RecordRepository(recordSorter);

            _recordsController = new RecordsController(recordParser, recordRepository);
        }
Exemple #6
0
        static int Main(string[] args)
        {
            // Create services classes that will be injected into Application instance
            //
            var recordParser = new RecordParser();
            var recordSorter = new RecordSorter();

            // Create a run the application
            //
            var application = new Application(args, recordParser, recordSorter);

            return(application.Run());
        }
 public override void ChangeSorter(RecordSorter sorter)
 {
     RequestRefresh();
     base.ChangeSorter(sorter);
 }
Exemple #8
0
        /// <summary>
        /// Searches the specified fields.
        /// </summary>
        /// <param name="fields">The fields.</param>
        /// <param name="filters">The filters.</param>
        public void Search(IEnumerable <SearchField> fields, IEnumerable <ICmObject> filters)
        {
            // If we abort this search (because the user typed), but somehow the system becomes idle before we complete a new
            // search, go ahead and complete the original one.
            m_pendingFields  = fields;
            m_pendingFilters = filters;
            m_mediator.IdleQueue.Add(IdleQueuePriority.High, DoPendingSearchWhenIdle);

            CreateSearchers();

            var       results        = new HashSet <ICmObject>();
            ITsString firstSearchStr = null;

            foreach (SearchField field in fields)
            {
                if (ShouldAbort())
                {
                    return;
                }
                if (firstSearchStr == null)
                {
                    firstSearchStr = field.String;
                }
                results.UnionWith(m_searcher.Search(field.Flid, field.String));
            }

            if (filters != null)
            {
                results.ExceptWith(filters);
            }

            if (ShouldAbort())
            {
                return;
            }
            // The following fixes LT-10293.
            RecordSorter sorter = null;

            if (firstSearchStr != null)
            {
                int  ws     = firstSearchStr.get_WritingSystemAt(0);
                bool isVern = m_cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Contains(ws);
                sorter = m_bvMatches.CreateSorterForFirstColumn(isVern, ws);
            }
            if (sorter != null)
            {
                // Convert each ICmObject in results to a IManyOnePathSortItem, and sort
                // using the sorter.
                var records = new ArrayList(results.Count);
                foreach (ICmObject obj in results)
                {
                    records.Add(new ManyOnePathSortItem(obj));
                }
                sorter.Sort(records);
                var hvos = new int[records.Count];
                for (int i = 0; i < records.Count; ++i)
                {
                    hvos[i] = (((IManyOnePathSortItem)records[i]).KeyObject);
                }
                UpdateResults(hvos);
            }
            else
            {
                UpdateResults(results.Select(obj => obj.Hvo).ToArray());
            }
            // Completed successfully, don't want to do again.
            m_pendingFields = null;
            m_mediator.IdleQueue.Remove(DoPendingSearchWhenIdle);
        }
Exemple #9
0
 public FindResultSorter(ITsString searchString, RecordSorter sorter)
 {
     m_comp = searchString.Text != null ? new ExactMatchFirstComparer(searchString.Text, sorter.getComparer()) : sorter.getComparer();
 }
Exemple #10
0
        private void UpdateResults(SearchField firstField, IEnumerable <int> results)
        {
            ITsString firstSearchStr = firstField.String;
            // if the firstSearchStr is null we can't get its writing system
            RecordSorter sorter = null;

            if (firstSearchStr != null)
            {
                int ws = firstSearchStr.get_WritingSystemAt(0);
                sorter = CreateFindResultSorter(firstSearchStr, ws);
            }
            int[] hvos;
            if (sorter != null)
            {
                // Convert each ICmObject in results to a IManyOnePathSortItem, and sort
                // using the sorter.
                var records = new ArrayList();
                foreach (int hvo in results.Where(hvo => StartingObject == null || StartingObject.Hvo != hvo))
                {
                    records.Add(new ManyOnePathSortItem(hvo, null, null));
                }
                sorter.Sort(records);
                hvos = records.Cast <IManyOnePathSortItem>().Select(i => i.KeyObject).ToArray();
            }
            else
            {
                hvos = results.Where(hvo => StartingObject == null || StartingObject.Hvo != hvo).ToArray();
            }

            int count     = hvos.Length;
            int prevIndex = m_bvMatches.SelectedIndex;
            int prevHvo   = prevIndex == -1 ? 0 : m_bvMatches.AllItems[prevIndex];

            m_listPublisher.CacheVecProp(m_cache.LanguageProject.LexDbOA.Hvo, hvos);
            TabStop = count > 0;
            // Disable the list so that it doesn't steal the focus (LT-9481)
            m_bvMatches.Enabled = false;
            try
            {
                // LT-6366
                if (count == 0)
                {
                    if (m_bvMatches.BrowseView.IsHandleCreated)
                    {
                        m_bvMatches.SelectedIndex = -1;
                    }
                    m_selObject = null;
                }
                else
                {
                    int newIndex = 0;
                    var allItems = m_bvMatches.AllItems;                     // This is an important optimization; each call marshals the whole list!
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        if (allItems[i] == prevHvo)
                        {
                            newIndex = i;
                            break;
                        }
                    }
                    if (m_bvMatches.BrowseView.IsHandleCreated)
                    {
                        m_bvMatches.SelectedIndex = newIndex;
                    }
                    m_selObject = m_cache.ServiceLocator.GetObject(allItems[newIndex]);
                    FireSelectionChanged();
                }
            }
            finally
            {
                m_bvMatches.Enabled = true;
            }

            if (!m_searchEngine.IsBusy && SearchCompleted != null)
            {
                SearchCompleted(this, new EventArgs());
            }
        }