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


C# MongoUrlBuilder.ToMongoUrl方法代碼示例

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


在下文中一共展示了MongoUrlBuilder.ToMongoUrl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: JobStore

        /// <summary>
        /// Initializes a new instance of the <see cref="JobStore"/> class.
        /// </summary>
        public JobStore()
        {
            log = LogManager.GetLogger(GetType());

            string connectionString;

            if( ConfigurationManager.ConnectionStrings["quartznet-mongodb"] != null )
                connectionString = ConfigurationManager.ConnectionStrings["quartznet-mongodb"].ConnectionString;
            else
                connectionString = DefaultConnectionString;

            //
            // If there is no connection string to use then throw an 
            // exception to abort construction.
            //

            if (string.IsNullOrWhiteSpace(connectionString))
                throw new ApplicationException("Connection string is missing for the MongoDB job store.");

            lock (lockObject)
            {
                var urlBuilder = new MongoUrlBuilder(connectionString);
                var client = new MongoClient(urlBuilder.ToMongoUrl());
                this.database = client.GetServer().GetDatabase(urlBuilder.DatabaseName);
            }
        }
開發者ID:Jiangew,項目名稱:quartz.net-mongodb,代碼行數:29,代碼來源:JobStore.cs

示例2: InitiateDatabase

 private void InitiateDatabase()
 {
     var connectionString = ConfigurationManager.ConnectionStrings["Mongo.ConnectionString"].ConnectionString;
     var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
     mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
     Database = mongoClient.GetDatabase(mongoUrlBuilder.DatabaseName);
 }
開發者ID:tareq89,項目名稱:TaskCat,代碼行數:7,代碼來源:DbContext.cs

示例3: MongoUriConstructor

        public void MongoUriConstructor()
        {
            var uriBuilder = new MongoUrlBuilder("mongodb://myUsername:[email protected]/myDatabase");
            IMongoDatabaseFactory mongoDbFactory = new SimpleMongoDatabaseFactory(uriBuilder.ToMongoUrl());

            Assert.That(ReflectionUtils.GetInstanceFieldValue(mongoDbFactory, "_credentials"), Is.EqualTo(new MongoCredentials("myUsername", "myPassword")));
            Assert.That(ReflectionUtils.GetInstanceFieldValue(mongoDbFactory, "_databaseName").ToString(), Is.EqualTo("myDatabase"));
        }
開發者ID:thomast74,項目名稱:spring-net-data-mongodb,代碼行數:8,代碼來源:SimpleMongoDbFactoryTests.cs

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

示例5: MongoEventStore

        public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
        {
            _eventHashRef = new Dictionary<string, string>();
            typeCatalog.GetDerivedTypes(typeof(DomainEvent)).ToList().
                ForEach(x => BsonClassMap.RegisterClassMap(new DomainEventMapper(x, _eventHashRef)));

            var connection = new MongoUrlBuilder(connectionString);
            _collection = MongoServer.Create(connection.ToMongoUrl()).GetDatabase(connection.DatabaseName).GetCollection<DomainEvent>("events");
        }
開發者ID:brianwigfield,項目名稱:SimpleCQRS,代碼行數:9,代碼來源:MongoEventStore.cs

示例6: GetDatabase

        private static MongoDatabase GetDatabase()
        {
            var testDbConnStrBuilder = new MongoUrlBuilder("mongodb://localhost/Guid-vs-ObjectId?safe=true");
            var connectionString = testDbConnStrBuilder.ToMongoUrl();
            var client = new MongoClient(connectionString);
            var mongoDatabase = client.GetServer().GetDatabase(connectionString.DatabaseName);

            mongoDatabase.SetProfilingLevel(ProfilingLevel.All);
            return mongoDatabase;
        }
開發者ID:Restuta,項目名稱:mongo.Guid-vs-ObjectId-performance,代碼行數:10,代碼來源:Program.cs

示例7: Init

		public void Init()
		{
			var connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
			var connectionStringBuilder = new MongoUrlBuilder(connectionString);

			var mongoClient = new MongoClient(connectionStringBuilder.ToMongoUrl());

			_server = mongoClient.GetServer();
			
			var dbName = connectionStringBuilder.DatabaseName;

			_db = _server.GetDatabase(dbName);
		}
