• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Driver.MongoUrl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoDB.Driver.MongoUrl的典型用法代码示例。如果您正苦于以下问题:C# MongoUrl类的具体用法?C# MongoUrl怎么用?C# MongoUrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoUrl类属于MongoDB.Driver命名空间,在下文中一共展示了MongoUrl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestOneIPv6AddressWithPort

 public void TestOneIPv6AddressWithPort()
 {
     var connectionString = "mongodb://[::1:]:1234/?w=1";
     var url = new MongoUrl(connectionString);
     Assert.AreEqual("[::1:]", url.Server.Host);
     Assert.AreEqual(1234, url.Server.Port);
 }
开发者ID:bollinim,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp346Tests.cs


示例2: MongoRepository

 public MongoRepository(MongoUrl mongoUrl, string databaseName)
 {
     _client = new MongoClient(mongoUrl);
     _server = _client.GetServer();
     _database = databaseName;
     _server.Connect();
 }
开发者ID:WuLex,项目名称:PerformanceCounterCollect,代码行数:7,代码来源:MongoRepository.cs


示例3: DropDatabaseTask

 public DropDatabaseTask(IAppConfig appConfig)
 {
     var url = new MongoUrl(appConfig.ProxyDbConnectionString);
     _mongoDatabase = new MongoClient(url)
         .GetServer()
         .GetDatabase(url.DatabaseName);
 }
开发者ID:ryanande,项目名称:ApiProxy,代码行数:7,代码来源:DropDatabaseTask.cs


示例4: MongoGateway

 public MongoGateway(string mongoConnectionString)
 {
     var mongoUrl = new MongoUrl(mongoConnectionString);
     var client = new MongoClient(mongoConnectionString); 
     _dataBase = client.GetDatabase(mongoUrl.DatabaseName);
     CreateIndex();
 }
开发者ID:anktsrkr,项目名称:MongoMembership,代码行数:7,代码来源:MongoGateway.cs


示例5: PurgeOrphanedBlobs

        private static void PurgeOrphanedBlobs(HashSet<String> blobsToDelete, String connectionString, String format)
        {
            Console.WriteLine("Found {0} orphaned blobs in BlobStorage named {1}", blobsToDelete.Count, format);
            if (blobsToDelete.Count > 0)
            {
                Console.WriteLine("Press y if you want to delete them, any other key to list without deletion");
                var key = Console.ReadKey();
                Console.WriteLine();
                if (Char.ToLower(key.KeyChar) == 'y')
                {
                    var uri = new MongoUrl(ConfigurationManager.AppSettings[connectionString]);
                    var client = new MongoClient(uri);

                    var database = client.GetServer().GetDatabase(uri.DatabaseName);
                    var settings = new MongoGridFSSettings()
                    {
                        Root = format
                    };
                    var gridfs = database.GetGridFS(settings);
                    foreach (var blobToDelete in blobsToDelete)
                    {
                        gridfs.DeleteById(blobToDelete);
                        Console.WriteLine("Deleted {0} in database {1}", blobToDelete, ConfigurationManager.AppSettings[connectionString]);
                    }
                }
                else
                {
                    foreach (var blobToDelete in blobsToDelete)
                    {
                        Console.WriteLine("Blob {0} in database {1} is orphaned", blobToDelete, ConfigurationManager.AppSettings[connectionString]);
                    }
                }
            }

        }
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:35,代码来源:CheckOrphanedBlobs.cs


示例6: SetUp

 public void SetUp()
 {
     var url = new MongoUrl(ConnectionString);
     var server = MongoServer.Create(url);
     var database = server.GetDatabase(url.DatabaseName);
     database.Drop();
 }
开发者ID:cdmckay,项目名称:mongodb-aspnet-providers,代码行数:7,代码来源:TestProfileProvider.cs


示例7: GetDatabase

 public static MongoDatabase GetDatabase(string cstringName)
 {
     var cstring = ConfigurationManager.ConnectionStrings[cstringName].ConnectionString;
     var mongoUrl = new MongoUrl(cstring);
     var server = new MongoClient(mongoUrl).GetServer();
     return server.GetDatabase(mongoUrl.DatabaseName, new MongoDatabaseSettings());
 }
开发者ID:barissonmez,项目名称:nes-training,代码行数:7,代码来源:MongoHelper.cs


示例8: Initialize

 public void Initialize(string connectionString)
 {
   var mongoUrl = new MongoUrl( connectionString );
   var client = new MongoClient( mongoUrl );
   _server = client.GetServer();
   _database = _server.GetDatabase( mongoUrl.DatabaseName );
 }
