Beispiel #1
0
        /// <summary>
        /// Initialise cluster configuration using configuration supplied or using default configuration
        /// </summary>
        /// <param name="clusterConfiguration">Used if not null</param>
        /// <returns></returns>
        public int Initialise(ClusterConfiguration clusterConfiguration = null)
        {
            if (clusterConfiguration == null)
            {
                _clusterConfiguration = ClusterConfiguration.LocalhostPrimarySilo();
                _clusterConfiguration.AddMemoryStorageProvider();
                _clusterConfiguration.AddMemoryStorageProvider("PubSubStore");
                _clusterConfiguration.AddSimpleMessageStreamProvider(MemoryChatConfiguration.MemoryChatStreamProvider);
                //_clusterConfiguration.AddAzureTableStorageProvider("AzureStore", "UseDevelopmentStorage=true");
            }
            else
            {
                _clusterConfiguration = clusterConfiguration;
            }

            return(0);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
            var    builder     = new ConfigurationBuilder()
                                 .SetBasePath(Directory.GetCurrentDirectory())
                                 .AddInMemoryCollection(new Dictionary <string, string> // add default settings, that will be overridden by commandline
            {
                { "Id", "OrleansHost" },
                { "Version", "1.0.0" },
                { "DeploymentId", "testdeploymentid" },
            })
                                 .AddCommandLine(args)
                                 .AddJsonFile($"appconfig.json", optional: true)
                                 .AddJsonFile($"appconfig.{environment}.json", optional: true)
                                 .AddEnvironmentVariables("ASPNETCORE_"); // The CloudService will pass settings (such as) the connectionstring through environment variables

            if ("Development".Equals(environment) && builder.GetFileProvider().GetFileInfo("OrleansHost.csproj").Exists)
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets <Program>();
            }

            var config = builder.Build();

            loggerFactory.AddConsole(config.GetSection("Logging"));
            loggerFactory.AddDebug();
            var logger = loggerFactory.CreateLogger <Program>();

            ClusterConfiguration clusterConfig = ClusterConfiguration.LocalhostPrimarySilo();

            clusterConfig.Globals.DeploymentId         = config["Id"];
            clusterConfig.Globals.DataConnectionString = config.GetConnectionString("DataConnectionString");
            clusterConfig.AddMemoryStorageProvider("Default");
            clusterConfig.AddMemoryStorageProvider("PubSubStore");
            clusterConfig.AddSimpleMessageStreamProvider("Default");
            clusterConfig.Defaults.DefaultTraceLevel = Orleans.Runtime.Severity.Warning;
            clusterConfig.Defaults.TraceFileName     = "";
            clusterConfig.UseStartupType <Startup>();

            var siloHost = new SiloHost(config["Id"], clusterConfig);

            try
            {
                siloHost.InitializeOrleansSilo();
                bool ok = siloHost.StartOrleansSilo(catchExceptions: false);

                if (!ok)
                {
                    logger.LogError(string.Format($"Failed to start Orleans silo '{siloHost.Name}' as a {siloHost.Type} node."));
                    return(1);
                }
            }
            catch (Exception exc)
            {
                siloHost.ReportStartupError(exc);
                return(2);
            }

            Console.WriteLine("OrleansHost is running. Press [Ctrl]-C to stop...");
            siloHost.WaitForOrleansSiloShutdown();
            // logger.LogInformation(string.Format($"Orleans silo '{siloHost.Name}' shutdown. Press [Enter]"));
            // Console.ReadLine();
            return(0);
        }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
            var    builder     = new ConfigurationBuilder()
                                 .SetBasePath(Directory.GetCurrentDirectory())
                                 .AddInMemoryCollection(new Dictionary <string, string> // add default settings, that will be overridden by commandline
            {
                { "Id", "OrleansHost" },
                { "Version", "1.0.0" },
                { "DeploymentId", "testdeploymentid" },
            })
                                 .AddCommandLine(args)
                                 .AddJsonFile($"appconfig.json", optional: true)
                                 .AddJsonFile($"appconfig.{environment}.json", optional: true)
                                 .AddEnvironmentVariables("ASPNETCORE_"); // The CloudService will pass settings (such as) the connectionstring through environment variables

            if ("Development".Equals(environment) && builder.GetFileProvider().GetFileInfo("OrleansHost.csproj").Exists)
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets <Program>();
            }

            var config = builder.Build();

            loggerFactory.AddConsole(config.GetSection("Logging"));
            loggerFactory.AddDebug();
            var logger = loggerFactory.CreateLogger <Program>();

            logger.LogWarning(string.Format($"Starting Orleans silo..."));

            ClusterConfiguration clusterConfig = ClusterConfiguration.LocalhostPrimarySilo();

            clusterConfig.Globals.DeploymentId         = config["Id"];
            clusterConfig.Globals.DataConnectionString = config.GetConnectionString("DataConnectionString");
            clusterConfig.AddMemoryStorageProvider("Default");
            clusterConfig.AddMemoryStorageProvider("PubSubStore");
            clusterConfig.AddSimpleMessageStreamProvider("Default");
            string siloName = config["Id"];

            var host = new SiloHostBuilder()
                       .UseConfiguration(clusterConfig)
                       .ConfigureSiloName(siloName)
                       .ConfigureServices(services =>
            {
                services.AddOptions();
                services.TryAdd(ServiceDescriptor.Singleton <ILoggerFactory, LoggerFactory>());
                services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger <>), typeof(Logger <>)));
                services.Configure <ConnectionStrings>(config.GetSection("ConnectionStrings"));
                string reduxConnectionString = config.GetConnectionString("ReduxConnectionString");
                services.AddSingleton(new ReduxTableStorage <CertState>(reduxConnectionString));
                services.AddSingleton(new ReduxTableStorage <UserState>(reduxConnectionString));
                services.AddSingleton(new ReduxTableStorage <CounterState>(reduxConnectionString));
            })
                       .AddApplicationPart(typeof(CounterGrain).Assembly)
                       .AddApplicationPartsFromReferences(typeof(CounterGrain).Assembly)
                       .Build();

            try
            {
                await host.StartAsync();

                logger.LogInformation(string.Format($"Successfully started Orleans silo {siloName}"));
                Console.WriteLine($"Silo {siloName} is running. Press [enter] to stop...");
                Console.ReadLine();

                await host.StopAsync();

                logger.LogWarning(string.Format($"Orleans silo shutdown."));
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "Silo stopping fatally with exception: " + e.Message);
            }
        }