/// <summary>
 /// Initializes a new instance of the <see cref="GooglePlayGames.BasicApi.PlayGamesClientConfiguration"/> struct.
 /// </summary>
 /// <param name="builder">Builder for this configuration.</param>
 private PlayGamesClientConfiguration(Builder builder)
 {
     this.mEnableSavedGames = builder.HasEnableSaveGames();
     this.mInvitationDelegate = builder.GetInvitationDelegate();
     this.mMatchDelegate = builder.GetMatchDelegate();
     this.mPermissionRationale = builder.GetPermissionRationale();
 }
Exemple #2
0
        public SRegex(string pattern, SRegexOptions options = SRegexOptions.Default)
        {
            var ast = Language.Parse(new SreSyntax(), pattern).Result.Node;
            switch (options)
            {
                case SRegexOptions.ByteCodeCompilation:
                    var compiler = new NfaVMBytecodeBackend(ast);
                    matcher = (int[] input) =>
                        {
                            var vm = new PikeNfaVM(compiler.Code.ToArray());
                            vm.Feed(input.Select(ch => (int)ch)).Done();
                            return vm.HasMatch;
                        };
                    break;
                case SRegexOptions.ILCompilation:
                    string methodName = "MatchSrePattern" + PatternID++;

                    var builder = new CachedMethod<MatchDelegate>(
                        methodName,
                        (emit, args) => EmitAst(emit, ast, args[0]));

                    matcher = builder.Delegate;
                    break;
                case SRegexOptions.NfaCompilation:
                    var nfa = new Nfa(ast);
                    matcher = nfa.Match;
                    break;
                case SRegexOptions.DfaCompilation:
                    var dfa = new RegularToDfaAlgorithm(new RegularTree(ast));
                    var simulation = new DfaSimulation(dfa.Data);
                    matcher = input => simulation.Match(input);
                    break;
            }
        }
        public void RegisterMatchDelegate(MatchDelegate del)
        {
            mRegisteredMatchDelegate = del;

            // Report pending matches if any.
            if (mRegisteredMatchDelegate != null && mPendingMatchDelegates != null && mPendingMatchDelegates.Count > 0)
            {
                RuntimeHelper.RunOnMainThread(() =>
                {
                    while (mPendingMatchDelegates.Count > 0)
                    {
                        var pendingDel = mPendingMatchDelegates.Dequeue();
                        mRegisteredMatchDelegate(TurnBasedMatch.FromGPGSTurnBasedMatch(pendingDel.Match), pendingDel.ShouldAutoLaunch, false);      // playerWantsToQuit doesn't occur on GPG.
                    }

                    mPendingMatchDelegates = null;
                });
            }

            // Register the delegate with GPGS.
            PlayGamesPlatform.Instance.TurnBased.RegisterMatchDelegate((match, flag) =>
            {
                if (del == null)
                {
                    return;
                }

                del(TurnBasedMatch.FromGPGSTurnBasedMatch(match), flag, false);     // playerWantsToQuit doesn't occur on GPG.
            }
                                                                       );
        }
Exemple #4
0
        public static object[] Merge(this object[] a, Type t, object n, MatchDelegate match)
        {
            var j = -1;

            for (int i = 0; i < a.Length; i++)
            {
                if (match(a[i], n))
                {
                    j = i;
                }
            }

            if (j >= 0)
            {
                //a[j] = n;

                n.CopyAssignedFieldsTo(t, a[j]);
                return(a);
            }

            var x = (object[])Array.CreateInstance(t, a.Length + 1);

            Array.Copy(a, x, a.Length);
            x[a.Length] = n;

            return(x);
        }
