当前位置: 首页>>代码示例>>C#>>正文


C# MongoUrl.ToServerSettings方法代码示例

本文整理汇总了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;
        }
开发者ID:petedavis,项目名称:Memflex,代码行数:55,代码来源:IoC.cs

示例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();
        }
开发者ID:EffieArditi,项目名称:AspNet-WebApi-Boilerplate,代码行数:12,代码来源:QuestionRepositoryTests.cs

示例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();
        }
开发者ID:EffieArditi,项目名称:AspNet-WebApi-Boilerplate,代码行数:20,代码来源:BaseClassDBOrientedTests.cs

示例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);
 }
开发者ID:gazeth,项目名称:Bullet,代码行数:9,代码来源:GridFS.cs


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