Beispiel #1
0
        public void TestResolveExtensionMethod()
        {
            var methodResolver = new EngineImportServiceImpl(
                false,
                false,
                false,
                false,
                MathContext.DECIMAL32,
                TimeZoneInfo.Local,
                TimeAbacusMilliseconds.INSTANCE,
                new ConfigurationEngineDefaults.ThreadingProfile(),
                null,
                null,
                false,
                null,
                null,
                _container.Resolve <ClassLoaderProvider>());

            var targetType   = typeof(SupportBean);
            var targetMethod = "GetNameExtended";
            var args         = new Type[0];

            var method = methodResolver.ResolveMethod(targetType, targetMethod, args, null, null);

            Assert.That(method, Is.Not.Null);
            Assert.That(method.DeclaringType, Is.EqualTo(typeof(SupportBeanExtensions)));
            Assert.That(method.Name, Is.EqualTo(targetMethod));
            Assert.That(method.IsExtensionMethod(), Is.True);
        }
        /// <summary>Constructs the auto import service. </summary>
        /// <param name="configSnapshot">config info</param>
        /// <returns>service</returns>
        internal static EngineImportService MakeEngineImportService(
            ConfigurationInformation configSnapshot,
            AggregationFactoryFactory aggregationFactoryFactory)
        {
            var expression          = configSnapshot.EngineDefaults.ExpressionConfig;
            var engineImportService = new EngineImportServiceImpl(
                expression.IsExtendedAggregation,
                expression.IsUdfCache,
                expression.IsDuckTyping,
                configSnapshot.EngineDefaults.LanguageConfig.IsSortUsingCollator,
                expression.MathContext,
                expression.TimeZone,
                configSnapshot.EngineDefaults.ExecutionConfig.ThreadingProfile,
                aggregationFactoryFactory);

            engineImportService.AddMethodRefs(configSnapshot.MethodInvocationReferences);

            // Add auto-imports
            try
            {
                foreach (var importName in configSnapshot.Imports)
                {
                    engineImportService.AddImport(importName);
                }

                foreach (var importName in configSnapshot.AnnotationImports)
                {
                    engineImportService.AddAnnotationImport(importName);
                }

                foreach (ConfigurationPlugInAggregationFunction config in configSnapshot.PlugInAggregationFunctions)
                {
                    engineImportService.AddAggregation(config.Name, config);
                }

                foreach (ConfigurationPlugInAggregationMultiFunction config in configSnapshot.PlugInAggregationMultiFunctions)
                {
                    engineImportService.AddAggregationMultiFunction(config);
                }

                foreach (ConfigurationPlugInSingleRowFunction config in configSnapshot.PlugInSingleRowFunctions)
                {
                    engineImportService.AddSingleRow(config.Name, config.FunctionClassName, config.FunctionMethodName, config.ValueCache, config.FilterOptimizable, config.RethrowExceptions);
                }
            }
            catch (EngineImportException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            return(engineImportService);
        }
        public void TestResolveExtensionMethod()
        {
            var methodResolver = new EngineImportServiceImpl(
                false,
                false,
                false,
                false,
                MathContext.DECIMAL32,
                TimeZoneInfo.Local,
                new ConfigurationEngineDefaults.ThreadingProfile(),
                null);

            var targetType   = typeof(SupportAggMFFunc);
            var targetMethod = "GetName";
            var args         = new Type[0];

            var method = methodResolver.ResolveMethod(targetType, targetMethod, args, null, null);

            Assert.That(method, Is.Not.Null);
            Assert.That(method.DeclaringType, Is.EqualTo(typeof(SupportAggMFFuncExtensions)));
            Assert.That(method.Name, Is.EqualTo(targetMethod));
            Assert.That(method.IsExtensionMethod(), Is.True);
        }
        /// <summary>
        /// Constructs the auto import service.
        /// </summary>
        /// <param name="classLoaderProvider">The class loader provider.</param>
        /// <param name="configSnapshot">config INFO</param>
        /// <param name="aggregationFactoryFactory">factory of aggregation service provider</param>
        /// <param name="engineURI">The engine URI.</param>
        /// <returns>
        /// service
        /// </returns>
        /// <exception cref="ConfigurationException">Invalid time-source time unit of " + timeUnit + ", expected millis or micros
        /// or
        /// Error configuring engine: " + ex.Message</exception>
        internal static EngineImportService MakeEngineImportService(
            ClassLoaderProvider classLoaderProvider,
            ConfigurationInformation configSnapshot,
            AggregationFactoryFactory aggregationFactoryFactory,
            String engineURI)
        {
            TimeUnit   timeUnit = configSnapshot.EngineDefaults.TimeSource.TimeUnit;
            TimeAbacus timeAbacus;

            if (timeUnit == TimeUnit.MILLISECONDS)
            {
                timeAbacus = TimeAbacusMilliseconds.INSTANCE;
            }
            else if (timeUnit == TimeUnit.MICROSECONDS)
            {
                timeAbacus = TimeAbacusMicroseconds.INSTANCE;
            }
            else
            {
                throw new ConfigurationException(
                          "Invalid time-source time unit of " + timeUnit + ", expected millis or micros");
            }

            var codegenGetters = configSnapshot.EngineDefaults.Execution.CodeGeneration.IsEnablePropertyGetter;

            if (codegenGetters)
            {
                if (CheckPackageName("uri_" + engineURI) == PackageName.INVALID)
                {
                    throw new ConfigurationException("Invalid engine URI '" + engineURI + "', code generation requires an engine URI that is a valid Java-language identifier and may not contain Java language keywords");
                }
            }

            var expression          = configSnapshot.EngineDefaults.Expression;
            var engineImportService = new EngineImportServiceImpl(
                expression.IsExtendedAggregation,
                expression.IsUdfCache, expression.IsDuckTyping,
                configSnapshot.EngineDefaults.Language.IsSortUsingCollator,
                configSnapshot.EngineDefaults.Expression.MathContext,
                configSnapshot.EngineDefaults.Expression.TimeZone, timeAbacus,
                configSnapshot.EngineDefaults.Execution.ThreadingProfile,
                configSnapshot.TransientConfiguration,
                aggregationFactoryFactory,
                codegenGetters,
                engineURI,
                null,
                classLoaderProvider);

            engineImportService.AddMethodRefs(configSnapshot.MethodInvocationReferences);

            // Add auto-imports
            try
            {
                foreach (var importName in configSnapshot.Imports)
                {
                    engineImportService.AddImport(importName);
                }

                foreach (var importName in configSnapshot.AnnotationImports)
                {
                    engineImportService.AddAnnotationImport(importName);
                }

                foreach (var config in configSnapshot.PlugInAggregationFunctions)
                {
                    engineImportService.AddAggregation(config.Name, config);
                }

                foreach (var config in configSnapshot.PlugInAggregationMultiFunctions)
                {
                    engineImportService.AddAggregationMultiFunction(config);
                }

                foreach (var config in configSnapshot.PlugInSingleRowFunctions)
                {
                    engineImportService.AddSingleRow(
                        config.Name, config.FunctionClassName, config.FunctionMethodName, config.ValueCache,
                        config.FilterOptimizable, config.IsRethrowExceptions, config.EventTypeName);
                }
            }
            catch (EngineImportException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            return(engineImportService);
        }
        /// <summary>
        /// Constructs the auto import service.
        /// </summary>
        /// <param name="configSnapshot">config INFO</param>
        /// <param name="aggregationFactoryFactory">factory of aggregation service provider</param>
        /// <returns>service</returns>
        internal static EngineImportService MakeEngineImportService(
            ConfigurationInformation configSnapshot,
            AggregationFactoryFactory aggregationFactoryFactory)
        {
            TimeUnit   timeUnit = configSnapshot.EngineDefaults.TimeSource.TimeUnit;
            TimeAbacus timeAbacus;

            if (timeUnit == TimeUnit.MILLISECONDS)
            {
                timeAbacus = TimeAbacusMilliseconds.INSTANCE;
            }
            else if (timeUnit == TimeUnit.MICROSECONDS)
            {
                timeAbacus = TimeAbacusMicroseconds.INSTANCE;
            }
            else
            {
                throw new ConfigurationException(
                          "Invalid time-source time unit of " + timeUnit + ", expected millis or micros");
            }

            var expression          = configSnapshot.EngineDefaults.Expression;
            var engineImportService = new EngineImportServiceImpl(
                expression.IsExtendedAggregation,
                expression.IsUdfCache, expression.IsDuckTyping,
                configSnapshot.EngineDefaults.Language.IsSortUsingCollator,
                configSnapshot.EngineDefaults.Expression.MathContext,
                configSnapshot.EngineDefaults.Expression.TimeZone, timeAbacus,
                configSnapshot.EngineDefaults.Execution.ThreadingProfile,
                configSnapshot.TransientConfiguration,
                aggregationFactoryFactory);

            engineImportService.AddMethodRefs(configSnapshot.MethodInvocationReferences);

            // Add auto-imports
            try
            {
                foreach (var importName in configSnapshot.Imports)
                {
                    engineImportService.AddImport(importName);
                }

                foreach (var importName in configSnapshot.AnnotationImports)
                {
                    engineImportService.AddAnnotationImport(importName);
                }

                foreach (var config in configSnapshot.PlugInAggregationFunctions)
                {
                    engineImportService.AddAggregation(config.Name, config);
                }

                foreach (var config in configSnapshot.PlugInAggregationMultiFunctions)
                {
                    engineImportService.AddAggregationMultiFunction(config);
                }

                foreach (var config in configSnapshot.PlugInSingleRowFunctions)
                {
                    engineImportService.AddSingleRow(
                        config.Name, config.FunctionClassName, config.FunctionMethodName, config.ValueCache,
                        config.FilterOptimizable, config.IsRethrowExceptions, config.EventTypeName);
                }
            }
            catch (EngineImportException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            return(engineImportService);
        }