Skip to content

Commit

Permalink
Fix issue setting empty comments Issue #1264 (#1265)
Browse files Browse the repository at this point in the history
* Fix issue setting empty comments

On Acknowledge and Confirm, if a comment with an empty Locale and empty Text is passed from the client, then the comment should remain untouched.
Also fixed issue when firing an event, clearing the change mask on all children of the alarm will update any monitored item watching the alarm parameters, like Comment, EventId, etc.

fixes #1264
  • Loading branch information
Archie-Miller committed Jan 29, 2021
1 parent b363442 commit fac8ed2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 40 additions & 2 deletions Stack/Opc.Ua.Core/Stack/State/AcknowledgeableConditionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ protected override void UpdateEffectiveState(ISystemContext context)
if (ServiceResult.IsGood(error))
{
SetAcknowledgedState(context, true);
SetComment(context, comment, GetCurrentUserId(context));
if (CanSetComment(comment))
{
SetComment(context, comment, GetCurrentUserId(context));
}
}

if (this.AreEventsMonitored)
Expand Down Expand Up @@ -291,7 +294,10 @@ protected virtual void UpdateStateAfterUnacknowledge(ISystemContext context)
if (ServiceResult.IsGood(error))
{
SetConfirmedState(context, true);
SetComment(context, comment, GetCurrentUserId(context));
if (CanSetComment(comment))
{
SetComment(context, comment, GetCurrentUserId(context));
}
}

if (this.AreEventsMonitored)
Expand Down Expand Up @@ -417,6 +423,38 @@ protected virtual void UpdateStateAfterUnconfirm(ISystemContext context)
UpdateEffectiveState(context);
}
}

/// <summary>
/// Determines if a comment should be added on Acknowledgement or Confirm.
/// </summary>
/// <param name="comment">The client provided comment.</param>
/// <returns>Boolean stating whether the comment should be set</returns>
/// <remarks>
/// According to the specification for Alarms, the Acknowledgement states that
/// "If the comment field is NULL (both locale and text are empty) it will be
/// ignored and any existing comments will remain unchanged."
/// This also applies to the Confirm method, although the spec needs updating
/// (Mantis issue 6405)
/// </remarks>
private bool CanSetComment(LocalizedText comment)
{
bool canSetComment = false;

if (comment != null)
{
canSetComment = true;

bool emptyComment = comment.Text == null || comment.Text.Length == 0;
bool emptyLocale = comment.Locale == null || comment.Locale.Length == 0;

if (emptyComment && emptyLocale)
{
canSetComment = false;
}
}

return canSetComment;
}
#endregion

#region Public Interface
Expand Down
2 changes: 2 additions & 0 deletions Stack/Opc.Ua.Core/Stack/State/ConditionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ protected void ReportStateChange(ISystemContext context, bool ignoreDisabledStat
this.Time.Value = DateTime.UtcNow;
this.ReceiveTime.Value = this.Time.Value;

ClearChangeMasks(context, includeChildren: true);

// report a state change event.
if (this.AreEventsMonitored)
{
Expand Down

0 comments on commit fac8ed2

Please sign in to comment.