Beispiel #1
0
        public GameEventReceiver()
        {
            // Read Environment Variables for configuration
            // TODO: Fix configuration to be in line with other configuration in Nether

            Console.WriteLine("Configuring GameEventReceiver (from Environment Variables");
            string outputStorageAccountConnectionString =
                Environment.GetEnvironmentVariable("NETHER_ANALYTICS_STORAGE_CONNECTIONSTRING");

            Console.WriteLine($"outputStorageAccountConnectionString: {outputStorageAccountConnectionString}");
            string outputContainer =
                Environment.GetEnvironmentVariable("NETHER_ANALYTICS_STORAGE_CONTAINER");

            Console.WriteLine($"outputContainer: {outputContainer}");
            string outputEventHubConnectionString =
                Environment.GetEnvironmentVariable("NETHER_INTERMEDIATE_EVENTHUB_CONNECTIONSTRING");

            Console.WriteLine($"outputEventHubConnectionString: {outputEventHubConnectionString}");
            string outputEventHubName =
                Environment.GetEnvironmentVariable("NETHER_INTERMEDIATE_EVENTHUB_NAME");

            Console.WriteLine($"outputEventHubName: {outputEventHubName}");
            Console.WriteLine();

            // Configure Blob Output
            _blobOutputManager = new BlobOutputManager(
                outputStorageAccountConnectionString,
                outputContainer,
                BlobOutputFolderStructure.YearMonthDayHour,
                100 * 1024 * 1024); // 100MB

            // Configure EventHub Output
            _eventHubOutputManager = new EventHubOutputManager(outputEventHubConnectionString, outputEventHubName);

            // Setup Handler to use above configured output managers
            _handler = new GameEventHandler(_blobOutputManager, _eventHubOutputManager);

            // Configure Router to switch handeling to correct method depending on game event type
            _router = new GameEventRouter(GameEventHandler.ResolveEventType,
                                          GameEventHandler.UnknownGameEventFormatHandler,
                                          GameEventHandler.UnknownGameEventTypeHandler);

            _router.RegEventTypeAction("count", "1.0.0", _handler.HandleCountEvent);
            _router.RegEventTypeAction("game-heartbeat", "1.0.0", _handler.HandleGameHeartbeat);
            _router.RegEventTypeAction("game-start", "1.0.0", _handler.HandleGameStartEvent);
            _router.RegEventTypeAction("game-stop", "1.0.0", _handler.HandleGameStopEvent);
            _router.RegEventTypeAction("location", "1.0.0", _handler.HandleLocationEvent);
            _router.RegEventTypeAction("score", "1.0.0", _handler.HandleScoreEvent);
            _router.RegEventTypeAction("start", "1.0.0", _handler.HandleStartEvent);
            _router.RegEventTypeAction("stop", "1.0.0", _handler.HandleStopEvent);
        }
