Exemplo n.º 1
0
        public void HandleScoreEvent(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("gameSessionId", "score");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 2
0
        public void HandleStopEvent(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("eventCorrelationId");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 3
0
        public void HandleGenericEvent(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv();

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 4
0
        //TODO: Fix Game Event Handlers to use reflection over properties if possible
        //TODO: Enrich events with knows facts, such as location on heartbeats, etc.
        public void HandleCountEvent(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("displayName", "value", "gameSessionId");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            _eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 5
0
        public async Task HandleGameStartEventAsync(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("gameSessionId", "gamerTag");

            await _blobOutputManager.QueueAppendToBlobAsync(data, serializedGameEvent);

            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 6
0
        public async Task HandleGenericEventAsync(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv();

            await _blobOutputManager.QueueAppendToBlobAsync(data, serializedGameEvent);

            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 7
0
        public void HandleLocationEvent(GameEventData data)
        {
            //TODO: Implement more properties on Location Event
            var serializedGameEvent = data.ToCsv("gameSessionId");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 8
0
        //TODO: Fix Game Event Handlers to use reflection over properties if possible
        //TODO: Enrich events with knows facts, such as location on heartbeats, etc.
        public async Task HandleCountEventAsync(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("displayName", "value", "gameSessionId");

            await _blobOutputManager.QueueAppendToBlobAsync(data, serializedGameEvent);

            await _eventHubOutputManager.SendToEventHubAsync(data, serializedGameEvent);
        }
Exemplo n.º 9
0
        public async Task HandleStopEventAsync(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("eventCorrelationId");

            await _blobOutputManager.QueueAppendToBlobAsync(data, serializedGameEvent);

            //_eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 10
0
        public async Task HandleLocationEventAsync(GameEventData data)
        {
            const int GeoHashBitPrecision = 32;                //bits
            const int LocationLookupGeoHashBitPrecistion = 30; //bits

            var inEvent = JsonConvert.DeserializeObject <IncommingLocationEvent>(data.Data);

            var geoHash = GeoHash.EncodeInt(inEvent.Lat, inEvent.Lon, GeoHashBitPrecision);
            var geoHashCenterCoordinates = GeoHash.DecodeInt(geoHash, GeoHashBitPrecision).Coordinates;
            var locationLookupGeoHash    = GeoHash.EncodeInt(inEvent.Lat, inEvent.Lon, LocationLookupGeoHashBitPrecistion);

            var l        = new LocationEventHandler(_locationLookupProvider);
            var location = l.LookupGeoHash(locationLookupGeoHash, LocationLookupGeoHashBitPrecistion);

            var outEvent = new OutgoingLocationEvent
            {
                EnqueueTime      = data.EnqueuedTime,
                DequeueTime      = data.DequeuedTime,
                ClientUtcTime    = inEvent.ClientUtcTime,
                GameSessionId    = inEvent.GameSessionId,
                Lat              = inEvent.Lat,
                Lon              = inEvent.Lon,
                GeoHash          = geoHash,
                GeoHashPrecision = GeoHashBitPrecision,
                GeoHashCenterLat = geoHashCenterCoordinates.Lat,
                GeoHashCenterLon = geoHashCenterCoordinates.Lon,
                Country          = location.Country,
                District         = location.District,
                City             = location.City,
                Properties       = inEvent.Properties
            };

            //TODO: Optimize this so we don't serialize back to JSON first and then to CSV

            var jsonObject = JsonConvert.SerializeObject(
                outEvent,
                Formatting.Indented,
                new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            data.Data = jsonObject;

            var csvObject = data.ToCsv("gameSessionId", "lat", "lon",
                                       "geoHash", "geoHashPrecision",
                                       "geoHashCenterLat", "geoHashCenterLon", "country", "district", "city");

            // Output CSV to BLOB Storage and JSON to StreamAnalytics (via EventHub)
            await _blobOutputManager.QueueAppendToBlobAsync(data, csvObject);

            await _eventHubOutputManager.SendToEventHubAsync(data, jsonObject);
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Inspects gameEvent to figure out what GameEventType we are working with.
        ///     This implementation assumes messages as sent as JSON with two properties
        ///     "type" and "version".
        /// </summary>
        /// <param name="gameEvent">The JSON Game Event to inspect</param>
        /// <returns>The Game Event Type</returns>
        public static void ResolveEventType(GameEventData gameEvent)
        {
            var json          = JObject.Parse(gameEvent.Data);
            var gameEventType = (string)json["type"];
            var version       = (string)json["version"];

            if (gameEventType == null || version == null)
            {
                throw new ApplicationException(
                          "Unable to resolve Game Event Type, since game event doesn't contain type and/or version property");
            }

            gameEvent.EventType    = gameEventType;
            gameEvent.EventVersion = version;
        }
Exemplo n.º 12
0
        //public void HandleOne([EventHubTrigger("%NETHER_INGEST_EVENTHUB_NAME%")] string data)
        //{
        //    //TODO: Figure out how to configure above EventHubName now named ingest

        //    // Forward data to "router" in order to handle the event
        //    _router.HandleGameEvent(data);
        //}

        public static void HandleBatch([EventHubTrigger("%NETHER_INGEST_EVENTHUB_NAME%")] EventData[] events)
        {
            var dequeueTime = DateTime.UtcNow;

            if (events.Length > 1)
            {
                Console.WriteLine($"....Received batch of {events.Length} events");
            }

            foreach (var ev in events)
            {
                var gameEventData = new GameEventData(ev, dequeueTime);
                s_router.HandleGameEvent(gameEventData);
            }

            s_router.Flush();
        }
Exemplo n.º 13
0
        public static async Task HandleBatchAsync([EventHubTrigger("%NETHER_INGEST_EVENTHUB_NAME%")] EventData[] events)
        {
            await InitializeGameEventReceiverAsync();

            var dequeueTime = DateTime.UtcNow;

            if (events.Length > 1)
            {
                Console.WriteLine($"....Received batch of {events.Length} events");
            }

            foreach (var ev in events)
            {
                var gameEventData = new GameEventData(ev, dequeueTime);
                await s_router.HandleGameEventAsync(gameEventData);
            }

            await s_router.FlushAsync();
        }
Exemplo n.º 14
0
        public void HandleLocationEvent(GameEventData data)
        {
            var locationEvent = JsonConvert.DeserializeObject <LocationEvent>(data.Data);

            var geoHash = GeoHash.Encode(locationEvent.Latitude, locationEvent.Longitude);

            locationEvent.Geohash = geoHash;

            //TODO: Optimize this so we don't serialize back to JSON first and then to CSV

            data.Data = JsonConvert.SerializeObject(
                locationEvent,
                Formatting.Indented,
                new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var serializedGameEvent = data.ToCsv("gameSessionId", "longitude", "latitude", "geohash");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
            _eventHubOutputManager.SendToEventHub(data, serializedGameEvent);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Handles a Game Event by looking at the Game Event Type and routing the event data to the
        /// correct registered action.
        /// </summary>
        /// <param name="data">Game Event Data</param>
        public void HandleGameEvent(GameEventData gameEventData)
        {
            try
            {
                _resolveGameEventTypeAction(gameEventData);
            }
            catch (Exception)
            {
                // Resolving game event type failed. Unknown Game Event format?!?!
                // Invoke action to handle Unknown Game Event Formats if registered (not null)
                _unknownGameEventFormatAction?.Invoke(gameEventData);

                // No more can be done, so return
                return;
            }

            // GameEventData object from now on contains game event type and version information
            // since it was set by the _gameEventTypeResolver

            // Check if game event type is known
            if (!_gameEventTypeActions.ContainsKey(gameEventData.VersionedType))
            {
                // No registered action found for the found Game Event Type
                // Invoke action to handle Unknown Game Event Type if registered (not null)
                _unknownGameEventTypeAction?.Invoke(gameEventData);

                // No more can be done, so return
                return;
            }

            // Get correct game event handler from dictionary of registered handlers
            var handler = _gameEventTypeActions[gameEventData.VersionedType];

            // Pass game event data to correct action
            handler(gameEventData);
        }
Exemplo n.º 16
0
        public void HandleLevelStartEvent(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("gameSessionId", "level");

            _blobOutputManager.QueueAppendToBlob(data, serializedGameEvent);
        }
Exemplo n.º 17
0
 public static void UnknownGameEventFormatHandler(GameEventData gameEvent)
 {
     Console.WriteLine("Unknown Game Event Format found in ...");
     Console.WriteLine(gameEvent.Data);
 }
Exemplo n.º 18
0
        public async Task HandleLevelStartEventAsync(GameEventData data)
        {
            var serializedGameEvent = data.ToCsv("gameSessionId", "level");

            await _blobOutputManager.QueueAppendToBlobAsync(data, serializedGameEvent);
        }
Exemplo n.º 19
0
 public static void UnknownGameEventTypeHandler(GameEventData gameEvent)
 {
     Console.WriteLine($"Unknown and unhandled Game Event Type [{gameEvent.VersionedType}] found in event ...");
     Console.WriteLine(gameEvent.Data);
 }