當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.MongoClientSettings類代碼示例

本文整理匯總了C#中MongoDB.Driver.MongoClientSettings的典型用法代碼示例。如果您正苦於以下問題:C# MongoClientSettings類的具體用法?C# MongoClientSettings怎麽用?C# MongoClientSettings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MongoClientSettings類屬於MongoDB.Driver命名空間,在下文中一共展示了MongoClientSettings類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetSettings

        MongoClientSettings GetSettings()
        {
            if (String.IsNullOrEmpty(MongoSettings.ConnectionString))
             {
                 throw new ArgumentNullException("Connection string not found.");
             }

             if (String.IsNullOrEmpty(MongoSettings.Database))
             {
                 throw new ArgumentNullException("Database string not found.");
             }

             var ips = MongoSettings.ConnectionString.Split(';');
             var servicesList = new List<MongoServerAddress>();

             foreach (var ip in ips)
             {
                 var host = ip.Split(':')[0];
                 var port = Convert.ToInt32(ip.Split(':')[1]);

                 servicesList.Add(new MongoServerAddress(host, port));
             }

             var setting = new MongoClientSettings();
             setting.ReplicaSetName = MongoSettings.ReplicaSetName;

             //集群中的服務器列表
             setting.Servers = servicesList;

             return setting;
        }
開發者ID:ideayapai,項目名稱:docviewer,代碼行數:31,代碼來源:MongoContext.cs

示例2: GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings

        public void GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings()
        {
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var servers = new[] { new MongoServerAddress("localhost"), new MongoServerAddress("127.0.0.1", 30000), new MongoServerAddress("[::1]", 27018) };

            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols = SslProtocols.Tls
            };

            var clientSettings = new MongoClientSettings
            {
                ApplicationName = "app1",
                ConnectionMode = ConnectionMode.ReplicaSet,
                ConnectTimeout = TimeSpan.FromSeconds(1),
                Credentials = credentials,
                GuidRepresentation = GuidRepresentation.Standard,
                HeartbeatInterval = TimeSpan.FromSeconds(7),
                HeartbeatTimeout = TimeSpan.FromSeconds(8),
                IPv6 = true,
                MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize = 10,
                MinConnectionPoolSize = 5,
                ReplicaSetName = "rs",
                LocalThreshold = TimeSpan.FromMilliseconds(20),
                Servers = servers,
                ServerSelectionTimeout = TimeSpan.FromSeconds(5),
                SocketTimeout = TimeSpan.FromSeconds(4),
                SslSettings = sslSettings,
                UseSsl = true,
                VerifySslCertificate = true,
                WaitQueueSize = 20,
                WaitQueueTimeout = TimeSpan.FromSeconds(6)
            };

            var subject = new ClusterRegistry();

            using (var cluster = subject.GetOrCreateCluster(clientSettings.ToClusterKey()))
            {
                var endPoints = new EndPoint[]
                {
                    new DnsEndPoint("localhost", 27017),
                    new IPEndPoint(IPAddress.Parse("127.0.0.1"), 30000),
                    new IPEndPoint(IPAddress.Parse("[::1]"), 27018)
                };
                cluster.Settings.ConnectionMode.Should().Be(ClusterConnectionMode.ReplicaSet);
                cluster.Settings.EndPoints.Equals(endPoints);
                cluster.Settings.ReplicaSetName.Should().Be("rs");
                cluster.Settings.ServerSelectionTimeout.Should().Be(clientSettings.ServerSelectionTimeout);
                cluster.Settings.PostServerSelector.Should().NotBeNull().And.Subject.Should().BeOfType<LatencyLimitingServerSelector>();
                cluster.Settings.MaxServerSelectionWaitQueueSize.Should().Be(20);

                cluster.Description.Servers.Select(s => s.EndPoint).Should().Contain(endPoints);

                // TODO: don't know how to test the rest of the settings because they are all private to the cluster
            }
        }
開發者ID:mfidemraizer,項目名稱:mongo-csharp-driver,代碼行數:59,代碼來源:ClusterRegistryTests.cs

