• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Driver.MongoServerSettings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoDB.Driver.MongoServerSettings的典型用法代码示例。如果您正苦于以下问题:C# MongoServerSettings类的具体用法?C# MongoServerSettings怎么用?C# MongoServerSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoServerSettings类属于MongoDB.Driver命名空间,在下文中一共展示了MongoServerSettings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TestApplicationName_too_long

        public void TestApplicationName_too_long()
        {
            var subject = new MongoServerSettings();
            var value = new string('x', 129);

            var exception = Record.Exception(() => subject.ApplicationName = value);

            var argumentException = exception.Should().BeOfType<ArgumentException>().Subject;
            argumentException.ParamName.Should().Be("value");
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:MongoServerSettingsTests.cs


示例17: Db

 public static MongoDatabase Db()
 {
     // Create server settings to pass connection string, timeout, etc.
     MongoServerSettings settings = new MongoServerSettings();
     settings.Server = new MongoServerAddress("localhost", 27017);
     // Create server object to communicate with our server
     MongoServer server = new MongoServer(settings);
     // Get our database instance to reach collections and data
     var database = server.GetDatabase("shouter");
     return database;
 }
开发者ID:galbarello,项目名称:Shouter,代码行数:11,代码来源:DBConnection.cs


示例18: TestCreateMongoServerSettings

 public void TestCreateMongoServerSettings()
 {
     var settings = new MongoServerSettings
     {
         Server = new MongoServerAddress("localhost"),
         SafeMode = SafeMode.True
     };
     var server1 = MongoServer.Create(settings);
     var server2 = MongoServer.Create(settings);
     Assert.AreSame(server1, server2);
     Assert.AreEqual(settings, server1.Settings);
 }
开发者ID:nuknuk,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoServerTests.cs


示例19: NewBlockShouldBe1SpecificConstructor

        public void NewBlockShouldBe1SpecificConstructor()
        {
            MongoServerSettings settings = new MongoServerSettings();
            settings.Server = new MongoServerAddress("localhost");

            MongoOptimisticDataStore ds = new MongoOptimisticDataStore(settings, "SnowMaker", "IntegrationTests");

            Assert.NotNull(ds);

            Guid blockName = Guid.NewGuid();

            Assert.AreEqual("1", ds.GetData(blockName.ToString()));
        }
开发者ID:cyberprune,项目名称:SnowMaker,代码行数:13,代码来源:MongoDbTests.cs


示例20: TestConnectTimeout

        public void TestConnectTimeout()
        {
            var settings = new MongoServerSettings();
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);

            var connectTimeout = new TimeSpan(1, 2, 3);
            settings.ConnectTimeout = connectTimeout;
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);

            settings.Freeze();
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);
            Assert.Throws<InvalidOperationException>(() => { settings.ConnectTimeout = connectTimeout; });
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoServerSettingsTests.cs



注:本文中的MongoDB.Driver.MongoServerSettings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Driver.MongoUrl类代码示例发布时间:2022-05-26
下一篇:
C# Driver.MongoInsertOptions类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap