Example #1
0
        private static MockClient <IWampClientProxy <MockRaw> > GetPublisher(Type scenario, WampMockClientBuilder <MockRaw> builder, IEnumerable <WampMessage <MockRaw> > calls)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.BrokerToPublisher,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            long sessionId = (long)welcome.Arguments[0].Value;

            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> recorder =
                new ResponsiveMessageRecorder(calls,
                                              new Dictionary <WampMessageType, string>()
            {
                { WampMessageType.v2Published, "publicationId" }
            });

            IWampClientProxy <MockRaw> built =
                builder.Create(nullPlayer,
                               recorder,
                               welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, recorder);

            return(result);
        }
Example #2
0
        private static MockClient <IWampClientProxy <MockRaw> > GetSubscriber(Type scenario, WampMockClientBuilder <MockRaw> clientBuilder, IWampIncomingMessageHandler <MockRaw, IWampClientProxy <MockRaw> > handler, IEnumerable <WampMessage <MockRaw> > calls)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.BrokerToSubscriber,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            // TODO: After enough events unsubscribe.
            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> recorder =
                new ResponsiveMessageRecorder(calls,
                                              new Dictionary <WampMessageType, string>()
            {
                { WampMessageType.v2Subscribed, "subscriptionId" }
            });

            IWampClientProxy <MockRaw> built =
                clientBuilder.Create(nullPlayer,
                                     recorder,
                                     welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, recorder);

            return(result);
        }
Example #3
0
        public static void NullObjectDemo()
        {
            ISpeakable notNullPlayer = new Player();

            notNullPlayer.WritePostMessage("Hello everybody!");
            ISpeakable nullPlayer = new NullPlayer();

            // if we would initialize it as null (not NullPlayer) we get exception.
            nullPlayer.WritePostMessage("Hello everybody!");
        }
Example #4
0
        /// <summary>
        /// エンジンなどの切断処理
        /// </summary>
        private void Disconnect()
        {
            // Playerの終了処理をしてNullPlayerを突っ込んでおく。

            foreach (var c in All.IntColors())
            {
                Players[c].Dispose();
                Players[c] = new NullPlayer();
            }
        }
Example #5
0
        /// <summary>
        /// エンジンなどの切断処理
        /// </summary>
        private void Disconnect()
        {
            InTheGame = false;

            // Playerの終了処理をしてNullPlayerを突っ込んでおく。
            foreach (var c in All.Colors())
            {
                var player = Player(c);
                if (player != null)
                {
                    player.Dispose();
                }

                Players[(int)c] = new NullPlayer();
            }

            NotifyTurnChanged();
        }
Example #6
0
        /// <summary>
        /// エンジンなどの切断処理。
        /// 簡単な終了処理を兼ねている。
        /// </summary>
        private void Disconnect()
        {
            // Playerの終了処理をしてNullPlayerを突っ込んでおく。

            foreach (var c in All.IntColors())
            {
                Players[c].Dispose();
                Players[c] = new NullPlayer();
            }

            // 連続対局のためのカウンターをリセットする。
            continuousGame.ResetCounter();

            if (continuousGame.GameSetting != null)
            {
                GameSetting = continuousGame.GameSetting; // プレイヤーの入れ替えで破壊している可能性があるので復元する。
                //continuousGame.GameSetting = null; // これ次のGameStartまで残ってないと対局者名の表示などで困る。
            }
        }
        private static MockClient <IWampClientProxy <MockRaw> > GetCaller(Type scenario, WampMockClientBuilder <MockRaw> builder)
        {
            WampMessage <MockRaw> welcome =
                GetCalls(scenario, Channel.DealerToCaller,
                         new WampMessageType[] { WampMessageType.v2Welcome })
                .FirstOrDefault();

            NullPlayer <MockRaw> nullPlayer =
                new NullPlayer <MockRaw>();

            IMessageRecorder <MockRaw> messageRecorder =
                new MessageRecorder <MockRaw>();

            IWampClientProxy <MockRaw> built =
                builder.Create(nullPlayer,
                               messageRecorder,
                               welcome);

            MockClient <IWampClientProxy <MockRaw> > result =
                new MockClient <IWampClientProxy <MockRaw> >(built, messageRecorder);

            return(result);
        }