开发者ID:Epstone,项目名称:CentralLog.Net,代码行数:7,代码来源:JobRepository.cs


示例9: ConfigureDatabase

 private static void ConfigureDatabase(string connection_string)
 {
     var url = new MongoUrl(connection_string);
     var client = new MongoClient(url);
     var server = client.GetServer();
     Configuration.Database = server.GetDatabase(url.DatabaseName);
 }
开发者ID:rashid-siddiqui,项目名称:Reader,代码行数:7,代码来源:Configuration.cs


示例10: BaseController

 protected BaseController()
 {
     var url = new MongoUrl(ConnectionString());
     var client = new MongoClient(url);
     var server = client.GetServer();
     _mongoDatabase = server.GetDatabase(url.DatabaseName);
 }
开发者ID:pmprete,项目名称:dondeducar,代码行数:7,代码来源:BaseController.cs


示例11: MongoDBSink

 /// <summary>
 /// Construct a sink posting to the specified database.
 /// </summary>
 /// <param name="databaseUrl">The URL of a CouchDB database.</param>
 /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
 /// <param name="period">The time to wait between checking for event batches.</param>
 /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
 public MongoDBSink(string databaseUrl, int batchPostingLimit, TimeSpan period, IFormatProvider formatProvider)
     : base(batchPostingLimit, period)
 {
     if (databaseUrl == null) throw new ArgumentNullException("databaseUrl");
     _formatProvider = formatProvider;
     _mongoUrl = new MongoUrl(databaseUrl);
 }
开发者ID:nicholaspei,项目名称:serilog,代码行数:14,代码来源:MongoDBSink.cs


示例12: Install

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var logUrl = new MongoUrl(_config.LogsConnectionString);
            var logDb = new MongoClient(logUrl).GetDatabase(logUrl.DatabaseName);
          
               
            container.Register(
                 Component
                    .For<IMessagesTracker>()
                    .ImplementedBy<MongoDbMessagesTracker>()
                    .DependsOn(Dependency.OnValue<IMongoDatabase>(logDb)),
                Component
                    .For<ICommandBus, IInProcessCommandBus>()
                    .ImplementedBy<DocumentStoreMultiTenantCommandBus>()
                );

            container.Register(
                Component
                    .For<IDocumentFormatTranslator>()
                    .ImplementedBy<StandardDocumentFormatTranslator>(),
                Component
                    .For<DocumentDescriptor>()
                    .LifestyleCustom(typeof(TransientNotTrackingLifestyle))
            );
        }
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:25,代码来源:CoreInstaller.cs


示例13: MongoStationRepository

 public MongoStationRepository(String connectionString)
 {
     var url = new MongoUrl(connectionString);
     var client = new MongoClient(connectionString);
     var server = client.GetServer();
     database = server.GetDatabase(url.DatabaseName);
 }
开发者ID:305088020,项目名称:ChART,代码行数:7,代码来源:MongoStationRepository.cs


示例14: MongoLogger

        public MongoLogger() {
            var mongoUrl = new MongoUrl(ConfigurationManager.ConnectionStrings["LogDB"].ConnectionString);
            var client = new MongoClient(mongoUrl);
            var database = client.GetServer().GetDatabase(mongoUrl.DatabaseName);

            collection = database.GetCollection<MongoDBLogDo>("Log", WriteConcern.Unacknowledged);
        }
开发者ID:wudan330260402,项目名称:Danwu.Core,代码行数:7,代码来源:MongoLogger.cs


示例15: FullTextSearch

        public FullTextSearch(string databaseName = "test", MongoUrl url = null)
        {
            mongoClient = url == null ? new MongoClient() : new MongoClient(url);
            database = mongoClient.GetDatabase(databaseName);

            database.CreateCollectionAsync("Students").Wait();
        }
开发者ID:maximburyak,项目名称:TODA,代码行数:7,代码来源:FullTextSearch.cs


示例16: TestDefaults

        public void TestDefaults()
        {
            string connectionString = "mongodb://localhost";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.IsNull(url.DefaultCredentials);
            Assert.AreEqual(1, url.Servers.Count());
            Assert.AreEqual("localhost", url.Servers.Single().Host);
            Assert.AreEqual(27017, url.Servers.Single().Port);
            Assert.IsNull(url.DatabaseName);
            Assert.AreEqual(ConnectionMode.Automatic, url.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, url.ConnectTimeout);
            Assert.AreEqual(MongoDefaults.GuidRepresentation, url.GuidRepresentation);
            Assert.AreEqual(false, url.IPv6);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, url.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, url.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, url.MaxConnectionPoolSize);
            Assert.AreEqual(null, url.ReplicaSetName);
            Assert.AreEqual(null, url.SafeMode);
            Assert.AreEqual(MongoDefaults.SecondaryAcceptableLatency, url.SecondaryAcceptableLatency);