Beispiel #2
0
        static GameEventReceiver()
        {
            // Read Environment Variables for configuration
            // TODO: Fix configuration to be in line with other configuration in Nether

            Console.WriteLine("Configuring GameEventReceiver (from Environment Variables");

            var storageAccountConnectionString = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_CONNECTIONSTRING");

            Console.WriteLine($"outputStorageAccountConnectionString: {storageAccountConnectionString}");

            var outputContainer = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_CONTAINER");

            if (string.IsNullOrWhiteSpace(outputContainer))
            {
                outputContainer = "gameevents";
            }
            Console.WriteLine($"outputContainer: {outputContainer}");

            var tmpContainer = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_TMP_CONTAINER");

            if (string.IsNullOrWhiteSpace(tmpContainer))
            {
                tmpContainer = "tmp";
            }
            Console.WriteLine($"tmpContainer: {tmpContainer}");

            var outputEventHubConnectionString = ConfigResolver.Resolve("NETHER_INTERMEDIATE_EVENTHUB_CONNECTIONSTRING");

            Console.WriteLine($"outputEventHubConnectionString: {outputEventHubConnectionString}");

            var outputEventHubName = ConfigResolver.Resolve("NETHER_INTERMEDIATE_EVENTHUB_NAME");

            Console.WriteLine($"outputEventHubName: {outputEventHubName}");

            var maxBlobSize = 10 * 1024; // 10kB

            Console.WriteLine($"Max Blob Size: {maxBlobSize / 1024 / 1024}MB ({maxBlobSize}B)");
            Console.WriteLine();

            // Configure Blob Output
            var blobOutputManager = new BlobOutputManager(
                storageAccountConnectionString,
                tmpContainer,
                outputContainer,
                maxBlobSize);

            // Configure EventHub Output
            var eventHubOutputManager = new EventHubOutputManager(outputEventHubConnectionString, outputEventHubName);

            // Setup Handler to use above configured output managers
            var handler = new GameEventHandler(blobOutputManager, eventHubOutputManager);

            // Configure Router to switch handeling to correct method depending on game event type
            s_router = new GameEventRouter(GameEventHandler.ResolveEventType,
                                           GameEventHandler.UnknownGameEventFormatHandler,
                                           GameEventHandler.UnknownGameEventTypeHandler,
                                           handler.Flush);

            s_router.RegisterKnownGameEventTypeHandler("count/v1.0.0", handler.HandleCountEvent);
            s_router.RegisterKnownGameEventTypeHandler("game-heartbeat/v1.0.0", handler.HandleGameHeartbeat);
            s_router.RegisterKnownGameEventTypeHandler("game-start/v1.0.0", handler.HandleGameStartEvent);
            s_router.RegisterKnownGameEventTypeHandler("game-stop/v1.0.0", handler.HandleGameStopEvent);
            s_router.RegisterKnownGameEventTypeHandler("location/v1.0.0", handler.HandleLocationEvent);
            s_router.RegisterKnownGameEventTypeHandler("score/v1.0.0", handler.HandleScoreEvent);
            s_router.RegisterKnownGameEventTypeHandler("start/v1.0.0", handler.HandleStartEvent);
            s_router.RegisterKnownGameEventTypeHandler("stop/v1.0.0", handler.HandleStopEvent);
            s_router.RegisterKnownGameEventTypeHandler("generic/v1.0.0", handler.HandleGenericEvent);
        }
 public static void RegEventTypeAction(this GameEventRouter router, string gameEventType, string version, Action <string, string> action)
 {
     router.RegisterKnownGameEventTypeHandler(GameEventHandler.VersionedName(gameEventType, version), action);
 }
