Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic data 6.3.1 echo #606

Merged
merged 3 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SemanticData/AddressSpaceComplianceTestTool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<remove name="Default" />
</listeners>
</source>
<source name="UANodeSetValidation" switchValue="All" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="LogFile" />
<remove name="Default" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="LogFile" type="System.Diagnostics.DelimitedListTraceListener" initializeData="asp.log" traceOutputOptions="DateTime">
Expand Down
7 changes: 7 additions & 0 deletions SemanticData/BuildingErrorsHandling/BuildErrors.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

//__________________________________________________________________________________________________
//
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions
//__________________________________________________________________________________________________

namespace UAOOI.SemanticData.BuildingErrorsHandling
{
/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions SemanticData/BuildingErrorsHandling/BuildErrors.tt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<#@ import namespace="System.Xml" #>
<#@ output extension=".cs" #>

//__________________________________________________________________________________________________
//
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions
//__________________________________________________________________________________________________

namespace UAOOI.SemanticData.BuildingErrorsHandling
{
/// <summary>
Expand Down
50 changes: 33 additions & 17 deletions SemanticData/BuildingErrorsHandling/TraceMessage.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//___________________________________________________________________________________
//__________________________________________________________________________________________________
//
// Copyright (C) 2019, Mariusz Postol LODZ POLAND.
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________
// To be in touch join the community at GitHub: https://github.com/mpostol/OPC-UA-OOI/discussions
//__________________________________________________________________________________________________

using System;
using System.Diagnostics;

namespace UAOOI.SemanticData.BuildingErrorsHandling
{
/// <summary>
/// Class TraceMessage.
/// Class TraceMessage - supports formatting of the warnings for the tracing purpose
/// </summary>
public class TraceMessage : IFormattable
{
#region public API

/// <summary>
/// Creates new instance of the <see cref="TraceMessage"/> to be used for diagnostic purpose
/// </summary>
Expand All @@ -24,6 +26,7 @@ public static TraceMessage DiagnosticTraceMessage(string message)
{
return new TraceMessage(BuildError.DiagnosticInformation, TraceEventType.Verbose, message);
}

/// <summary>
/// creates new <see cref="TraceMessage" /> to be used for diagnostic purpose
/// </summary>
Expand All @@ -32,37 +35,43 @@ public static TraceMessage DiagnosticTraceMessage(string message)
/// <returns>The new <see cref="TraceMessage" /> diagnostic message.</returns>
public static TraceMessage BuildErrorTraceMessage(BuildError error, string message)
{
return new TraceMessage(error, TraceEventType.Information, message);
return new TraceMessage(error, TraceEventType.Warning, message);
}

/// <summary>
/// Gets the build error.
/// </summary>
/// <value>The build error.</value>
public BuildError BuildError
{
get { return b_BuildError; }
private set { b_BuildError = value; }
get => b_BuildError;
private set => b_BuildError = value;
}

/// <summary>
/// Gets the trace level.
/// </summary>
/// <value>The trace level.</value>
public TraceEventType TraceLevel
{
get { return b_TraceLevel; }
private set { b_TraceLevel = value; }
get => b_TraceLevel;
private set => b_TraceLevel = value;
}

/// <summary>
/// Gets the message.
/// </summary>
/// <value>The message.</value>
public string Message
{
get { return b_Location; }
private set { b_Location = value; }
get => b_Location;
private set => b_Location = value;
}

#endregion public API

#region IFormattable

/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
Expand All @@ -72,30 +81,37 @@ public string Message
public string ToString(string format, IFormatProvider formatProvider)
{
//TODO implement IFormattable
return this.ToString();
return ToString();
}
#endregion

#endregion IFormattable

#region object

/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString()
{
return String.Format("Trace: {0}, Error {1} {2}", TraceLevel, BuildError.ToString(), Message);
return string.Format("Trace: {0}, Error {1} {2}", TraceLevel, BuildError.ToString(), Message);
}

#endregion object

#region private

private TraceMessage(BuildError buildError, TraceEventType traceLevel, string message)
{
BuildError = buildError;
TraceLevel = traceLevel;
Message = message;
}

private TraceEventType b_TraceLevel;
private BuildError b_BuildError;
private string b_Location;
#endregion

#endregion private
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void AddressSpaceContextConstructorTest()
List<IUANodeBase> _invalidNodes = new List<IUANodeBase>();
TracedAddressSpaceContext _asp = new TracedAddressSpaceContext();
_asp.AddressSpaceContext.UTAddressSpaceCheckConsistency(x => _invalidNodes.Add(x));
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
}

[TestMethod]
Expand All @@ -40,7 +40,7 @@ public void ReferencesCheckConsistencyTest()
{
TracedAddressSpaceContext _asp = new TracedAddressSpaceContext();
_asp.AddressSpaceContext.UTReferencesCheckConsistency((x, y, z, v) => Assert.Fail());
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
}

[TestMethod]
Expand All @@ -63,7 +63,7 @@ public void AddressSpaceContextContentCheck()
_asp.AddressSpaceContext.UTTryGetUANodeContext(ObjectTypes.FolderType, x => _content.Add(x));
Assert.AreEqual<int>(1, _content.Count);
Assert.IsTrue(new NodeId(ObjectTypes.FolderType) == _content[0].NodeIdContext);
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
}

[TestMethod]
Expand All @@ -78,7 +78,7 @@ public void AddressSpaceReferencesContentCheck()
_content.Clear();
_asp.AddressSpaceContext.UTGetReferences(ObjectIds.ObjectsFolder, x => _content.Add(x));
Assert.AreEqual<int>(3, _content.Count);
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
}

[TestMethod]
Expand Down Expand Up @@ -146,7 +146,7 @@ public void AddressSpaceContextValidateAndExportModelOpcUa()
{
TracedAddressSpaceContext _asp = new TracedAddressSpaceContext();
((IAddressSpaceContext)_asp.AddressSpaceContext).ValidateAndExportModel(new Uri(UAInformationModel.Namespaces.OpcUa));
_asp.TestConsistency(683, 1);
_asp.TestConsistency(1);
Assert.AreEqual<string>(BuildError.WrongReference2Property.Identifier, _asp.TraceList[0].BuildError.Identifier);
}

Expand All @@ -167,10 +167,10 @@ public void AddressSpaceContextValidateAndExportIndex0()
IEnumerable<IUANodeContext> _returnValue = null;
_asp.AddressSpaceContext.UTValidateAndExportModel(0, x => _returnValue = x);
Assert.AreEqual<int>(3909, (_returnValue.Count<IUANodeContext>()));
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
_asp.AddressSpaceContext.UTValidateAndExportModel(1, x => _returnValue = x);
Assert.AreEqual<int>(0, _returnValue.Count<IUANodeContext>());
_asp.TestConsistency(4, 0);
_asp.TestConsistency(0);
}