#pragma warning disable 618
            Assert.AreEqual(false, url.SlaveOk);
#pragma warning restore
            Assert.AreEqual(MongoDefaults.SocketTimeout, url.SocketTimeout);
            Assert.AreEqual(false, url.UseSsl);
            Assert.AreEqual(MongoDefaults.WaitQueueMultiple, url.WaitQueueMultiple);
            Assert.AreEqual(MongoDefaults.WaitQueueSize, url.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, url.WaitQueueTimeout);
            Assert.AreEqual(connectionString, url.ToString());
        }
开发者ID:staywellandy,项目名称:mongo-csharp-driver,代码行数:29,代码来源:MongoUrlTests.cs


示例17: MongoDBUtility

        // ---------- PROPERTIES ----------
        // ---------- CONSTRUCTORS ----------
        /// <summary>
        /// Creates a utility object that can be used to perform operations against a MongoDB server.
        /// Note:
        /// Uses the authentication and database information from the supplied configuration item.
        /// </summary>
        /// <param name="configurationFolderPath">The path to the folder containing the encrypted configuration file containing information required to establish the connection to the server.</param>
        /// <param name="configurationItemName">The name of configuration item containing the information required to connect to the server. (Typically it's filename without the extension.)</param>
        public MongoDBUtility(string configurationFolderPath, string configurationItemName)
        {
            if (!string.IsNullOrWhiteSpace(configurationFolderPath) && !string.IsNullOrWhiteSpace(configurationItemName))
            {
                ConfigurationItem configItem = new ConfigurationItem(configurationFolderPath, configurationItemName, true);

                try
                {
                    // Read the connection string from the configuration file.
                    url = MongoUrl.Create(configItem.Value);
                    client = new MongoClient(url);
                    server = client.GetServer();
                    database = server.GetDatabase(url.DatabaseName);
                }
                catch
                {
                    throw new FormatException("Could not load configuration data from file. File is not of the correct format.");
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(configurationFolderPath))
                {
                    throw new ArgumentNullException("configurationFolderPath", "A path to a configuration items folder must be supplied.");
                }
                else
                {
                    throw new ArgumentNullException("configurationItemName", "The name of the configuration item to load must be supplied.");
                }
            }
        }
开发者ID:TheHunter,项目名称:Galactic,代码行数:40,代码来源:MongoDBUtility.cs


示例18: IsRestored

    public bool IsRestored(string connectionName)
    {
      MongoServer server = null;
      var connectionString = ConfigurationManager.ConnectionStrings[connectionName]?.ConnectionString;

      if (string.IsNullOrEmpty(connectionString))
      {
        return false;
      }

      try
      {
        var mongoUrl = new MongoUrl(connectionString);
        var mongoClient = new MongoClient(mongoUrl);
        server = mongoClient.GetServer();

        return server.GetDatabase(mongoUrl.DatabaseName).CollectionExists(MongoRestoreSettings.RestoredDbTokenCollection);
      }
      catch (FormatException ex)
      {
        Log.Error("Wrong connection string format", ex, this);
        throw;
      }
      finally
      {
        server?.Disconnect();
      }
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:28,代码来源:MongoRestoreService.cs


示例19: TestConnectTimeout

        public void TestConnectTimeout()
        {
            string connectionString = "mongodb://localhost/?connectTimeout=123";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString + "s", url.ToString()); // "s" units added

            connectionString = "mongodb://localhost/?connectTimeout=123ms";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMilliseconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123s";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123m";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMinutes(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123h";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromHours(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeoutMS=123";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMilliseconds(123), url.ConnectTimeout);
            Assert.AreEqual("mongodb://localhost/?connectTimeout=123ms", url.ToString()); // changed to "ms" suffix
        }
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:32,代码来源:MongoUrlTests.cs


示例20: UseCaseUpdateTask

        public UseCaseUpdateTask(IAppConfig appConfig, IDataList<UseCase> useCases)
        {
            var url = new MongoUrl(appConfig.ProxyDbConnectionString);
            _db = new MongoClient(url).GetServer().GetDatabase(url.DatabaseName);

            _useCases = useCases;
        }
开发者ID:ryanande,项目名称:ApiProxy,代码行数:7,代码来源:UseCaseUpdateTask.cs



注:本文中的MongoDB.Driver.MongoUrl类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Driver.MongoUrlBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Driver.MongoServerSettings类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap