示例#1
0
 public string ExecuteHTML()
 {
     Interpreter pret = new Interpreter(htmlTemplate, null);
     pret.SetAttribute("ds", GetDataSource(customSQL ?? musTemp.SQLQuery, sqlParams));
     pret.Parse();
     pret.Execute();
     return pret.Output;
 }
示例#2
0
        public static void Run()
        {
            Interpreter engine = new Interpreter(File.ReadAllText("d:\\deneme.csc"), null);
            engine.SetAttribute("musteri", new Musteri { Ad="Microsoft"});
            engine.Parse();
            engine.Execute();

            Console.WriteLine(engine.Output);
        }
示例#3
0
文件: FormMain.cs 项目: fizikci/Cinar
        private void cmdExecuteScript(string arg)
        {
            Interpreter engine = new Interpreter(CurrSQLEditor.SQLEditor.Text, new List<string> { "Cinar.DBTools" });
            engine.SetAttribute("db", Provider.Database);
            engine.SetAttribute("util", new Util());
            engine.SetAttribute("table", findSelectedTable());
            engine.SetAttribute("tree", treeView);
            engine.Parse();
            engine.Execute();

            CurrSQLEditor.ShowInfoText(engine.Output);

            SetStatusText("Script executed succesfully.");
        }
示例#4
0
        private void executeTask(DBIntegrationTask task)
        {
            if (task.Name.StartsWith("[DISABLED]"))
                return;

            ConnectionSettings csSrc = Provider.GetConnection(task.SourceDB);
            ConnectionSettings csDst = Provider.GetConnection(task.DestDB);
            if(csSrc==null)
            {
                Log(task, task.SourceDB + " doesnt exist!");
                return;
            }
            if(csDst==null)
            {
                Log(task, task.DestDB + " doesnt exist!");
                return;
            }

            string code = integData.ScriptIncludeCode + Environment.NewLine + task.Code;

            Interpreter pret = new Interpreter(code, null);
            pret.AddAssembly(typeof(POP3.Pop3Client).Assembly);
            pret.SetAttribute("dbSrc", csSrc.Database);
            pret.SetAttribute("dbDst", csDst.Database);
            pret.SetAttribute("this", task);
            pret.SetAttribute("form", this);
            pret.Parse();
            pret.Execute();

            if (!pret.Successful)
                Log(task, "Error: " + pret.Output);
            else
                Log(task, pret.Output.Trim() + " in " + pret.ExecutingTime + " ms.");
        }
示例#5
0
        private void btnRunTests_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in grid.Rows)
            {
                ScriptingTest test = (ScriptingTest) row.DataBoundItem;

                Interpreter pret = new Interpreter(test.Code, null);
                pret.AddAssembly(typeof(POP3.Pop3Client).Assembly);
                pret.SetAttribute("db", Provider.Database);
                pret.Parse();
                pret.Execute();

                test.Result = pret.Output;

                if (pret.Successful && test.Result.Trim() == "OK")
                    row.Cells["Result"].Style.BackColor = Color.Green;
                else
                    row.Cells["Result"].Style.BackColor = Color.Red;

                row.Cells["Result"].Style.ForeColor = Color.White;
            }
        }
示例#6
0
        public GeneratedCode GenerateCode(string basePath, Table table)
        {
            string path = Name;
            if (!string.IsNullOrEmpty(this.FileNameTemplate))
            {
                Interpreter engineForPath = new Interpreter(this.FileNameTemplate, null);
                engineForPath.SetAttribute("this", this);
                engineForPath.SetAttribute("db", Provider.Database);
                engineForPath.SetAttribute("table", table);
                engineForPath.SetAttribute("util", new Util());
                engineForPath.Parse();
                engineForPath.Execute();
                path = engineForPath.Output;
            }

            return new GeneratedCode
            {
                Path = basePath + "\\" + path,
                IsFolder = true
            };
        }
示例#7
0
        private void btnGenerateAll_Click(object sender, EventArgs e)
        {
            if (lbEntities.CheckedItems.Count == 0)
            {
                MessageBox.Show("Please check one or more entity first", "Warning");
                return;
            }
            if (lbTemplates.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please check one or more template first", "Warning");
                return;
            }

            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "Select the directory in which the code is gonna be generated";
            fbd.SelectedPath = @"c:\temp";
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                foreach (Template tmp in lbTemplates.SelectedItems)
                {
                    foreach (Table selectedTable in lbEntities.CheckedItems)
                    {
                        Interpreter engine = new Interpreter(tmp.Code, null);
                        engine.SetAttribute("table", selectedTable);
                        engine.SetAttribute("util", new Util());
                        engine.Parse();
                        engine.Execute();

                        string code = engine.Output;

                        Interpreter engine2 = new Interpreter(tmp.FileNameFormat.Replace("\\", "|"), null);
                        engine2.SetAttribute("table", selectedTable);
                        engine2.SetAttribute("util", new Util());
                        engine2.Parse();
                        engine2.Execute();

                        string path = fbd.SelectedPath + "\\" + engine2.Output.Replace("|", "\\");

                        createDirectories(Path.GetDirectoryName(path));
                        File.WriteAllText(path, code, Encoding.UTF8);
                    }
                }
                System.Diagnostics.Process.Start(fbd.SelectedPath);
            }
        }
