예제 #1
0
        public async Task LocalhostSiloTest()
        {
            using var portAllocator    = new TestClusterPortAllocator();
            var(siloPort, gatewayPort) = portAllocator.AllocateConsecutivePortPairs(1);
            var silo = new SiloHostBuilder()
                       .AddMemoryGrainStorage("MemoryStore")
                       .UseLocalhostClustering(siloPort, gatewayPort)
                       .Build();

            var client = new ClientBuilder()
                         .UseLocalhostClustering(gatewayPort)
                         .Build();

            try
            {
                await silo.StartAsync();

                await client.Connect();

                var grain  = client.GetGrain <IEchoGrain>(Guid.NewGuid());
                var result = await grain.Echo("test");

                Assert.Equal("test", result);
            }
            finally
            {
                await OrleansTaskExtentions.SafeExecute(() => silo.StopAsync());

                await OrleansTaskExtentions.SafeExecute(() => client.Close());

                Utils.SafeExecute(() => silo.Dispose());
                Utils.SafeExecute(() => client.Close());
            }
        }
예제 #2
0
        public async Task LocalhostSiloTest()
        {
            var opts = TestSiloSpecificOptions.Create(new TestClusterOptions(), 1, true);
            var silo = new SiloHostBuilder()
                       .AddMemoryGrainStorage("MemoryStore")
                       .UseLocalhostClustering(opts.SiloPort, opts.GatewayPort)
                       .Build();

            var client = new ClientBuilder()
                         .UseLocalhostClustering(opts.GatewayPort)
                         .Build();

            try
            {
                await silo.StartAsync();

                await client.Connect();

                var grain  = client.GetGrain <IEchoGrain>(Guid.NewGuid());
                var result = await grain.Echo("test");

                Assert.Equal("test", result);
            }
            finally
            {
                await OrleansTaskExtentions.SafeExecute(() => silo.StopAsync());

                await OrleansTaskExtentions.SafeExecute(() => client.Close());

                Utils.SafeExecute(() => silo.Dispose());
                Utils.SafeExecute(() => client.Close());
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "1";
            })
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            Console.WriteLine("Press key to exit...");
            Console.ReadKey();

            silo.StopAsync().Wait();
        }
예제 #4
0
파일: Program.cs 프로젝트: timb33/orleans
        static void Main(string[] args)
        {
            Console.Title = nameof(Silo);

            var host = new SiloHostBuilder()
                       .UseLocalhostClustering()
                       .ConfigureApplicationParts(_ => _.AddApplicationPart(typeof(ChirperAccount).Assembly).WithReferences())
                       .ConfigureLogging(_ =>
            {
                _.AddFilter("Orleans.Runtime.Management.ManagementGrain", LogLevel.Warning);
                _.AddFilter("Orleans.Runtime.SiloControl", LogLevel.Warning);
                _.AddConsole();
            })
                       .AddMemoryGrainStorageAsDefault()
                       .AddMemoryGrainStorage("PubSubStore")
                       .UseDashboard()
                       .Build();

            host.StartAsync().Wait();

            Console.CancelKeyPress += (sender, e) =>
            {
                e.Cancel = true;
                host.StopAsync().Wait();
            };

            host.Stopped.Wait();
        }
예제 #5
0
        public static async Task Main(string[] args)
        {
            Console.Title = nameof(Silo);

            var host = new SiloHostBuilder()
                       .UseLocalhostClustering()
                       .ConfigureApplicationParts(_ =>
            {
                _.AddApplicationPart(typeof(GameGrain).Assembly).WithReferences();
            })
                       .ConfigureLogging(_ =>
            {
                _.AddConsole();
            })
                       .Build();

            await host.StartAsync();

            Console.CancelKeyPress += async(sender, eargs) =>
            {
                eargs.Cancel = true;
                await host.StopAsync();
            };

            await host.Stopped;
        }
예제 #6
0
        static async Task Main(string[] args)
        {
            var silo = new SiloHostBuilder()
                       .UseLocalhostClustering()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "server";
            })
                       .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(RecommendationGrain).Assembly).WithReferences())
                       //.AddMemoryGrainStorageAsDefault()
                       .ConfigureLogging(logging => logging.AddConsole())
                       .AddMongoDBGrainStorageAsDefault(options =>
            {
                options.DatabaseName     = "ProductRecommendations";
                options.ConnectionString = "mongodb://localhost:27017/admin";
            })
                       .Build();

            await silo.StartAsync();

            Console.WriteLine("Server has started. Press any key to exit.");
            Console.ReadKey();
            await silo.StopAsync();
        }
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // TODO: Replace the following with your own logic.
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()
                .UseDashboard(options =>
            {
                options.HostSelf  = true;
                options.HideTrace = false;
            })
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .UseInMemoryReminderService()
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster")
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .Build();

            await silo.StartAsync();

            while (!cancellationToken.IsCancellationRequested)
            {
                await Task.Delay(1000);
            }

            await silo.StopAsync();
        }
예제 #8
0
        public static void Main(string[] args)
        {
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()
                .UseDashboard(options =>
            {
                options.HostSelf  = true;
                options.HideTrace = false;
            })
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .UseInMemoryReminderService()
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "1";
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri()))
                .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "1";
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            Console.WriteLine("Press key to exit...");
            Console.ReadLine();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #9
