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


C# Driver.MongoServerSettings類代碼示例

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


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

示例1: TestDefaults

        public void TestDefaults()
        {
            var localhost = new MongoServerAddress("localhost");

            var settings = new MongoServerSettings();
            Assert.AreEqual(ConnectionMode.Direct, settings.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);
            Assert.AreEqual(null, settings.DefaultCredentials);
            Assert.AreEqual(MongoDefaults.GuidRepresentation, settings.GuidRepresentation);
            Assert.AreEqual(false, settings.IPv6);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
            Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.AreEqual(ReadPreference.Primary, settings.ReadPreference);
            Assert.AreEqual(null, settings.ReplicaSetName);
            Assert.AreEqual(SafeMode.False, settings.SafeMode);
            Assert.AreEqual(1, settings.Servers.Count());
            Assert.AreEqual(localhost, settings.Server);
            Assert.AreEqual(localhost, settings.Servers.First());
            Assert.AreEqual(MongoDefaults.SocketTimeout, settings.SocketTimeout);
            Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, settings.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, settings.WaitQueueTimeout);

            Assert.IsFalse(settings.IsFrozen);
            var hashCode = settings.GetHashCode();
            var stringRepresentation = settings.ToString();
            Assert.AreEqual(settings, settings);

            settings.Freeze();
            Assert.IsTrue(settings.IsFrozen);
            Assert.AreEqual(hashCode, settings.GetHashCode());
            Assert.AreEqual(stringRepresentation, settings.ToString());
        }
開發者ID:yfann,項目名稱:mongo-csharp-driver,代碼行數:34,代碼來源:MongoServerSettingsTests.cs

示例2: Go

        private static void Go(long userId)
        {
            var settings = new MongoServerSettings
            {
                Server = new MongoServerAddress("127.0.0.1", 27017),
                SafeMode = SafeMode.False
            };
            var mongoServer = new MongoServer(settings);

            var database = mongoServer.GetDatabase("Test");

            var map = new NoteMap();
            var collection = new EntityCollection<Note>(database, map.GetDescriptor(), true);

            var note = new Note
            {
                NoteID = "1",
                Title = "This is a book.",
                Content = "Oh yeah",
                UserID = 123321L
            };
            // collection.InsertOnSubmit(note);
            // collection.SubmitChanges();
            // var data = collection.SelectTo(n => new { n.NoteID, n.UserID });
            collection.Log = Console.Out;
            var a = 4;
            collection.Update(
                n => new Note { },
                n => true);
        }
開發者ID:jefth,項目名稱:EasyMongo,代碼行數:30,代碼來源:Program.cs

示例3: TestAddressFamilyObsolete

        public void TestAddressFamilyObsolete(bool ipv6, AddressFamily addressFamily)
        {
#pragma warning disable 618
            var settings = new MongoServerSettings { IPv6 = ipv6 };
            Assert.AreEqual(addressFamily, settings.AddressFamily);
#pragma warning restore
        }
開發者ID:einaregilsson,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoServerSettingsTests.cs

示例4: ExtendedMongoDBCheck

        public ExtendedMongoDBCheck(string connectionString, bool isReplSet, bool dbStats)
        {
            _isReplSet = isReplSet;
            _dbStats = dbStats;

            if (connectionString.Contains("mongodb://"))
            {
                _mongoServer = MongoServer.Create(string.Format("{0}{1}?slaveok=true", connectionString, connectionString.EndsWith("/") ? "" : "/"));
            }
            else
            {
                MongoServerSettings settings = new MongoServerSettings();
                if (connectionString.Contains(":"))
                {
                    string[] bits = connectionString.Split(':');
                    settings.Server = new MongoServerAddress(bits[0], Convert.ToInt32(bits[1]));
                }
                else
                {
                    settings.Server = new MongoServerAddress(connectionString);
                }
                settings.SlaveOk = true;
                _mongoServer = MongoServer.Create(settings);
            }
        }