[TestMethod]
Expand All @@ -180,9 +180,9 @@ public void ImportObjectTest()
TracedAddressSpaceContext _asp = new TracedAddressSpaceContext();
UANodeSet _newNodeSet = TestData.CreateNodeSetModel();
((IAddressSpaceContext)_asp.AddressSpaceContext).ImportUANodeSet(_newNodeSet);
_asp.TestConsistency(7, 1);
_asp.TestConsistency(1);
_asp.AddressSpaceContext.UTAddressSpaceCheckConsistency(x => { Assert.Fail(); });
_asp.TestConsistency(7, 1);
_asp.TestConsistency(1);
List<UAReferenceContext> _content = new List<UAReferenceContext>();
_asp.AddressSpaceContext.UTGetReferences(ObjectIds.RootFolder, x => _content.Add(x));
Assert.AreEqual<int>(4, _content.Count);
Expand All @@ -192,7 +192,7 @@ public void ImportObjectTest()
Assert.AreEqual<int>(4, _content.Count);
IEnumerable<IUANodeContext> _toExport = _content.Where<UAReferenceContext>(x => x.TargetNode.NodeIdContext.NamespaceIndex == 1).Select<UAReferenceContext, IUANodeContext>(x => x.TargetNode);
Assert.AreEqual<int>(1, _toExport.Count<IUANodeContext>());
_asp.TestConsistency(7, 1);
_asp.TestConsistency(1);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public TracedAddressSpaceContext()
AddressSpaceContext = new AddressSpaceContext(this);
}

public void TestConsistency(int diagnosticCounter, int errorsCounter)
public void TestConsistency(int errorsCounter)
{
//TODO Enhance/Improve the Program logging and tracing infrastructure. #590
//Assert.AreEqual<int>(diagnosticCounter, Errors);
Assert.AreEqual<int>(errorsCounter, TraceList.Count);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace UAOOI.SemanticData.UANodeSetValidation.DataSerialization
public class ServiceResultExceptionUnitTest
{
[TestMethod]
[TestCategory("Code")]
public void ServiceResultExceptionCreateTestMethod()
{
ServiceResultException _ex = new ServiceResultException();
Expand All @@ -28,7 +27,6 @@ public void ServiceResultExceptionCreateTestMethod()
Assert.IsTrue(_ex.Message.Contains("UAOOI.SemanticData.UANodeSetValidation.DataSerialization"));
}
[TestMethod]
[TestCategory("Code")]
public void ServiceResultExceptionCreateWithMessageTestMethod()
{
TraceMessage traceMessage = TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdInvalidSyntax, "BuildError_BadNodeIdInvalid");
Expand All @@ -39,7 +37,7 @@ public void ServiceResultExceptionCreateWithMessageTestMethod()
Assert.AreEqual<string>("test message", _ex.Message);
Assert.IsNotNull(_ex.TraceMessage);
Assert.AreEqual<Focus>(BuildError.NodeIdInvalidSyntax.Focus, _ex.TraceMessage.BuildError.Focus);
Assert.AreEqual<TraceEventType>(TraceEventType.Information, _ex.TraceMessage.TraceLevel);
Assert.AreEqual<TraceEventType>(TraceEventType.Warning, _ex.TraceMessage.TraceLevel);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public void ImportNodeIdTest()
Assert.AreEqual<int>(2, trace.Count);
Assert.IsTrue(trace[0].Message.Contains("http://cas.eu/UA/CommServer/UnitTests/ObjectTypeTest"));
Assert.AreEqual<string>("P0-0001030000", trace[0].BuildError.Identifier);
Assert.AreEqual<TraceEventType>(TraceEventType.Information, trace[0].TraceLevel);
Assert.AreEqual<TraceEventType>(TraceEventType.Warning, trace[0].TraceLevel);
Assert.IsTrue(trace[1].Message.Contains(randomURI.ToString()));
Assert.AreEqual<string>("P3-0802020000", trace[1].BuildError.Identifier);
Assert.AreEqual<TraceEventType>(TraceEventType.Information, trace[1].TraceLevel);
Assert.AreEqual<TraceEventType>(TraceEventType.Warning, trace[1].TraceLevel);
}

[TestMethod]
Expand Down Expand Up @@ -124,7 +124,7 @@ public void ImportQualifiedNameWrongNamespaceIndexTest()
Assert.AreEqual<int>(1, trace.Count);
Assert.IsTrue(trace[0].Message.Contains(randomURI.ToString()));
Assert.AreEqual<string>("P3-0802020000", trace[0].BuildError.Identifier);
Assert.AreEqual<TraceEventType>(TraceEventType.Information, trace[0].TraceLevel);
Assert.AreEqual<TraceEventType>(TraceEventType.Warning, trace[0].TraceLevel);
}

