Пример #1
0
        internal ArrayList FindFiringRuleInfos(Type eventType, int eventCode)
        {
            ArrayList         list;
            object            obj2;
            bool              flag = eventCode < 0x186a0;
            CustomWebEventKey key  = null;
            int num  = 0;
            int num2 = 0;

            if (flag)
            {
                WebEventCodes.GetEventArrayIndexsFromEventCode(eventCode, out num, out num2);
                list = _cachedMatchedRules[num, num2];
            }
            else
            {
                key  = new CustomWebEventKey(eventType, eventCode);
                list = (ArrayList)this._cachedMatchedRulesForCustomEvents[key];
            }
            if (list != null)
            {
                return(list);
            }
            if (flag)
            {
                obj2 = _cachedMatchedRules;
            }
            else
            {
                obj2 = this._cachedMatchedRulesForCustomEvents;
            }
            lock (obj2)
            {
                if (flag)
                {
                    list = _cachedMatchedRules[num, num2];
                }
                else
                {
                    list = (ArrayList)this._cachedMatchedRulesForCustomEvents[key];
                }
                if (list != null)
                {
                    return(list);
                }
                ArrayList list2 = new ArrayList();
                for (int i = this._ruleInfos.Count - 1; i >= 0; i--)
                {
                    RuleInfo ruleInfo = (RuleInfo)this._ruleInfos[i];
                    if (ruleInfo.Match(eventType, eventCode))
                    {
                        list2.Add(new FiringRuleInfo(ruleInfo));
                    }
                }
                int count = list2.Count;
                for (int j = 0; j < count; j++)
                {
                    FiringRuleInfo info2 = (FiringRuleInfo)list2[j];
                    if (info2._ruleInfo._referencedProvider != null)
                    {
                        for (int k = j + 1; k < count; k++)
                        {
                            FiringRuleInfo info3 = (FiringRuleInfo)list2[k];
                            if (((info3._ruleInfo._referencedProvider != null) && (info3._indexOfFirstRuleInfoWithSameProvider == -1)) && (info2._ruleInfo._referencedProvider == info3._ruleInfo._referencedProvider))
                            {
                                if (info2._indexOfFirstRuleInfoWithSameProvider == -1)
                                {
                                    info2._indexOfFirstRuleInfoWithSameProvider = j;
                                }
                                info3._indexOfFirstRuleInfoWithSameProvider = j;
                            }
                        }
                    }
                }
                if (flag)
                {
                    _cachedMatchedRules[num, num2] = list2;
                }
                else
                {
                    this._cachedMatchedRulesForCustomEvents[key] = list2;
                }
                return(list2);
            }
        }
