Example #1
0
        public void Register(PlayerType requestedPlayer)
        {
            ITicTacToeCallback client = OperationContext.Current.GetCallbackChannel <ITicTacToeCallback>();

            // Reached Max Limit.
            if (_dictionary.Count == 2)
            {
                client.RegistrationFailed();
                return;
            }

            // Check Availability.
            PlayerType allottedPlayer = CheckAvailability(requestedPlayer);

            _dictionary.Add(allottedPlayer, client);
            client.Registered((_dictionary.Count == 1), allottedPlayer);

            if (_dictionary.Count == 2)
            {
                foreach (KeyValuePair <PlayerType, ITicTacToeCallback> pair in _dictionary)
                {
                    if (((ICommunicationObject)pair.Value).State == CommunicationState.Opened)
                    {
                        pair.Value.GameStarted();
                    }
                }
            }
        }