Beispiel #1
0
        public static void ProcessQueue()
        {
            if (!_isHandlingRequest && _packets.Count > 0)
            {
                lock (_syncRoot)
                {
                    if (_sasProvider == null)
                    {
                        _sasProvider = new SharedAccessSignatureTokenProvider(CommonConfiguration.Instance.BackboneConfiguration.IssuerName,
                                                                              CommonConfiguration.Instance.BackboneConfiguration.IssuerSecret,
                                                                              new TimeSpan(1, 0, 0));
                    }

                    _isHandlingRequest = true;
                    var packet = _packets.Dequeue();

                    var content = Encoding.Default.GetBytes(DatacontractSerializerHelper.Serialize <GamePacket>(packet));

                    using (WebClient webClient = new WebClient())
                    {
                        var token = _sasProvider.GetToken(CommonConfiguration.Instance.BackboneConfiguration.GetRealm(), "POST", new TimeSpan(1, 0, 0));
                        webClient.Headers[HttpRequestHeader.Authorization] = token.TokenValue;

                        // add the properties
                        var collection = new NameValueCollection();
                        collection.Add(GamePacket.VERSION, GamePacket.Namespace);
                        webClient.Headers.Add(collection);

                        webClient.UploadDataCompleted += WebClient_UploadDataCompleted;
                        webClient.UploadDataAsync(new Uri(CommonConfiguration.Instance.BackboneConfiguration.GetServiceMessagesAddress(packet.Queue)), "POST", content);
                    }
                }
            }
        }
Beispiel #2
0
        public void DatacontractSerializerHelperTest()
        {
            var gameEvent = SampleGenerator.GameEventTestLarge();
            var content   = DatacontractSerializerHelper.Serialize(gameEvent);

            Assert.IsTrue(content.Length > 0);
            var gameEvent2 = DatacontractSerializerHelper.Deserialize <GameEvent>(content);

            Assert.AreEqual(gameEvent.Properties.Count, gameEvent2.Properties.Count);
            Assert.AreEqual(gameEvent.Properties["stat_22"], gameEvent2.Properties["stat_22"]);
        }
Beispiel #3
0
        public void GamePacketReceiver_NoSession()
        {
            _correlation = Guid.NewGuid().ToString();

            var factory = new ServiceBusMessagingFactory(_backboneConfiguration);

            var receiver = new TestGamePacketReceiver(_configuration, factory);

            receiver.OnGamePacketCompleted += Receiver_OnGamePacketCompleted;
            receiver.OnListenerError       += Receiver_OnListenerError;

            Task.WaitAll(receiver.StartListening("GameEvents"));

            var client = factory.GetQueueClientByName("GameEvents").Result;

            for (var msg = 0; msg < 6; msg++)
            {
                var message = new Message
                {
                    CorrelationId = _correlation
                };
                client.SendAsync(message);
            }

            for (var msg = 0; msg < 50; msg++)
            {
                var packet = new GamePacket {
                    GameEvent = new GameEvent(), EventId = 100
                };
                var content = Encoding.Default.GetBytes(DatacontractSerializerHelper.Serialize(packet));
                var message = new Message
                {
                    CorrelationId = _correlation,
                    Body          = content
                };
                client.SendAsync(message);
            }

            var sw = new Stopwatch();

            sw.Start();
            while (sw.ElapsedMilliseconds < 50000 &&
                   (_errors != 6 || _success != 50))
            {
                Thread.Sleep(50);
            }
            sw.Stop();

            Assert.AreEqual(6, _errors);
            Assert.AreEqual(50, _success);
        }