Пример #2
0
        // Find the corresponding array of RuleInfo based on the fired event
        internal ArrayList FindFiringRuleInfos(Type eventType, int eventCode)
        {
            ArrayList         foundFiringRuleInfos;
            bool              systemEvent       = eventCode < WebEventCodes.WebExtendedBase;
            CustomWebEventKey customWebEventKey = null;
            object            lockObject;
            int index0 = 0, index1 = 0;

#if DBG
            if (systemEvent)
            {
                Type type;

                type = (Type)_cachedTypeOfMatchedRulesSystem[eventCode];
                if (type == null)
                {
                    lock (_cachedTypeOfMatchedRulesSystem) {
                        type = (Type)_cachedTypeOfMatchedRulesSystem[eventCode];
                        if (type == null)
                        {
                            _cachedTypeOfMatchedRulesSystem[eventCode] = eventType;
                        }
                    }
                }

                if (type != null)
                {
                    Debug.Assert(type == eventType,
                                 "For system events, we assume each event code will map only to one event type. " +
                                 "Eventcode= " + eventCode + "; stored type= " + type.ToString() +
                                 "; raised event type= " + eventType);
                }
            }
#endif

            // First, we look at the cache to see if we find the array.
            if (systemEvent)
            {
                WebEventCodes.GetEventArrayIndexsFromEventCode(eventCode, out index0, out index1);
                foundFiringRuleInfos = _cachedMatchedRules[index0, index1];
            }
            else
            {
                customWebEventKey    = new CustomWebEventKey(eventType, eventCode);
                foundFiringRuleInfos = (ArrayList)_cachedMatchedRulesForCustomEvents[customWebEventKey];
            }

            if (foundFiringRuleInfos != null)
            {
                return(foundFiringRuleInfos);
            }

            if (systemEvent)
            {
                lockObject = _cachedMatchedRules;
            }
            else
            {
                lockObject = _cachedMatchedRulesForCustomEvents;
            }

            lock (lockObject) {
                if (systemEvent)
                {
                    foundFiringRuleInfos = _cachedMatchedRules[index0, index1];
                }
                else
                {
                    Debug.Assert(customWebEventKey != null);
                    foundFiringRuleInfos = (ArrayList)_cachedMatchedRulesForCustomEvents[customWebEventKey];
                }

                if (foundFiringRuleInfos != null)
                {
                    return(foundFiringRuleInfos);
                }

                // Not found in cache.

                ArrayList matchedRules = new ArrayList();

                // Go thru the sorted ruleInfo array and look for matching ruleInfo,
                // starting from the most specific type.
                for (int i = _ruleInfos.Count - 1; i >= 0; i--)
                {
                    RuleInfo curRule = (RuleInfo)_ruleInfos[i];

                    // Now see if the current rule matches the raised event
                    if (curRule.Match(eventType, eventCode))
                    {
                        matchedRules.Add(new FiringRuleInfo(curRule));
                    }
                }

                // Then for each matched rule, we need to figure out if the provider it
                // uses is also used by other rules.  We need this info because if multiple rules are
                // using the same provider, we fire the event to the provider only once.
                int count = matchedRules.Count;
                for (int i = 0; i < count; i++)
                {
                    FiringRuleInfo info1 = (FiringRuleInfo)matchedRules[i];

                    if (info1._ruleInfo._referencedProvider != null)
                    {
                        for (int j = i + 1; j < count; j++)
                        {
                            FiringRuleInfo info2 = (FiringRuleInfo)matchedRules[j];
                            if (info2._ruleInfo._referencedProvider != null &&                              // ignore null-provider
                                info2._indexOfFirstRuleInfoWithSameProvider == -1 &&                        // ignore rules that were marked already
                                info1._ruleInfo._referencedProvider == info2._ruleInfo._referencedProvider) // they are pointing to the same provider

                            // We'll remember the index of the first rule info that share the same
                            // provider. For details on how this index is used, please see
                            // WebBaseEvent.RaiseInternal.
                            {
                                if (info1._indexOfFirstRuleInfoWithSameProvider == -1)
                                {
                                    info1._indexOfFirstRuleInfoWithSameProvider = i;
                                }

                                info2._indexOfFirstRuleInfoWithSameProvider = i;
                            }
                        }
                    }
                }


#if DBG
                Debug.Trace("FindRuleInfos", "------------------------------------------------");
                Debug.Trace("FindRuleInfos", "Find ruleInfos for event with type=" + eventType.ToString() +
                            ", EventCode=" + eventCode);

                foreach (FiringRuleInfo info in matchedRules)
                {
                    Debug.Trace("FindRuleInfos", "Provider=" + info._ruleInfo._ruleSettings.Provider +
                                "; eventNameType=" + info._ruleInfo._eventMappingSettings.RealType.ToString() +
                                "; _indexOfFirstRuleInfoWithSameProvider=" + info._indexOfFirstRuleInfoWithSameProvider);
                }
                Debug.Trace("FindRuleInfos", "------------------------------------------------");
#endif

                // save matchedRules in the cache
                if (systemEvent)
                {
                    _cachedMatchedRules[index0, index1] = matchedRules;
                }
                else
                {
                    Debug.Assert(customWebEventKey != null);
                    _cachedMatchedRulesForCustomEvents[customWebEventKey] = matchedRules;
                }

                return(matchedRules);
            }
        }