0
        public static void Main(string[] args)
        {
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()
                .UseDashboard(options =>
            {
                options.HostSelf  = true;
                options.HideTrace = false;
            })
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .UseInMemoryReminderService()
                .UsePerfCounterEnvironmentStatistics()
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster")
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .ConfigureServices(services =>
            {
                // Workaround for https://github.com/dotnet/orleans/issues/4129
                services.AddSingleton(cp => cp.GetRequiredService <IHostEnvironmentStatistics>() as ILifecycleParticipant <ISiloLifecycle>);
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri()))
                .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster")
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            Console.WriteLine("Press key to exit...");
            Console.ReadLine();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #10
0
        static async Task Main(string[] args)
        {
            var host = new SiloHostBuilder()
                       .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory())
                       .UseLocalhostClustering()
                       .Configure <SchedulingOptions>(options => options.AllowCallChainReentrancy = false)
                       .ConfigureLogging(builder => builder.AddConsole())
                       .Build();

            await host.StartAsync();

            Console.WriteLine("Press any key...");
            Console.ReadLine();

            await host.StopAsync();
        }
예제 #11
0
        public static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            var config = builder.Build();
            //单台服务器上模拟多个Silo集群
            Random rd          = new Random();
            var    siloPort    = rd.Next(40001, 50000);
            var    gatewayPort = rd.Next(30003, 40000);

            var silo = new SiloHostBuilder()
                       //.Configure<EndpointOptions>(options =>
                       //{
                       //    options.AdvertisedIPAddress = IPAddress.Loopback;
                       //})
                       .ConfigureEndpoints(siloPort: siloPort, gatewayPort: gatewayPort, listenOnAnyHostAddress: true, advertisedIP: IPAddress.Loopback)
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "excelapp";
            })

                       .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ExcelGrain).Assembly).WithReferences())
                       .UseAdoNetClustering(option =>
            {
                option.ConnectionString = config["ConnectionStrings:OrleansCluster"];
                option.Invariant        = "MySql.Data.MySqlClient";
            })
                       .AddAdoNetGrainStorageAsDefault(option =>
            {
                option.Invariant        = "MySql.Data.MySqlClient";
                option.ConnectionString = config["ConnectionStrings:OrleansGrain"];
            })
                       .ConfigureLogging(logging => logging.AddConsole())
                       .Build();

            Console.WriteLine("Starting");
            await silo.StartAsync();

            Console.WriteLine("Started");
            Console.ReadKey();
            Console.WriteLine("Shutting down");
            await silo.StopAsync();
        }
예제 #12
0
파일: Program.cs 프로젝트: raidnav/DDBMSP
        public static void Main(string[] args)
        {
            var configuration =
                ClusterConfiguration.LocalhostPrimarySilo(33333)
                .RegisterDashboard();

            var silo =
                new SiloHostBuilder()
                .UseConfiguration(configuration)
                .UseDashboard(options =>
            {
                options.HostSelf  = true;
                options.HideTrace = false;
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseConfiguration(ClientConfiguration.LocalhostSilo())
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            Console.WriteLine("Press key to exit...");
            Console.ReadLine();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #13
0
        static async Task Main(string[] args)
        {
            var host = new SiloHostBuilder()
                       .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory())
                       .UseLocalhostClustering()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "local";
                options.ServiceId = "HelloWorld";
            })
                       .ConfigureLogging(builder => builder.AddConsole())
                       .Build();

            await host.StartAsync();

            Console.WriteLine("Press any key...");
            Console.ReadLine();

            await host.StopAsync();
        }
예제 #14
0
        static async Task Main(string[] args)
        {
            var host = new SiloHostBuilder()
                       .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory())
                       .UseLocalhostClustering()
                       .ConfigureLogging(builder => builder.AddConsole())
                       .ConfigureServices(services =>
            {
                services.AddTransient(provider => HelloComponent.Create(provider.GetRequiredService <IGrainActivationContext>()));
            })
                       .Build();

            await host.StartAsync();

            Console.WriteLine("Press any key...");

            Console.ReadLine();

            await host.StopAsync();
        }
예제 #15
0
        public async Task LocalhostClusterTest()
        {
            using var portAllocator            = new TestClusterPortAllocator();
            var(baseSiloPort, baseGatewayPort) = portAllocator.AllocateConsecutivePortPairs(2);
            var silo1 = new SiloHostBuilder()
                        .AddMemoryGrainStorage("MemoryStore")
                        .UseLocalhostClustering(baseSiloPort, baseGatewayPort)
                        .Build();

            var silo2 = new SiloHostBuilder()
                        .AddMemoryGrainStorage("MemoryStore")
                        .UseLocalhostClustering(baseSiloPort + 1, baseGatewayPort + 1, new IPEndPoint(IPAddress.Loopback, baseSiloPort))
                        .Build();

            var client = new ClientBuilder()
                         .UseLocalhostClustering(new[] { baseGatewayPort, baseGatewayPort + 1 })
                         .Build();

            try
            {
                await Task.WhenAll(silo1.StartAsync(), silo2.StartAsync());

                await client.Connect();

                var grain  = client.GetGrain <IEchoGrain>(Guid.NewGuid());
                var result = await grain.Echo("test");

                Assert.Equal("test", result);
            }
            finally
            {
                var cancelled = new CancellationTokenSource();
                cancelled.Cancel();
                Utils.SafeExecute(() => silo1.StopAsync(cancelled.Token));
                Utils.SafeExecute(() => silo2.StopAsync(cancelled.Token));
                Utils.SafeExecute(() => silo1.Dispose());
                Utils.SafeExecute(() => silo2.Dispose());
                Utils.SafeExecute(() => client.Close());
                Utils.SafeExecute(() => client.Dispose());
            }
        }
