(1) Initialization of components : Inner exception displayed, (2) Clean-up.

This commit is contained in:
Milan Hanajik 2023-04-24 10:36:51 +02:00
parent 15c916ae66
commit 1eda22a391
3 changed files with 15 additions and 39 deletions

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2018-2019 Sensus Slovensko a.s.
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -134,22 +134,21 @@ namespace TBF.Rig.Output.DB.ProductionTracing
}
/// Register this test bench in the tracing DB for approx. 2 weeks
ISession session = sessionFactory.OpenSession();
var session = sessionFactory.OpenSession();
#if !DEBUG
/// Only a release version registers a workplace
TracingDB.DB.RegisterWorkplace(session,
workplace,
Users.CurrentUser.UserName(),
(ipAddress != null) ? ipAddress.ToString() : "1.2.3.4",
"<multiple>",
WorkstepName,
DateTime.Now + new TimeSpan(15, 0, 0, 0));
#endif
/// Only a release version registers a workplace
TracingDB.DB.RegisterWorkplace(session,
workplace,
Users.CurrentUser.UserName(),
(ipAddress != null) ? ipAddress.ToString() : "1.2.3.4",
"<multiple>",
WorkstepName,
DateTime.Now + new TimeSpan(15, 0, 0, 0));
session.Flush();
#endif
session.Close();
TracingDB.DB.SessionFactory = sessionFactory;
if (session != null) session.Dispose();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
else

View File

@ -289,10 +289,11 @@ namespace TBF.UI
form.CloseForm(null, new EventArgs());
formThread.Join();
string innerExcMsg = (exc.InnerException != null) ? Environment.NewLine + exc.InnerException.Message : string.Empty;
string errMsg = string.Format(Strings.Failed_to_initialize_device_0_1_2,
Rig.StateMachine.CurrentlyInitializedComponentName,
Environment.NewLine,
exc.Message);
Environment.NewLine + exc.Message,
innerExcMsg);
log.Fatal(errMsg);
MessageBox.Show(errMsg, Strings.Error,
System.Windows.Forms.MessageBoxButtons.OK,

View File

@ -19,9 +19,6 @@ namespace TracingDB
/// </summary>
public static ISessionFactory SessionFactory;
public static ISession Session;
/// <summary>
/// Connection string for all sessions
/// </summary>
@ -39,16 +36,6 @@ namespace TracingDB
}
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
/// <returns>A database session</returns>
static ISessionFactory CreateSessionFactory()
{
return CreateSessionFactory(false);
}
/// <summary>
/// NHibernate session factory (to create the database session 'SessionFactory')
/// </summary>
@ -86,17 +73,6 @@ namespace TracingDB
new SchemaExport(config).Create(true, true);
}
/// Create a NHibernate session for the given database
public static ISession CreateSession(string connectionString)
{
ConnectionString = connectionString; /// Clears session factory on connction string change
if (SessionFactory == null)
SessionFactory = CreateSessionFactory();
return SessionFactory.OpenSession();
}
/// <summary>
/// Create an empty database.