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

This commit is contained in:
Milan Hanajik
2018-08-30 14:10:20 +02:00
parent 34073844bc
commit 49ae2a84c4
5 changed files with 139 additions and 9 deletions
+97
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