Exemple #1
0
        /// <summary>
        /// Resolves the type of the attribute.
        /// </summary>
        /// <param name="desc">The desc.</param>
        /// <param name="engineImportService">The engine import service.</param>
        /// <returns></returns>
        public static Type ResolveAttributeType(AnnotationDesc desc, EngineImportService engineImportService)
        {
            // CLR attributes use a different notation that Java annotations.  Format
            // the attribute according to CLR conventions.
            var attributeTypeName       = desc.Name;
            var attributeTypeNameForCLR =
                (attributeTypeName.EndsWith("Attribute"))
                    ? attributeTypeName
                    : String.Format("{0}Attribute", attributeTypeName);

            // resolve attribute type
            try
            {
                return(engineImportService.ResolveType(attributeTypeNameForCLR));
            }
            catch (EngineImportException e)
            {
                throw new AttributeException("Failed to resolve @-annotation class: " + e.Message);
            }

            return(null);
        }
 public Type ResolveType(string className, bool forAnnotation)
 {
     return(_engineImportService.ResolveType(className, forAnnotation));
 }
Exemple #3
0
        public void CreateNewVariable(string optionalContextName, string variableName, string variableType, bool constant, bool array, bool arrayOfPrimitive, object value, EngineImportService engineImportService)
        {
            // Determime the variable type
            var       primitiveType = TypeHelper.GetPrimitiveTypeForName(variableType);
            var       type          = TypeHelper.GetTypeForSimpleName(variableType);
            Type      arrayType     = null;
            EventType eventType     = null;

            if (type == null)
            {
                if (variableType.ToLower() == "object")
                {
                    type = typeof(Object);
                }
                if (type == null)
                {
                    eventType = _eventAdapterService.GetEventTypeByName(variableType);
                    if (eventType != null)
                    {
                        type = eventType.UnderlyingType;
                    }
                }
                if (type == null)
                {
                    try
                    {
                        type = engineImportService.ResolveType(variableType, false);
                        if (array)
                        {
                            arrayType = TypeHelper.GetArrayType(type.GetBoxedType());
                        }
                    }
                    catch (EngineImportException e)
                    {
                        Log.Debug("Not found '" + type + "': " + e.Message, e);
                        // expected
                    }
                }
                if (type == null)
                {
                    throw new VariableTypeException("Cannot create variable '" + variableName + "', type '" +
                                                    variableType + "' is not a recognized type");
                }
                if (array && eventType != null)
                {
                    throw new VariableTypeException("Cannot create variable '" + variableName + "', type '" +
                                                    variableType + "' cannot be declared as an array type");
                }
            }
            else
            {
                if (array)
                {
                    if (arrayOfPrimitive)
                    {
                        if (primitiveType == null)
                        {
                            throw new VariableTypeException("Cannot create variable '" + variableName + "', type '" +
                                                            variableType + "' is not a primitive type");
                        }
                        arrayType = TypeHelper.GetArrayType(primitiveType);
                    }
                    else
                    {
                        arrayType = TypeHelper.GetArrayType(type.GetBoxedType());
                    }
                }
            }

            if ((eventType == null) && (!type.IsBuiltinDataType()) && (type != typeof(object)) && !type.IsArray && !type.IsEnum)
            {
                if (array)
                {
                    throw new VariableTypeException("Cannot create variable '" + variableName + "', type '" +
                                                    variableType + "' cannot be declared as an array, only scalar types can be array");
                }
                eventType = _eventAdapterService.AddBeanType(type.Name, type, false, false, false);
            }

            if (arrayType != null)
            {
                type = arrayType;
            }

            CreateNewVariable(variableName, optionalContextName, type, eventType, constant, value);
        }
Exemple #4
0
        private CountMinSketchSpec ValidateSpecification(ExprEvaluatorContext exprEvaluatorContext, EngineImportService engineImportService)
        {
            // default specification
            var spec = new CountMinSketchSpec(new CountMinSketchSpecHashes(DEFAULT__EPS_OF_TOTAL_COUNT, DEFAULT__CONFIDENCE, DEFAULT__SEED), null, DEFAULT__AGENT);

            // no parameters
            if (this.ChildNodes.Length == 0)
            {
                return(spec);
            }

            // check expected parameter type: a json object
            if (this.ChildNodes.Length > 1 || !(this.ChildNodes[0] is ExprConstantNode))
            {
                throw DeclaredWrongParameterExpr;
            }
            var constantNode = (ExprConstantNode)this.ChildNodes[0];
            var value        = constantNode.GetConstantValue(exprEvaluatorContext);

            if (!(value is IDictionary <string, object>))
            {
                throw DeclaredWrongParameterExpr;
            }

            // define what to populate
            var descriptors = new PopulateFieldWValueDescriptor[] {
                new PopulateFieldWValueDescriptor(NAME__EPS_OF_TOTAL_COUNT, typeof(double), spec.HashesSpec.GetType(), vv => {
                    if (vv != null)
                    {
                        spec.HashesSpec.EpsOfTotalCount = (double)vv;
                    }
                }, true),
                new PopulateFieldWValueDescriptor(NAME__CONFIDENCE, typeof(double), spec.HashesSpec.GetType(), vv => {
                    if (vv != null)
                    {
                        spec.HashesSpec.Confidence = (double)vv;
                    }
                }, true),
                new PopulateFieldWValueDescriptor(NAME__SEED, typeof(int), spec.HashesSpec.GetType(), vv => {
                    if (vv != null)
                    {
                        spec.HashesSpec.Seed = (int)vv;
                    }
                }, true),
                new PopulateFieldWValueDescriptor(NAME__TOPK, typeof(int), spec.GetType(), vv => {
                    if (vv != null)
                    {
                        spec.TopkSpec = (int)vv;
                    }
                }, true),
                new PopulateFieldWValueDescriptor(NAME__AGENT, typeof(string), spec.GetType(), vv => {
                    if (vv != null)
                    {
                        CountMinSketchAgent transform;
                        try {
                            var transformClass = engineImportService.ResolveType((string)vv);
                            transform          = TypeHelper.Instantiate <CountMinSketchAgent>(transformClass.FullName);
                        }
                        catch (Exception e) {
                            throw new ExprValidationException("Failed to instantiate agent provider: " + e.Message, e);
                        }
                        spec.Agent = transform;
                    }
                }, true),
            };

            // populate from json, validates incorrect names, coerces types, instantiates transform
            PopulateUtil.PopulateSpecCheckParameters(descriptors, (IDictionary <String, object>)value, spec, engineImportService);

            return(spec);
        }
Exemple #5
0
        public Type ResolveType(String className)

        {
            return(_engineImportService.ResolveType(className));
        }