예제 #16
0
        public static void Main(string[] args)
        {
            var siloHost = new SiloHostBuilder()
                           .UseLocalhostClustering(8000, 3500)
                           .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "UniqueIdentifierToFindSilo";
                options.ServiceId = "HelloWorldApp";
            })
                           .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
                           .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(Hello).Assembly).WithReferences())
                           .ConfigureLogging(logging => logging.AddConsole())
                           .Build();

            siloHost.StartAsync().Wait();

            Console.WriteLine("Press a button to stop silo");
            Console.ReadLine();

            siloHost.StopAsync().Wait();
        }
예제 #17
0
        public async Task LocalhostClusterTest()
        {
            var silo1 = new SiloHostBuilder()
                        .AddMemoryGrainStorage("MemoryStore")
                        .UseLocalhostClustering(12111, 30001)
                        .Build();

            var silo2 = new SiloHostBuilder()
                        .AddMemoryGrainStorage("MemoryStore")
                        .UseLocalhostClustering(12112, 30002, new IPEndPoint(IPAddress.Loopback, 12111))
                        .Build();

            var client = new ClientBuilder()
                         .UseLocalhostClustering(new[] { 30001, 30002 })
                         .Build();

            try
            {
                await Task.WhenAll(silo1.StartAsync(), silo2.StartAsync());

                await client.Connect();

                var grain  = client.GetGrain <IEchoGrain>(Guid.NewGuid());
                var result = await grain.Echo("test");

                Assert.Equal("test", result);
            }
            finally
            {
                var cancelled = new CancellationTokenSource();
                cancelled.Cancel();
                Utils.SafeExecute(() => silo1.StopAsync(cancelled.Token));
                Utils.SafeExecute(() => silo2.StopAsync(cancelled.Token));
                Utils.SafeExecute(() => silo1.Dispose());
                Utils.SafeExecute(() => silo2.Dispose());
                Utils.SafeExecute(() => client.Close());
                Utils.SafeExecute(() => client.Dispose());
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            var silo = new SiloHostBuilder()
                       .Configure <ClusterOptions>(options => {
                options.ClusterId = Constants.ClusterId;
                options.ServiceId = Constants.ServiceId;
            })
                       .UseLocalhostClustering()
                       .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
                       .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(Channel).Assembly).WithReferences())
                       .ConfigureLogging(logging => logging.AddConsole())
                       .AddMemoryGrainStorage("PubSubStorage")
                       .AddSimpleMessageStreamProvider(Constants.ChatRoomStreamNameProvider)
                       .Build();

            silo.StartAsync().Wait();

            Console.WriteLine("Press enter to close.");
            Console.ReadLine();

            // shut the silo down after we are done.
            silo.StopAsync().Wait();
        }
예제 #19
0
        public static async Task Main(string[] args)
        {
            var host = new SiloHostBuilder()
                       .UseLocalhostClustering()
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "OrleansBasics";
            })
                       .ConfigureApplicationParts(
                parts => parts.AddApplicationPart(typeof(Arithmetic).Assembly)
                .WithReferences()
                )
                       .ConfigureLogging(log => log.AddConsole())
                       .Build();

            await host.StartAsync();

            Console.WriteLine("Press Enter to terminate...\n\n");
            Console.ReadLine();

            await host.StopAsync();
        }
예제 #20
0
        public static async Task Main(string[] args)
        {
            var silo = new SiloHostBuilder()
                       .ConfigureEndpoints(siloPort: 30001, gatewayPort: 30002, listenOnAnyHostAddress: true)
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "votingapp";
            })
                       .UseAzureStorageClustering(options => options.ConnectionString = Environment.GetEnvironmentVariable("CLUSTERING_CONNECTION_STRING"))
                       .ConfigureLogging(logging => logging.AddConsole())
                       .AddAzureBlobGrainStorage("votes",
                                                 options =>
            {
                options.ContainerName    = "votes";
                options.UseJson          = true;
                options.ConnectionString = Environment.GetEnvironmentVariable("PERSISTENCE_CONNECTION_STRING");
            })
                       .Build();

            var stopEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = false;
                stopEvent.Set();
            };

            Console.WriteLine("Starting");
            await silo.StartAsync();

            Console.WriteLine("Started");

            stopEvent.WaitOne();
            Console.WriteLine("Shutting down");
            await silo.StopAsync();
        }