Beispiel #4
0
        /// <summary>
        /// Initialize the GameEventReceiver. Initialization is complete when the returned Task completes.
        /// Safe to call multiple times.
        /// </summary>
        /// <returns></returns>
        private static Task InitializeGameEventReceiverAsync()
        {
            /// double-check lock for perf
            if (s_initializationTask != null)
            {
                return(s_initializationTask);
            }
            lock (s_initializationLock)
            {
                if (s_initializationTask == null)
                {
                    s_initializationTask = InitializeInternal();
                }
                return(s_initializationTask);
            }
            async Task InitializeInternal()
            {
                // Read Environment Variables for configuration
                // TODO: Fix configuration to be in line with other configuration in Nether

                Console.WriteLine("Configuring GameEventReceiver (from Environment Variables");

                var storageAccountConnectionString = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_CONNECTIONSTRING");

                Console.WriteLine($"outputStorageAccountConnectionString: {storageAccountConnectionString}");

                var outputContainer = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_CONTAINER");

                if (string.IsNullOrWhiteSpace(outputContainer))
                {
                    outputContainer = "gameevents";
                }
                Console.WriteLine($"outputContainer: {outputContainer}");

                var tmpContainer = ConfigResolver.Resolve("NETHER_ANALYTICS_STORAGE_TMP_CONTAINER");

                if (string.IsNullOrWhiteSpace(tmpContainer))
                {
                    tmpContainer = "tmp";
                }
                Console.WriteLine($"tmpContainer: {tmpContainer}");

                var outputEventHubConnectionString = ConfigResolver.Resolve("NETHER_INTERMEDIATE_EVENTHUB_CONNECTIONSTRING");

                Console.WriteLine($"outputEventHubConnectionString: {outputEventHubConnectionString}");

                var outputEventHubName = ConfigResolver.Resolve("NETHER_INTERMEDIATE_EVENTHUB_NAME");

                Console.WriteLine($"outputEventHubName: {outputEventHubName}");

                string webJobDashboardAndStorageConnectionString = ConfigResolver.Resolve("NETHER_WEBJOB_DASHBOARD_AND_STORAGE_CONNECTIONSTRING");

                var maxBlobSize       = 100 * 1024 * 1024; // 100MB, USE CONFIG TO CHANGE MAX SIZE
                var maxBlobSizeConfig = ConfigResolver.Resolve("NETHER_BLOB_MAX_SIZE");

                if (!string.IsNullOrWhiteSpace(maxBlobSizeConfig))
                {
                    maxBlobSize = int.Parse(maxBlobSizeConfig);
                }


                Console.WriteLine($"Max Blob Size: {maxBlobSize / 1024 / 1024}MB ({maxBlobSize}B)");

                var bingMapsKey = ConfigResolver.Resolve("NETHER_BING_MAPS_KEY");

                if (string.IsNullOrWhiteSpace(bingMapsKey))
                {
                    Console.WriteLine("Location lookup is not configured, please specify a configuration for NETHER_BING_MAPS_KEY");
                }
                else
                {
                    Console.WriteLine($"Using Bing Maps to lookup locations with key: {bingMapsKey}");
                }


                Console.WriteLine();
                Console.WriteLine();

                // Configure Blob Output
                s_blobOutputManager = new BlobOutputManager(
                    storageAccountConnectionString,
                    webJobDashboardAndStorageConnectionString,
                    tmpContainer,
                    outputContainer,
                    maxBlobSize);
                await s_blobOutputManager.SetupAsync();

                // Configure EventHub Output
                var eventHubOutputManager = new EventHubOutputManager(outputEventHubConnectionString, outputEventHubName);

                ILocationLookupProvider lookupProvider;

                if (string.IsNullOrWhiteSpace(bingMapsKey))
                {
                    lookupProvider = new NullLocationLookupProvider();
                }
                else
                {
                    lookupProvider = new BingLocationLookupProvider(bingMapsKey);
                }

                // Setup Handler to use above configured output managers
                var handler = new GameEventHandler(s_blobOutputManager, eventHubOutputManager, lookupProvider);

                // Configure Router to switch handling to correct method depending on game event type
                s_router = new GameEventRouter(GameEventHandler.ResolveEventType,
                                               GameEventHandler.UnknownGameEventFormatHandler,
                                               GameEventHandler.UnknownGameEventTypeHandler,
                                               handler.FlushAsync);

                s_router.RegisterKnownGameEventTypeHandler("count/v1.0.0", handler.HandleCountEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("game-heartbeat/v1.0.0", handler.HandleGameHeartbeatAsync);
                s_router.RegisterKnownGameEventTypeHandler("game-start/v1.0.0", handler.HandleGameStartEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("game-stop/v1.0.0", handler.HandleGameStopEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("location/v1.0.0", handler.HandleLocationEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("score/v1.0.0", handler.HandleScoreEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("start/v1.0.0", handler.HandleStartEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("stop/v1.0.0", handler.HandleStopEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("generic/v1.0.0", handler.HandleGenericEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("level-completed/v1.0.0", handler.HandleLevelCompletedEventAsync);
                s_router.RegisterKnownGameEventTypeHandler("level-start/v1.0.0", handler.HandleLevelStartEventAsync);
            }
        }