本文整理汇总了C#中ISession.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.Dispose方法的具体用法?C# ISession.Dispose怎么用?C# ISession.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinalizeSession
private static void FinalizeSession(ISession session)
{
if (session == null || !session.IsOpen)
return;
try
{
if (session.Transaction != null && session.Transaction.IsActive)
{
session.Flush();
session.Transaction.Commit();
}
}
catch (Exception)
{
if (session.Transaction != null)
session.Transaction.Rollback();
throw;
}
finally
{
session.Close();
session.Dispose();
}
}
示例2: EndSession
private static void EndSession(ISession session, bool commitTransaction = true)
{
try {
if (session.Transaction != null && session.Transaction.IsActive) {
if (commitTransaction) {
try {
session.Transaction.Commit();
}
catch {
session.Transaction.Rollback();
throw;
}
}
else {
session.Transaction.Rollback();
}
}
}
finally {
if (session.IsOpen)
session.Close();
session.Dispose();
}
}
示例3: RebuildDatabase
public void RebuildDatabase()
{
ITransaction transaction = null;
try
{
var factoryFactory = new NHibernateSessionFactory();
ISessionFactory sessionFactory = factoryFactory.GetSessionFactory();
string[] dropScripts = factoryFactory.Configuration.GenerateDropSchemaScript(((ISessionFactoryImplementor)sessionFactory).Dialect);
string[] createScripts = factoryFactory.Configuration.GenerateSchemaCreationScript(((ISessionFactoryImplementor)sessionFactory).Dialect);
session = sessionFactory.OpenSession();
ExecuteScripts(dropScripts, session.Connection);
ExecuteScripts(createScripts, session.Connection);
SaveScripts(createScripts, "create.sql");
transaction = session.BeginTransaction();
var repository = new Repository(session);
var data = new Data();
data.Build(repository);
}
finally
{
if (session != null)
{
if (transaction != null && transaction.IsActive)
{
transaction.Commit();
}
session.Close();
session.Dispose();
}
}
}
示例4: Init
public void Init() {
_session = _sessionFactory.OpenSession();
foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
foreach (var killRecord in _session.CreateCriteria(killType).List()) {
_session.Delete(killRecord);
}
}
_session.Flush();
_session.Close();
_session.Dispose();
_session = _sessionFactory.OpenSession();
var builder = new ContainerBuilder();
builder.RegisterAutoMocking();
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(SettingsFormatter)).As(typeof(ISettingsFormatter));
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(_transactionManager = new TestTransactionManager(_session)).As<ITransactionManager>();
_container = builder.Build();
}
示例5: EndSession
private static void EndSession(ISession session)
{
if (session.Transaction != null && session.Transaction.IsActive) {
session.Transaction.Commit();
}
session.Dispose();
}
示例6: CloseTransaction
private void CloseTransaction(ISession session)
{
try
{
session.Transaction.Commit();
session.Transaction.Dispose();
}
catch
{
session.Transaction.Rollback();
session.Dispose();
}
finally
{
session.Dispose();
}
}
示例7: DisposeOfSession
public virtual void DisposeOfSession(ISession session)
{
if (!CanDisposeOfSession(session))
{
return;
}
session.Dispose();
}
示例8: ProcessRequest
public override void ProcessRequest(HttpContext context)
{
Session = NHWebConsoleSetup.OpenSession();
try {
Session.FlushMode = FlushMode.Never;
base.ProcessRequest(context);
} finally {
if (NHWebConsoleSetup.DisposeSession)
Session.Dispose();
}
}
示例9: EndSession
private static void EndSession(ISession session, HttpApplication application)
{
//TODO: What about rollbacks? => what to do then?
//error module do the rollbacks?
//transaction isn't automatically rollbacked!
if (application.Context.Error != null && session.Transaction != null && session.Transaction.IsActive)
{
session.Transaction.Rollback();
}
else if (session.Transaction != null && session.Transaction.IsActive)
{
session.Transaction.Commit();
}
session.Dispose();
}
示例10: Init
public void Init(HttpApplication application)
{
application.BeginRequest += delegate
{
CurrentSession = _sessionFactory.OpenSession();
};
application.EndRequest += delegate
{
if (CurrentSession != null)
{
CurrentSession.Dispose();
}
};
}
示例11: InitializeLibspotify
public static void InitializeLibspotify()
{
Session = SessionFactory.CreateSession(
Constants.ApplicationKey,
Constants.CacheFolder,
Constants.SettingsFolder,
Constants.UserAgent);
Application.Current.Exit += delegate
{
if (Session != null)
{
Session.Dispose();
}
};
}
示例12: SessionIs_
protected void SessionIs_(string action)
{
switch (action)
{
case Opened:
Session = OpenSession();
Assert.That(Session.IsOpen);
break;
case Closed:
Session.Close();
Assert.That(!Session.IsOpen);
Session.Dispose();
break;
}
}
示例13: ReleaseSession
/// <summary>
/// Releases the specified session
/// </summary>
/// <param name="session"></param>
public void ReleaseSession(ISession session)
{
if (!threadScopeInfo.HasInitializedScope)
{
session.Flush();
session.Dispose();
}
}
示例14: Setup
public void Setup()
{
blog = new Blog();
post1 = new Post();
post2 = new Post();
post1.Blog = blog;
post2.Blog = blog;
session = factory.OpenSession();
session.Save(blog);
session.Save(post1);
session.Save(post2);
session.Dispose();
session = factory.OpenSession();
}
示例15: DisposeSession
/// <summary>
/// Close the specified session
/// </summary>
/// <param name="sessionToClose">session to close</param>
public void DisposeSession(ISession sessionToClose) {
if(IsDebugEnabled)
log.Debug("NHibernate 세션 및 Connection을 닫습니다...");
//explicit disposing of connection is required (??) for in memory databases
//
if(sessionToClose != null) {
var conn = sessionToClose.Connection;
sessionToClose.Dispose();
if(conn != null)
conn.Dispose();
if(IsDebugEnabled)
log.Debug("NHibernate 세션 및 Connection을 닫았습니다.");
}
}