예제 #21
0
        public static void Main(string[] args)
        {
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()

                .ConfigureServices((context, services) =>
            {
                services.RemoveAll <RestClient>();

                services.AddScoped <MsvClientCtrlSDK>();
                var client = new RestClient(null, "http://172.16.135.116:9024", "http://172.16.0.205:10023");
                services.AddSingleton <RestClient>(client);
                services.AddSingleton <IDeviceMonitorService, DeviceMonitorService>();
                services.AddSingleton <IDeviceMonitorClient, DeviceMonitorClient>();

                services.AddTransient <ITaskHandlerFactory, TaskHandlerFactory>(sp => TaskHandlerFactory.Create(sp));
                services.AddSingleton <IGrainServiceDataBack, GrainServiceDataBack>();
                services.AddAutoMapper(typeof(GlobalProfile));
                services.AddSingletonNamedService <PlacementStrategy, ScheduleTaskPlacementStrategy>(nameof(ScheduleTaskPlacementStrategy));
                services.AddSingletonKeyedService <Type, IPlacementDirector, ScheduleTaskPlacementSiloDirector>(typeof(ScheduleTaskPlacementStrategy));
            })
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .UseInMemoryReminderService()
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "1";
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(IngestTestGrain.TestCalls).Assembly))
                .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory())
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .ConfigureAppConfiguration((config) =>
            {
                config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

                var dic = new Dictionary <string, string>();

                string fileName = "publicsetting.xml";
                string path     = string.Empty;
                if ((Environment.OSVersion.Platform == PlatformID.Unix) || (Environment.OSVersion.Platform == PlatformID.MacOSX))
                {
                    //str = string.Format(@"{0}/{1}", System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, fileName);
                    path = '/' + fileName;
                }
                else
                {
                    path = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/") + "/" + fileName;
                }

                if (File.Exists(path))
                {
                    XDocument xd = new XDocument();
                    xd           = XDocument.Load(path);
                    XElement ps  = xd.Element("PublicSetting");
                    XElement sys = ps.Element("System");

                    string vip = sys.Element("Sys_VIP").Value;
                    dic.Add("VIP", vip);
                    dic.Add("IngestDBSvr", CreateConfigURI(sys.Element("IngestDBSvr").Value));
                    dic.Add("IngestDEVCTL", CreateConfigURI(sys.Element("IngestDEVCTL").Value));
                    dic.Add("CMWindows", CreateConfigURI(sys.Element("CMserver_windows").Value));
                    dic.Add("CMServer", CreateConfigURI(sys.Element("CMServer").Value));
                    config.AddInMemoryCollection(dic);
                }
            })
                .AddMemoryGrainStorageAsDefault()
                .AddMemoryGrainStorage("PubSubStore")
                .AddGrainService <DeviceMonitorService>()
                .AddSimpleMessageStreamProvider(StreamProviderName.Default)
                .UseInMemoryReminderService()
                .UseDashboard(options =>
            {
                options.HostSelf  = true;
                options.HideTrace = false;
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri()))
                .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "1";
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(IngestTestGrain.TestCalls).Assembly))
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(IngestTestGrain.TestCalls).Assembly))
                .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory())
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            //TestCalls.Make(client, cts);
            IngestTestGrain.TestCalls.Make(client, cts);

            Console.WriteLine("Press key to exit...");
            Console.ReadLine();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #22
0
        public static void Main(string[] args)
        {
            var silo = new SiloHostBuilder()
                       .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(EmployeeGrain).Assembly).WithReferences();
            })
                       .UseMongoDBClustering(options =>
            {
                options.ConnectionString = "mongodb://localhost/OrleansTestApp";
            })
                       .AddStartupTask(async(s, ct) =>
            {
                var grainFactory = s.GetRequiredService <IGrainFactory>();

                await grainFactory.GetGrain <IHelloWorldGrain>((int)DateTime.UtcNow.TimeOfDay.Ticks).SayHello("HI");
            })
                       .UseMongoDBReminders(options =>
            {
                options.ConnectionString = "mongodb://localhost/OrleansTestApp";
            })
                       .AddMongoDBGrainStorage("MongoDBStore", options =>
            {
                options.ConnectionString = "mongodb://localhost/OrleansTestApp";
            })
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                       .ConfigureEndpoints(IPAddress.Loopback, 11111, 30000)
                       .ConfigureLogging(logging => logging.AddConsole())
                       .Build();

            silo.StartAsync().Wait();

            var client = new ClientBuilder()
                         .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(IHelloWorldGrain).Assembly);
            })
                         .UseMongoDBClustering(options =>
            {
                options.ConnectionString = "mongodb://localhost/OrleansTestApp";
            })
                         .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                         .ConfigureLogging(logging => logging.AddConsole())
                         .Build();

            client.Connect().Wait();

            // get a reference to the grain from the grain factory
            var helloWorldGrain = client.GetGrain <IHelloWorldGrain>(1);

            // call the grain
            helloWorldGrain.SayHello("World").Wait();

            var reminderGrain = client.GetGrain <INewsReminderGrain>(1);

            reminderGrain.StartReminder("TestReminder", TimeSpan.FromMinutes(10)).Wait();

            // Test State
            var employee   = client.GetGrain <IEmployeeGrain>(1);
            var employeeId = employee.ReturnLevel().Result;

            if (employeeId == 100)
            {
                employee.SetLevel(50);
            }
            else
            {
                employee.SetLevel(100);
            }

            employeeId = employee.ReturnLevel().Result;

            Console.WriteLine(employeeId);
            Console.ReadKey();

            silo.StopAsync().Wait();
        }
