Opc.Ua.DataChangeFilter.Validate C# (CSharp) Method

Validate() public method

Checks that the filter is valid.
public Validate ( ) : ServiceResult
return ServiceResult
        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;
        }