Exemplo n.º 1
0
        internal static bool ValidateEventActionPairs(InterceptorAgentEvent evt, InterceptorAgentRuleBehavior action, out LocalizedString error)
        {
            error = LocalizedString.Empty;
            foreach (KeyValuePair <InterceptorAgentRuleBehavior, InterceptorAgentEvent> keyValuePair in InterceptorAgentRule.InvalidActionEventPairs)
            {
                if ((ushort)(evt & keyValuePair.Value) != 0 && action == keyValuePair.Key)
                {
                    InterceptorAgentEvent validEventsMask = ~keyValuePair.Value;
                    IEnumerable <string>  values          = from InterceptorAgentEvent val in Enum.GetValues(typeof(InterceptorAgentEvent))
                                                            where (ushort)(val & validEventsMask) != 0
                                                            select val.ToString();

                    error = Strings.InterceptorErrorInvalidEventActionPair((evt & keyValuePair.Value).ToString(), keyValuePair.Key.ToString(), string.Join(", ", values));
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
 internal static bool ValidateEventConditionPairs(InterceptorAgentEvent evt, List <InterceptorAgentCondition> conditions, out LocalizedString error)
 {
     error = LocalizedString.Empty;
     using (IEnumerator <KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> > enumerator = InterceptorAgentRule.InvalidConditionEventPairs.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> pair = enumerator.Current;
             InterceptorAgentEvent evt2 = evt;
             KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> pair5 = pair;
             if (evt2 == pair5.Value)
             {
                 if (conditions.Exists(delegate(InterceptorAgentCondition c)
                 {
                     InterceptorAgentConditionType property = c.Property;
                     KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> pair4 = pair;
                     return(property == pair4.Key);
                 }))
                 {
                     IEnumerable <string> values = InterceptorAgentCondition.AllConditions.Except(new string[]
                     {
                         InterceptorAgentConditionType.Invalid.ToString()
                     }).Except(from p in InterceptorAgentRule.InvalidConditionEventPairs
                               where p.Value == evt
                               select p.Key.ToString());
                     KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> pair2 = pair;
                     string evt3 = pair2.Value.ToString();
                     KeyValuePair <InterceptorAgentConditionType, InterceptorAgentEvent> pair3 = pair;
                     error = Strings.InterceptorErrorInvalidEventConditionPair(evt3, pair3.Key.ToString(), string.Join(",", values));
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 3
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();
        }