예제 #23
0
        public static void Main(string[] args)
        {
            var connectionString = "mongodb://localhost/OrleansTestApp";
            var createShardKey   = false;

            var silo = new SiloHostBuilder()
                       .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(EmployeeGrain).Assembly).WithReferences();
            })
                       .UseMongoDBClient(connectionString)
                       .UseMongoDBClustering(options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;
            })
                       .AddStartupTask(async(s, ct) =>
            {
                var grainFactory = s.GetRequiredService <IGrainFactory>();

                await grainFactory.GetGrain <IHelloWorldGrain>((int)DateTime.UtcNow.TimeOfDay.Ticks).SayHello("HI");
            })
                       .UseMongoDBReminders(options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;
            })
                       .AddMongoDBGrainStorage("MongoDBStore", options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;

                options.ConfigureJsonSerializerSettings = settings =>
                {
                    settings.NullValueHandling      = NullValueHandling.Include;
                    settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                    settings.DefaultValueHandling   = DefaultValueHandling.Populate;
                };
            })
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                       .ConfigureEndpoints(IPAddress.Loopback, 11111, 30000)
                       .ConfigureLogging(logging => logging.AddConsole())
                       .Build();

            silo.StartAsync().Wait();

            var client = new ClientBuilder()
                         .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(IHelloWorldGrain).Assembly);
            })
                         .UseMongoDBClient(connectionString)
                         .UseMongoDBClustering(options =>
            {
                options.DatabaseName = "OrleansTestApp";
            })
                         .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                         .ConfigureLogging(logging => logging.AddConsole())
                         .Build();

            client.Connect().Wait();

            // get a reference to the grain from the grain factory
            var helloWorldGrain = client.GetGrain <IHelloWorldGrain>(1);

            // call the grain
            helloWorldGrain.SayHello("World").Wait();

            if (!args.Contains("--ship-reminders"))
            {
                var reminderGrain = client.GetGrain <INewsReminderGrain>(1);

                reminderGrain.StartReminder("TestReminder", TimeSpan.FromMinutes(1)).Wait();
            }

            // Test State
            var employee   = client.GetGrain <IEmployeeGrain>(1);
            var employeeId = employee.ReturnLevel().Result;

            if (employeeId == 100)
            {
                employee.SetLevel(50);
            }
            else
            {
                employee.SetLevel(100);
            }

            employeeId = employee.ReturnLevel().Result;

            Console.WriteLine(employeeId);

            // Test collections
            var vacationEmployee   = client.GetGrain <IEmployeeGrain>(2);
            var vacationEmployeeId = vacationEmployee.ReturnLevel().Result;

            if (vacationEmployeeId == 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    vacationEmployee.AddVacationLeave();
                }

                for (int i = 0; i < 2; i++)
                {
                    vacationEmployee.AddSickLeave();
                }

                vacationEmployee.SetLevel(101);
            }

            // Use ObjectCreationHandling.Replace in JsonSerializerSettings to replace the result during deserialization.
            var leaveCount = vacationEmployee.ReturnLeaveCount().Result;

            Console.WriteLine($"Total leave count: {leaveCount}");

            Console.ReadKey();
            silo.StopAsync().Wait();
        }
예제 #24
0
        public static void Main(string[] args)
        {
            var siloPort    = 11111;
            int gatewayPort = 30000;
            var siloAddress = IPAddress.Loopback;

            var silo =
                new SiloHostBuilder()
                .UseDashboard(options =>
            {
                options.HostSelf = false;
            })
                .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
                .UseInMemoryReminderService()
                .ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
                .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster")
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseDashboard()
                .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri()))
                .Configure <ClusterOptions>(options => options.ClusterId = "helloworldcluster")
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            WebHost.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddServicesForSelfHostedDashboard(client, options =>
                {
                    options.HideTrace = true;
                });
            })
            .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
            .Configure(app =>
            {
                app.UseOrleansDashboard();

                app.Map("/dashboard", d =>
                {
                    d.UseOrleansDashboard();
                });
            })
            .Build()
            .Run();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #25