開發者ID:MYJDMCIVICEM2,項目名稱:sd-agent-windows,代碼行數:25,代碼來源:ExtendedMongoDBCheck.cs

示例5: GetRepository

        internal IRepository GetRepository()
        {
            // We have a connection string name, grab this from the config and pass it too the parser.
            if (!string.IsNullOrWhiteSpace(this.ConnectionName))
            {
                if (ConfigurationManager.ConnectionStrings[this.ConnectionName] == null ||
                    string.IsNullOrWhiteSpace(ConfigurationManager.ConnectionStrings[this.ConnectionName].ConnectionString))
                    throw new MongoConnectionException("The connection string name specified was not found.");

                return GetProvider().GetRepository(
                        ConfigurationManager.ConnectionStrings[this.ConnectionName].ConnectionString,
                        this.Database);
            }
            
            // We have a connection string
            if (!string.IsNullOrWhiteSpace(this.ConnectionString))
                return GetProvider().GetRepository(this.ConnectionString, this.Database);

            // No connection strings at all, use the old method using the properties
            var database = this.Database;
            var settings = new MongoServerSettings {Server = new MongoServerAddress(this.Host, this.Port)};
            
            if (HasCredentials)
                settings.DefaultCredentials = new MongoCredentials(this.Username, this.Password);

            return GetProvider().GetRepository(settings, database);
        }
開發者ID:kayone,項目名稱:NLog.MongoDB,代碼行數:27,代碼來源:MongoDBTarget.cs

示例6: GetReplicaSetSettings

        public static MongoServerSettings GetReplicaSetSettings(string roleName)
        {
            var settings = new MongoServerSettings();
            var replicaSetName = RoleEnvironment.GetConfigurationSettingValue(ReplicaSetNameSetting);
            settings.ReplicaSetName = replicaSetName;

            ReadOnlyCollection<RoleInstance> workerRoleInstances;
            try
            {
                workerRoleInstances = RoleEnvironment.Roles[roleName].Instances;
            }
            catch (KeyNotFoundException ke)
            {
                throw new Exception(
                    string.Format("The MongoDB role should be called {0}", roleName),
                    ke);
            }

            var servers = new List<MongoServerAddress>();
            foreach (var instance in workerRoleInstances)
            {
                var endpoint = AzureRoleHelper.GetEndPoint(instance, MongodPortKey);
                var server = new MongoServerAddress(endpoint.Address.ToString(), endpoint.Port);
                servers.Add(server);
            }

            settings.Servers = servers;
            settings.ConnectionMode = ConnectionMode.ReplicaSet;
            return settings;
        }
開發者ID:bobasoft,項目名稱:framework,代碼行數:30,代碼來源:SettingsHelper.cs

示例7: MongoConfig

        public MongoConfig()
        {
            MongoConfigSection mongoSection = (MongoConfigSection)ConfigurationManager.GetSection(MongoConfigSection.DefaultSectionName);

            MongoServerSettings settings = new MongoServerSettings();
            MongoServerSettings reportingSettings = new MongoServerSettings();
            settings.ConnectionMode = mongoSection.ConnectionMode;
            settings.ReplicaSetName = mongoSection.ReplicaSetName;
            reportingSettings.ConnectionMode = mongoSection.ConnectionMode;
            reportingSettings.ReplicaSetName = mongoSection.ReplicaSetName;
            reportingSettings.SlaveOk = mongoSection.SlaveOk;

            if (mongoSection.ServerAddresses.Count == 0)
                throw new ConfigurationErrorsException("No server has been define in configuration");
            if (mongoSection.SlaveAddresses.Count == 0)
                throw new ConfigurationErrorsException("No server has been define in configuration");
            var servers = new List<MongoServerAddress>();
            foreach (ServerAddress serverAddr in mongoSection.ServerAddresses)
            {
                servers.Add(new MongoServerAddress(serverAddr.Server, serverAddr.Port));
            }
            settings.Servers = servers;
            var reportingServers = new List<MongoServerAddress>();
            foreach (SlaveAddress slaveAddr in mongoSection.SlaveAddresses)
            {
                reportingServers.Add(new MongoServerAddress(slaveAddr.Server, slaveAddr.Port));
            }
            reportingSettings.Servers = reportingServers;

            MongoServer = MongoServer.Create(settings);
            MongoDatabase = MongoServer.GetDatabase(mongoSection.Database, new MongoCredentials(mongoSection.UserName, mongoSection.Password, mongoSection.MongoAdmin));
            ReportingServer = MongoServer.Create(reportingSettings);
            ReportingDatabase = ReportingServer.GetDatabase(mongoSection.Database, new MongoCredentials(mongoSection.UserName, mongoSection.Password, mongoSection.MongoAdmin));
        }
