本文整理汇总了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);
}
示例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");
}
};
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
示例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));
};
}
示例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()));
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例14: GetServerSettings
private static ServerSettings GetServerSettings(IDocumentStore documentStore)
{
using (var session = documentStore.OpenSession())
{
return session.Load<ServerSettings>("ServerSettings/1");
}
}
示例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();
}
}