示例#8
0
        private void btnGenerateCode_Click(object sender, EventArgs e)
        {
            if (lbEntities.CheckedItems.Count == 0)
            {
                MessageBox.Show("Please check one or more entity first", "Warning");
                return;
            }
            if (lbTemplates.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please check one or more template first", "Warning");
                return;
            }

            List<GeneratedCode> generatedCodes = new List<GeneratedCode>();

            foreach (Template tmp in lbTemplates.SelectedItems)
            {
                foreach (Table selectedTable in lbEntities.CheckedItems)
                {
                    Interpreter engine = new Interpreter(tmp.Code, null);
                    engine.SetAttribute("table", selectedTable);
                    engine.SetAttribute("util", new Util());
                    engine.Parse();
                    engine.Execute();

                    string path = "";
                    if (!string.IsNullOrEmpty(tmp.FileNameFormat))
                    {
                        Interpreter engine2 = new Interpreter(tmp.FileNameFormat.Replace("\\", "|"), null);
                        engine2.SetAttribute("table", selectedTable);
                        engine2.SetAttribute("util", new Util());
                        engine2.Parse();
                        engine2.Execute();
                        //TODO: put code generation base path to settings
                        path = @"C:\Work\DealerSafe\DealerSafe2\" + engine2.Output.Replace("|", "\\");
                    }

                    generatedCodes.Add(new GeneratedCode {
                        Code = engine.Output,
                        Path = path,
                        Template = tmp
                    });

                }
            }

            FormGeneratedCode form = new FormGeneratedCode(generatedCodes);
            //form.Text = " - " + tmp.Name + " code for " + selectedTable.Name;
            //form.Path = path;
            form.Show();
        }
示例#9
0
        public override object Calculate(Context context, ParserNode parentNode)
        {
            if (Name == "write" || Name == "print" || Name == "echo")
            {
                if (fArguments.Length > 1 && fArguments[0] is StringConstant)
                {
                    string s = fArguments[0].Calculate(context, this).ToString();
                    object[] objParams = new object[fArguments.Length-1];
                    for(int i=1; i<fArguments.Length; i++)
                        objParams[i - 1] = fArguments[i].Calculate(context, this).ToString();
                    context.Output.Write(String.Format(s, objParams));
                }
                else
                    foreach (Expression expression in fArguments)
                        context.Output.Write(expression.Calculate(context, this));
            }
            else if (Name == "eval" && fArguments.Length>0)
            {
                Interpreter ip = new Interpreter("$" + fArguments[0].Calculate(context, this) + "$", null);
                ip.Parse();
                ip.Execute();
                return ip.Output;
            }
            else if (Name == "typeof")
            {
                if (fArguments.Length == 0 || !(fArguments[0] is Variable))
                    throw new Exception("typeof operator argument error. Usage: typeof(DateTime)");
                string typeName = (fArguments[0] as Variable).Name;
                return Context.GetType(typeName, context.Using);
            }
            else if (context.Functions[Name] != null)
            {
                FunctionDefinitionStatement func = (FunctionDefinitionStatement)context.Functions[Name];

                Hashtable arguments = new Hashtable();
                int i = 0;
                foreach (Expression expression in fArguments)
                {
                    object paramVal = expression.Calculate(context, this);
                    if (func.Parameters.Count > i)
                        arguments[func.Parameters[i]] = paramVal;
                    i++;
                }
                func.Block.Execute(context, this, arguments);
                object res = Context.ReturnValue;
                Context.ReturnValue = null;
                return res;
            }
            else
                throw new Exception("Undefined function: " + this);
            return null;
        }
示例#10
0
文件: FileItem.cs 项目: fizikci/Cinar
        public GeneratedCode GenerateCode(string basePath, Table table)
        {
            string code = null;

            if (!this.IsBinary)
            {
                Interpreter engineForCode = new Interpreter(File.ReadAllText(this.Path), null);
                engineForCode.SetAttribute("this", this);
                engineForCode.SetAttribute("db", Provider.Database);
                engineForCode.SetAttribute("table", table);
                engineForCode.SetAttribute("util", new Util());
                engineForCode.Parse();
                engineForCode.Execute();

                code = engineForCode.Output;
            }

            string path = Name;
            if (!string.IsNullOrEmpty(this.FileNameTemplate))
            {
                Interpreter engineForPath = new Interpreter(this.FileNameTemplate, null);
                engineForPath.SetAttribute("this", this);
                engineForPath.SetAttribute("db", Provider.Database);
                engineForPath.SetAttribute("table", table);
                engineForPath.SetAttribute("util", new Util());
                engineForPath.Parse();
                engineForPath.Execute();
                path = engineForPath.Output;
            }

            return new GeneratedCode {
                Code = code,
                Path = basePath + "\\" + path
            };
        }