Exemple #5
0
        /// <summary>Repeats a match action until boundaries are met</summary>
        /// <param name="matchAction">The match action</param>
        /// <param name="notFoundAction">An optional action that is executed when no match is found</param>
        /// <returns>The same code matcher</returns>
        ///
        public CodeMatcher Repeat(Action <CodeMatcher> matchAction, Action <string> notFoundAction = null)
        {
            var count = 0;

            if (lastMatchCall == null)
            {
                throw new InvalidOperationException("No previous Match operation - cannot repeat");
            }

            while (IsValid)
            {
                matchAction(this);
                _ = lastMatchCall();
                count++;
            }

            lastMatchCall = null;

            if (count == 0 && notFoundAction != null)
            {
                notFoundAction(lastError);
            }

            return(this);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public StringMatcher(StringMatchingMethod method, string pattern)
        {
            switch (method)
            {
            case StringMatchingMethod.NoWildcards:
                m_pattern = prepareNoWildcard(pattern);
                Match     = buildNoWildcard;
                break;

            case StringMatchingMethod.UseWildcards:
                m_pattern = prepareWithWildcards(pattern);
                Match     = buildWithWildcards;
                break;

            case StringMatchingMethod.UseWildcardsStartsWith:
                m_pattern = prepareWithWildcardsStartsWith(pattern);
                Match     = buildWithWildcards;
                break;

            case StringMatchingMethod.UseRegexs:
                m_pattern = prepareRegex(pattern);
                Match     = buildRegex;
                break;

            default:
                throw new ArgumentException("Unknown StringMatchingMethod value");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GooglePlayGames.BasicApi.PlayGamesClientConfiguration"/> struct.
 /// </summary>
 /// <param name="builder">Builder for this configuration.</param>
 private PlayGamesClientConfiguration(Builder builder)
 {
     this.mEnableSavedGames    = builder.HasEnableSaveGames();
     this.mInvitationDelegate  = builder.GetInvitationDelegate();
     this.mMatchDelegate       = builder.GetMatchDelegate();
     this.mPermissionRationale = builder.GetPermissionRationale();
 }
 private PlayGamesClientConfiguration(Builder builder)
 {
     this.mEnableSavedGames          = builder.mEnableSaveGames;
     this.mEnableDeprecatedCloudSave = builder.mEnableDeprecatedCloudSave;
     this.mInvitationDelegate        = builder.mInvitationDelegate;
     this.mMatchDelegate             = builder.mMatchDelegate;
 }
 private PlayGamesClientConfiguration(Builder builder)
 {
     this.mEnableSavedGames = builder.HasEnableSaveGames();
     this.mEnableDeprecatedCloudSave = builder.HasEnableDeprecatedCloudSave();
     this.mInvitationDelegate = builder.GetInvitationDelegate();
     this.mMatchDelegate = builder.GetMatchDelegate();
 }
        public static object[] Merge(this object[] a, Type t, object n, MatchDelegate match)
        {
            var j = -1;
            for (int i = 0; i < a.Length; i++)
            {
                if (match(a[i], n))
                {
                    j = i;
                }
            }

            if (j >= 0)
            {
                //a[j] = n;

                n.CopyAssignedFieldsTo(t, a[j]);
                return a;
            }

            var x = (object[])Array.CreateInstance(t, a.Length + 1);
            Array.Copy(a, x, a.Length);
            x[a.Length] = n;

            return x;
        }
Exemple #11
0
 void AddMatchToList(Game game, List <Match> list, MatchDelegate matchDelegate)
 {
     FirebaseDatabase.DefaultInstance.GetReference("matches/" + game.id).ChildAdded += delegate(object sender, ChildChangedEventArgs e)
     {
         var match = e.Snapshot.ToClass <Match>();
         list.Add(match);
         matchDelegate(match);
     };
 }
        public static object[] MergeArray(this object[] a, Type t, object[] n, MatchDelegate match)
        {
            foreach (var k in n)
            {
                a = a.Merge(t, k, match);
            }

            return a;
        }
Exemple #13
0
        public static object[] MergeArray(this object[] a, Type t, object[] n, MatchDelegate match)
        {
            foreach (var k in n)
            {
                a = a.Merge(t, k, match);
            }

            return(a);
        }
        public T Find<T>(MatchDelegate<T> matchDelegate)
        {
            foreach (IBaseViewA managedView in managedViews)
            {
                if (managedView is T && matchDelegate((T)managedView)) return (T)managedView;
            }

            return default(T);
        }
        internal ViewCollection<T> FindAll<T>(MatchDelegate<T> matchDelegate)
        {
            var result = new ViewCollection<T>();

            foreach (IBaseViewA managedView in managedViews)
            {
                if (managedView is T && matchDelegate((T)managedView)) result.InternalAdd((T)managedView);
            }

            return result;
        }
 public void RegisterMatchDelegate(MatchDelegate del)
 {
     if (del == null)
     {
         this.mMatchDelegate = (Action <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch, bool>)null;
     }
     else
     {
         this.mMatchDelegate = Callbacks.AsOnGameThreadCallback <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch, bool>((Action <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch, bool>)((match, autoLaunch) => del(match, autoLaunch)));
     }
 }
 public EvaluatorRule(EvaluatorRuleConfig config)
 {
     Config = config;
     Id = Config.ConfigFileName;
     _getSource = CreateMatchDelegate(Config.EventSource);
     _getCounterCategory = CreateMatchDelegate(Config.CounterCategory);
     _getCounterInstance = CreateMatchDelegate(Config.CounterInstance);
     _getCounterName = CreateMatchDelegate(Config.CounterName);
     _getExtendedData = CreateMatchDelegate(Config.ExtendedData);
     _getValue = CreateMatchDelegate(Config.Value);
     _getDateTime = CreateMatchDelegate(Config.DateTime);
 }
Exemple #18
0
 public void RegisterMatchDelegate(MatchDelegate del)
 {
     if (del == null)
     {
         mMatchDelegate = null;
     }
     else
     {
         mMatchDelegate = Callbacks.AsOnGameThreadCallback <TurnBasedMatch, bool>(
             (match, autoLaunch) => del(match, autoLaunch));
     }
 }
 public EvaluatorRule(EvaluatorRuleConfig config)
 {
     Config              = config;
     Id                  = Config.ConfigFileName;
     _getSource          = CreateMatchDelegate(Config.EventSource);
     _getCounterCategory = CreateMatchDelegate(Config.CounterCategory);
     _getCounterInstance = CreateMatchDelegate(Config.CounterInstance);
     _getCounterName     = CreateMatchDelegate(Config.CounterName);
     _getExtendedData    = CreateMatchDelegate(Config.ExtendedData);
     _getValue           = CreateMatchDelegate(Config.Value);
     _getDateTime        = CreateMatchDelegate(Config.DateTime);
 }
Exemple #20
0
        public void RegisterMatchDelegate(MatchDelegate deleg)
        {
            Logger.d("iOSTbmpClient.RegisterMatchDelegate");
            if (deleg == null)
            {
                Logger.w("Can't register a null match delegate.");
                return;
            }

            mMatchDelegate = deleg;

            GPGSTBMPRegisterYourTurnNotificationCallback(TbmpYourTurnCallback);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GooglePlayGames.BasicApi.PlayGamesClientConfiguration"/> struct.
 /// </summary>
 /// <param name="builder">Builder for this configuration.</param>
 private PlayGamesClientConfiguration(Builder builder)
 {
     this.mEnableSavedGames   = builder.HasEnableSaveGames();
     this.mInvitationDelegate = builder.GetInvitationDelegate();
     this.mMatchDelegate      = builder.GetMatchDelegate();
     this.mScopes             = builder.getScopes();
     this.mHidePopups         = builder.IsHidingPopups();
     this.mRequestAuthCode    = builder.IsRequestingAuthCode();
     this.mForceRefresh       = builder.IsForcingRefresh();
     this.mRequestEmail       = builder.IsRequestingEmail();
     this.mRequestIdToken     = builder.IsRequestingIdToken();
     this.mAccountName        = builder.GetAccountName();
 }
 public void RegisterMatchDelegate(MatchDelegate del)
 {
     if (del == null)
     {
         mMatchDelegate = null;
     }
     else
     {
         mMatchDelegate = Callbacks.AsOnGameThreadCallback(delegate(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, bool autoLaunch)
         {
             del(match, autoLaunch);
         });
     }
 }
 public EventEvaluatorRule(EventType eventType, Regex regexRule, List<Regex> excludingRules, string eventSource, string counterCategory, string counterInstance, string counterName, string extendedData, string value, string dateTime, string dateFormat)
 {
     EventType = eventType;
     RegexRule = regexRule;
     HasExcludingRules = excludingRules.Count > 0;
     ExcludingRules = excludingRules;
     DateFormat = dateFormat;
     _getSource = CreateMatchDelegate(eventSource);
     _getCounterCategory = CreateMatchDelegate(counterCategory);
     _getCounterInstance = CreateMatchDelegate(counterInstance);
     _getCounterName = CreateMatchDelegate(counterName);
     _getExtendedData = CreateMatchDelegate(extendedData);
     _getValue = CreateMatchDelegate(value);
     _getDateTime = CreateMatchDelegate(dateTime);
 }
Exemple #24
0
 public EventEvaluatorRule(EventType eventType, Regex regexRule, List <Regex> excludingRules, string eventSource, string counterCategory, string counterInstance, string counterName, string extendedData, string value, string dateTime, string dateFormat)
 {
     EventType           = eventType;
     RegexRule           = regexRule;
     HasExcludingRules   = excludingRules.Count > 0;
     ExcludingRules      = excludingRules;
     DateFormat          = dateFormat;
     _getSource          = CreateMatchDelegate(eventSource);
     _getCounterCategory = CreateMatchDelegate(counterCategory);
     _getCounterInstance = CreateMatchDelegate(counterInstance);
     _getCounterName     = CreateMatchDelegate(counterName);
     _getExtendedData    = CreateMatchDelegate(extendedData);
     _getValue           = CreateMatchDelegate(value);
     _getDateTime        = CreateMatchDelegate(dateTime);
 }
 public LogEventEvaluationRule(string fileName, string regexRule, string logEventType, string sourceEvaluationRule,
                               string counterCategoryEvaluationRule, string counterNameEvaluationRule,
                               string instanceEvaluationRule, string extendedDataEvaluationRule, string valueEvaluationRule,
                               string dateTimeEvaluationRule, string dateFormat)
 {
     Id                  = fileName;
     _rule               = new Regex(regexRule, RegexOptions.Compiled);
     DateFormat          = dateFormat;
     EventType           = GetLogEventType(logEventType);
     _getSource          = CreateMatchDelegate(sourceEvaluationRule);
     _getCounterCategory = CreateMatchDelegate(counterCategoryEvaluationRule);
     _getInstance        = CreateMatchDelegate(instanceEvaluationRule);
     _getCounterName     = CreateMatchDelegate(counterNameEvaluationRule);
     _getExtendedData    = CreateMatchDelegate(extendedDataEvaluationRule);
     _getValue           = CreateMatchDelegate(valueEvaluationRule);
     _getDateTime        = CreateMatchDelegate(dateTimeEvaluationRule);
 }
 public LogEventEvaluationRule(string fileName, string regexRule, string logEventType, string sourceEvaluationRule,
                               string counterCategoryEvaluationRule, string counterNameEvaluationRule,
                               string instanceEvaluationRule, string extendedDataEvaluationRule, string valueEvaluationRule,
                               string dateTimeEvaluationRule, string dateFormat)
 {
     Id = fileName;
     _rule = new Regex(regexRule, RegexOptions.Compiled);
     DateFormat = dateFormat;
     EventType = GetLogEventType(logEventType);
     _getSource = CreateMatchDelegate(sourceEvaluationRule);
     _getCounterCategory = CreateMatchDelegate(counterCategoryEvaluationRule);
     _getInstance = CreateMatchDelegate(instanceEvaluationRule);
     _getCounterName = CreateMatchDelegate(counterNameEvaluationRule);
     _getExtendedData = CreateMatchDelegate(extendedDataEvaluationRule);
     _getValue = CreateMatchDelegate(valueEvaluationRule);
     _getDateTime = CreateMatchDelegate(dateTimeEvaluationRule);
 }
        internal void HandleMatchFromNotification(TurnBasedMatch match)
        {
            Logger.d("AndroidTbmpClient.HandleMatchFromNotification");
            Logger.d("Got match from notification: " + match);

            if (mMatchDelegate != null)
            {
                Logger.d("Delivering match directly to match delegate.");
                MatchDelegate del = mMatchDelegate;
                PlayGamesHelperObject.RunOnGameThread(() => {
                    del.Invoke(match, true);
                });
            }
            else
            {
                Logger.d("Since we have no match delegate, holding on to the match until we have one.");
                mMatchFromNotification = match;
            }
        }
        public void RegisterMatchDelegate(MatchDelegate del)
        {
            if (del == null)
            {
                mMatchDelegate = null;
            }
            else
            {
                mMatchDelegate =
                    ToOnGameThread <TurnBasedMatch, bool>(
                        (turnBasedMatch, autoAccept) => del(turnBasedMatch, autoAccept));

                TurnBasedMatchUpdateCallbackProxy callbackProxy = new TurnBasedMatchUpdateCallbackProxy(mMatchDelegate);
                AndroidJavaObject turnBasedMatchUpdateCallback  =
                    new AndroidJavaObject("com.google.games.bridge.TurnBasedMatchUpdateCallbackProxy", callbackProxy);
                using (mClient.Call <AndroidJavaObject>("registerTurnBasedMatchUpdateCallback",
                                                        turnBasedMatchUpdateCallback));
            }
        }
Exemple #29
0
        /// <summary>
        /// Starts the search.
        /// </summary>
        /// <param name="matchDelegate">The search delegate.</param>
        public void DoSearch(MatchDelegate matchDelegate)
        {
            foreach (var itemMatcher in Matchers)
            {
                if (string.IsNullOrEmpty(itemMatcher.ItemName) && !itemMatcher.Enabled)
                {
                    continue;
                }

                if (itemMatcher.AuctionConditions.Count > 0)
                {
                    Search(TradeType.Auction, itemMatcher, matchDelegate);
                }
                if (itemMatcher.SalesConditions.Count > 0)
                {
                    Search(TradeType.Sale, itemMatcher, matchDelegate);
                }
            }
        }
 public void RegisterMatchDelegate(MatchDelegate deleg)
 {
     Logger.d("AndroidTbmpClient.RegisterMatchDelegate");
     if (deleg == null)
     {
         Logger.w("Can't register a null match delegate.");
         return;
     }
     this.mMatchDelegate = deleg;
     if (this.mMatchFromNotification != null)
     {
         Logger.d("Delivering pending match to the newly registered delegate.");
         TurnBasedMatch match = this.mMatchFromNotification;
         this.mMatchFromNotification = null;
         PlayGamesHelperObject.RunOnGameThread(delegate
         {
             deleg(match, true);
         });
     }
 }
Exemple #31
0
        private void Search(TradeType tradeType, StuffSearchCondition itemMatcher, MatchDelegate matchDelegate)
        {
            AppCore.LogAccountant.DebugFormat("Ищем {0} {1}.",
                                              itemMatcher.ItemName, tradeType == TradeType.Auction ? "на аукционе" : "в продаже");

            var matchers = itemMatcher.GetConditions(tradeType).GetActive();

            var hasGold     = matchers.Any(e => e.Price.Resource == Resource.Gold);
            var hasCristall = matchers.Any(e => e.Price.Resource == Resource.Crystals);
            var minLevel    = matchers.Min(e => e.MinResalesCount);

            controller.DoSearchOnMarket(tradeType, itemMatcher.ItemName, GetResealesFilter(minLevel), hasCristall, hasGold);

            foreach (var itemController in EnumerateTradeItems())
            {
                foreach (var matcher in matchers.ToArray())
                {
                    var matchResult = matcher.Match(Player, itemController, tradeType);
                    switch (matchResult)
                    {
                    case MatchResult.Ok:
                        if (!matchDelegate(tradeType, itemMatcher, itemController))
                        {
                            return;
                        }
                        break;

                    case MatchResult.BadPriceAmmount:
                        matchers.Remove(matcher);
                        break;

                    default:
                        break;
                    }
                }
                if (matchers.Count == 0)
                {
                    return;
                }
            }
        }
Exemple #32
0
        public void RegisterMatchDelegate(MatchDelegate del)
        {
            // Create and register a default local player listener if needed.
            if (mLocalPlayerListener == null)
            {
                mLocalPlayerListener = new InternalGKLocalPlayerListenerImpl()
                {
                    CloseAndResetMatchmakerVC = () =>
                    {
                        if (mCurrentMatchmakerVC != null)
                        {
                            mCurrentMatchmakerVC.DismissViewController(true, null);
                            mCurrentMatchmakerVC = null;
                        }
                    }
                };
                GKLocalPlayer.LocalPlayer.RegisterListener(mLocalPlayerListener);
            }

            mLocalPlayerListener.MatchDelegate = del;
        }
        public void RegisterMatchDelegate(MatchDelegate deleg)
        {
            Logger.d("AndroidTbmpClient.RegisterMatchDelegate");
            if (deleg == null)
            {
                Logger.w("Can't register a null match delegate.");
                return;
            }

            mMatchDelegate = deleg;

            // if we have a pending match to deliver, deliver it now
            if (mMatchFromNotification != null)
            {
                Logger.d("Delivering pending match to the newly registered delegate.");
                TurnBasedMatch match = mMatchFromNotification;
                mMatchFromNotification = null;
                PlayGamesHelperObject.RunOnGameThread(() => {
                    deleg.Invoke(match, true);
                });
            }
        }
Exemple #34
0
        public SRegex(string pattern, SRegexOptions options = SRegexOptions.Default)
        {
            var ast = Language.Parse(new SreSyntax(), pattern).Result.Node;

            switch (options)
            {
            case SRegexOptions.ByteCodeCompilation:
                var compiler = new NfaVMBytecodeBackend(ast);
                matcher = (int[] input) =>
                {
                    var vm = new PikeNfaVM(compiler.Code.ToArray());
                    vm.Feed(input.Select(ch => (int)ch)).Done();
                    return(vm.HasMatch);
                };
                break;

            case SRegexOptions.ILCompilation:
                string methodName = "MatchSrePattern" + PatternID++;

                var builder = new CachedMethod <MatchDelegate>(
                    methodName,
                    (emit, args) => EmitAst(emit, ast, args[0]));

                matcher = builder.Delegate;
                break;

            case SRegexOptions.NfaCompilation:
                var nfa = new Nfa(ast);
                matcher = nfa.Match;
                break;

            case SRegexOptions.DfaCompilation:
                var dfa        = new RegularToDfaAlgorithm(new RegularTree(ast));
                var simulation = new DfaSimulation(dfa.Data);
                matcher = input => simulation.Match(input);
                break;
            }
        }
Exemple #35
0
        private CodeMatcher Match(CodeMatch[] matches, int direction, bool useEnd)
        {
            lastMatchCall = delegate()
            {
                FixStart();
                while (IsValid)
                {
                    if (MatchSequence(Pos, matches))
                    {
                        if (useEnd)
                        {
                            Pos += matches.Length - 1;
                        }
                        break;
                    }

                    Pos += direction;
                }

                lastError = IsInvalid ? $"Cannot find {matches.Join()}" : null;
                return(this);
            };
            return(lastMatchCall());
        }
 public void RegisterMatchDelegate(MatchDelegate deleg) {
     Logger.d("AndroidTbmpClient.RegisterMatchDelegate");
     if (deleg == null) {
         Logger.w("Can't register a null match delegate.");
         return;
     }
     
     mMatchDelegate = deleg;
     
     // if we have a pending match to deliver, deliver it now
     if (mMatchFromNotification != null) {
         Logger.d("Delivering pending match to the newly registered delegate.");
         TurnBasedMatch match = mMatchFromNotification;
         mMatchFromNotification = null;
         PlayGamesHelperObject.RunOnGameThread(() => {
             deleg.Invoke(match, true);
         });                
     }
 }
Exemple #37
0
 public void ExpectType(Type type)
 {
     property = type.GetProperty(Field);
     matcher  = GetMatchDelegate();
 }
 /// <summary>
 /// Adds the match delegate.  This is called when a match notification
 /// is received.
 /// </summary>
 /// <returns>The builder.</returns>
 /// <param name="matchDelegate">Match delegate.</param>
 public Builder WithMatchDelegate(MatchDelegate matchDelegate)
 {
     this.mMatchDelegate = Misc.CheckNotNull(matchDelegate);
     return(this);
 }
        public static List <PDFSearchResult> SearchPage(PDFDocument pdf_document, int page, string terms, MatchDelegate match)
        {
            // Tidy up the keywords
            if (null == terms)
            {
                terms = "";
            }

            string[] keywords = GenerateIndividualKeywords(terms);

            List <PDFSearchResult> search_results = new List <PDFSearchResult>();
            WordList words = new WordList();
            var      SPLITTER_WHITESPACE = new char[] { ' ', '\n', '\r', '\t' };

            // Add the comments
            {
                if (1 == page && !String.IsNullOrEmpty(pdf_document.Comments))
                {
                    var splits = pdf_document.Comments.Split(SPLITTER_WHITESPACE, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var split in splits)
                    {
                        words.Add(new Word {
                            Text = split
                        });
                    }
                }
            }

            // Add the annotations
            {
                foreach (var pdf_annotation in pdf_document.GetAnnotations())
                {
                    if (page == pdf_annotation.Page)
                    {
                        if (!String.IsNullOrEmpty(pdf_annotation.Text))
                        {
                            var splits = pdf_annotation.Text.Split(SPLITTER_WHITESPACE, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var split in splits)
                            {
                                words.Add(new Word {
                                    Text = split
                                });
                            }
                        }
                    }
                }
            }

            // Add the PDF running text
            {
                WordList words_pdf = pdf_document.GetOCRText(page);
                if (null != words_pdf)
                {
                    words.AddRange(words_pdf);
                }
            }

            // Find the text
            if (null != words && null != keywords)
            {
                // Split keywords
                string[][] split_keywords = new string[keywords.Length][];
                for (int i = 0; i < keywords.Length; ++i)
                {
                    split_keywords[i] = StringTools.Split_NotInDelims(keywords[i].ToLower(), '"', '"', " ").ToArray();
                }

                for (int w = 0; w < words.Count; ++w)
                {
                    Word   first_word       = words[w];
                    string first_word_lower = first_word.Text.ToLower();

                    for (int i = 0; i < split_keywords.Length; ++i)
                    {
                        string[] split_keyword = split_keywords[i];

                        // Ignore spurious empty keyword sets
                        if (1 > split_keyword.Length)
                        {
                            continue;
                        }

                        // Don't process single keywords that are too short
                        if (2 > split_keyword[0].Length)
                        {
                            continue;
                        }

                        // Process the first word - if it doesn't match we are done here
                        if (!match(first_word_lower, split_keyword[0]))
                        {
                            continue;
                        }

                        // If there are more words we have to get a little crafty and check the remaining words
                        bool follows_match = true;
                        for (int j = 0; j < split_keyword.Length; ++j)
                        {
                            if (w + j < words.Count)
                            {
                                Word   follow_word       = words[w + j];
                                string follow_word_lower = follow_word.Text.ToLower();
                                if (!match(follow_word_lower, split_keyword[j]))
                                {
                                    follows_match = false;
                                    break;
                                }
                            }
                            else
                            {
                                follows_match = false;
                                break;
                            }
                        }

                        // If the remaining words dont match, bail
                        if (!follows_match)
                        {
                            continue;
                        }

                        // If we get here, the word (any any follow words) match
                        {
                            PDFSearchResult search_result = new PDFSearchResult();
                            search_results.Add(search_result);

                            // Store the page
                            search_result.keywords = keywords;
                            search_result.page     = page;

                            // Get the words associated with this result
                            {
                                search_result.keyword_index = i;
                                search_result.words         = new Word[split_keyword.Length];
                                for (int j = 0; j < split_keyword.Length; ++j)
                                {
                                    Word follow_word = words[w + j];
                                    search_result.words[j] = follow_word;
                                }
                            }

                            // Create the context sentence
                            {
                                int  MIN_CONTEXT_SIZE = 3;
                                int  MAX_CONTEXT_SIZE = 10;
                                bool ellipsis_start   = false;
                                bool ellipsis_end     = false;
                                int  w_start          = w;
                                while (w_start > 0)
                                {
                                    // Stop at a preceding sentence
                                    if (ContainsASentenceTerminator(words[w_start - 1].Text))
                                    {
                                        if (w - w_start >= MIN_CONTEXT_SIZE)
                                        {
                                            break;
                                        }
                                    }

                                    // Stop if we are going too far
                                    if (w - w_start > MAX_CONTEXT_SIZE)
                                    {
                                        ellipsis_start = true;
                                        break;
                                    }

                                    --w_start;
                                }
                                int w_end = w;
                                while (w_end < words.Count)
                                {
                                    // Stop at the end of a sentence
                                    if (ContainsASentenceTerminator(words[w_end].Text))
                                    {
                                        if (w_end - w >= MIN_CONTEXT_SIZE)
                                        {
                                            break;
                                        }
                                    }

                                    // Stop if we are going too far
                                    if (w_end - w > MAX_CONTEXT_SIZE)
                                    {
                                        ellipsis_end = true;
                                        break;
                                    }


                                    if (w_end + 1 == words.Count)
                                    {
                                        break;
                                    }

                                    ++w_end;
                                }

                                StringBuilder sb = new StringBuilder();
                                sb.AppendFormat("p{0}: ", page);
                                if (ellipsis_start)
                                {
                                    sb.Append("...");
                                }
                                for (int w_current = w_start; w_current <= w_end; ++w_current)
                                {
                                    sb.Append(words[w_current].Text);
                                    sb.Append(" ");
                                }
                                if (ellipsis_end)
                                {
                                    sb.Append("...");
                                }
                                search_result.context_sentence = sb.ToString();
                            }
                        }
                    }
                }
            }

            return(search_results);
        }
 public void RegisterMatchDelegate(MatchDelegate del)
 {
     if (del == null)
     {
         mMatchDelegate = null;
     }
     else
     {
         mMatchDelegate = Callbacks.AsOnGameThreadCallback<TurnBasedMatch, bool>(
             (match, autoLaunch) => del(match, autoLaunch));
     }
 }
        public void RegisterMatchDelegate (MatchDelegate deleg)
        {
            Logger.d("iOSTbmpClient.RegisterMatchDelegate");
            if (deleg == null) {
                Logger.w("Can't register a null match delegate.");
                return;
            }
            
            mMatchDelegate = deleg;

            GPGSTBMPRegisterYourTurnNotificationCallback(TbmpYourTurnCallback);
        }
 /// <summary>
 /// Adds the match delegate.  This is called when a match notification
 /// is received.
 /// </summary>
 /// <returns>The builder.</returns>
 /// <param name="matchDelegate">Match delegate.</param>
 public Builder WithMatchDelegate(MatchDelegate matchDelegate)
 {
     this.mMatchDelegate = Misc.CheckNotNull(matchDelegate);
     return this;
 }