Skip to content

Commit

Permalink
Merge pull request #572 from mpostol/SemanticData-6.1.3
Browse files Browse the repository at this point in the history
Enhance/Improve node selection algorithm for ValidateAndExportModel #531
  • Loading branch information
mpostol committed Apr 10, 2021
2 parents 4842372 + 71ea2c8 commit 38f3372
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions SemanticData/UANodeSetValidation/AddressSpaceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,14 @@ private IUANodeContext TryGetUANodeContext(NodeId nodeId)
private void ValidateAndExportModel(int nameSpaceIndex)
{
IValidator validator = new Validator(this, m_TraceEvent);
//TODO Enhance/Improve node selection algorithm for ValidateAndExportModel #531
IEnumerable<IUANodeContext> _stubs = from _key in m_NodesDictionary.Values where _key.NodeIdContext.NamespaceIndex == nameSpaceIndex select _key;
IEnumerable<IUANodeContext> undefindNodes = from _node in _stubs
where Object.ReferenceEquals(_node.UANode, null)
select _node;
IEnumerable<IUANodeContext> stubs = from _key in m_NodesDictionary.Values where _key.NodeIdContext.NamespaceIndex == nameSpaceIndex select _key;
IEnumerable<IUANodeContext> undefindNodes = from node in stubs
where Object.ReferenceEquals(node.UANode, null)
select node;
foreach (IUANodeContext item in undefindNodes)
m_TraceEvent.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeCannotBeNull, $"the node {item.ToString()} is not defined in the UANodeSet model"));
List <IUANodeContext> _nodes = (from _node in _stubs where _node.UANode != null && (_node.UANode is UAType) select _node).ToList();
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage($"Selected {_nodes.Count} types to be validated."));
List <IUANodeContext> nodes = (from _node in stubs where _node.UANode != null && (_node.UANode is UAType) select _node).ToList();
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage($"Selected {nodes.Count} types to be validated."));
IUANodeBase _objects = TryGetUANodeContext(UAInformationModel.ObjectIds.ObjectsFolder);
if (_objects is null)
throw new ArgumentNullException("Cannot find ObjectsFolder in the standard information model");
Expand All @@ -361,35 +360,35 @@ where Object.ReferenceEquals(_node.UANode, null)
(x.TargetNode.NodeIdContext.NamespaceIndex == nameSpaceIndex))
.Select<UAReferenceContext, IUANodeContext>(x => x.TargetNode);
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage($"Selected {_allInstances.Count<IUANodeContext>()} instances referenced by the ObjectsFolder to be validated."));
_nodes.AddRange(_allInstances);
foreach (IModelTableEntry _ns in ExportNamespaceTable)
nodes.AddRange(_allInstances);
foreach (IModelTableEntry modelTableEntry in ExportNamespaceTable)
{
string _publicationDate = _ns.PublicationDate.HasValue ? _ns.PublicationDate.Value.ToShortDateString() : DateTime.UtcNow.ToShortDateString();
string _version = _ns.Version;
InformationModelFactory.CreateNamespace(_ns.ModelUri.ToString(), _publicationDate, _version);
string _publicationDate = modelTableEntry.PublicationDate.HasValue ? modelTableEntry.PublicationDate.Value.ToShortDateString() : DateTime.UtcNow.ToShortDateString();
string _version = modelTableEntry.Version;
InformationModelFactory.CreateNamespace(modelTableEntry.ModelUri.ToString(), _publicationDate, _version);
}
foreach (IUANodeBase _item in _nodes)
foreach (IUANodeBase item in nodes)
{
try
{
validator.ValidateExportNode(_item, InformationModelFactory);
validator.ValidateExportNode(item, InformationModelFactory);
}
catch (Exception _ex)
catch (Exception ex)
{
string msg = string.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace);
string msg = string.Format("Error caught while processing the node {0}. The message: {1} at {2}.", item.UANode.NodeId, ex.Message, ex.StackTrace);
m_TraceEvent.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, msg));
}
}
string _msg = null;
string message = null;
if (m_TraceEvent.Errors == 0)
{
_msg = $"Finishing Validator.ValidateExportModel - the model contains {_nodes.Count} nodes and no errors/warnings reported";
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage(_msg));
message = $"Finishing Validator.ValidateExportModel - the model contains {nodes.Count} nodes and no errors/warnings reported";
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage(message));
}
else
{
_msg = $"Finishing Validator.ValidateExportModel - the model contains {_nodes.Count} nodes and {m_TraceEvent.Errors} errors reported.";
m_TraceEvent.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.ModelContainsErrors, _msg));
message = $"Finishing Validator.ValidateExportModel - the model contains {nodes.Count} nodes and {m_TraceEvent.Errors} errors reported.";
m_TraceEvent.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.ModelContainsErrors, message));
}
}

Expand Down

0 comments on commit 38f3372

Please sign in to comment.