示例3: parse_from_connection_string

		protected void parse_from_connection_string( string connection_string ) {
			var mongo_url = MongoUrl.Create( connection_string );
			
			ConnectionString = connection_string;
			DatabaseName = mongo_url.DatabaseName;
			
			MongoClientSettings = MongoClientSettings.FromUrl( mongo_url );
		}
開發者ID:magriffsla,項目名稱:Mongo.Entity,代碼行數:8,代碼來源:DatabaseSettings.cs

示例4: GetDatabase

		public IMongoDatabase GetDatabase(string user, string password, string db = defaultDB) {
            var credential = MongoCredential.CreateMongoCRCredential(db, user, password);
            var settings = new MongoClientSettings { Credentials = new[] { credential } };
            var mongoClient = new MongoClient(settings);

			return GetDatabase(mongoClient, db);
		}
開發者ID:DamienSaillard,項目名稱:AppliMongoDB,代碼行數:7,代碼來源:MyMongoClient.cs

示例5: ToMongoClientSettings

        /// <summary>
        /// Converts the current instance to a <see cref="MongoClientSettings"/>.
        /// </summary>
        /// <returns>The current instance as a <see cref="MongoClientSettings"/>.</returns>
        public virtual MongoClientSettings ToMongoClientSettings()
        {
            MongoClientSettings settings;
            if (this.Servers == null || !this.Servers.Any())
            {
                settings = new MongoClientSettings
                {
                    Server = new MongoServerAddress(this.Host, this.Port)
                };
            }
            else
            {
                // Support multiple servers if needed (e.g. replication)
                settings = new MongoClientSettings
                {
                    Servers = this.Servers.Select(s => new MongoServerAddress(s.Host, s.Port))
                };
            }

            // Set replica set
            settings.ReplicaSetName = this.ReplicaSet;

            if (this.Authenticate)
            {
                settings.Credentials = new[] { MongoCredential.CreateMongoCRCredential(this.Database, this.Username, this.Password) };
            }

            return settings;
        }
開發者ID:cgavieta,項目名稱:WORKPAC2016-poc,代碼行數:33,代碼來源:MongoConfiguration.cs

示例6: Connect

        public override bool Connect() {
            bool opened = true;

            if (this.Client == null) {
                try {
                    MongoClientSettings settings = new MongoClientSettings();

                    if (this.Settings.Hostname != null && this.Settings.Port.HasValue == true) {
                        settings.Server = new MongoServerAddress(this.Settings.Hostname, (int)this.Settings.Port.Value);
                    }
                    else if (this.Settings.Hostname != null) {
                        settings.Server = new MongoServerAddress(this.Settings.Hostname);
                    }

                    if (this.Database != null && this.Settings.Username != null && this.Settings.Password != null) {
                        settings.Credentials = new List<MongoCredential>() {
                        MongoCredential.CreateMongoCRCredential(this.Settings.Database, this.Settings.Username, this.Settings.Password)
                    };
                    }

                    this.Client = new MongoClient(settings);

                    this.Database = this.Client.GetServer().GetDatabase(this.Settings.Database);
                }
                catch {
                    opened = false;
                }
            }

            return opened;
        }
開發者ID:EBassie,項目名稱:Potato,代碼行數:31,代碼來源:MongoDbDriver.cs

示例7: TestRealMongo

        public ActionResult TestRealMongo()
        {
            //Connect to MongoDB in C# with Credentials

            var credential = MongoCredential.CreateMongoCRCredential("alertsmd", "rangle", "m3anstack");
            //Server settings
            var settings = new MongoClientSettings
            {
                Credentials = new[] { credential },
                Server = new MongoServerAddress("ds033757.mongolab.com",33757)
            };

            //Get a Reference to the Client Object
            var mongoClient = new MongoClient(settings);
            var mongoServer = mongoClient.GetServer();
            var database = mongoServer.GetDatabase("alertsmd");

            var collections = database.GetCollectionNames();

            var usersCollection = database.GetCollection("users");

            var mconditions = database.GetCollection("conditions").FindAll();
            var mfeedbacks = database.GetCollection("feedbacks").FindAll();
            var mprofiles = database.GetCollection("profiles").FindAll();
            var msessions = database.GetCollection("sessions").FindAll();
            var msymptoms = database.GetCollection("symptoms").FindAll();
            var msystem_indexes = database.GetCollection("system.indexes").FindAll();
            var msystem_users = database.GetCollection("system.users").FindAll();
            var muserDatas = database.GetCollection("userDatas").FindAll();
            var musers = database.GetCollection("users").FindAll();

            return View();
        }
開發者ID:pabloelustondo,項目名稱:WellCastServer,代碼行數:33,代碼來源:TestMongoController.cs

示例8: LocalContext

 public LocalContext()
 {
     MongoClientSettings settings = new MongoClientSettings();
     settings.Server = new MongoServerAddress("localhost", 27017);
     //settings.Server = new MongoServerAddress("192.168.0.103", 27017);
     var client = new MongoClient(settings);
     Database = client.GetDatabase("admin");
 }
開發者ID:nithin8702,項目名稱:MyRepository,代碼行數:8,代碼來源:LocalContext.cs

示例9: MongoDashboardContext

 public MongoDashboardContext()
 {
     var settings = new MongoClientSettings();
     settings.Server = new MongoServerAddress("127.0.0.1");
     var client = new MongoClient(settings);
     var database = client.GetDatabase("Workspaces");
     Dashboards = database.GetCollection<Dashboard>("Dashboard");
 }
開發者ID:florinszilagyi,項目名稱:storeme,代碼行數:8,代碼來源:DashboardContext.cs

示例10: MongoStore

 public MongoStore(string db)
 {
     var clientSettings = new MongoClientSettings();
     //clientSettings.Server = new MongoServerAddress("mongodb://host:22666");
     var mongo = new MongoClient("mongodb://localhost:22666");
     var l = mongo.ListDatabasesAsync().Result;
     _mongodb = mongo.GetDatabase(db);
 }
開發者ID:grrrrinaldi,項目名稱:emveeseefive,代碼行數:8,代碼來源:MongoStore.cs

示例11: GetTestDatabase

 protected static MongoDatabase GetTestDatabase()
 {
     var settings = new MongoClientSettings
     {
         Server = new MongoServerAddress("localhost")
     };
     return new MongoClient(settings).GetServer().GetDatabase("mongo-learning");
 }
開發者ID:hanu412,項目名稱:mongo-learning,代碼行數:8,代碼來源:TestsBase.cs

示例12: Create

        public IMongoDatabase Create()
        {
            MongoClientSettings setting = new MongoClientSettings();
            setting.Server = new MongoServerAddress(_serverAddress, 27017);
            var mongoClient = new MongoClient(setting);
            var db = mongoClient.GetDatabase(_databaseName);

            return db;
        }
開發者ID:AChehre,項目名稱:Paran,代碼行數:9,代碼來源:ConnectionFactory.cs

示例13: MongoOptimisticDataStore

 public MongoOptimisticDataStore(MongoClientSettings settings, string databaseName, string collectionName)
 {
     MongoClient client = new MongoClient(settings);
     this.Server = client.GetServer();
     this.CollectionName = collectionName;
     this.Database = this.Server.GetDatabase(databaseName);
     SetCollection();
     this.IsConnected = true;
 }
開發者ID:cyberprune,項目名稱:SnowMaker,代碼行數:9,代碼來源:MongoOptimisticDataStore.cs

示例14: BookController

 public BookController()
 {
     _repo = new Repository();
     string connectionString = "mongodb://localhost:27017/";
     var mongoClientSettings = new MongoClientSettings();
     mongoClientSettings.Server = new MongoServerAddress(connectionString);
     var client = new MongoClient();
     var db = client.GetDatabase("BookMVC");
     var collection = db.GetCollection<Book>("Book");
 }
開發者ID:mattwoPhre,項目名稱:MongoDB,代碼行數:10,代碼來源:BookController.cs

示例15: UseMongoStorage

		public static MongoStorage UseMongoStorage(this IBootstrapperConfiguration configuration,
			MongoClientSettings mongoClientSettings,
			string databaseName)
		{
			MongoStorage storage = new MongoStorage(mongoClientSettings, databaseName);

			configuration.UseStorage(storage);

			return storage;
		}
開發者ID:Trov,項目名稱:Hangfire.Mongo,代碼行數:10,代碼來源:MongoBootstrapperConfigurationExtensions.cs


注:本文中的MongoDB.Driver.MongoClientSettings類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。