0
        public static async Task Main(string[] args)
        {
            var connectionString = "mongodb://localhost/OrleansTestApp";
            var createShardKey   = false;

            var silo = new SiloHostBuilder()
                       .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(EmployeeGrain).Assembly).WithReferences();
            })
                       .UseMongoDBClient(connectionString)
                       .UseMongoDBClustering(options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;
            })
                       .AddStartupTask(async(s, ct) =>
            {
                var grainFactory = s.GetRequiredService <IGrainFactory>();

                await grainFactory.GetGrain <IHelloWorldGrain>((int)DateTime.UtcNow.TimeOfDay.Ticks).SayHello("HI");
            })
                       .UseMongoDBReminders(options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;
            })
                       .AddSimpleMessageStreamProvider("OrleansTestStream", options =>
            {
                options.FireAndForgetDelivery    = true;
                options.OptimizeForImmutableData = true;
                options.PubSubType = Orleans.Streams.StreamPubSubType.ExplicitGrainBasedOnly;
            })
                       .AddMongoDBGrainStorage("PubSubStore", options =>
            {
                options.DatabaseName            = "OrleansTestAppPubSubStore";
                options.CreateShardKeyForCosmos = createShardKey;

                options.ConfigureJsonSerializerSettings = settings =>
                {
                    settings.NullValueHandling      = NullValueHandling.Include;
                    settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                    settings.DefaultValueHandling   = DefaultValueHandling.Populate;
                };
            })
                       .AddMongoDBGrainStorage("MongoDBStore", options =>
            {
                options.DatabaseName            = "OrleansTestApp";
                options.CreateShardKeyForCosmos = createShardKey;

                options.ConfigureJsonSerializerSettings = settings =>
                {
                    settings.NullValueHandling      = NullValueHandling.Include;
                    settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                    settings.DefaultValueHandling   = DefaultValueHandling.Populate;
                };
            })
                       .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                       .ConfigureEndpoints(IPAddress.Loopback, 11111, 30000)
                       .ConfigureLogging(logging => logging.AddConsole())
                       .Build();

            await silo.StartAsync();

            var client = new ClientBuilder()
                         .ConfigureApplicationParts(options =>
            {
                options.AddApplicationPart(typeof(IHelloWorldGrain).Assembly);
            })
                         .UseMongoDBClient(connectionString)
                         .UseMongoDBClustering(options =>
            {
                options.DatabaseName = "OrleansTestApp";
            })
                         .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "helloworldcluster";
                options.ServiceId = "helloworldcluster";
            })
                         .ConfigureLogging(logging => logging.AddConsole())
                         .Build();

            await client.Connect();

            await TestBasic(client);

            if (!args.Contains("--skip-reminders"))
            {
                await TestReminders(client);
            }

            if (!args.Contains("--skip-streams"))
            {
                await TestStreams(client);
            }

            await TestState(client);
            await TestStateWithCollections(client);

            Console.ReadKey();

            await silo.StopAsync();
        }
예제 #26
0
파일: Program.cs 프로젝트: raidnav/DDBMSP
        public static void Main(string[] args)
        {
            var configuration =
                ClusterConfiguration.LocalhostPrimarySilo(33333)
                .RegisterDashboard();

            var silo =
                new SiloHostBuilder()
                .UseConfiguration(configuration)
                .UseDashboard(options =>
            {
                options.HostSelf = false;
            })
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            silo.StartAsync().Wait();

            var client =
                new ClientBuilder()
                .UseConfiguration(ClientConfiguration.LocalhostSilo())
                .UseDashboard()
                .ConfigureApplicationParts(appParts => appParts.AddApplicationPart(typeof(TestCalls).Assembly))
                .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
                .Build();

            client.Connect().Wait();

            var cts = new CancellationTokenSource();

            TestCalls.Make(client, cts);

            WebHost.CreateDefaultBuilder(args)
            .ConfigureServices(services =>
            {
                services.AddServicesForSelfHostedDashboard(client, options =>
                {
                    options.HideTrace = true;
                });
            })
            .ConfigureLogging(builder =>
            {
                builder.AddConsole();
            })
            .Configure(app =>
            {
                app.UseOrleansDashboard();

                app.Map("/dashboard", d =>
                {
                    d.UseOrleansDashboard();
                });
            })
            .Build()
            .Run();

            cts.Cancel();

            silo.StopAsync().Wait();
        }
