예제 #1
0
        private void LoopAndSendRandom()
        {
            var j = ConsoleEx.ReadLine("Number of messages to send (0 for infinite or until ESC is pressed)", 0);

            for (var i = 0; i < j || j == 0; i++)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }

                var typeToSend = GetMessageTypes().TakeRandom();
                var gameEvent  = (ITypeVersionMessage)Activator.CreateInstance(typeToSend);

                var props = gameEvent.GetType().GetProperties();

                foreach (var prop in props)
                {
                    var propName = prop.Name;
                    if (propName != "ClientUtcTime" && Program.PropertyCache.ContainsKey(propName))
                    {
                        prop.SetValue(gameEvent, Program.PropertyCache[propName]);
                    }
                }

                _client.SendMessageAsync(gameEvent).Wait();
            }

            _client.FlushAsync().Wait();
        }
예제 #2
0
        protected async override Task OnTickAsync(IAnalyticsClient client, DateTime now, TimeSpan timeAlive, TimeSpan sinceLastTick, long tickNo)
        {
            await base.OnTickAsync(client, now, timeAlive, sinceLastTick, tickNo);

            if (_geoOptions.GeoLocationMsgInterval > TimeSpan.Zero && now - _lastGeoLocationMsgSent >= _geoOptions.GeoLocationMsgInterval.WithRandomDeviation(1))
            {
                var currentPosition = _geoRoute.GetPosition(timeAlive);

                if (currentPosition == null)
                {
                    // We've reached the end of the route for the bot
                    _endOfRoute = true;
                    return;
                }

                var msg = new GeoLocation
                {
                    GameSession = GameSession,
                    Lat         = currentPosition.Latitude,
                    Lon         = currentPosition.Longitude
                };

                await client.SendMessageAsync(msg, now);

                _lastGeoLocationMsgSent = now;
            }
        }
        private void SampleFileSelected(string file)
        {
            var fileContent = File.ReadAllText(file);
            var templateObj = JObject.Parse(fileContent);
            var obj         = new JObject();


            foreach (var property in templateObj)
            {
                var propertyType = property.Value.Type.ToString();

                switch (propertyType.ToLower())
                {
                case "string":
                    var s = ConsoleEx.ReadLine(property.Key, (string)property.Value);
                    obj.Add(property.Key, s);
                    break;

                case "integer":
                    var i = ConsoleEx.ReadLine(property.Key, (int)property.Value);
                    obj.Add(property.Key, i);
                    break;

                default:
                    break;
                }
            }

            _client.SendMessageAsync(obj.ToString()).Wait();
            _client.FlushAsync().Wait();
        }
예제 #4
0
        protected async virtual Task OnStartAsync(IAnalyticsClient client, DateTime now)
        {
            _lastHeartBeatMsgSent = now + TimeSpan.Zero.WithRandomDeviation(3);

            if (_options.SessionStartMessage)
            {
                var msg = new SessionStart
                {
                    GamerTag    = GamerTag,
                    GameSession = GameSession
                };

                await client.SendMessageAsync(msg, now);
            }
        }
예제 #5
0
        protected async virtual Task OnTickAsync(IAnalyticsClient client, DateTime now, TimeSpan timeAlive, TimeSpan sinceLastTick, long tickNo)
        {
            if (_options.HeartBeatMessageInterval > TimeSpan.Zero && now - _lastHeartBeatMsgSent >= _options.HeartBeatMessageInterval.WithRandomDeviation())
            {
                // Send HeartBeat msg if enough time has passed since
                var msg = new HeartBeat
                {
                    GameSession = GameSession
                };

                await client.SendMessageAsync(msg, now);

                _lastHeartBeatMsgSent = now;
            }
        }
예제 #6
0
        private void SendCustomGameEvent()
        {
            var msg = (string)EditProperty("Custom Message", $"This is a custom msg at {DateTime.UtcNow}", typeof(string));

            _client.SendMessageAsync(msg).Wait();
        }