Exemplo n.º 1
0
        public override Type Resolve(
            string providedTypeName,
            ClassForNameProvider classForNameProvider)
        {
            try {
                if (Namespace == null)
                {
                    if (providedTypeName == TypeName)
                    {
                        return(classForNameProvider.ClassForName(providedTypeName));
                    }
                }
                else
                {
                    if (providedTypeName == TypeNameBase)
                    {
                        return(classForNameProvider.ClassForName(TypeName));
                    }
                }
            }
            catch (TypeLoadException e) {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug($"TypeLoadException while resolving typeName = '{providedTypeName}'", e);
                }

                return(null);
            }

            return(null);
        }
        public Type ResolveEnumMethod(string name)
        {
            var enumMethod = _enumMethods.Get(name);

            if (enumMethod == null)
            {
                enumMethod = _enumMethods.Get(name.ToLowerInvariant());
            }

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

            Type clazz;

            try {
                clazz = ClassForNameProvider.ClassForName(enumMethod.ForgeClassName);
            }
            catch (TypeLoadException ex) {
                throw new ImportException("Could not load enum-method forge class by name '" + enumMethod.ForgeClassName + "'", ex);
            }

            return(clazz);
        }
        public Type ResolveDateTimeMethod(string name)
        {
            var dtm = _dateTimeMethods.Get(name);

            if (dtm == null)
            {
                dtm = _dateTimeMethods.Get(name.ToLowerInvariant());
            }

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

            Type clazz;

            try {
                clazz = ClassForNameProvider.ClassForName(dtm.ForgeClassName);
            }
            catch (TypeLoadException ex) {
                throw new ImportException("Could not load date-time-method forge class by name '" + dtm.ForgeClassName + "'", ex);
            }

            return(clazz);
        }
        public Pair <Type, ImportSingleRowDesc> ResolveSingleRow(
            string name,
            ExtensionSingleRow classpathExtensionSingleRow)
        {
            var inlined = classpathExtensionSingleRow.ResolveSingleRow(name);

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

            var pair = _singleRowFunctions.Get(name);

            if (pair == null)
            {
                pair = _singleRowFunctions.Get(name.ToLowerInvariant());
            }

            if (pair == null)
            {
                throw new ImportUndefinedException("A function named '" + name + "' is not defined");
            }

            Type clazz;

            try {
                clazz = ClassForNameProvider.ClassForName(pair.ClassName);
            }
            catch (TypeLoadException ex) {
                throw new ImportException("Could not load single-row function class by name '" + pair.ClassName + "'", ex);
            }

            return(new Pair <Type, ImportSingleRowDesc>(clazz, pair));
        }
        public AggregationFunctionForge ResolveAggregationFunction(
            string functionName,
            ExtensionAggregationFunction extension)
        {
            var inlined = extension.ResolveAggregationFunction(functionName);

            Type   forgeClass;
            string className;

            if (inlined != null)
            {
                forgeClass = inlined;
                className  = inlined.Name;
            }
            else
            {
                var desc = _aggregationFunctions.Get(functionName);
                if (desc == null)
                {
                    desc = _aggregationFunctions.Get(functionName.ToLowerInvariant());
                }

                if (desc == null || desc.ForgeClassName == null)
                {
                    throw new ImportUndefinedException("A function named '" + functionName + "' is not defined");
                }

                className = desc.ForgeClassName;
                try {
                    forgeClass = ClassForNameProvider.ClassForName(className);
                }
                catch (TypeLoadException ex) {
                    throw new ImportException("Could not load aggregation factory class by name '" + className + "'", ex);
                }
            }

            object @object;

            try {
                @object = TypeHelper.Instantiate(forgeClass);
            }
            catch (TypeLoadException e) {
                throw new ImportException(
                          "Error instantiating aggregation factory class by name '" + className + "'",
                          e);
            }
            catch (MemberAccessException e) {
                throw new ImportException(
                          "Illegal access instatiating aggregation factory class by name '" + className + "'",
                          e);
            }

            if (!(@object is AggregationFunctionForge))
            {
                throw new ImportException("Class by name '" + className + "' does not implement the " + typeof(AggregationFunctionForge).Name + " interface");
            }

            return((AggregationFunctionForge)@object);
        }