예제 #27
0
파일: Program.cs 프로젝트: yf-ashu/rrod
        private static async Task Main(string[] args)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";

            ISiloHost silo;

            try
            {
                // string connectionString = config.GetConnectionString("DataConnectionString");
                silo = new SiloHostBuilder()
                       .UseEnvironment(environment)
                       .ConfigureLogging((context, logging) =>
                {
                    logging.AddConfiguration(context.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                    logging.AddDebug();
                })
                       .ConfigureAppConfiguration((context, builder) => {
                    builder
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddInMemoryCollection(new Dictionary <string, string>        // add default settings, that will be overridden by commandline
                    {
                        { "Id", "OrleansHost" },
                        { "Version", "1.0.0" },
                        { "ClusterId", "rrod-cluster" },
                        { "ServiceId", "rrod" }
                    })
                    .AddCommandLine(args)
                    .AddJsonFile("OrleansHost.settings.json", optional: true, reloadOnChange: true)
                    .AddJsonFile($"OrleansHost.settings.{environment}.json", optional: true, reloadOnChange: true)
                    .AddJsonFile("/run/config/OrleansHost.settings.json", optional: true, reloadOnChange: true)
                    .AddDockerSecrets("/run/secrets", optional: true)           // we can pas connectionstring as a docker secret
                    .AddUserSecrets <Program>(optional: true)                   // for development
                    .AddEnvironmentVariables("RROD_");                          // can override all settings (i.e. URLS) by passing an environment variable
                })
                       .AddStartupTask <SettingsLogger>()
                       .UseAzureStorageClustering(builder => builder.Configure((AzureStorageClusteringOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString")))
                       .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
                       .ConfigureServices((context, services) =>
                {
                    var config = context.Configuration;

                    var dataConnectionString  = config.GetConnectionString("DataConnectionString");
                    var reduxConnectionString = config.GetConnectionString("ReduxConnectionString");

                    services.AddOptions();
                    services.Configure <ClusterOptions>(config);
                    services.UseAzureTableReminderService(options => options.ConnectionString = dataConnectionString);
                    services.AddSingleton(new ReduxTableStorage <CertState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <UserState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <CounterState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <StringStoreState>(reduxConnectionString));
                })
                       .ConfigureApplicationParts(parts =>
                {
                    parts.AddApplicationPart(typeof(CounterGrain).Assembly).WithReferences();
                    parts.AddApplicationPart(typeof(AzureQueueDataAdapterV2).Assembly).WithReferences();
                })
                       .AddAzureTableGrainStorageAsDefault(builder => builder.Configure((AzureTableStorageOptions options, IConfiguration cfg) => options.ConnectionString                 = cfg.GetConnectionString("DataConnectionString")))
                       .AddAzureTableGrainStorage("PubSubStore", builder => builder.Configure((AzureTableStorageOptions options, IConfiguration cfg) => options.ConnectionString           = cfg.GetConnectionString("DataConnectionString")))
                       .AddAzureQueueStreams <AzureQueueDataAdapterV2>("Default", builder => builder.Configure((AzureQueueOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString"))
                                                                       )
                       .Build();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error building silo host: " + e.Message);
                throw;
            }

            // If our process is stopped, close the silo nicely so active grains get deactivated
            AssemblyLoadContext.Default.Unloading += context =>
            {
                StopSilo.Set();
            };

            // Make Ctrl-C stop our process
            Console.CancelKeyPress += (sender, e) =>
            {
                Environment.Exit(0);
            };

            try
            {
                Console.WriteLine("Silo starting...");
                await silo.StartAsync();

                Console.WriteLine("Silo started");

                StopSilo.WaitOne();

                Console.WriteLine("Silo stopping...");
                await silo.StopAsync();

                Console.WriteLine("Silo Stopped");
            }
            catch (OrleansLifecycleCanceledException e)
            {
                Console.WriteLine("Silo could not be started with exception: " + e.InnerException.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Silo could not be started with exception: " + e.Message);
            }
        }
예제 #28
0
        private static async Task Main(string[] args)
        {
            var 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("Starting Orleans silo...");

            var clusterConfig = ClusterConfiguration.LocalhostPrimarySilo();

            clusterConfig.Globals.ClusterId            = config["Id"];
            clusterConfig.Globals.DataConnectionString = config.GetConnectionString("DataConnectionString");
            clusterConfig.AddMemoryStorageProvider("Default");
            clusterConfig.AddMemoryStorageProvider("PubSubStore");
            clusterConfig.AddSimpleMessageStreamProvider("Default");
            var 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"));
                var reduxConnectionString = config.GetConnectionString("ReduxConnectionString");
                services.AddSingleton(new ReduxTableStorage <CertState>(reduxConnectionString));
                services.AddSingleton(new ReduxTableStorage <UserState>(reduxConnectionString));
                services.AddSingleton(new ReduxTableStorage <CounterState>(reduxConnectionString));
            })
                       .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(CounterGrain).Assembly).WithReferences())
                       .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("Orleans silo shutdown.");
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "Silo stopping fatally with exception: " + e.Message);
            }
        }
