本文整理汇总了C#中MongoDB.Driver.MongoUrl.ToServerSettings方法的典型用法代码示例。如果您正苦于以下问题:C# MongoUrl.ToServerSettings方法的具体用法?C# MongoUrl.ToServerSettings怎么用?C# MongoUrl.ToServerSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoUrl
的用法示例。
在下文中一共展示了MongoUrl.ToServerSettings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public static IContainer Initialize()
{
ObjectFactory.Initialize(x => {
x.Scan(scan => {
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
x.For<IFilterProvider>().Use<SmFilterProvider>();
x.For<IFlexMembershipProvider>().HybridHttpOrThreadLocalScoped().Use<FlexMembershipProvider>();
x.For<IFlexRoleProvider>().HybridHttpOrThreadLocalScoped().Use<FlexRoleProvider>();
x.For<IFlexUserStore>().HybridHttpOrThreadLocalScoped().Use<FlexMembershipUserStore<User, Role>>();
x.For<IFlexRoleStore>().HybridHttpOrThreadLocalScoped().Use<FlexMembershipUserStore<User, Role>>();
x.SetAllProperties(p => p.OfType<IFlexRoleProvider>());
x.Forward<IFlexMembershipProvider, IFlexOAuthProvider>();
x.For<IApplicationEnvironment>().Singleton().Use<AspnetEnvironment>();
x.For<ISecurityEncoder>().Singleton().Use<DefaultSecurityEncoder>();
x.For<MongoDatabase>().Singleton().Use(c => {
var connectionString = ConfigurationManager.ConnectionStrings["MongoConnectionString"].ConnectionString;
if (String.IsNullOrEmpty(connectionString))
throw new ConfigurationErrorsException("MongoConnectionString was not found in the App/Web.config.");
var url = new MongoUrl(connectionString);
var server = MongoServer.Create(url.ToServerSettings());
var database = server.GetDatabase(url.DatabaseName);
BsonClassMap.RegisterClassMap<User>(ctx => {
ctx.SetIgnoreExtraElements(true);
ctx.AutoMap();
ctx.SetIdMember(ctx.GetMemberMap(u => u.Id).SetRepresentation(BsonType.ObjectId));
});
BsonClassMap.RegisterClassMap<Role>(ctx => {
ctx.SetIgnoreExtraElements(true);
ctx.AutoMap();
ctx.SetIdMember(ctx.GetMemberMap(r => r.Id).SetRepresentation(BsonType.ObjectId));
});
var userCollection = database.GetCollection<User>("user");
var roleCollection = database.GetCollection<User>("role");
userCollection.EnsureIndex(IndexKeys<User>.Ascending(u => u.Username), IndexOptions.SetUnique(true));
userCollection.EnsureIndex(IndexKeys.Ascending("OAuthAccounts.Provider", "OAuthAccounts.ProviderUserId"), IndexOptions.SetUnique(true));
roleCollection.EnsureIndex(IndexKeys<Role>.Ascending(r => r.Name), IndexOptions.SetUnique(true));
roleCollection.EnsureIndex(IndexKeys<Role>.Ascending(r => r.Users));
return database;
});
x.For<MongoCollection<User>>().Use(c => c.GetInstance<MongoDatabase>().GetCollection<User>("user"));
x.For<MongoCollection<Role>>().Use(c => c.GetInstance<MongoDatabase>().GetCollection<Role>("role"));
});
return ObjectFactory.Container;
}
示例2: DeleteAllQuestions
public void DeleteAllQuestions()
{
// Connecting the MongoDb and deleting its entire collections state
var cnn = new MongoUrl(ConfigurationHelper.GetCurrentEnvDbConnString());
var server = MongoServer.Create(cnn.ToServerSettings());
MongoDatabase db = server.GetDatabase(cnn.DatabaseName);
// deleting questions
MongoCollection questionsCollection = db.GetCollection(typeof(Question).Name);
questionsCollection.RemoveAll();
}
示例3: CleanDbBeforeTests
private static void CleanDbBeforeTests()
{
// Validate that we are not runing on the production DB
Assert.AreNotEqual(ConfigurationHelper.GetCurrentEnvDbConnString(), "YOU WERE JUST TRYING TO DELETE THE PRODUCTION DB!!");
// Connecting the MongoDb and deleting its entire collections state
var cnn = new MongoUrl(ConfigurationHelper.GetCurrentEnvDbConnString());
var server = MongoServer.Create(cnn.ToServerSettings());
MongoDatabase db = server.GetDatabase(cnn.DatabaseName);
// deleting users
MongoCollection userCollection = db.GetCollection(typeof(User).Name);
var query = Query.NE("Name", "effie");
userCollection.Remove(query);
// deleting questions
MongoCollection questionsCollection = db.GetCollection(typeof(Question).Name);
questionsCollection.RemoveAll();
}
示例4: OpenStore
/// <summary>
/// Creates and returns a MongoDatabase from the specified url.
/// </summary>
/// <param name="url">The url of the database</param>
private void OpenStore(MongoUrl url)
{
var server = MongoServer.Create(url.ToServerSettings());
this.store = server.GetDatabase(url.DatabaseName);
}