Esempio n. 1
0
        protected internal static Type[] ValidateContextDesc(string contextName, ContextDetailPartitioned segmentedSpec)
        {
            if (segmentedSpec.Items.IsEmpty())
            {
                throw new ExprValidationException("Empty list of partition items");
            }

            // verify properties exist
            foreach (var item in segmentedSpec.Items)
            {
                var type = item.FilterSpecCompiled.FilterForEventType;
                foreach (var property in item.PropertyNames)
                {
                    var getter = type.GetGetter(property);
                    if (getter == null)
                    {
                        throw new ExprValidationException(
                                  "For context '" + contextName + "' property name '" + property + "' not found on type " +
                                  type.Name);
                    }
                }
            }

            // verify property number and types compatible
            ContextDetailPartitionItem firstItem = segmentedSpec.Items[0];

            if (segmentedSpec.Items.Count > 1)
            {
                // verify the same filter event type is only listed once

                for (var i = 0; i < segmentedSpec.Items.Count; i++)
                {
                    EventType compareTo = segmentedSpec.Items[i].FilterSpecCompiled.FilterForEventType;

                    for (var j = 0; j < segmentedSpec.Items.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }

                        EventType compareFrom = segmentedSpec.Items[j].FilterSpecCompiled.FilterForEventType;
                        if (compareFrom == compareTo)
                        {
                            throw new ExprValidationException(
                                      "For context '" + contextName + "' the event type '" + compareFrom.Name +
                                      "' is listed twice");
                        }
                        if (EventTypeUtility.IsTypeOrSubTypeOf(compareFrom, compareTo) ||
                            EventTypeUtility.IsTypeOrSubTypeOf(compareTo, compareFrom))
                        {
                            throw new ExprValidationException(
                                      "For context '" + contextName + "' the event type '" + compareFrom.Name +
                                      "' is listed twice: Event type '" +
                                      compareFrom.Name + "' is a subtype or supertype of event type '" + compareTo.Name + "'");
                        }
                    }
                }

                // build property type information
                var names      = new string[firstItem.PropertyNames.Count];
                var types      = new Type[firstItem.PropertyNames.Count];
                var typesBoxed = new Type[firstItem.PropertyNames.Count];
                for (var i = 0; i < firstItem.PropertyNames.Count; i++)
                {
                    string property = firstItem.PropertyNames[i];
                    names[i]      = property;
                    types[i]      = firstItem.FilterSpecCompiled.FilterForEventType.GetPropertyType(property);
                    typesBoxed[i] = types[i].GetBoxedType();
                }

                // compare property types and numbers
                for (var item = 1; item < segmentedSpec.Items.Count; item++)
                {
                    ContextDetailPartitionItem nextItem = segmentedSpec.Items[item];

                    // compare number of properties
                    if (nextItem.PropertyNames.Count != types.Length)
                    {
                        throw new ExprValidationException(
                                  "For context '" + contextName +
                                  "' expected the same number of property names for each event type, found " +
                                  types.Length + " properties for event type '" +
                                  firstItem.FilterSpecCompiled.FilterForEventType.Name +
                                  "' and " + nextItem.PropertyNames.Count + " properties for event type '" +
                                  nextItem.FilterSpecCompiled.FilterForEventType.Name + "'");
                    }

                    // compare property types
                    for (var i = 0; i < nextItem.PropertyNames.Count; i++)
                    {
                        string property  = nextItem.PropertyNames[i];
                        var    type      = nextItem.FilterSpecCompiled.FilterForEventType.GetPropertyType(property).GetBoxedType();
                        var    typeBoxed = type.GetBoxedType();
                        var    left      = TypeHelper.IsSubclassOrImplementsInterface(typeBoxed, typesBoxed[i]);
                        var    right     = TypeHelper.IsSubclassOrImplementsInterface(typesBoxed[i], typeBoxed);
                        if (typeBoxed != typesBoxed[i] && !left && !right)
                        {
                            throw new ExprValidationException(
                                      "For context '" + contextName + "' for context '" + contextName +
                                      "' found mismatch of property types, property '" + names[i] +
                                      "' of type '" + types[i].GetTypeNameFullyQualPretty() +
                                      "' compared to property '" + property +
                                      "' of type '" + typeBoxed.GetTypeNameFullyQualPretty() + "'");
                        }
                    }
                }
            }

            var propertyTypes = new Type[firstItem.PropertyNames.Count];

            for (var i = 0; i < firstItem.PropertyNames.Count; i++)
            {
                string property = firstItem.PropertyNames[i];
                propertyTypes[i] = firstItem.FilterSpecCompiled.FilterForEventType.GetPropertyType(property);
            }
            return(propertyTypes);
        }
        public ContextControllerPartitionedFilterCallback(EPServicesContext servicesContext, AgentInstanceContext agentInstanceContextCreateContext, ContextDetailPartitionItem partitionItem, ContextControllerPartitionedInstanceCreateCallback callback, ContextInternalFilterAddendum filterAddendum)
        {
            _agentInstanceContextCreateContext = agentInstanceContextCreateContext;
            _callback = callback;

            _filterHandle = new EPStatementHandleCallback(agentInstanceContextCreateContext.EpStatementAgentInstanceHandle, this);

            _getters = new EventPropertyGetter[partitionItem.PropertyNames.Count];
            for (int i = 0; i < partitionItem.PropertyNames.Count; i++)
            {
                var propertyName = partitionItem.PropertyNames[i];
                var getter       = partitionItem.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                _getters[i] = getter;
            }

            var addendum = filterAddendum != null?filterAddendum.GetFilterAddendum(partitionItem.FilterSpecCompiled) : null;

            var filterValueSet = partitionItem.FilterSpecCompiled.GetValueSet(null, null, addendum);

            _filterServiceEntry = servicesContext.FilterService.Add(filterValueSet, _filterHandle);
            var filtersVersion = servicesContext.FilterService.FiltersVersion;

            agentInstanceContextCreateContext.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = filtersVersion;
        }
Esempio n. 3
0
        public static FilterValueSetParam[][] GetAddendumFilters(
            object keyValue,
            FilterSpecCompiled filtersSpec,
            ContextDetailPartitioned segmentedSpec,
            StatementSpecCompiled optionalStatementSpecCompiled)
        {
            // determine whether create-named-window
            var isCreateWindow = optionalStatementSpecCompiled != null &&
                                 optionalStatementSpecCompiled.CreateWindowDesc != null;
            ContextDetailPartitionItem foundPartition = null;

            if (!isCreateWindow)
            {
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(
                        filtersSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                    if (typeOrSubtype)
                    {
                        foundPartition = partitionItem;
                    }
                }
            }
            else
            {
                var declaredAsName = optionalStatementSpecCompiled.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName == null)
                {
                    return(null);
                }
                foreach (var partitionItem in segmentedSpec.Items)
                {
                    if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                    {
                        foundPartition = partitionItem;
                        break;
                    }
                }
            }

            if (foundPartition == null)
            {
                return(null);
            }

            var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);

            if (foundPartition.PropertyNames.Count == 1)
            {
                var propertyName           = foundPartition.PropertyNames[0];
                var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(propertyName);
                var lookupable             = new FilterSpecLookupable(propertyName, getter, resultType, false);
                FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue);
                addendumFilters.Add(filter);
            }
            else
            {
                var keys = ((MultiKeyUntyped)keyValue).Keys;
                for (var i = 0; i < foundPartition.PropertyNames.Count; i++)
                {
                    var partitionPropertyName = foundPartition.PropertyNames[i];
                    var getter                 = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                    var resultType             = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                    var lookupable             = new FilterSpecLookupable(partitionPropertyName, getter, resultType, false);
                    FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keys[i]);
                    addendumFilters.Add(filter);
                }
            }

            var addendum = new FilterValueSetParam[1][];

            addendum[0] = addendumFilters.ToArray();

            var partitionFilters = foundPartition.ParametersCompiled;

            if (partitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, addendum[0]);
            }

            return(addendum);
        }
Esempio n. 4
0
        // Compare filters in statement with filters in segmented context, addendum filter compilation
        public static void PopulateAddendumFilters(
            Object keyValue,
            IList <FilterSpecCompiled> filtersSpecs,
            ContextDetailPartitioned segmentedSpec,
            StatementSpecCompiled optionalStatementSpecCompiled,
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums)
        {
            // determine whether create-named-window
            bool isCreateWindow = optionalStatementSpecCompiled != null && optionalStatementSpecCompiled.CreateWindowDesc != null;

            if (!isCreateWindow)
            {
                foreach (FilterSpecCompiled filtersSpec in filtersSpecs)
                {
                    ContextDetailPartitionItem foundPartition = null;
                    foreach (ContextDetailPartitionItem partitionItem in segmentedSpec.Items)
                    {
                        bool typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(filtersSpec.FilterForEventType, partitionItem.FilterSpecCompiled.FilterForEventType);
                        if (typeOrSubtype)
                        {
                            foundPartition = partitionItem;
                        }
                    }

                    if (foundPartition == null)
                    {
                        continue;
                    }

                    var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);
                    if (foundPartition.PropertyNames.Count == 1)
                    {
                        var propertyName = foundPartition.PropertyNames[0];
                        var getter       = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(propertyName);
                        var resultType   = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(propertyName);
                        var lookupable   = new FilterSpecLookupable(propertyName, getter, resultType);
                        var filter       = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keyValue);
                        addendumFilters.Add(filter);
                    }
                    else
                    {
                        var keys = ((MultiKeyUntyped)keyValue).Keys;
                        for (int i = 0; i < foundPartition.PropertyNames.Count; i++)
                        {
                            var partitionPropertyName = foundPartition.PropertyNames[i];
                            var getter     = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                            var resultType = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                            var lookupable = new FilterSpecLookupable(partitionPropertyName, getter, resultType);
                            var filter     = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, keys[i]);
                            addendumFilters.Add(filter);
                        }
                    }

                    // add those predefined filter parameters, if any
                    FilterValueSetParam[][] partitionFilters = foundPartition.ParametersCompiled;

                    // add to existing if any are present
                    AddAddendums(addendums, addendumFilters, filtersSpec, partitionFilters);
                }
            }
            // handle segmented context for create-window
            else
            {
                String declaredAsName = optionalStatementSpecCompiled.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName != null)
                {
                    foreach (FilterSpecCompiled filtersSpec in filtersSpecs)
                    {
                        ContextDetailPartitionItem foundPartition = null;
                        foreach (ContextDetailPartitionItem partitionItem in segmentedSpec.Items)
                        {
                            if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                            {
                                foundPartition = partitionItem;
                                break;
                            }
                        }

                        if (foundPartition == null)
                        {
                            continue;
                        }

                        var addendumFilters = new List <FilterValueSetParam>(foundPartition.PropertyNames.Count);
                        var propertyNumber  = 0;
                        foreach (String partitionPropertyName in foundPartition.PropertyNames)
                        {
                            var getter     = foundPartition.FilterSpecCompiled.FilterForEventType.GetGetter(partitionPropertyName);
                            var resultType = foundPartition.FilterSpecCompiled.FilterForEventType.GetPropertyType(partitionPropertyName);
                            var lookupable = new FilterSpecLookupable(partitionPropertyName, getter, resultType);

                            Object propertyValue;
                            if (keyValue is MultiKeyUntyped)
                            {
                                propertyValue = ((MultiKeyUntyped)keyValue).Get(propertyNumber);
                            }
                            else
                            {
                                propertyValue = keyValue;
                            }

                            FilterValueSetParam filter = new FilterValueSetParamImpl(lookupable, FilterOperator.EQUAL, propertyValue);
                            addendumFilters.Add(filter);
                            propertyNumber++;
                        }

                        // add to existing if any are present
                        AddAddendums(addendums, addendumFilters, filtersSpec, foundPartition.ParametersCompiled);
                    }
                }
            }
        }