當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。