開發者ID:dnywu,項目名稱:sales,代碼行數:34,代碼來源:MongoConfig.cs

示例8: MongoServerInstance

        // constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="MongoServerInstance"/> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="address">The address.</param>
        internal MongoServerInstance(MongoServerSettings settings, MongoServerAddress address)
        {
            _settings = settings;
            _address = address;
            _sequentialId = Interlocked.Increment(ref __nextSequentialId);
            _state = MongoServerState.Disconnected;
            _serverInfo = new ServerInformation
            {
                MaxDocumentSize = MongoDefaults.MaxDocumentSize,
                MaxMessageLength = MongoDefaults.MaxMessageLength,
                InstanceType = MongoServerInstanceType.Unknown
            };
            _connectionPool = new MongoConnectionPool(this);
            _pingTimeAggregator = new PingTimeAggregator(5);
            _permanentlyDisconnected = false;
            // Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);

            _stateVerificationAcquireConnectionOptions = new MongoConnectionPool.AcquireConnectionOptions
            {
                OkToAvoidWaitingByCreatingNewConnection = false,
                OkToExceedMaxConnectionPoolSize = true,
                OkToExceedWaitQueueSize = true,
                WaitQueueTimeout = TimeSpan.FromSeconds(2)
            };
        }
開發者ID:petarvucetin,項目名稱:mongo-csharp-driver,代碼行數:31,代碼來源:MongoServerInstance.cs

示例9: TestDefaults

        public void TestDefaults()
        {
            var settings = new MongoServerSettings();
            Assert.AreEqual(ConnectionMode.Direct, settings.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);
            Assert.AreEqual(null, settings.DefaultCredentials);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
            Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.AreEqual(null, settings.ReplicaSetName);
            Assert.AreEqual(SafeMode.False, settings.SafeMode);
            Assert.AreEqual(null, settings.Server);
            Assert.AreEqual(null, settings.Servers);
            Assert.AreEqual(MongoDefaults.SocketTimeout, settings.SocketTimeout);
            Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, settings.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, settings.WaitQueueTimeout);

            Assert.IsFalse(settings.IsFrozen);
            var hashCode = settings.GetHashCode();
            var stringRepresentation = settings.ToString();
            Assert.AreEqual(settings, settings);

            settings.Freeze();
            Assert.IsTrue(settings.IsFrozen);
            Assert.AreEqual(hashCode, settings.GetHashCode());
            Assert.AreEqual(stringRepresentation, settings.ToString());
        }
開發者ID:jenrom,項目名稱:mongo-csharp-driver,代碼行數:28,代碼來源:MongoServerSettingsTests.cs

示例10: MongoOptimisticDataStore

        public MongoOptimisticDataStore(MongoServerSettings settings, string databaseName, string collectionName)
        {
            this.ServerSettings = settings;
            this.DatabaseName = databaseName;
            this.CollectionName = collectionName;

            this.IsConnected = false;
        }
開發者ID:cyberprune,項目名稱:SnowMaker,代碼行數:8,代碼來源:MongoOptimisticDataStore.cs

