本文整理汇总了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());
}
示例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);
}
示例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
}
示例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);
}
}
示例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);
}
示例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;
}
示例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));
}
示例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)
};
}
示例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());
}
示例10: MongoOptimisticDataStore
public MongoOptimisticDataStore(MongoServerSettings settings, string databaseName, string collectionName)
{
this.ServerSettings = settings;
this.DatabaseName = databaseName;
this.CollectionName = collectionName;
this.IsConnected = false;
}
示例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);
}
示例12: MongoRepository
public MongoRepository(
MongoServerSettings settings,
string database)
{
_Server = new MongoServer(settings);
_Database = database;
_Server.Connect();
}
示例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;
}
示例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);
}
示例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");
}