예제 #1
0
        internal static IClientBuilder AddLoggers(this IClientBuilder clientBuilder, PiraeusGatewayOptions options)
        {
            clientBuilder.ConfigureLogging(builder =>
            {
                if (options.LoggerTypes.HasFlag(LoggerType.Console) && options.LoggingLevel != LogLevel.None)
                {
                    builder.AddConsole();
                }

                if (options.LoggerTypes.HasFlag(LoggerType.Debug) && options.LoggingLevel != LogLevel.None)
                {
                    builder.AddDebug();
                }

                if (options.LoggingLevel != LogLevel.None)
                {
                    builder.SetMinimumLevel(options.LoggingLevel);
                }
            });

            if (options.LoggingLevel.HasFlag(LoggerType.AppInsights) && options.LoggingLevel != LogLevel.None && !string.IsNullOrEmpty(options.AppInsightKey))
            {
                clientBuilder.AddApplicationInsightsTelemetryConsumer(options.AppInsightKey);
            }

            return(clientBuilder);
        }
예제 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            OrleansConfig oconfig = null;
            PiraeusConfig pconfig = null;

            //LoggerFactory loggerFactory = new LoggerFactory();

            IConfigurationBuilder configBuilder = new ConfigurationBuilder();

            configBuilder.AddOrleansConfiguration(out oconfig);
            configBuilder.AddPiraeusConfiguration(out pconfig);

            PiraeusGatewayOptions pgo = new PiraeusGatewayOptions(oconfig);
            //services.AddGatewayService(typeof(TcpGatewayService), null);

            //services.AddOrleansConfiguration();
            //services.AddPiraeusConfiguration();
            //services.AddOrleansClusterClient(loggerFactory, options => options.IsLocal = false);

            IServiceProvider sp         = services.BuildServiceProvider();
            LoggerType       loggerType = oconfig.GetLoggerTypes();

            if (!loggerType.HasFlag(LoggerType.None))
            {
                services.AddLogging(builder =>
                {
                    if (loggerType.HasFlag(LoggerType.Console))
                    {
                        builder.AddConsole();
                    }
                    if (loggerType.HasFlag(LoggerType.Debug))
                    {
                        builder.AddDebug();
                    }
                    if (loggerType.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(oconfig.AppInsightsKey))
                    {
                        builder.AddApplicationInsights(oconfig.AppInsightsKey);
                    }

                    builder.SetMinimumLevel(LogLevel.Warning);
                });
            }

            TcpGatewayService tgs = sp.GetRequiredService <TcpGatewayService>();

            tgs.Init(oconfig.Dockerized);

            //services.AddSingleton<TcpGatewayService>((f) => f.GetRequiredService<TcpGatewayService>());
        }
예제 #3
0
        private static IClusterClient CreateClusterClient(IServiceProvider serviceProvider)
        {
            PiraeusGatewayOptions options = serviceProvider.GetOptionsByName <PiraeusGatewayOptions>("PiraeusGatewayOptions");

            if (!options.Dockerized)
            {
                var localClient = new ClientBuilder()
                                  .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IPiSystem).Assembly))
                                  .UseLocalhostClustering()
                                  .AddLoggers(options)
                                  .Build();

                localClient.Connect(RetryFilter).GetAwaiter();

                return(localClient);
            }
            else
            {
                var client = new ClientBuilder()
                             .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IPiSystem).Assembly))
                             .Configure <OrleansConfiguration.ClusterOptions>(op =>
                {
                    op.ClusterId = options.ClusterId;
                    op.ServiceId = options.ServiceId;
                });

                client.AddLoggers(options);
                if (options.StorageType == OrleansStorageType.Redis)
                {
                    client.UseRedisGatewayListProvider(op => op.ConnectionString = options.DataConnectionString);
                }
                if (options.StorageType == OrleansStorageType.AzureStorage)
                {
                    client.UseAzureStorageClustering(op => op.ConnectionString = options.DataConnectionString);
                }

                IClusterClient clusterClient = client.Build();

                clusterClient.Connect(RetryFilter).GetAwaiter();
                return(clusterClient);
            }
        }