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


C# IDocumentStore.OpenSession方法代码示例

本文整理汇总了C#中IDocumentStore.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentStore.OpenSession方法的具体用法?C# IDocumentStore.OpenSession怎么用?C# IDocumentStore.OpenSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocumentStore的用法示例。


在下文中一共展示了IDocumentStore.OpenSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUp

        public void SetUp()
        {
            _store = NewDocumentStore();
            _store.Initialize();

            // We first have to create the static indexes
            IndexCreation.CreateIndexes(typeof(Player_Index_R03).Assembly, _store);

            _teams = DataGenerator.CreateTeamList();

            // Store some players and teams in the database
            using (var session = _store.OpenSession())
            {
                foreach (var team in _teams)
                {
                    session.Store(team);
                }

                _players = DataGenerator.CreatePlayerListWithTeamIds();

                foreach (var player in _players)
                {
                    session.Store(player);
                }

                session.SaveChanges();
            }

            // Let's wait for indexing to happen
            // this method is part of RavenTestBase and thus should only be used in tests
            WaitForIndexing(_store);
        }
开发者ID:Zuehlke,项目名称:ravendb-workshop,代码行数:32,代码来源:R09_LoadDocumentInIndex.cs

示例2: HeuristicsModule

        public HeuristicsModule(IDocumentStore documentStore)
            : base("/heuritics")
        {
            Get["/delivery"] = x =>
                                   {
                                       using (var session = documentStore.OpenSession())
                                       {
                                           var rules = session
                                               .LoadSingle<DeliverabilityClassificationRules>()
                                                ?? new DeliverabilityClassificationRules();

                                           return Response.AsJson(rules);
                                       }
                                   };

            Post["/delivery"] = x =>
                                    {
                                        var model = this.Bind<ServiceEndpoints.Heuristics.SetDeliveryRules>();

                                        using (var session = documentStore.OpenSession())
                                        {
                                            var rules = session.LoadSingle<DeliverabilityClassificationRules>()
                                                ?? new DeliverabilityClassificationRules();

                                            rules.Rules = model.DeliverabilityClassificationRules.Rules;

                                            session.StoreSingle(rules);
                                            session.SaveChanges();

                                            return Response.AsText("OK");
                                        }
                                    };
        }
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:33,代码来源:HeuristicsModule.cs

