void BuildSiloHost() { var instrumentationKey = _configuration.GetValue <string>("ApplicationInsights:InstrumentationKey"); var hostname = _configuration.GetValue <string>("HOSTNAME"); var azureStorageConnectionString = _configuration.GetValue <string>("Storage:AzureStorageConnectionString"); var redisClusteringUrl = _configuration.GetValue <string>("REDIS_URL"); var builder = new SiloHostBuilder() .ConfigureLogging(loggingBuilder => { if (!string.IsNullOrEmpty(instrumentationKey)) { loggingBuilder.AddApplicationInsights(instrumentationKey); } loggingBuilder.AddConsole(); }) // Configure ClusterId and ServiceId .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "TwitchServices"; }) .AddStartupTask <LoadConfigurationStartupTask>() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ChannelGrain).Assembly).WithReferences()) // Configure connectivity .ConfigureEndpoints(hostname: hostname, siloPort: 11111, gatewayPort: 30000); if (!string.IsNullOrEmpty(azureStorageConnectionString)) { builder.AddAzureTableGrainStorage("profileStore", (AzureTableStorageOptions options) => { options.ConnectionString = azureStorageConnectionString; options.TableName = "profiles"; options.UseJson = true; options.IndentJson = false; }); builder.AddAzureTableGrainStorage("channelStore", (AzureTableStorageOptions options) => { options.ConnectionString = azureStorageConnectionString; options.TableName = "channels"; options.UseJson = true; options.IndentJson = false; }); builder.AddAzureTableGrainStorage("botSettingsStore", (AzureTableStorageOptions options) => { options.ConnectionString = azureStorageConnectionString; options.TableName = "botsettings"; options.UseJson = true; options.IndentJson = false; }); builder.AddCustomCategoriesStorage("customCategoriesStore", (CustomCategoriesStorageOptions options) => { options.ConnectionString = azureStorageConnectionString; options.TableName = "customcategories"; }); } else { builder.AddMemoryGrainStorage("profileStore"); builder.AddMemoryGrainStorage("channelStore"); builder.AddMemoryGrainStorage("botSettingsStore"); builder.AddMemoryGrainStorage("customCategoriesStore"); } if (!string.IsNullOrEmpty(redisClusteringUrl)) { // Use redis clustering when available builder.UseRedisClustering(redisClusteringUrl); } else { // Use localhost clustering for a single local silo builder.UseLocalhostClustering(11111, 30000, null, "TwitchServices", "dev"); } // Temp builder.ConfigureServices((context, services) => { // Load channels and command configuration from static json file, and inject var channelsConfig = new ConfigurationBuilder().AddJsonFile("channels.json").Build(); IEnumerable <ChannelOptions> channelOptions = new List <ChannelOptions>(); channelsConfig.GetSection("channels").Bind(channelOptions); services.AddTransient <IEnumerable <ChannelOptions> >((_) => channelOptions); // Configure services services.AddHttpClient(); services.Configure <TwitchApplicationOptions>(_configuration.GetSection("twitch")); services.Configure <TwitchChatClientOptions>(_configuration.GetSection("twitch").GetSection("IrcOptions")); services.Configure <AzureGameLocalizationStoreOptions>(_configuration.GetSection("loc:azure")); services.AddSingleton <IMessageProcessor, TracingMessageProcessor>(); services.AddTransient <TwitchChatClient>(); services.AddTransient <TwitchAPIClient>(); services.AddTransient <IGDBClient>(); services.AddSingleton <IMemoryCache, MemoryCache>(); services.AddSingleton <SteamStoreClient>(); services.AddSingleton <IAuthenticated>(s => Twitch.Authenticate() .FromAppCredentials( s.GetService <IOptions <TwitchApplicationOptions> >().Value.ClientId, s.GetService <IOptions <TwitchApplicationOptions> >().Value.ClientSecret) .Build() ); services.AddTransient <ITwitchCategoryProvider, GrainTwitchCategoryProvider>(); services.AddSingleton <IGameLocalizationStore, AzureStorageGameLocalizationStore>(); services.PostConfigure <TwitchChatClientOptions>(options => { var oauth = Twitch.Authenticate() .FromOAuthToken(options.OAuthToken) .Build(); var loggerFactory = new LoggerFactory(); using (var httpClient = new HttpClient()) using (var apiClient = TwitchAPIClient.Create(oauth)) { options.TokenInfo = apiClient.ValidateToken().Result; } }); // Configure commands services.AddCommand <GameSynopsisCommand>("GameSynopsis"); services.AddCommand <TracingMessageProcessor>("Logger"); services.AddCommand <ResponseCommandProcessor>("Response"); }); _siloHost = builder.Build(); }
private static async Task <ISiloHost> StartSilo() { var baseDir = Path.Combine(AppContext.BaseDirectory); Configuration = AppConfiguration.GetIConfigurationRoot(baseDir); var appOptions = AppConfiguration.GetApplicationConfiguration(baseDir); var dashboardOptions = AppConfiguration.GetConfiguration <DashboardOptions>(baseDir, "Dashboard"); // define the cluster configuration var builder = new SiloHostBuilder(); switch (appOptions.StorageType) { case StorageType.AzureTable: builder.AddAzureTableGrainStorage(Constants.StorageName, options => { options.ConnectionString = appOptions.OrleansConnectionString; options.TableName = appOptions.AzureTableName; options.UseJson = appOptions.UseJson; }); builder.UseAzureTableReminderService(options => { options.ConnectionString = appOptions.OrleansConnectionString; }); break; default: builder.AddAdoNetGrainStorage(Constants.StorageName, options => { options.Invariant = appOptions.AdoInvariant; options.ConnectionString = appOptions.OrleansConnectionString; options.UseJsonFormat = appOptions.UseJson; }); builder.UseAdoNetReminderService(options => { options.ConnectionString = appOptions.OrleansConnectionString; }); break; } builder.UseLocalhostClustering() .Configure <ClusterOptions>(options => { options.ClusterId = appOptions.ClusterId; options.ServiceId = appOptions.ServiceId; }) .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IGrainMarker).Assembly).WithReferences()) .AddSimpleMessageStreamProvider(Constants.StreamProvider) .AddMemoryGrainStorage(Constants.StreamStorage) .ConfigureServices((service) => { service.Configure <ApplicationOptions>(Configuration); service.AddOptions(); service.AddSingleton <ApplicationOptions>(appOptions); DependencyInjectionHelper.IocContainerRegistration(service); }) .ConfigureLogging(logging => logging.AddConsole()) .UseDashboard(options => { options.Host = dashboardOptions.Host; options.Port = dashboardOptions.Port; options.HostSelf = dashboardOptions.HostSelf; options.CounterUpdateIntervalMs = dashboardOptions.CounterUpdateIntervalMs; }); var host = builder.Build(); await host.StartAsync(); return(host); }