/// <summary>
/// Acknowledges the specified context.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="eventId">The event id.</param>
/// <param name="comment">The comment.</param>
/// <returns></returns>
public uint Acknowledge(
ServerSystemContext context,
byte[] eventId,
LocalizedText comment)
{
// get the user name from the context.
string userName = String.Empty;
if (context.UserIdentity != null)
{
userName = context.UserIdentity.DisplayName;
}
// get the comment.
string commentText = String.Empty;
if (comment != null)
{
commentText = comment.Text;
}
System.Runtime.InteropServices.ComTypes.FILETIME ftActiveTime;
// unpack the event id.
ServiceMessageContext messageContext = new ServiceMessageContext();
messageContext.NamespaceUris = context.NamespaceUris;
messageContext.ServerUris = context.ServerUris;
messageContext.Factory = context.EncodeableFactory;
BinaryDecoder decoder = new BinaryDecoder(eventId, messageContext);
string source = decoder.ReadString(null);
string conditionName = decoder.ReadString(null);
ftActiveTime.dwHighDateTime = decoder.ReadInt32(null);
ftActiveTime.dwLowDateTime = decoder.ReadInt32(null);
int cookie = decoder.ReadInt32(null);
decoder.Close();
string methodName = "IOPCEventServer.AckCondition";
IntPtr pErrors = IntPtr.Zero;
try
{
IOPCEventServer server = BeginComCall<IOPCEventServer>(methodName, true);
server.AckCondition(
1,
userName,
commentText,
new string[] { source },
new string[] { conditionName },
new System.Runtime.InteropServices.ComTypes.FILETIME[] { ftActiveTime },
new int[] { cookie },
out pErrors);
}
catch (Exception e)
{
ComCallError(methodName, e);
return StatusCodes.BadUnexpectedError;
}
finally
{
EndComCall(methodName);
}
// unmarshal results.
int[] errors = ComUtils.GetInt32s(ref pErrors, 1, true);
if (errors[0] == ResultIds.S_ALREADYACKED)
{
return StatusCodes.BadConditionBranchAlreadyAcked;
}
else if (errors[0] < 0)
{
return StatusCodes.BadEventIdUnknown;
}
return StatusCodes.Good;
}