當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.MongoCredentials類代碼示例

本文整理匯總了C#中MongoDB.Driver.MongoCredentials的典型用法代碼示例。如果您正苦於以下問題:C# MongoCredentials類的具體用法?C# MongoCredentials怎麽用?C# MongoCredentials使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MongoCredentials類屬於MongoDB.Driver命名空間,在下文中一共展示了MongoCredentials類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的MongoDB.Driver.MongoCredentials類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。