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

C# MongoServerAddress类代码示例

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

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



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

示例1: 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


示例2: 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(false, settings.UseSsl);
            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:nickgervasi,项目名称:mongo-csharp-driver,代码行数:35,代码来源:MongoServerSettingsTests.cs


示例3: TestEquals

        public void TestEquals()
        {
            var a = new MongoServerAddress("host1");
            var b = new MongoServerAddress("host1");
            var c = new MongoServerAddress("host2");
            var n = (MongoServerAddress)null;

            Assert.True(object.Equals(a, b));
            Assert.False(object.Equals(a, c));
            Assert.False(a.Equals(n));
            Assert.False(a.Equals(null));

            Assert.True(a == b);
            Assert.False(a == c);
            Assert.False(a == null);
            Assert.False(null == a);
            Assert.True(n == null);
            Assert.True(null == n);

            Assert.False(a != b);
            Assert.True(a != c);
            Assert.True(a != null);
            Assert.True(null != a);
            Assert.False(n != null);
            Assert.False(null != n);
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:26,代码来源:MongoServerAddressTests.cs


示例4: 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


示例5: 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


示例6: 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


示例7: GetMongoSvrAddrByConnectionName

		/// <summary>
		///     通过连接名称获得Host信息
		/// </summary>
		/// <param name="ConnectionName"></param>
		/// <returns></returns>
		public static MongoServerAddress GetMongoSvrAddrByConnectionName(String ConnectionName)
		{
			MongoServerAddress mongosrvAddr = null;
			if (SystemManager.config.ConnectionList.ContainsKey(ConnectionName)) {
				mongosrvAddr = new MongoServerAddress(SystemManager.config.ConnectionList[ConnectionName].Host,
					SystemManager.config.ConnectionList[ConnectionName].Port);
			}
			return mongosrvAddr;
		}
开发者ID:jango2015,项目名称:MongoCola,代码行数:14,代码来源:ConfigHelper.cs


示例8: PrimaryIsAtAddress

 public void PrimaryIsAtAddress(MongoServerAddress address)
 {
     Config.Out.WriteLine("Forcing primary to be at address {0}.", address);
     Util.Timeout(TimeSpan.FromMinutes(5),
         string.Format("Unable to make member at address {0} primary.", address),
         TimeSpan.FromSeconds(10),
         remaining => TryMakePrimaryAtAddress(address));
     Config.Out.WriteLine("Primary is at address {0}.", address);
 }
开发者ID:craiggwilson,项目名称:mongo-dotnet-automation,代码行数:9,代码来源:ReplicaSetController.cs


示例9: MongoServerInstance

        private MongoServerState state; // always use property to set value so event gets raised
        #endregion

        #region constructors
        internal MongoServerInstance(
            MongoServer server,
            MongoServerAddress address
        ) {
            this.server = server;
            this.address = address;
            this.maxDocumentSize = MongoDefaults.MaxDocumentSize;
            this.maxMessageLength = MongoDefaults.MaxMessageLength;
            this.state = MongoServerState.Disconnected;
        }
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoServerInstance.cs


示例10: MongoServerInstance

        private MongoServerState _state; // always use property to set value so event gets raised

        // constructors
        internal MongoServerInstance(MongoServer server, MongoServerAddress address)
        {
            _server = server;
            _address = address;
            _sequentialId = Interlocked.Increment(ref __nextSequentialId);
            _maxDocumentSize = MongoDefaults.MaxDocumentSize;
            _maxMessageLength = MongoDefaults.MaxMessageLength;
            _state = MongoServerState.Disconnected;
            _connectionPool = new MongoConnectionPool(this);
            // Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);
        }
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoServerInstance.cs


示例11: MongoServerInstance

 // constructors
 internal MongoServerInstance(MongoServer server, MongoServerAddress address)
 {
     this.server = server;
     this.address = address;
     this.sequentialId = Interlocked.Increment(ref nextSequentialId);
     this.maxDocumentSize = MongoDefaults.MaxDocumentSize;
     this.maxMessageLength = MongoDefaults.MaxMessageLength;
     this.state = MongoServerState.Disconnected;
     this.connectionPool = new MongoConnectionPool(this);
     this.tags = new HashSet<string>();
     // Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);
 }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoServerInstance.cs


示例12: GetCollection

        private IMongoCollection<Task> GetCollection() {
            var mongoCredential = MongoCredential.CreateMongoCRCredential(databaseName, mongoToken.Key, mongoToken.Secret);
            var serverAddress = new MongoServerAddress(serverName, serverPort);

            var mongoClientSettings = new MongoClientSettings {
                Credentials = new[] { mongoCredential },
                Server = serverAddress
            };

            var client = new MongoClient(mongoClientSettings);
            var database = client.GetDatabase(databaseName);
            var collection = database.GetCollection<Task>(collectionName);
            return collection;
        }
开发者ID:slieser,项目名称:sandbox2,代码行数:14,代码来源:TaskStore.cs


示例13: GetDB

        public MongoDatabase GetDB()
        {
            MongoServerAddress address = new MongoServerAddress("127.0.0.1", 27017);

            MongoServerSettings settings = new MongoServerSettings();

            settings.Server = address;

            MongoServer server = new MongoServer(settings);

            MongoDatabase myDB = server.GetDatabase("MyDB");

            return myDB;
        }
开发者ID:hktangudu,项目名称:MongoCSharp,代码行数:14,代码来源:MongoRep.cs


示例14: MongoServerInstance

 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoServerInstance"/> class.
 /// </summary>
 /// <param name="server">The server.</param>
 /// <param name="address">The address.</param>
 internal MongoServerInstance(MongoServer server, MongoServerAddress address)
 {
     _server = server;
     _address = address;
     _sequentialId = Interlocked.Increment(ref __nextSequentialId);
     _state = MongoServerState.Disconnected;
     _stateInfo = new ServerInformation
     {
         MaxDocumentSize = MongoDefaults.MaxDocumentSize,
         MaxMessageLength = MongoDefaults.MaxMessageLength,
         InstanceType = MongoServerInstanceType.Unknown
     };
     _connectionPool = new MongoConnectionPool(this);
     _pingTimeAggregator = new PingTimeAggregator(5);
     // Console.WriteLine("MongoServerInstance[{0}]: {1}", sequentialId, address);
 }
开发者ID:titolarz,项目名称:mongo-csharp-driver,代码行数:22,代码来源:MongoServerInstance.cs


示例15: GetReplicaSetConnectionUri

 public static MongoUrlBuilder GetReplicaSetConnectionUri()
 {
     var connection = new MongoUrlBuilder();
     // TODO - Should only have 1 setting across both roles
     var replicaSetName = RoleEnvironment.GetConfigurationSettingValue(ReplicaSetNameSetting);
     connection.ReplicaSetName = replicaSetName;
     int replicaSetRoleCount = RoleEnvironment.Roles[MongoDBHelper.MongoRoleName].Instances.Count;
     var servers = new List<MongoServerAddress>();
     foreach (var instance in RoleEnvironment.Roles[MongoDBHelper.MongoRoleName].Instances)
     {
         var endpoint = instance.InstanceEndpoints[MongoDBHelper.MongodPortKey].IPEndpoint;
         int instanceId = ParseNodeInstanceId(instance.Id);
         var server = new MongoServerAddress(
             endpoint.Address.ToString(),
             (RoleEnvironment.IsEmulated ? endpoint.Port + instanceId : endpoint.Port)
             );
         servers.Add(server);
     }
     connection.Servers = servers;
     return connection;
 }
开发者ID:sridharn,项目名称:mongoazureplicaset,代码行数:21,代码来源:MongoDBHelper.cs


示例16: SetConnection

        public ApiResponse SetConnection(ConnectionModel model)
        {
            var builder = new MongoUrlBuilder();
            var server = new MongoServerAddress(model.Server, model.Port ?? 27017);
            builder.Server = server;

            var url = builder.ToMongoUrl();

            try
            {
                var conn = MongoServer.Create(url);
                conn.Connect();
                conn.Disconnect();
            }
            catch
            {
                return new ApiResponse(false, string.Format("Connection to {0} failed.", url));
            }

            HttpContext.Current.Response.Cookies.Add(new HttpCookie("Mongo.Manager.Connection", url.ToString()));
            return new ApiResponse();
        }
开发者ID:bgertonson,项目名称:mongo-manager,代码行数:22,代码来源:ConnectionService.cs


示例17: Main

 static void Main(string[] args)
 {
     var mongoServerAddress = new MongoServerAddress("127.0.0.1", 27017);
     var mongoServerSettings = new MongoServerSettings();
     mongoServerSettings.Server = mongoServerAddress;
     var mongoServer = new MongoServer(mongoServerSettings);
     mongoServer.Connect();
     IEnumerable<string> databases = mongoServer.GetDatabaseNames();
     var mongoDatabase = mongoServer.GetDatabase("classfrogdb");
     var classCollection = mongoDatabase.GetCollection("classes");
     classCollection.RemoveAll();
     var documents = classCollection.FindAll();
     ClassInstance instance = new ClassInstance();
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     mongoServer.Disconnect();
 }
开发者ID:nirmalclassfrog,项目名称:classfrog,代码行数:24,代码来源:Program.cs


示例18: GetMongoSvrAddrByConnectionName

 /// <summary>
 /// 通过连接名称获得Host信息
 /// </summary>
 /// <param name="ConnectionName"></param>
 /// <returns></returns>
 public MongoServerAddress GetMongoSvrAddrByConnectionName(String ConnectionName)
 {
     MongoServerAddress mongosrvAddr = null;
     if (ConnectionList.ContainsKey(ConnectionName))
     {
         mongosrvAddr = new MongoServerAddress(ConnectionList[ConnectionName].IpAddr, ConnectionList[ConnectionName].Port);
     }
     return mongosrvAddr;
 }
开发者ID:seaman,项目名称:MagicMongoDBTool,代码行数:14,代码来源:ConfigHelper.cs


示例19: TestConstructor_with_host_and_port

 public void TestConstructor_with_host_and_port(string host, int port)
 {
     var address = new MongoServerAddress(host, port);
     Assert.Equal(host, address.Host);
     Assert.Equal(port, address.Port);
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:6,代码来源:MongoServerAddressTests.cs


示例20: TestConstructor_with_host

 public void TestConstructor_with_host(string host)
 {
     var address = new MongoServerAddress(host);
     Assert.Equal(host, address.Host);
     Assert.Equal(27017, address.Port);
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:6,代码来源:MongoServerAddressTests.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# MongoServerInstance类代码示例发布时间:2022-05-24
下一篇:
C# MongoServer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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