Пример #1
0
        // methods
        private ICluster CreateCluster(ClusterKey clusterKey)
        {
            var builder = new ClusterBuilder()
                          .ConfigureCluster(settings => ConfigureCluster(settings, clusterKey))
                          .ConfigureServer(settings => ConfigureServer(settings, clusterKey))
                          .ConfigureConnectionPool(settings => ConfigureConnectionPool(settings, clusterKey))
                          .ConfigureConnection(settings => ConfigureConnection(settings, clusterKey))
                          .ConfigureTcp(settings => ConfigureTcp(settings, clusterKey));

            if (clusterKey.UseSsl)
            {
                builder.ConfigureSsl(settings => ConfigureSsl(settings, clusterKey));
            }

            if (clusterKey.ClusterConfigurator != null)
            {
                clusterKey.ClusterConfigurator(builder);
            }

            var cluster = builder.BuildCluster();

            cluster.Initialize();

            return(cluster);
        }
        // methods
        public static ClusterBuilder ConfigureCluster()
        {
            var builder = new ClusterBuilder().ConfigureWithConnectionString(__connectionString);

            if (__connectionString.Ssl.HasValue && __connectionString.Ssl.Value)
            {
                var certificateFilename = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_FILE");
                if (certificateFilename != null)
                {
                    builder.ConfigureSsl(ssl =>
                    {
                        var password = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_PASS");
                        X509Certificate cert;
                        if (password == null)
                        {
                            cert = new X509Certificate2(certificateFilename);
                        }
                        else
                        {
                            cert = new X509Certificate2(certificateFilename, password);
                        }

                        return(ssl.With(
                                   clientCertificates: new[] { cert }));
                    });
                }
            }

            return(builder);
        }
        public static ClusterBuilder ConfigureCluster(ClusterBuilder builder)
        {
            var serverSelectionTimeoutString = Environment.GetEnvironmentVariable("MONGO_SERVER_SELECTION_TIMEOUT_MS");

            if (serverSelectionTimeoutString == null)
            {
                serverSelectionTimeoutString = "10000";
            }

            builder = builder
                      .ConfigureWithConnectionString(__connectionString)
                      .ConfigureCluster(c => c.With(serverSelectionTimeout: TimeSpan.FromMilliseconds(int.Parse(serverSelectionTimeoutString))));

            if (__connectionString.Ssl.HasValue && __connectionString.Ssl.Value)
            {
                var certificateFilename = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_FILE");
                if (certificateFilename != null)
                {
                    builder.ConfigureSsl(ssl =>
                    {
                        var password = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_PASS");
                        X509Certificate cert;
                        if (password == null)
                        {
                            cert = new X509Certificate2(certificateFilename);
                        }
                        else
                        {
                            cert = new X509Certificate2(certificateFilename, password);
                        }
                        return(ssl.With(
                                   clientCertificates: new[] { cert }));
                    });
                }
            }

            var traceSource = new TraceSource("mongodb-tests", SourceLevels.Information);

            traceSource.Listeners.Clear(); // remove the default listener
            var listener = new ConsoleTraceListener();

            traceSource.Listeners.Add(listener);
            builder = builder.TraceWith(traceSource);

            return(builder);
        }
Пример #4
0
        public static ClusterBuilder ConfigureCluster(ClusterBuilder builder)
        {
            var serverSelectionTimeoutString = Environment.GetEnvironmentVariable("MONGO_SERVER_SELECTION_TIMEOUT_MS");

            if (serverSelectionTimeoutString == null)
            {
                serverSelectionTimeoutString = "10000";
            }

            builder = builder
                      .ConfigureWithConnectionString(__connectionString)
                      .ConfigureCluster(c => c.With(serverSelectionTimeout: TimeSpan.FromMilliseconds(int.Parse(serverSelectionTimeoutString))));

            if (__connectionString.Ssl.HasValue && __connectionString.Ssl.Value)
            {
                var certificateFilename = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_FILE");
                if (certificateFilename != null)
                {
                    builder.ConfigureSsl(ssl =>
                    {
                        var password = Environment.GetEnvironmentVariable("MONGO_SSL_CERT_PASS");
                        X509Certificate cert;
                        if (password == null)
                        {
                            cert = new X509Certificate2(certificateFilename);
                        }
                        else
                        {
                            cert = new X509Certificate2(certificateFilename, password);
                        }
                        return(ssl.With(
                                   clientCertificates: new[] { cert }));
                    });
                }
            }

            return(builder);
        }