PolicyBasedSynchronousEventHandlerPerformPolicyValidation Method Content Studio 5.7 SDK
Content Studio Web Content Management System

[This is preliminary documentation and is subject to change.]

Performs the policy validation.

Namespace: ContentStudio.EventActions.SynchronousEventHandlers
Assembly: SyncEvtHand (in SyncEvtHand.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax

protected virtual void PerformPolicyValidation()
Exceptions

ExceptionCondition
InvalidOperationExceptionA policy rule has been violated by the status of the document passed in.
Remarks

This method gets called before the DoWork method and it, in its turn, will call your implementation of the ValidatePolicy method, once for each found enabled policy definition. If ValidatePolicy(Policy) method returns false the passed in Policy is concidered as being violated and an InvalidOperationException is thrown. This execption will be catched by Content Studio and communicated to the caller that performed the action tha triggered the event.

Developers can override this method if they want to do their own policy validation entirely. In this case, unless your code also calls the base class provided implementation, ValidatePolicy will not be called.

Examples

This code shows an example of a validation operation, in fact it is similar to the implementation already provided by Content Studio.

C#
protected override void PerformPolicyValidation()
{
    foreach (var policy in Policies)
    {
        if (policy.Enabled)
        {
            if (!ValidatePolicy(policy))
            {
                string message;
                if (!String.IsNullOrEmpty(policy.ViolationMessage))
                {
                    if (policy.ViolationMessage.Contains("{0}"))
                        message = String.Format(policy.ViolationMessage, InterpretPolicyValue(policy));
                    else
                        message = policy.ViolationMessage;
                }
                else
                    message = "A policy rule has been violated by this document. No specific message has been configured.";

                throw new InvalidOperationException(String.Concat(message, "\r\nPolicy:", policy.Name, "; ", policy.Description));
            }
        }
    }
}
See Also

Reference

Other Resources