[TestMethod]
Expand Down Expand Up @@ -161,7 +161,7 @@ public void ModelUriModelsIsEmptyTest()
//Assert.AreEqual<string>("http://opcfoundation.org/UA/ADI/", _modelContext.ModelUri.ToString());
Assert.AreEqual<int>(1, trace.Count);
Assert.AreEqual<string>("P0-0001030000", trace[0].BuildError.Identifier);
Assert.AreEqual<TraceEventType>(TraceEventType.Information, trace[0].TraceLevel);
Assert.AreEqual<TraceEventType>(TraceEventType.Warning, trace[0].TraceLevel);
asMock.Verify(x => x.RegisterModel(It.IsAny<IModelTableEntry>()), Times.Once);
}

Expand Down
13 changes: 0 additions & 13 deletions SemanticData/UANodeSetValidation/AddressSpaceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________

using System;
using UAOOI.SemanticData.BuildingErrorsHandling;
using UAOOI.SemanticData.UANodeSetValidation.Diagnostic;

namespace UAOOI.SemanticData.UANodeSetValidation
Expand All @@ -20,16 +18,5 @@ public static class AddressSpaceFactory
/// Creates Address Space infrastructure exposed to the API clients as the <see cref="IAddressSpaceContext"/> interface using default tracing infrastructure.
/// </summary>
public static IAddressSpaceContext AddressSpace => new AddressSpaceContext(new AssemblyTraceSource());

//TODO Enhance/Improve the Program logging and tracing infrastructure. #590
///// <summary>
///// Gets the address space.
///// </summary>
///// <param name="traceCallback">The trace callback.</param>
///// <returns>An instance of the <see cref="IAddressSpaceContext"/> type.</returns>
//public static IAddressSpaceContext GetAddressSpace(Action<TraceMessage> traceCallback)
//{
// return new AddressSpaceContext(traceCallback);
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using UAOOI.Common.Infrastructure.Diagnostic;
using UAOOI.SemanticData.BuildingErrorsHandling;

//TODO BuildErrorsHandling - review the code #578
//TODO Enhance/Improve the Program logging and tracing infrastructure. #590
namespace UAOOI.SemanticData.UANodeSetValidation.Diagnostic
{
/// <summary>
Expand All @@ -19,6 +17,8 @@ namespace UAOOI.SemanticData.UANodeSetValidation.Diagnostic
/// <seealso cref="ITraceSource" />
internal class AssemblyTraceSource : IBuildErrorsHandling
{
#region constructors

/// <summary>
/// Initializes a new instance of the <see cref="AssemblyTraceSource"/> class using the default of the <see cref="ITraceSource"/>.
/// </summary>
Expand All @@ -36,6 +36,8 @@ internal AssemblyTraceSource(ITraceSource traceEvent)
traceSource = traceEvent;
}

#endregion constructors

#region IBuildErrorsHandling

/// <summary>
Expand Down Expand Up @@ -69,6 +71,10 @@ public void TraceData(TraceEventType eventType, int id, object data)

#endregion ITraceSource

#region private

private readonly ITraceSource traceSource;

#endregion private
}
}
2 changes: 1 addition & 1 deletion SemanticData/UANodeSetValidation/IUANodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal interface IUANodeBase: IEquatable<IUANodeBase>
/// <summary>
/// Exports the browse name of the wrapped node by this instance.
/// </summary>
/// <returns>An instance of <see cref="XmlQualifiedName" /> representing the <see cref="BrowseName"/> of the node.</returns>
/// <returns>An instance of <see cref="XmlQualifiedName" /> representing the browse name of the node.</returns>
XmlQualifiedName ExportNodeBrowseName();
/// <summary>
/// Gets a value indicating whether this instance is a property.
Expand Down
Loading