開發者ID:cihanozhan,項目名稱:NLog.MongoDB,代碼行數:13,代碼來源:IntegrationTests.cs

示例8: Initialize

        public async Task<bool> Initialize(JryVideoDataSourceProviderManagerMode mode)
        {
            var builder = new MongoUrlBuilder();

            builder.Server = MongoServerAddress.Parse("127.0.0.1:50710");
            builder.DatabaseName = "admin";

            builder.Username = "conanvista";
            builder.Password = "LVpMQhAt31hli8Uiq2Ir";

            this.Client = new MongoClient(builder.ToMongoUrl());

            this.Database = this.Client.GetDatabase("JryVideo_" + mode.ToString());

            return true;
        }
開發者ID:gitter-badger,項目名稱:JRYVideo,代碼行數:16,代碼來源:JryVideoMongoDbDataSourceSetProvider.cs

示例9: TestClone

        public void TestClone()
        {
            // set everything to non default values to test that all settings are cloned
            var connectionString =
                "mongodb://user1:[email protected]/?" +
                "connect=direct;connectTimeout=123;uuidRepresentation=pythonLegacy;ipv6=true;" +
                "maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;" +
                "readPreference=secondary;readPreferenceTags=a:1,b:2;readPreferenceTags=c:3,d:4;secondaryAcceptableLatency=128;socketTimeout=129;" +
                "ssl=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
                "fireAndForget=false;fsync=true;journal=true;w=2;wtimeout=131";
            var builder = new MongoUrlBuilder(connectionString);
            var url = builder.ToMongoUrl();
            var settings = MongoClientSettings.FromUrl(url);

            var clone = settings.Clone();
            Assert.AreEqual(settings, clone);
        }
開發者ID:subbuballa,項目名稱:mongo-csharp-driver,代碼行數:17,代碼來源:MongoClientSettingsTests.cs

示例10: Setup

        public void Setup()
        {
            _runner = MongoDbRunner.Start();
            var mongoUrlBuilder = new MongoUrlBuilder(_runner.ConnectionString);
            mongoUrlBuilder.DatabaseName = "AutomatedTest";

            //setup mongo database
            var client = new MongoClient(mongoUrlBuilder.ToMongoUrl());
            Database = client.GetDatabase(mongoUrlBuilder.DatabaseName);
            Collection = Database.GetCollection<RootEntity>("Root");
            ContainsNotProvidedTagsEntityId = ObjectId.GenerateNewId();
            SubEntityId = ObjectId.GenerateNewId();

            //add mock data
            var entities = new List<RootEntity>()
            {
                new RootEntity()
                {
                    Id = ObjectId.GenerateNewId(),
                    Tags = new List<string>() {"tag1"},
                    SubCollection = new List<SubEntity>()
                    {
                        new SubEntity()
                        {
                            Id = SubEntityId
                        }
                    }
                },
                new RootEntity()
                {
                    Id = ContainsNotProvidedTagsEntityId,
                    Tags = new List<string>() {"tag1", "tag2"},
                    SubCollection = new List<SubEntity>()
                    {
                        new SubEntity()
                        {
                            Id = SubEntityId
                        }
                    }
                }
            };
            Collection.InsertManyAsync(entities).Wait();
        }
開發者ID:nickmkk,項目名稱:UpdateWhereItemsArentInProvidedList,代碼行數:43,代碼來源:RemoveSubEntityServiceTests.cs

