protected override void InternalValidate()
        {
            base.InternalValidate();
            if (base.Fields.IsModified("ExpireTime") && DateTime.UtcNow > this.ExpireTime.ToUniversalTime())
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorExpireTimePassed(this.ExpireTime.ToString("G"))), ErrorCategory.InvalidData, "ExpireTime");
            }
            List <InterceptorAgentCondition> conditions;
            LocalizedString localizedString;

            if (!InterceptorHelper.TryCreateConditions(this.Condition, out conditions, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Condition);
                return;
            }
            if (this.Event == InterceptorAgentEvent.Invalid)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorEventInvalid), ErrorCategory.InvalidData, this.Event);
            }
            if (this.Action == InterceptorAgentRuleBehavior.NoOp)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorActionInvalid), ErrorCategory.InvalidData, this.Action);
            }
            if (!InterceptorHelper.ValidateEventConditionPairs(this.Event, conditions, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
            }
            if (!InterceptorHelper.ValidateEventActionPairs(this.Event, this.Action, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
            }
            InterceptorAgentAction interceptorAgentAction;
            LocalizedString        warning;

            if (!InterceptorHelper.TryCreateAction(this.Action, this.CustomResponseCode, base.Fields.IsChanged("CustomResponseCode"), this.CustomResponseString, base.Fields.IsChanged("CustomResponseText"), this.TimeInterval, this.Path, out interceptorAgentAction, out warning, out localizedString))
            {
                base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Action);
            }
            this.WriteWarningAndReset(warning);
            if (InterceptorAgentAction.IsArchivingBehavior(interceptorAgentAction.Action))
            {
                this.WriteWarning(InterceptorHelper.GetArchivedItemRetentionMessage(interceptorAgentAction.Action, this.Name, this.Path, 14));
            }
            this.ResolveTargets();
            if (!base.HasErrors)
            {
                this.rule = new InterceptorAgentRule(this.Name, this.Description, conditions, interceptorAgentAction, this.Event, this.Source, this.CreatedBy);
            }
        }
Example #2
0
        protected override void InternalValidate()
        {
            bool flag  = base.Fields.IsModified("Event");
            bool flag2 = base.Fields.IsModified("Action");
            bool flag3 = base.Fields.IsModified("Condition");
            bool flag4 = base.Fields.IsModified("CustomResponseCode");
            bool flag5 = base.Fields.IsModified("CustomResponseText");
            bool flag6 = base.Fields.IsModified("Description");
            bool flag7 = base.Fields.IsModified("TimeInterval");
            bool flag8 = base.Fields.IsModified("Path");

            this.xmlNeedsUpdating = (flag2 || flag || flag3 || flag4 || flag5 || flag7 || flag6 || flag8 || base.Fields.IsModified("Identity"));
            if (base.Fields.IsModified("ExpireTime") && DateTime.UtcNow > this.ExpireTime.ToUniversalTime())
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorExpireTimePassed(this.ExpireTime.ToString("G"))), ErrorCategory.InvalidData, "ExpireTime");
            }
            this.DataObject = (InterceptorRule)this.ResolveDataObject();
            if (this.xmlNeedsUpdating)
            {
                try
                {
                    this.rule = InterceptorAgentRule.CreateRuleFromXml(this.DataObject.Xml);
                    this.rule.SetPropertiesFromAdObjet(this.DataObject);
                }
                catch (FormatException exception)
                {
                    base.WriteError(exception, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
                catch (InvalidOperationException exception2)
                {
                    base.WriteError(exception2, ErrorCategory.InvalidData, null);
                    TaskLogger.LogExit();
                    return;
                }
            }
            if (this.rule.RuleVersion > InterceptorAgentRule.Version)
            {
                base.WriteError(new LocalizedException(Strings.InterceptorErrorModifyingNewerVersion(this.rule.RuleVersion.ToString())), ErrorCategory.InvalidOperation, null);
            }
            if (flag2 || flag)
            {
                InterceptorAgentRuleBehavior action = flag2 ? this.Action : this.rule.Action.Action;
                InterceptorAgentEvent        interceptorAgentEvent = flag ? this.Event : this.rule.Events;
                LocalizedString localizedString;
                if (!InterceptorHelper.ValidateEventActionPairs(interceptorAgentEvent, action, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = interceptorAgentEvent;
                string customResponseCode;
                if (flag2 && !flag4 && InterceptorHelper.TryGetStatusCodeForModifiedRejectAction(this.Action, this.rule.Action.Action, this.rule.Action.Response.StatusCode, out customResponseCode))
                {
                    this.CustomResponseCode = customResponseCode;
                    flag4 = base.Fields.IsModified("CustomResponseCode");
                }
            }
            if (flag3)
            {
                LocalizedString localizedString;
                List <InterceptorAgentCondition> conditions;
                if (!InterceptorHelper.TryCreateConditions(this.Condition, out conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidData, this.Condition);
                    return;
                }
                InterceptorAgentEvent evt = flag ? this.Event : this.rule.Events;
                if (!InterceptorHelper.ValidateEventConditionPairs(evt, conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Conditions = conditions;
            }
            if (flag)
            {
                LocalizedString localizedString;
                if (!flag3 && !InterceptorHelper.ValidateEventConditionPairs(this.Event, this.rule.Conditions, out localizedString))
                {
                    base.WriteError(new LocalizedException(localizedString), ErrorCategory.InvalidArgument, this.Condition);
                }
                this.rule.Events = this.Event;
            }
            if (flag6)
            {
                this.rule.Description = this.Description;
            }
            this.SetAction(flag4, flag5, flag2, flag8, flag7);
            this.ResolveTargets();
        }