예제 #29
0
파일: Program.cs 프로젝트: Sveer/rrod
        private static async Task Main(string[] args)
        {
            var       environment      = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
            string    connectionString = null;
            ISiloHost silo;

            try
            {
                // string connectionString = config.GetConnectionString("DataConnectionString");
                silo = new SiloHostBuilder()
                       .UseEnvironment(environment)
                       .ConfigureLogging((context, logging) =>
                {
                    logging.AddConfiguration(context.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                    logging.AddDebug();
                })
                       .ConfigureAppConfiguration((context, builder) => {
                    builder
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddInMemoryCollection(new Dictionary <string, string>        // add default settings, that will be overridden by commandline
                    {
                        { "Id", "OrleansHost" },
                        { "Version", "1.0.0" },
                        { "ClusterId", "rrod-cluster" },
                        { "ServiceId", "rrod" }
                    })
                    .AddCommandLine(args)
                    .AddJsonFile("OrleansHost.settings.json", optional: true, reloadOnChange: true)
                    .AddJsonFile($"OrleansHost.settings.{environment}.json", optional: true, reloadOnChange: true)
                    .AddJsonFile("/run/config/OrleansHost.settings.json", optional: true, reloadOnChange: true)
                    .AddDockerSecrets("/run/secrets", optional: true)           // we can pas connectionstring as a docker secret
                    .AddUserSecrets <Program>(optional: true)                   // for development
                    .AddEnvironmentVariables("RROD_");                          // can override all settings (i.e. URLS) by passing an environment variable
                })
                       .AddStartupTask <SettingsLogger>()
                       //Испольузем  в качестве кластера SQL Server
                       .UseAdoNetClustering(builder => builder.Configure((AdoNetClusteringSiloOptions options, IConfiguration cfg) =>
                {
                    if (!CheckDBInit(cfg.GetConnectionString("AdoNetConnectionString")))
                    {
                        InitDB(cfg.GetConnectionString("AdoNetConnectionString"));
                    }
                    options.ConnectionString = cfg.GetConnectionString("AdoNetConnectionString");
                    options.Invariant        = cfg.GetValue <string>("SQLProvider");
                }))
                       //Prev 4 use Azure - Для использоания Azure
                       //.UseAzureStorageClustering(builder => builder.Configure((AzureStorageClusteringOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString")))

                       .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
                       .ConfigureServices((context, services) =>
                {
                    var config = context.Configuration;

                    var dataConnectionString   = config.GetConnectionString("DataConnectionString");   //Для Azure
                    var reduxConnectionString  = config.GetConnectionString("ReduxConnectionString");
                    var adoNetConnectionString = config.GetConnectionString("AdoNetConnectionString"); //Для SQL

                    services.AddOptions();
                    services.Configure <ClusterOptions>(config);


                    //    services.UseAzureTableReminderService(options => options.ConnectionString = dataConnectionString);
                    services.AddSingleton(new ReduxTableStorage <CertState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <UserState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <CounterState>(reduxConnectionString));
                    services.AddSingleton(new ReduxTableStorage <StringStoreState>(reduxConnectionString));
                })
                       .ConfigureApplicationParts(parts =>
                {
                    parts.AddApplicationPart(typeof(CounterGrain).Assembly).WithReferences();
                    parts.AddApplicationPart(typeof(AzureQueueDataAdapterV2).Assembly).WithReferences();
                })
                       .AddAdoNetGrainStorageAsDefault(builder => builder.Configure((AdoNetGrainStorageOptions options, IConfiguration cfg) =>
                {
                    connectionString         = cfg.GetConnectionString("AdoNetConnectionString");
                    options.ConnectionString = cfg.GetConnectionString("AdoNetConnectionString");
                    options.Invariant        = cfg.GetValue <string>("SQLProvider"); //Провайдер
                }))
                       .AddAdoNetGrainStorage("PubSubStore", builder => builder.Configure((AdoNetGrainStorageOptions options, IConfiguration cfg) =>
                {
                    options.ConnectionString = cfg.GetConnectionString("AdoNetConnectionString");
                    options.Invariant        = cfg.GetValue <string>("SQLProvider"); //Провайдер
                }))
                       .UseAdoNetReminderService(builder => builder.Configure((AdoNetReminderTableOptions options, IConfiguration cfg) =>
                {
                    options.ConnectionString = cfg.GetConnectionString("AdoNetConnectionString");
                    options.Invariant        = cfg.GetValue <string>("SQLProvider");//Провайдер
                }))
                       .AddSimpleMessageStreamProvider("Default", builder => builder.Configure((SimpleMessageStreamProviderOptions options, IConfiguration cfg) =>
                {
                    options.FireAndForgetDelivery    = true;
                    options.OptimizeForImmutableData = true;
                    options.PubSubType = Orleans.Streams.StreamPubSubType.ExplicitGrainBasedAndImplicit;
                    //   cfg.GetSection("AdoNetConnectionString").Bind(options);
                }))


                       //.AddRe
                       //Меняем на Redis
                       //  .AddAzureTableGrainStorageAsDefault(builder => builder.Configure((AzureTableStorageOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString")))
                       // .AddAzureTableGrainStorage("PubSubStore", builder => builder.Configure((AzureTableStorageOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString")))
                       // .AddAzureQueueStreams<AzureQueueDataAdapterV2>("Default", builder => builder.Configure((AzureQueueOptions options, IConfiguration cfg) => options.ConnectionString = cfg.GetConnectionString("DataConnectionString"))
                       //)
                       .Build();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error building silo host: " + e.Message);
                throw;
            }

            // If our process is stopped, close the silo nicely so active grains get deactivated
            AssemblyLoadContext.Default.Unloading += context =>
            {
                StopSilo.Set();
            };

            // Make Ctrl-C stop our process
            Console.CancelKeyPress += (sender, e) =>
            {
                Environment.Exit(0);
            };

            try
            {
                Console.WriteLine("Silo starting...");
                await silo.StartAsync();

                Console.WriteLine("Silo started");

                StopSilo.WaitOne();

                Console.WriteLine("Silo stopping...");
                await silo.StopAsync();

                Console.WriteLine("Silo Stopped");
            }
            catch (SqlException e)
            {
                //Инициализация БД
            }
            catch (OrleansLifecycleCanceledException e)
            {
                if (e.InnerException is SqlException && ((SqlException)e.InnerException).Number == 208) //Error DB Not init
                {
                    Console.WriteLine("DataBase Not initialised...");
                }
                Console.WriteLine("Silo could not be started with exception: " + e.InnerException.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Silo could not be started with exception: " + e.Message);
            }
        }