Remote DB : (1) Bug fix in DatabaseSettings.Clone(), (2) Compatibility check on startup.

This commit is contained in:
Milan Hanajik 2018-08-30 08:04:58 +02:00
parent 34073844bc
commit 49ae2a84c4
5 changed files with 139 additions and 9 deletions

View File

@ -37,7 +37,7 @@ namespace Config
result.IsRealBench = IsRealBench;
result.ProceduresDBSettings = (Users.DBSettings)ProceduresDBSettings.Clone();
result.WaterMetersDBSettings = (Users.DBSettings)WaterMetersDBSettings.Clone();
result.UsersDBSettings = (Users.DBSettings)ProceduresDBSettings.Clone();
result.UsersDBSettings = (Users.DBSettings)UsersDBSettings.Clone();
return result;
}

View File

@ -370,6 +370,103 @@ namespace TBF.BenchControl
}
}
/// <summary>
/// Checks remote and local configuration DB paths and transitions for compatibility
/// </summary>
/// <returns>true when DB-s are compatible</returns>
public static bool IsRemoteDBCompatible(out string message)
{
ISession localSession = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
var localFeedingPaths = localSession.QueryOver<Config.Entities.FeedingPath>().List();
var localBenchPaths = localSession.QueryOver<Config.Entities.BenchPath>().List();
var localOutputPaths = localSession.QueryOver<Config.Entities.OutputPath>().List();
var localMetersPaths = localSession.QueryOver<Config.Entities.MetersPath>().List();
var localTransitions = localSession.QueryOver<Config.Entities.TransitionSequence>().List();
ISession remoteSession = Config.FluentCommon.CreateSession(Users.Entities.DBKind.RemoteConfig);
var remoteFeedingPaths = remoteSession.QueryOver<Config.Entities.FeedingPath>().List();
var remoteBenchPaths = remoteSession.QueryOver<Config.Entities.BenchPath>().List();
var remoteOutputPaths = remoteSession.QueryOver<Config.Entities.OutputPath>().List();
var remoteMetersPaths = remoteSession.QueryOver<Config.Entities.MetersPath>().List();
var remoteTransitions = remoteSession.QueryOver<Config.Entities.TransitionSequence>().List();
string subMsg;
if (!IsCompatible(localFeedingPaths, remoteFeedingPaths, out subMsg))
{
message = string.Format("Feeding: {0}", subMsg);
return false;
}
if (!IsCompatible(localBenchPaths, remoteBenchPaths, out subMsg))
{
message = string.Format("Bench: {0}", subMsg);
return false;
}
if (!IsCompatible(localOutputPaths, remoteOutputPaths, out subMsg))
{
message = string.Format("Output: {0}", subMsg);
return false;
}
if (!IsCompatible(localMetersPaths, remoteMetersPaths, out subMsg))
{
message = string.Format("Sensors: {0}", subMsg);
return false;
}
if (!IsCompatible(localTransitions, remoteTransitions, out subMsg))
{
message = string.Format("Transitions: {0}", subMsg);
return false;
}
message = string.Empty;
return true;
}
/// <summary>
///
/// </summary>
/// <typeparam name="T">FeedingPath, BenchPath, OutputPath, MetersPath or TransitionSequence</typeparam>
/// <param name="localList">Local list of paths or transitions</param>
/// <param name="remoteList">Remote list of paths or transitions</param>
/// <param name="message">Message specifying a cause of incompatibility</param>
/// <returns>true when lists are compatible, otherwise false</returns>
private static bool IsCompatible<T>(IList<T> localList, IList<T> remoteList, out string message)
{
message = "Local list is empty";
if ((localList == null) || (localList.Count == 0) || !(localList[0] is IHasName)) return false;
message = "Remote list is empty";
if ((remoteList == null) || (remoteList.Count == 0) || !(remoteList[0] is IHasName)) return false;
///
/// Each path or transition on a remote list must exist on a local list
///
foreach (var rItem in remoteList)
{
bool exists = false;
foreach (var lItem in localList)
{
if ((rItem as IHasName).Name == (lItem as IHasName).Name)
{
exists = true;
break;
}
}
if (!exists)
{
message = string.Format("Remote item {0} does not exist on a local list", (rItem as IHasName).Name);
return false;
}
}
message = string.Empty;
return true;
}
/// <summary>
/// Start the state machine

View File

@ -127,21 +127,42 @@ namespace TBF
{
try
{
/// Load components, initialize the control board, etc.
BenchControl.StateMachine.InitializeBoardEtc(ctrlBrdComponent);
/// Check remote and local configuration DB compatibility
string msg;
BenchControl.GenericDevices.IBenchInfo benchInfo = BenchControl.Sequences.ProcessData.BenchInfo;
RemoteDBUse remoteDbUse = (benchInfo != null) ? benchInfo.RemoteDBUse : RemoteDBUse.LocalDBOnly;
log.FatalFormat("RemoteDbUse = {0}", remoteDbUse);
if ((remoteDbUse != RemoteDBUse.LocalDBOnly) && !BenchControl.StateMachine.IsRemoteDBCompatible(out msg))
{
log.FatalFormat("{0} {1}", Strings.Remote_db_is_not_compatible, msg);
throw new Exception(string.Format("{0}{1}{2}", Strings.Remote_db_is_not_compatible, Environment.NewLine, msg));
}
testProgressControls = new TestProgressControls(progressFlowLayoutPanel);
log.Fatal("Remote database is compatible");
}
catch (Exception exc)
{
benchInitializationFailed = true;
string errMsg = string.Format(Strings.Failed_to_initialize_component_0_1_2,
BenchControl.TbfComponents.CurrentlyLoadedComponentName,
Environment.NewLine,
exc.Message);
string errMsg;
if (string.IsNullOrEmpty(BenchControl.TbfComponents.CurrentlyLoadedComponentName))
{
errMsg = exc.Message;
}
else
{
errMsg = string.Format(Strings.Failed_to_initialize_component_0_1_2,
BenchControl.TbfComponents.CurrentlyLoadedComponentName,
Environment.NewLine,
exc.Message);
}
log.Fatal(errMsg);
MessageBox.Show(errMsg, Strings.Error,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
MessageBox.Show(errMsg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
@ -789,4 +810,4 @@ namespace TBF
}
}
}
}
}

View File

@ -3516,6 +3516,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Remote database is not compatible..
/// </summary>
internal static string Remote_db_is_not_compatible {
get {
return ResourceManager.GetString("Remote_db_is_not_compatible", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt; Remove.
/// </summary>

View File

@ -1849,4 +1849,7 @@
<data name="Filter" xml:space="preserve">
<value>Filter</value>
</data>
<data name="Remote_db_is_not_compatible" xml:space="preserve">
<value>Remote database is not compatible.</value>
</data>
</root>