本文整理汇总了C#中MongoDB.Driver.MongoCredentials类的典型用法代码示例。如果您正苦于以下问题:C# MongoCredentials类的具体用法?C# MongoCredentials怎么用?C# MongoCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoCredentials类属于MongoDB.Driver命名空间,在下文中一共展示了MongoCredentials类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MongoServerSettings
public MongoServerSettings(
ConnectionMode connectionMode,
TimeSpan connectTimeout,
MongoCredentials defaultCredentials,
TimeSpan maxConnectionIdleTime,
TimeSpan maxConnectionLifeTime,
int maxConnectionPoolSize,
int minConnectionPoolSize,
string replicaSetName,
SafeMode safeMode,
IEnumerable<MongoServerAddress> servers,
bool slaveOk,
TimeSpan socketTimeout,
int waitQueueSize,
TimeSpan waitQueueTimeout
)
{
this.connectionMode = connectionMode;
this.connectTimeout = connectTimeout;
this.defaultCredentials = defaultCredentials;
this.maxConnectionIdleTime = maxConnectionIdleTime;
this.maxConnectionLifeTime = maxConnectionLifeTime;
this.maxConnectionPoolSize = maxConnectionPoolSize;
this.minConnectionPoolSize = minConnectionPoolSize;
this.replicaSetName = replicaSetName;
this.safeMode = safeMode;
this.servers = servers;
this.slaveOk = slaveOk;
this.socketTimeout = socketTimeout;
this.waitQueueSize = waitQueueSize;
this.waitQueueTimeout = waitQueueTimeout;
}
开发者ID:Teun,项目名称:mongo-csharp-driver,代码行数:32,代码来源:MongoServerSettings.cs
示例2: MongoDatabaseSettings
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
ReadPreference readPreference,
WriteConcern writeConcern)
{
if (databaseName == null)
{
throw new ArgumentNullException("databaseName");
}
if (databaseName == "admin" && credentials != null && !credentials.Admin)
{
throw new ArgumentOutOfRangeException("credentials", "Credentials for the admin database must have the admin flag set to true.");
}
if (readPreference == null)
{
throw new ArgumentNullException("readPreference");
}
if (writeConcern == null)
{
throw new ArgumentNullException("writeConcern");
}
_databaseName.Value = databaseName;
_credentials.Value = credentials;
_guidRepresentation.Value = guidRepresentation;
_readPreference.Value = readPreference;
_writeConcern.Value = writeConcern;
}
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:30,代码来源:MongoDatabaseSettings.cs
示例3: Main
static void Main(string[] args)
{
var server = MongoServer.Create("mongodb://localhost");
MongoDatabase test = server.GetDatabase("test");
MongoCredentials credentials = new MongoCredentials("username", "password");
MongoDatabase salaries = server.GetDatabase("salaries", credentials);
MongoCollection docs = test.GetCollection("docs");
docs.EnsureIndex("title");
Console.WriteLine("adding some test documents");
for (int x = 0; x < 1000; x++) {
BsonDocument doc = new BsonDocument();
doc.Add("title", "title: " + x);
doc.Add("body", "body: " + x);
docs.Insert(doc);
}
Console.WriteLine("querying");
foreach (var doc in docs.FindAllAs<BsonDocument>()) {
Console.WriteLine("doc: {0}", doc["body"]);
}
}
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:27,代码来源:_Main.cs
示例4: TestEquals
public void TestEquals()
{
var a = new MongoCredentials("user1", "password");
var b = new MongoCredentials("user1", "password");
var c = new MongoCredentials("user2", "password");
var n = (MongoCredentials)null;
Assert.IsTrue(object.Equals(a, b));
Assert.IsFalse(object.Equals(a, c));
Assert.IsFalse(a.Equals(n));
Assert.IsFalse(a.Equals(null));
Assert.IsTrue(a == b);
Assert.IsFalse(a == c);
Assert.IsFalse(a == null);
Assert.IsFalse(null == a);
Assert.IsTrue(n == null);
Assert.IsTrue(null == n);
Assert.IsFalse(a != b);
Assert.IsTrue(a != c);
Assert.IsTrue(a != null);
Assert.IsTrue(null != a);
Assert.IsFalse(n != null);
Assert.IsFalse(null != n);
}
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:26,代码来源:MongoCredentialTests.cs
示例5: MongoServerSettings
// constructors
/// <summary>
/// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead.
/// </summary>
public MongoServerSettings()
{
_connectionMode = ConnectionMode.Automatic;
_connectTimeout = MongoDefaults.ConnectTimeout;
_credentialsStore = new MongoCredentialsStore();
_defaultCredentials = null;
_guidRepresentation = MongoDefaults.GuidRepresentation;
_ipv6 = false;
_maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime;
_maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime;
_maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize;
_minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize;
_readPreference = ReadPreference.Primary;
_replicaSetName = null;
_secondaryAcceptableLatency = MongoDefaults.SecondaryAcceptableLatency;
_servers = new List<MongoServerAddress> { new MongoServerAddress("localhost") };
_socketTimeout = MongoDefaults.SocketTimeout;
_useSsl = false;
_verifySslCertificate = true;
_waitQueueSize = MongoDefaults.ComputedWaitQueueSize;
_waitQueueTimeout = MongoDefaults.WaitQueueTimeout;
#pragma warning disable 612, 618
_writeConcern = MongoDefaults.SafeMode.WriteConcern;
#pragma warning restore
}
开发者ID:tkellogg,项目名称:mongo-csharp-driver,代码行数:29,代码来源:MongoServerSettings.cs
示例6: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="readPreference">The read preference.</param>
/// <param name="safeMode">The safe mode to use.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
ReadPreference readPreference,
SafeMode safeMode)
{
if (databaseName == null)
{
throw new ArgumentNullException("databaseName");
}
if (databaseName == "admin" && credentials != null && !credentials.Admin)
{
throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true.");
}
if (readPreference == null)
{
throw new ArgumentNullException("readPreference");
}
if (safeMode == null)
{
throw new ArgumentNullException("safeMode");
}
_databaseName = databaseName;
_credentials = credentials;
_guidRepresentation = guidRepresentation;
_readPreference = readPreference;
_safeMode = safeMode;
}
开发者ID:nickgervasi,项目名称:mongo-csharp-driver,代码行数:38,代码来源:MongoDatabaseSettings.cs
示例7: CreatDataBase
static MongoDatabase CreatDataBase(string bdName, string userName, string userPw)
{
var mongoUrlBuilder = new MongoUrlBuilder("mongodb://localhost");
MongoServer server = MongoServer.Create(mongoUrlBuilder.ToMongoUrl());
MongoCredentials credentials = new MongoCredentials(userName, userPw);
MongoDatabase database = server.GetDatabase(bdName, credentials);
return database;
}
开发者ID:ilnur-slv,项目名称:-mvc3-_FanFictionDB,代码行数:8,代码来源:BookRepository.cs
示例8: MongoUser
/// <summary>
/// Creates a new instance of MongoUser.
/// </summary>
/// <param name="credentials">The user's credentials.</param>
/// <param name="isReadOnly">Whether the user has read-only access.</param>
public MongoUser(
MongoCredentials credentials,
bool isReadOnly
) {
this.username = credentials.Username;
this.passwordHash = HashPassword(credentials.Username, credentials.Password);
this.isReadOnly = isReadOnly;
}
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoUser.cs
示例9: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk)
{
_databaseName = databaseName;
_credentials = credentials;
_guidRepresentation = guidRepresentation;
_safeMode = safeMode;
_slaveOk = slaveOk;
}
开发者ID:moonreplace,项目名称:mongo-csharp-driver,代码行数:16,代码来源:MongoDatabaseSettings.cs
示例10: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, ReadPreference readPreference)
{
this.databaseName = databaseName;
this.credentials = credentials;
this.guidRepresentation = guidRepresentation;
this.safeMode = safeMode;
this.readPreference = readPreference;
}
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:16,代码来源:MongoDatabaseSettings.cs
示例11: AddUserToDB
/// <summary>
/// 添加用户
/// </summary>
/// <param name="strDBPath">数据库路径</param>
/// <param name="strUser">用户名</param>
/// <param name="password">密码</param>
/// <param name="isReadOnly">是否为只读</param>
public static void AddUserToDB(string strDBPath, string strUser, string password, bool isReadOnly)
{
MongoDatabase mongoDB = GetMongoDBBySvrPath(strDBPath);
MongoCredentials newUser = new MongoCredentials(strUser, password, false);
if (mongoDB.FindUser(strUser) == null)
{
mongoDB.AddUser(newUser,isReadOnly);
}
}
开发者ID:seaman,项目名称:MagicMongoDBTool,代码行数:16,代码来源:MongoDBHelper_Auth.cs
示例12: AddUserToDB
/// <summary>
/// Add User
/// </summary>
/// <param name="strUser">Username</param>
/// <param name="password">Password</param>
/// <param name="isReadOnly">Is ReadOnly</param>
public static void AddUserToDB(String strUser, String password, Boolean isReadOnly)
{
MongoDatabase mongoDB = SystemManager.GetCurrentDataBase();
MongoCredentials newUser = new MongoCredentials(strUser, password, false);
if (mongoDB.FindUser(strUser) == null)
{
mongoDB.AddUser(newUser, isReadOnly);
}
}
开发者ID:zwq194,项目名称:MagicMongoDBTool,代码行数:15,代码来源:MongoDBHelper_Opration_Other.cs
示例13: AddUserToSvr
/// <summary>
/// 添加User到Admin数据库[效果如同添加USER到整个服务器]
/// </summary>
/// <param name="strDBPath"></param>
/// <param name="strUser"></param>
/// <param name="password"></param>
/// <param name="isReadOnly"></param>
public static void AddUserToSvr(string strDBPath, string strUser, string password, bool isReadOnly)
{
MongoServer mongoSvr = SystemManager.GetCurrentService();
//必须使用MongoCredentials来添加用户不然的话,Password将使用明文登入到数据库中!
//这样的话,在使用MongoCredentials登入的时候,会发生密码错误引发的认证失败
MongoCredentials newUser = new MongoCredentials(strUser, password,true);
if (mongoSvr.AdminDatabase.FindUser(strUser) == null)
{
mongoSvr.AdminDatabase.AddUser(newUser,isReadOnly);
}
}
开发者ID:seaman,项目名称:MagicMongoDBTool,代码行数:18,代码来源:MongoDBHelper_Auth.cs
示例14: AddUserToSvr
//这里有个漏洞,对于数据库来说,对于local的验证和对于admin的验证是相同的。
//如果是加入用户到服务器中,是加入到local还是admin,需要考虑一下。
/// <summary>
/// Add A User to Admin database
/// </summary>
/// <param name="strUser">Username</param>
/// <param name="password">Password</param>
/// <param name="isReadOnly">Is ReadOnly</param>
public static void AddUserToSvr(String strUser, String password, Boolean isReadOnly)
{
MongoServer mongoSvr = SystemManager.GetCurrentServer();
//必须使用MongoCredentials来添加用户不然的话,Password将使用明文登入到数据库中!
//这样的话,在使用MongoCredentials登入的时候,会发生密码错误引发的认证失败
MongoCredentials newUser = new MongoCredentials(strUser, password, true);
if (mongoSvr.GetDatabase(DATABASE_NAME_ADMIN).FindUser(strUser) == null)
{
mongoSvr.GetDatabase(DATABASE_NAME_ADMIN).AddUser(newUser, isReadOnly);
}
}
开发者ID:zwq194,项目名称:MagicMongoDBTool,代码行数:19,代码来源:MongoDBHelper_Opration_Other.cs
示例15: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
SafeMode safeMode,
bool slaveOk
) {
this.databaseName = databaseName;
this.credentials = credentials;
this.safeMode = safeMode;
this.slaveOk = slaveOk;
}
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:18,代码来源:MongoDatabaseSettings.cs
示例16: TestCreateCredentials
public void TestCreateCredentials()
{
var credentials = new MongoCredentials("username", "password");
Assert.AreEqual("username", credentials.Username);
Assert.AreEqual("password", credentials.Password);
Assert.IsFalse(credentials.Admin);
credentials = new MongoCredentials("username", "password", false);
Assert.AreEqual("username", credentials.Username);
Assert.AreEqual("password", credentials.Password);
Assert.IsFalse(credentials.Admin);
}
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoCredentialTests.cs
示例17: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
SafeMode safeMode,
bool slaveOk
) {
this.databaseName = databaseName;
this.credentials = credentials;
this.guidRepresentation = guidRepresentation;
this.safeMode = safeMode;
this.slaveOk = slaveOk;
}
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:21,代码来源:MongoDatabaseSettings.cs
示例18: SimpleMongoDatabaseFactory
private SimpleMongoDatabaseFactory(MongoServer mongo, string databaseName, MongoCredentials credentials,
bool mongoInstanceCreated)
{
AssertUtils.ArgumentNotNull(mongo, "mongo");
AssertUtils.ArgumentHasText(databaseName, "databaseName");
AssertUtils.IsTrue(!Regex.IsMatch(databaseName, @"[^A-Za-z0-9-_]+"),
"Database name must only contain letters, numbers, underscores and dashes!");
_mongo = mongo;
_databaseName = databaseName;
_mongoInstanceCreated = mongoInstanceCreated;
_credentials = credentials;
}
开发者ID:thomast74,项目名称:spring-net-data-mongodb,代码行数:13,代码来源:SimpleMongoDatabaseFactory.cs
示例19: MongoConfig
public MongoConfig()
{
MongoConfigSection mongoSection = (MongoConfigSection)ConfigurationManager.GetSection(MongoConfigSection.DefaultSectionName);
MongoServerSettings settings = new MongoServerSettings();
settings.ConnectionMode = ConnectionMode.Direct;
settings.Server = new MongoServerAddress(mongoSection.Host, mongoSection.Port);
MongoCredentials credential = new MongoCredentials(mongoSection.UserName, mongoSection.Password);
settings.DefaultCredentials = credential;
settings.SafeMode = SafeMode.True;
settings.SlaveOk = true;
MongoServer mongoSvr = MongoServer.Create(settings);
MongoDatabase = mongoSvr.GetDatabase(mongoSection.Database);
}
开发者ID:BonaStoco,项目名称:AP2,代码行数:14,代码来源:MongoConfig.cs
示例20: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
SafeMode safeMode,
bool slaveOk)
{
if (databaseName == "admin" && credentials != null && !credentials.Admin)
{
throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true.");
}
_databaseName = databaseName;
_credentials = credentials;
_guidRepresentation = guidRepresentation;
_safeMode = safeMode;
_slaveOk = slaveOk;
}
开发者ID:abel,项目名称:sinan,代码行数:25,代码来源:MongoDatabaseSettings.cs
注:本文中的MongoDB.Driver.MongoCredentials类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论