Esempio n. 1
0
 void SearchCompleted()
 {
     disposed = true;
     cancellationTokenSource.Cancel();
     cancellationTokenSource.Dispose();
     Debug.Assert(OnSearchCompleted != null);
     OnSearchCompleted?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 2
0
        public void Search(string text, bool exactMatch, OnSearchCompleted onCompletion)
        {
            text = text.ToLower();
            text = exactMatch ? Universe.FillPageBlank(text) : Universe.FillPageRandomly(text);

            var absoluteLocation = library.PageTextToAbsoluteLocation(text);

            // Extract the segment(s) in the absolute location that contain the relative location information
            var relativeSegment = (absoluteLocation % (library.relativeLocationOffset * 10000000)) / library.relativeLocationOffset;
            var pageSegment     = relativeSegment / 10000;
            var bookSegment     = (relativeSegment % 100000) / 100;
            var shelfSegment    = (relativeSegment % 100) / 10;
            var wallSegment     = relativeSegment % 10;

            // Extract the possible range of wall, shelf, book and page numbers
            var maxPage  = System.Math.Min(409, BigInteger.ToInt32(pageSegment));
            var maxBook  = System.Math.Min(31, BigInteger.ToInt32(bookSegment));
            var maxShelf = System.Math.Min(4, BigInteger.ToInt32(shelfSegment));
            var maxWall  = System.Math.Min(3, BigInteger.ToInt32(wallSegment));

            // Pick random a random relative location within the given limits
            var page  = UnityEngine.Random.Range(0, maxPage);
            var book  = UnityEngine.Random.Range(0, maxBook);
            var shelf = UnityEngine.Random.Range(0, maxShelf);
            var wall  = UnityEngine.Random.Range(0, maxWall);

            // Reconstruct the hexagon location
            var relativeLocation = page * 10000 + book * 100 + shelf * 10 + wall;
            var hexLocation      = absoluteLocation - library.relativeLocationOffset * relativeLocation;

            var pageLocation = new PageLocation()
            {
                Hex   = new HexagonLocation(hexLocation),
                Wall  = wall + 1,
                Shelf = shelf + 1,
                Book  = book + 1,
                Page  = page + 1
            };

            onCompletion(new SearchResult()
            {
                Title = "",                 //library.PageLocationToTitle(pageLocation),
                Hex   = pageLocation.Hex,
                Wall  = pageLocation.Wall,
                Shelf = pageLocation.Shelf,
                Book  = pageLocation.Book,
                Page  = pageLocation.Page
            });
        }
        //-------------------------------------------------------------------
        private void SearchCompleted(List <TaxonTreeNodeNamed> _results)
        {
            lock (_SearchLock)
            {
                //Console.WriteLine("Search completed");

                if (_SearchingThread != null)
                {
                    _SearchingThread = null;
                }
                OnSearchCompleted?.Invoke(this, new TaxonSearchAsyncCompletedArgs(_SearchString, _results));

                //Console.WriteLine("Seach completed end");
            }
        }
Esempio n. 4
0
    public void Search(string text, bool exactMatch, OnSearchCompleted onCompleted)
    {
        throw new System.InvalidOperationException();
        // text = Regex.Replace(text, string.Format("[^{0}]", Universe.Alphabet), "", RegexOptions.IgnoreCase);
        // if (text == "") return;

        // text = exactMatch ? Universe.FillPageBlank(text) : Universe.FillPageRandomly(text);

        // WWWForm form = new WWWForm();
        // form.AddField("find",text);
        // form.AddField("method","x");

        // StartCoroutine(WaitForRequest(BASE_URL, form, (www, error) => {

        //  if (error != SearchError.None)
        //      return;

        //  onCompleted(Parse(www.text));
        // }));
    }