Esempio n. 1
0
        public void BuildWithDependency(string functionFileName)
        {
            // Compile
            var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName);

            var functionFile = environment.FunctionFile;
            var projectFile  = environment.ProjectFile;
            var assemblyFile = environment.AssemblyFile;

            var restorer = new DependencyRestorer(environment);

            restorer.CopyAndRestore();

            var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager());
            var function = FunctionCreator.CreateFunction(functionFile, projectFile);

            compiler.Compile(function);

            // Invoke
            var invoker = new DefaultInvoker();

            var args = WebManager.GetHttpRequest();

            object result = invoker.Execute(function, args);
        }
Esempio n. 2
0
        public void BuildWithDependency(string functionFileName)
        {
            var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName);

            var functionFile = environment.FunctionFile;
            var projectFile  = environment.ProjectFile;
            var assemblyFile = environment.AssemblyFile;

            Assert.True(File.Exists(functionFile));
            Assert.True(File.Exists(projectFile));
            Assert.False(File.Exists(assemblyFile));

            var restorer = new DependencyRestorer(environment);

            restorer.CopyAndRestore();

            var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager());
            var function = FunctionCreator.CreateFunction(functionFile, projectFile);

            Assert.False(function.IsCompiled());

            compiler.Compile(function);

            Assert.True(function.IsCompiled());

            Assert.True(File.Exists(assemblyFile));
            Assert.NotEmpty(File.ReadAllBytes(assemblyFile));
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var f = new FunctionCreator <int, int>();

            f.CreateFunction(x => x * x, x => x < 0);
            f.CreateFunction(y => y * 2 + 1, y => y > 0);

            Console.WriteLine($"f(-2) = {f.Invoke(-2) } \n");
            Console.WriteLine($"f(2) = {f.Invoke(2) }");
            Console.ReadKey();
        }
Esempio n. 4
0
        // Register an expression that will be used in a query
        // An expression is the RHS of an attribute assignment (not just a function)
        // Can only be Rename, Project, Open, Aggregate: only last two needed
        public bool RegisterExpression(ExpressionEval expr, int naccum)
        {
            if (!(expr.IsOpen || expr.HasFold))
            {
                return(true);
            }

            // Check whether new registration or update (to new evaluator)
            // TODO: check it's the same expr
            var updating = ExprDict.ContainsKey(expr.Serial);
            var name     = SqlGen.FuncName(expr);

            ExprDict[expr.Serial] = expr;
            Logger.WriteLine(3, $"Register {name} upd={updating} nacc={naccum} expr={expr}");
            if (updating)
            {
                return(true);
            }

            // notify database, set up callbacks
            // may require sql to register (PG)
            // FIX: would be better in PostgresDatabase, but does not have access to sql gen (and data types).
            var args = expr.Lookup.Columns.Select(c => ToSqlCommon[c.DataType.BaseType]).ToArray();
            var retn = ToSqlCommon[expr.ReturnType.BaseType];

            if (expr.HasFold)
            {
                // note: type must match low level wrappers
                var stype = DataTypes.Number;
                var init  = NumberValue.Zero;
                var col0  = new DataColumn[] { DataColumn.Create("_state_", stype) };
                OptionalExpressionSql(_sqlgen.CreateFunction(name, col0.Concat(expr.Lookup.Columns).ToArray(), stype));
                OptionalExpressionSql(_sqlgen.CreateFunction(name + "F", col0, expr.ReturnType));
                OptionalExpressionSql(_sqlgen.CreateAggregate(name, expr.Lookup.Columns, stype, init, name, name + "F"));
                return(FunctionCreator.CreateAggFunction(name, expr.Serial, naccum, args, retn));
            }
            // expr.IsOpen
            OptionalExpressionSql(_sqlgen.CreateFunction(name, expr.Lookup.Columns, expr.ReturnType));
            return(FunctionCreator.CreateFunction(name, FuncTypes.Open, expr.Serial, args, retn));
        }
Esempio n. 5
0
        private static IFunction GetCompiledFunctionWithDepedencies(string functionFileName)
        {
            // Creates Environment
            var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName);

            var functionFile = environment.FunctionFile;
            var projectFile  = environment.ProjectFile;
            var assemblyFile = environment.AssemblyFile;

            // Restore Dependencies
            var restorer = new DependencyRestorer(environment);

            restorer.CopyAndRestore();

            // Compile
            var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager());
            var function = FunctionCreator.CreateFunction(functionFile, projectFile);

            compiler.Compile(function);

            return(function);
        }