示例3: MultiTenant

        public MultiTenant()
        {
            store = NewRemoteDocumentStore(databaseName: _dbid);

            // Configure the default versioning configuration
            using (var session = store.OpenSession(_dbid))
            {
                session.Store(new VersioningConfiguration
                {
                    Id = "Raven/Versioning/DefaultConfiguration",
                    MaxRevisions = 5
                });
                session.SaveChanges();
            }

            // Add an entity, creating the first version.
            using (var session = store.OpenSession(_dbid))
            {
                session.Store(new Ball { Id = "balls/1", Color = "Red" });
                session.SaveChanges();
            }

            // Change the entity, creating the second version.
            using (var session = store.OpenSession(_dbid))
            {
                var ball = session.Load<Ball>("balls/1");
                ball.Color = "Blue";
                session.SaveChanges();
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:30,代码来源:MultiTenant.cs

示例4: DoTest

	    private void DoTest(IDocumentStore store1, IDocumentStore store2)
	    {
	        using (var session = store1.OpenSession())
	        {
	            session.Store(new Company());
	            session.SaveChanges();
	        }

	        using (var session = store2.OpenSession())
	        {
	            session.Store(new Company());
	            session.SaveChanges();
	        }

	        store1.DatabaseCommands.Put("marker", null, new RavenJObject(), new RavenJObject());

	        TellFirstInstanceToReplicateToSecondInstance();

	        WaitForReplication(store2, "marker");

	        var conflictException = Assert.Throws<ConflictException>(() =>
	        {
	            using (var session = store2.OpenSession())
	            {
	                var loadStartingWith = session.Advanced.LoadStartingWith<Company>("companies/");
	            }
	        });

	        Assert.Equal("Conflict detected on companies/1, conflict must be resolved before the document will be accessible",
	                     conflictException.Message);
	    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:31,代码来源:RavenDB_1760.cs

示例5: DoTest

		private void DoTest(IDocumentStore documentStore)
		{
			using (var session = documentStore.OpenSession())
			{
				session.Store(new Foo { Id = "foos/1", Name = "A" });
				session.SaveChanges();
			}

			DateTime firstDate;
			using (var session = documentStore.OpenSession())
			{
				var foo = session.Load<Foo>("foos/1");
				var metadata = session.Advanced.GetMetadataFor(foo);
				firstDate = metadata.Value<DateTime>("Last-Modified");
			}

			SystemTime.UtcDateTime = () => DateTime.UtcNow.AddDays(1);
			using (var session = documentStore.OpenSession())
			{
				var foo = session.Load<Foo>("foos/1");
				foo.Name = "B";
				session.SaveChanges();
			}
			DateTime secondDate;
			using (var session = documentStore.OpenSession())
			{
				var foo = session.Load<Foo>("foos/1");
				var metadata = session.Advanced.GetMetadataFor(foo);
				secondDate = metadata.Value<DateTime>("Last-Modified");
			}

			Assert.NotEqual(secondDate, firstDate);
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:33,代码来源:RavenDB845.cs

示例6: Start

 public void Start()
 {
     _documentStore = new EmbeddableDocumentStore
     {
         DataDirectory = "./continuity.db",
         UseEmbeddedHttpServer = true,
     };
     _documentStore.Initialize();
     var container = new CompositionContainer(
                  new AggregateCatalog(
                      new AssemblyCatalog(GetType().Assembly),
                     new AssemblyCatalog(typeof(IBus).Assembly),
                     new DirectoryCatalog("extensions")
                  ));
     container.ComposeExportedValue<IDocumentStore>(_documentStore);
     container.ComposeExportedValue<IDocumentSession>(_documentStore.OpenSession());
     container.ComposeExportedValue<IBus>(new StandardBus());
     container.ComposeParts(this);
     _kernel.Bind<IDocumentStore>().ToConstant(_documentStore);
     _kernel.Bind<IDocumentSession>().ToMethod(c => _documentStore.OpenSession());
     //var startupTasks = _kernel.GetAll<INeedToRunAtStartup>();
     foreach (var task in StartupItems)
         task.Run();
     HttpServer.Start();
     var config = _kernel.Get<ContinuityConfiguration>();
     _serverAddress = "localhost";
     _serverPort = config.Port.ToString();
 }
开发者ID:caseykramer,项目名称:Continuity,代码行数:28,代码来源:Bootstrapper.cs

示例7: AdminLoginModule

        public AdminLoginModule(ILoginService loginService, IDocumentStore store)
            : base("/admin")
        {
            this.RequiresInstallerDisabled(() => store.OpenSession());
            this.RequiresHttpsOrXProto();

            Get["/login"] =
                parameters =>
                {
                    using (IDocumentSession session = store.OpenSession())
                    {
                        SiteSettings site = session.GetSiteSettings();

                        if (site == null)
                        {
                            site = new SiteSettings
                            {
                                Title = "Admin",
                                SubTitle = "Go to Site -> Settings"
                            };
                        }

                        return View["admin/login", new
                        {
                            site.Title,
                            SubTitle = "Login"
                        }];
                    }
                };

            Get["/logout"] = parameters =>
            {
                // Called when the user clicks the sign out button in the application. Should
                // perform one of the Logout actions (see below)

                return View["admin/logout"];
            };

            Post["/login"] = parameters =>
            {
                // Called when the user submits the contents of the login form. Should
                // validate the user based on the posted form data, and perform one of the
                // Login actions (see below)
                var loginParameters = this.Bind<LoginParameters>();

                User user;
                if (!loginService.Login(loginParameters.UserName, loginParameters.Password, out user))
                {
                    return global::System.Net.HttpStatusCode.Unauthorized;
                }

                return this.LoginAndRedirect(
                    user.Identifier,
                    fallbackRedirectUrl: "/admin",
                    cookieExpiry: DateTime.Now.AddHours(1));
            };
        }
开发者ID:pekkah,项目名称:tanka,代码行数:57,代码来源:AdminLoginModule.cs

示例8: Initialize

        public static void Initialize(IContainer container)
        {
            if (_documentStore != null) {
                return;
            }

            var documentStore = new EmbeddableDocumentStore {
                //DataDirectory = "App_Data",
                RunInMemory = true,
                UseEmbeddedHttpServer = true
            };
            documentStore.Configuration.PluginsDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "Plugins");
            documentStore.RegisterListener(new DocumentStoreListener());
            documentStore.Initialize();

            _documentStore = documentStore;

            IndexCreation.CreateIndexes(typeof (RavenConfig).Assembly, _documentStore);

            RavenProfiler.InitializeFor(_documentStore);

            using (var session = _documentStore.OpenSession()) {
                RavenQueryStatistics stats;
                session.Query<Document>().Statistics(out stats).Take(0).ToList();
                if (stats.TotalResults == 0) {
                    // we need to create some documents
                    var rootDoc = new Document {
                        Slug = string.Empty, Title = "Home page", Body = "<p>Welcome to this site. Go and see <a href=\"/blog\">the blog</a>.</p><p><a href=\"/about\">here</a> is the about page.</p>"
                    };
                    session.Store(rootDoc);
                    session.Store(new Document {
                        ParentId = rootDoc.Id,
                        Slug = "about",
                        Title = "About",
                        Body = "This is about this site."
                    });

                    var blogDoc = new Document {
                        ParentId = rootDoc.Id,
                        Slug = "blog",
                        Title = "Blog",
                        Body = "This is my blog."
                    };
                    session.Store(blogDoc);
                    session.Store(new Document {
                        ParentId = blogDoc.Id,
                        Slug = "First",
                        Title = "my first blog post",
                        Body = "Hooray"
                    });

                    session.SaveChanges();
                }
            }

            container.Configure(x => x.For<IDocumentSession>().HybridHttpOrThreadLocalScoped().Use(() => _documentStore.OpenSession()));
        }
开发者ID:thoemmi,项目名称:ViewComposition,代码行数:57,代码来源:RavenConfig.cs

示例9: PopulateData

        public static void PopulateData(IDocumentStore initializedStore)
        {
            using (var session = initializedStore.OpenSession())
            {
                LoadFoodGroupsAndFoods(session);
                session.SaveChanges();
            }

            using (var session = initializedStore.OpenSession())
            {
                LoadSurveys(session);   //Load survey uses some randomness from above
                session.SaveChanges();
            }
        }
开发者ID:AlexShkor,项目名称:FluentKnockoutHelpers,代码行数:14,代码来源:DataInitailizer.cs

示例10: PopulateData

        public static void PopulateData(IDocumentStore initializedStore)
        {
            using (var session = initializedStore.OpenSession())
            {
                LoadFoodGroupsAndFoods(session);
                session.SaveChanges();
            }

            using (var session = initializedStore.OpenSession())
            {
                LoadSurveys(session);   //Load survey uses some randomness from above
                session.SaveChanges();
            }

            using (var session = initializedStore.OpenSession())
            {
                //add a few colors...

                session.Store(new Color
                {
                    Id = Guid.NewGuid().ToString(),
                    HexCode = "FF0000",
                    Name = "Red"
                });

                session.Store(new Color
                {
                    Id = Guid.NewGuid().ToString(),
                    HexCode = "FFFF00",
                    Name = "Yellow"
                });

                session.Store(new Color
                {
                    Id = Guid.NewGuid().ToString(),
                    HexCode = "0000FF",
                    Name = "Blue"
                });

                session.Store(new Color
                {
                    Id = Guid.NewGuid().ToString(),
                    HexCode = "008000",
                    Name = "Green"
                });

                session.SaveChanges();
            }
        }
开发者ID:GusMar,项目名称:FluentKnockoutHelpers,代码行数:49,代码来源:DataInitailizer.cs

示例11: ExecuteTest

		private void ExecuteTest(IDocumentStore store)
		{
			var expected = new DateTimeOffset(2010, 11, 10, 19, 13, 26, 509, TimeSpan.FromHours(2));
			using (var session = store.OpenSession())
			{
				session.Store(new FooBar {Foo = expected});
				session.SaveChanges();
			}

			using (var session = store.OpenSession())
			{
				var fooBar = session.Load<FooBar>("foobars/1");
				Assert.Equal(expected, fooBar.Foo);
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:15,代码来源:CanStoreAndGetDateTimeOffset.cs

示例12: Update

 public static void Update(IDocumentStore documentStore)
 {
     using(var session = documentStore.OpenSession())
     {
         var updater = new ShowUpdater(session, Console.WriteLine); //TODO: Send to signalr
         updater.UpdateShows();
         session.SaveChanges();
     }
     using (var session = documentStore.OpenSession())
     {
         var updater = new ShowUpdater(session, Console.WriteLine); //TODO: Send to signalr
         updater.UpdateShowNames();
         session.SaveChanges();
     }
 }
开发者ID:alundgren,项目名称:alun-tv,代码行数:15,代码来源:Program.cs

示例13: SetUp

        public virtual void SetUp()
        {
            MetricsMock = new Mock<IMetricTracker>();
            Metrics = MetricsMock.Object;

            HttpContext.Current = null; //This needs to be cleared because EmbeddableDocumentStore will try to set a virtual directory via HttpContext.Current.Request.ApplicationPath, which is null
            Store = new EmbeddableDocumentStore { RunInMemory = true }.Initialize();
            ((DocumentStore) Store).RegisterListener(new ForceNonStaleQueryListener());
            IndexCreation.CreateIndexes(typeof(User).Assembly, Store);
            Session = Store.OpenSession();

            StructureMap.ObjectFactory.Inject(typeof(IDocumentStore), Store);
            StructureMap.ObjectFactory.Inject(typeof(IDocumentSession), Store.OpenSession());
            RavenConfig.Bootstrap();
        }
开发者ID:jgeurts,项目名称:LunchLearn20121107,代码行数:15,代码来源:TestBase.cs

示例14: GetServerSettings

 private static ServerSettings GetServerSettings(IDocumentStore documentStore)
 {
     using (var session = documentStore.OpenSession())
     {
         return session.Load<ServerSettings>("ServerSettings/1");
     }
 }
开发者ID:tobiaszuercher,项目名称:PowerDeploy,代码行数:7,代码来源:Bootstrapper.cs

示例15: SetUp

        public void SetUp()
        {
            store = NewDocumentStore();
            using(var session = store.OpenSession())
            {
                session.Store(new Account
                {
                    Transactions =
                        {
                            new Transaction(1),
                            new Transaction(3),
                        }
                });
                session.Store(new Account
                {
                    Transactions =
                        {
                            new Transaction(2),
                            new Transaction(4),
                        }
                });

                session.SaveChanges();
            }
        }
开发者ID:keithbloom,项目名称:Suteki.TardisBank,代码行数:25,代码来源:RavenDbAnyOfPropertyCollection.cs


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