本文整理汇总了C#中MongoServerAddress类的典型用法代码示例。如果您正苦于以下问题:C# MongoServerAddress类的具体用法?C# MongoServerAddress怎么用?C# MongoServerAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoServerAddress类属于命名空间,在下文中一共展示了MongoServerAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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());
}
示例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);
}
示例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)
};
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}