当前位置: 首页>>代码示例>>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;未经允许,请勿转载。