public static Create ( |
||
e | ||
defaultCode | uint | |
format | string | |
return |
public static ServiceResult Create(Exception e, uint defaultCode, string format, params object[] args)
{
// replace the default code with the one from the exception.
ServiceResultException sre = e as ServiceResultException;
if (sre != null)
{
defaultCode = sre.StatusCode;
}
if (format == null)
{
return new ServiceResult(e, defaultCode);
}
if (args == null || args.Length == 0)
{
return new ServiceResult(defaultCode, format, e);
}
return new ServiceResult(defaultCode, Utils.Format(format, args), e);
}
/// <summary> /// Checks that the filter is valid. /// </summary> public ServiceResult Validate() { // check deadband type enumeration. if ((int)DeadbandType < (int)Opc.Ua.DeadbandType.None || (int)DeadbandType > (int)Opc.Ua.DeadbandType.Percent) { return(ServiceResult.Create( StatusCodes.BadDeadbandFilterInvalid, "Deadband type '{0}' is not recognized.", DeadbandType)); } // check data change trigger enumeration. if ((int)Trigger < (int)DataChangeTrigger.Status || (int)Trigger > (int)DataChangeTrigger.StatusValueTimestamp) { return(ServiceResult.Create( StatusCodes.BadDeadbandFilterInvalid, "Deadband trigger '{0}' is not recognized.", Trigger)); } // deadband value must always be greater than 0. if (DeadbandValue < 0) { return(ServiceResult.Create( StatusCodes.BadDeadbandFilterInvalid, "Deadband value '{0}' cannot be less than zero.", DeadbandValue)); } // deadband percentage must be less than 100. if ((int)DeadbandType == (int)Opc.Ua.DeadbandType.Percent) { if (DeadbandValue > 100) { return(ServiceResult.Create( StatusCodes.BadDeadbandFilterInvalid, "Percentage deadband value '{0}' cannot be greater than 100.", DeadbandValue)); } } // passed initial validation. return(ServiceResult.Good); }