Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        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.");
        }
Ejemplo n.º 4
0
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            if (Context.debugging)
                return;

            try
            {
                interpreter = new Interpreter(this.Text, null);
                interpreter.Parse();
                Document.FoldingManager.UpdateFoldings(null, interpreter);
            }
            catch { }
        }
Ejemplo n.º 5
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.");
        }
Ejemplo n.º 6
0
        protected override string getCellHTML(int row, int col)
        {
            string html = this.DataTemplate;

            if (html.Trim() == "")
                return "";

            int index = row * this.cols + col;

            if (data.Rows.Count <= index)
                return String.Empty;

            dr = data.Rows[index];

            if (engineCell == null)
            {
                engineCell = Provider.GetInterpreter(html, this);
                engineCell.Parse();
            }
            engineCell.SetAttribute("row", dr);
            engineCell.SetAttribute("index", index + 1);
            engineCell.Execute();
            html = engineCell.Output;

            return html;
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
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
            };
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
0
        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
            };
        }