示例11: Main

        public static void Main(string[] args)
        {
            var definition = Configuration.Configure<CmdLine>();
            CmdLine cmdLine = null;

            try
            {
                cmdLine = definition.CreateAndBind(args);
            }
            catch (InvalidOperationException)
            {
                ShowHelp(definition);
                Environment.Exit(0);
            }

            if (cmdLine.ShowHelp || !cmdLine.IsValid())
            {
                ShowHelp(definition);
                Environment.Exit(0);
            }

            var mongoUrlBuilder = new MongoUrlBuilder
            {
                DatabaseName = cmdLine.Database,
                ConnectTimeout = TimeSpan.FromSeconds(30),
                Server = new MongoServerAddress(cmdLine.DatabaseHost, cmdLine.DatabasePort),
            };

            var scriptRunner = new MongoScriptRunner(cmdLine.MongoClient, mongoUrlBuilder.ToMongoUrl());

            if (cmdLine.DryRun)
            {
                System.Console.Out.WriteLine("*** Dry run - nothing is executed.");
            }

            var consoleInteraction = (cmdLine.DryRun)
                ? (IUserInteraction)new DryRunConsoleInteraction()
                : new InteractiveConsoleInteraction();

            Synchronize(scriptRunner, consoleInteraction, cmdLine, mongoUrlBuilder);
        }
開發者ID:kahlin,項目名稱:mongomigrations,代碼行數:41,代碼來源:Main.cs

示例12: Initialize

        public Task<bool> Initialize(JryVideoDataSourceProviderManagerMode mode)
        {
            if (!Enum.IsDefined(typeof(JryVideoDataSourceProviderManagerMode), mode))
                throw new ArgumentOutOfRangeException(nameof(mode));

            this.Mode = mode;

            var builder = new MongoUrlBuilder();

            builder.Server = MongoServerAddress.Parse("127.0.0.1:50710");
            builder.DatabaseName = "admin";

            builder.Username = "conanvista";
            builder.Password = "LVpMQhAt31hli8Uiq2Ir";

            this.Client = new MongoClient(builder.ToMongoUrl());

            this.Database = this.Client.GetDatabase("JryVideo_" + mode.ToString());

            return Task.FromResult(true);
        }
開發者ID:Cologler,項目名稱:JRYVideo,代碼行數:21,代碼來源:JryVideoMongoDbDataSourceSetProvider.cs

示例13: TestClone

        public void TestClone()
        {
            // set everything to non default values to test that all settings are cloned
            var connectionString =
                "mongodb://user1:[email protected]/?" +
                "connect=direct;connectTimeout=123;uuidRepresentation=pythonLegacy;ipv6=true;" +
                "maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;" +
                "readPreference=secondary;readPreferenceTags=a:1,b:2;readPreferenceTags=c:3,d:4;secondaryAcceptableLatency=128;socketTimeout=129;" +
                "ssl=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
                "w=1;fsync=true;journal=true;w=2;wtimeout=131;gssapiServiceName=other";
            var builder = new MongoUrlBuilder(connectionString);
            var url = builder.ToMongoUrl();
            var settings = MongoClientSettings.FromUrl(url);

            // a few settings can only be made in code
            settings.Credentials = new[] { MongoCredential.CreateMongoCRCredential("database", "username", "password").WithMechanismProperty("SERVICE_NAME", "other") };
            settings.SslSettings = new SslSettings { CheckCertificateRevocation = false };

            var clone = settings.Clone();
            Assert.AreEqual(settings, clone);
        }
開發者ID:Nakro,項目名稱:mongo-csharp-driver,代碼行數:21,代碼來源:MongoClientSettingsTests.cs

示例14: MongoContext

        public MongoContext()
        {
            var pack = new ConventionPack()
            {
                new CamelCaseElementNameConvention(),
                new EnumRepresentationConvention(BsonType.String)
            };

            ConventionRegistry.Register("CamelCaseConvensions", pack, t => true);

            var mongoUrlBuilder = new MongoUrlBuilder(ConfigurationManager.ConnectionStrings["AuthContext"].ConnectionString);

            var mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
            var server = mongoClient.GetServer();

            Database = server.GetDatabase(mongoUrlBuilder.DatabaseName);

            userCollection = Database.GetCollection<User>("users");
            roleCollection = Database.GetCollection<Role>("roles");
            clientCollection = Database.GetCollection<Client>("clients");
            refreshTokenCollection = Database.GetCollection<RefreshToken>("refreshTokens");
        }
開發者ID:AnilAwadh,項目名稱:AngularJSAuthentication,代碼行數:22,代碼來源:MongoContext.cs

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


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