本文整理汇总了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);
}
}
示例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);
}
示例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"));
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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();
}