示例11: MongoServerInstance

 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoServerInstance"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="address">The address.</param>
 /// <param name="cluster">The cluster.</param>
 internal MongoServerInstance(MongoServerSettings settings, MongoServerAddress address, ICluster cluster)
 {
     _settings = settings;
     _address = address;
     _cluster = cluster;
     _sequentialId = Interlocked.Increment(ref __nextSequentialId);
     _endPoint = new DnsEndPoint(address.Host, address.Port);
 }
開發者ID:bollinim,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoServerInstance.cs

示例12: MongoRepository

		public MongoRepository(
			MongoServerSettings settings,
			string database)
		{
			_Server = new MongoServer(settings);
            _Database = database;
			_Server.Connect();
		}
開發者ID:kayone,項目名稱:NLog.MongoDB,代碼行數:8,代碼來源:MongoRepository.cs

示例13: MongoServerInstance

 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoServerInstance" /> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="address">The address.</param>
 /// <param name="cluster">The cluster.</param>
 /// <param name="endPoint">The end point.</param>
 internal MongoServerInstance(MongoServerSettings settings, MongoServerAddress address, ICluster cluster, EndPoint endPoint)
 {
     _settings = settings;
     _address = address;
     _cluster = cluster;
     _sequentialId = Interlocked.Increment(ref __nextSequentialId);
     _endPoint = endPoint;
 }
開發者ID:huoxudong125,項目名稱:mongo-csharp-driver,代碼行數:16,代碼來源:MongoServerInstance.cs

示例14: JsonAction2

        public ActionResult JsonAction2()
        {
            var mongoServSettings = new MongoDB.Driver.MongoServerSettings();

            mongoServSettings.Server = new MongoDB.Driver.MongoServerAddress("localhost");

            var mongoServer = new MongoDB.Driver.MongoServer(mongoServSettings);

            mongoServer.Connect();

            var db = mongoServer.GetDatabase("monitera");

            var collection = db.GetCollection<db>("dbo.post");
            //collection.Insert(new db { gender = "m"});

            var pozitif = Query<db>.Where(f => f.sentimentid == 1);
            var notr = Query<db>.Where(f => f.sentimentid == 2);
            var negatif = Query<db>.Where(f => f.sentimentid == 3);
            var poznotr = Query<db>.Where(f => f.sentimentid == 4);
            var negnotr = Query<db>.Where(f => f.sentimentid == 5);

            var poz = collection.Count(pozitif);
            var no = collection.Count(notr);
            var ne = collection.Count(negatif);
            var pn = collection.Count(poznotr);
            var nn = collection.Count(negnotr);

            var oranlar = (new[]{
                                 new{
                                     Durum = "Pozitif",
                                     value = poz
                                 },

               new {
                Durum = "Nötr",
                value = no

            },
            new {
                Durum = "Negatif",
                value = ne

            },
            new {
                Durum = "Pozitif - Nötr",
                value = pn

            },
            new {
                Durum = "Negatif - Nötr",
                value = nn

            }
            }
            );

            return Json(oranlar, JsonRequestBehavior.AllowGet);
        }
開發者ID:modulexcite,項目名稱:dashboard-4,代碼行數:58,代碼來源:HomeController.cs

示例15: DatabaseManager

 public DatabaseManager()
 {
     // Bouwt een connection string
     MongoServerSettings settings = new MongoServerSettings();
     settings.Server = new MongoServerAddress("145.24.222.160", 8010);
     // Maakt een MongoDB server object, met dit object kunnen we communiceren met de server. Het maakt kortom verbinding met de mongodb server
     MongoServer server = new MongoServer(settings);
     // Vraagt onze database op van de server, zodat we read/write kunnen toepassen
     database = server.GetDatabase("Dataflow");
 }
開發者ID:swenmeeuwes,項目名稱:Project-5-Dataflow-ASP.NET-Webservice,代碼行數:10,代碼來源:DatabaseManager.cs


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