Esempio n. 1
0
        /// <summary>
        /// Reads the xmlfile containing the information of the script  executes it
        /// and returns the assembly if the script is being
        /// excuted or null if no ecript executed or an error occures.
        /// </summary>
        /// <param name="scriptname">the full path in which the script's directory is located</param>
        /// <returns>the assembly which is the result of the executed script</returns>
        public object ReadScript2(string scriptname)
        {
            try
            {
                int     i   = 0;
                object  ap  = null;
                DataSet set = new DataSet();

                if (scriptname != null)
                {
                    string code, clas, func, names, lang, tfilename;
                    if (Path.GetExtension(scriptname) == null)
                    {
                        tfilename = Path.Combine(scriptname, scriptext);
                    }
                    else
                    {
                        tfilename = scriptname;
                    }

                    string[] refs;
                    //  MessageBox.Show(tfilename);

                    ado.AttachDataBaseinDataSet(set, tfilename);
                    //    MessageBox.Show(set.Tables[0].TableName);
                    refs  = this.GetReferences(set);
                    names = this.GetNameSace(set);
                    code  = this.GetCode(set);
                    clas  = this.GetClass(set);
                    func  = this.GetFunction(set);
                    lang  = this.GetLanguage(set);

                    /*    if ((definedConstants != null) && (definedValues != null) && (definedConstants.Length == definedValues.Length))
                     *  {
                     *      for (i = 0; i < definedConstants.Length; i++)
                     *      {
                     *          code = replacer.findandreplaceDefinedConsts(code, definedConstants[i], definedValues[i]);
                     *
                     *          code = replacer.findandreplaceSymbols(code);
                     *      }
                     *
                     *
                     *  }
                     *  else
                     *  {
                     *
                     *      code = replacer.findandreplaceSymbols(code);
                     *
                     *  } */

                    // MessageBox.Show(code);

                    ScriptsSet = set;
                    ScriptInfo scrinfo = this.GetScriptInfo(set);
                    scrinfo.Filename = scriptname;
                    //  MessageBox.Show(scrinfo.Language);
                    ap = Eval2(code.Split('\n'), scriptname, names, clas, func, refs, scrinfo);
                }

                return(ap);
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                Program.Bugtracking(e);

                return(null);
            }
        }
Esempio n. 2
0
        public object EvalWithParams(string[] sCSCode, string scriptname, string NameSapce, string Clas, string func, string[] refs, WareForm winGUI, ScriptInfo scrinf)
        {
            try
            {
                if ((sCSCode != null) && (scriptname != null) && (NameSapce != null) && (Clas != null) && (func != null) && (refs != null) && (winGUI != null) && (scrinf != null) && (checkCompatibility(scrinf) == true))
                {
                    if ((scrinf.Language == "C#") || (scrinf.Language == "c#"))
                    {
                        ICodeCompiler icc = c.CreateCompiler();


                        cp.ReferencedAssemblies.Add("system.dll");
                        cp.ReferencedAssemblies.Add("system.xml.dll");
                        cp.ReferencedAssemblies.Add("system.data.dll");
                        // cp.ReferencedAssemblies.Add("system.windows.objects.dll");
                        cp.ReferencedAssemblies.Add("system.drawing.dll");
                        cp.ReferencedAssemblies.Add(Application.ExecutablePath);
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\Hydrobase.dll");
                        //cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "HydrobaseSDK.dll");
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "WareForms.dll");
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "Scrabler.dll");
                        cp.ReferencedAssemblies.AddRange(refs);


                        cp.CompilerOptions  = "/t:library";
                        cp.GenerateInMemory = true;
                        StringBuilder sb = new StringBuilder("");

                        /* sb.Append("using System;\n");
                         * sb.Append("using System.Xml;\n");
                         * sb.Append("using System.Data;\n");
                         * sb.Append("using System.Data.SqlClient;\n");
                         * //  sb.Append("using System.Windows.objects;\n");
                         * sb.Append("using System.Drawing;\n");
                         * sb.Append("using Hydrobase;\n");
                         * sb.Append("using HydrobaseSDK;\n");
                         *
                         * //sb.Append("using Frogy_Base_Hydrobase_Data_Enviroment;\n");
                         * sb.Append("using WareForms;\n");
                         *
                         * /* sb.Append("namespace CSCodeEvaler{ \n");
                         * sb.Append("public class CSCodeEvaler{ \n");
                         * sb.Append("public object EvalCode(){\n");
                         * //sb.Append("return " + sCSCode + "; \n");
                         * sb.Append(sCSCode + "; \n"); */
                        /*sb.Append("} \n");
                         * sb.Append("} \n");
                         * sb.Append("}\n");*/
                        //string stat;
                        //sb.Replace(func + "(WareForm gui", func + "( WareForm " + winGUI);


                        //   CompilerResults cr = icc.CompileAssemblyFromSource(cp, sb.ToString());
                        CompilerResults cr = icc.CompileAssemblyFromFileBatch(cp, sCSCode);

                        if (cr.Errors.Count > 0)
                        {
                            //  string tmp = sb.ToString().Replace("\n", Environment.NewLine);
                            ErrorWindow errwin = new ErrorWindow();
                            // MessageBox.Show("ERROR in " + cr.Errors[0].Line + ": " + cr.Errors[0].ErrorText + cr.Errors[0].ToString() +"\n" + sb.ToString(), "Error evaluating cs code" , MessageBoxButtons.OK, MessageBoxIcon.Error);

                            errwin.listErrors.Text = "ERROR in line " + cr.Errors[0].Line + ": " + cr.Errors[0].ErrorText;

                            // errwin.txtCode.Text = cr.
                            errwin.Show();

                            return(null);
                        }

                        System.Reflection.Assembly a = cr.CompiledAssembly;
                        object o = a.CreateInstance(NameSapce + "." + Clas);
                        AssemblyCol.Add(a, scrinf);
                        Type t = o.GetType();

                        MethodInfo mi      = t.GetMethod(func);
                        WareForm[] oParams = new WareForm[1];
                        oParams[0] = winGUI;
                        object s = mi.Invoke(o, oParams);
                        return(s);
                    }
                    else if ((scrinf.Language == "VB") || (scrinf.Language == "vb"))
                    {
                        ICodeCompiler icc = vb.CreateCompiler();
                        // ErrorWindow errwin = new ErrorWindow();



                        cp.ReferencedAssemblies.Add("system.dll");
                        cp.ReferencedAssemblies.Add("system.xml.dll");
                        cp.ReferencedAssemblies.Add("system.data.dll");
                        // cp.ReferencedAssemblies.Add("system.windows.objects.dll");
                        cp.ReferencedAssemblies.Add("system.drawing.dll");
                        cp.ReferencedAssemblies.Add(Application.ExecutablePath);
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\Hydrobase.dll");
                        // cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "HydrobaseSDK.dll");
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "WareForms.dll");
                        cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\" + "Scrabler.dll");
                        cp.ReferencedAssemblies.AddRange(refs);


                        cp.CompilerOptions  = "/t:library";
                        cp.GenerateInMemory = true;

                        /* StringBuilder sb = new StringBuilder("");
                         * sb.Append("Imports System\n");
                         * sb.Append("Imports System.Xml\n");
                         * sb.Append("Imports System.Data\n");
                         * sb.Append("Imports System.Data.SqlClient\n");
                         *
                         * sb.Append("Imports System.Drawing\n");
                         * sb.Append("Imports Hydrobase\n");
                         * sb.Append("Imports HydrobaseSDK\n");
                         *
                         * sb.Append("Imports WareForms\n");
                         *
                         *
                         * sb.Append(sCSCode + " \n");*/

                        CompilerResults cr = icc.CompileAssemblyFromFileBatch(cp, sCSCode);
                        if (cr.Errors.Count > 0)
                        {
                            // MessageBox.Show("ERROR in " + cr.Errors[0].Line + ": " + cr.Errors[0].ErrorText + cr.Errors[0].ToString() +"\n" + sb.ToString(), "Error evaluating cs code" , MessageBoxButtons.OK, MessageBoxIcon.Error);
                            // string tmp = sb.ToString().Replace("\n", Environment.NewLine);
                            ErrorWindow errwin = new ErrorWindow();
                            errwin.listErrors.Text = "ERROR in line " + cr.Errors[0].Line + ": " + cr.Errors[0].ErrorText;

                            //errwin.txtCode.Text = tmp;
                            errwin.Show();

                            return(null);
                        }

                        System.Reflection.Assembly a = cr.CompiledAssembly;


                        object o = a.CreateInstance(NameSapce + "." + Clas);

                        AssemblyCol.Add(a, scrinf);

                        Type t = o.GetType();

                        MethodInfo mi      = t.GetMethod(func);
                        WareForm[] oParams = new WareForm[1];
                        oParams[0] = winGUI;
                        object s = mi.Invoke(o, oParams);
                        // object s = mi.Invoke(o, null);
                        return(s);
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                Program.Bugtracking(e);

                return(null);
            }
        }
        /// <summary>
        /// this method will install the given script to the script folder
        /// and copy the dll neede by the sript to the needed folder
        /// </summary>
        /// <param name="script_Archfilename">the full path of the script </param>
        /// <param name="installfolder_scriptanddll">the path that
        /// script and dll wll be installed</param>
        public void Install(string script_Archfilename, string installfolder_scriptanddll)
        {
            try
            {
                ScriptInfo   scrinf = null;
                ScrablerCore core = new ScrablerCore();
                DataSet      set = new DataSet();
                hydrobaseADO ad = new hydrobaseADO();
                string       tscrfilename = null, str;
                string[]     files;
                if ((script_Archfilename != null) && (installfolder_scriptanddll != null) &&
                    (File.Exists(script_Archfilename) == true) && (Directory.Exists(installfolder_scriptanddll) == true))
                {
                    if (Directory.Exists(installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolderDLL) != true)
                    {
                        Directory.CreateDirectory(installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolderDLL);
                    }



                    FastZip  ziphandler = new FastZip();
                    FileInfo fileinf    = new FileInfo(script_Archfilename);

                    ziphandler.ExtractZip(script_Archfilename, SDKBase.UsersTempDirectory + "\\" + fileinf.Name, "scrf");



                    files = Directory.GetFiles(SDKBase.UsersTempDirectory + "\\" + fileinf.Name);
                    ad.AttachDataBaseinDataSet(set, files[0]);
                    // MessageBox.Show(files[0]);
                    scrinf = core.GetScriptInfo(set);
                    core.SetReferences(set, installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolderDLL + "\\" + scrinf.Title, files[0]);
                    File.Copy(files[0], installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolder + "\\" + files[0].Substring(files[0].LastIndexOf("\\") + 1));
                    str          = files[0];
                    tscrfilename = files[0];

                    File.Delete(files[0]);
                    ziphandler.ExtractZip(script_Archfilename, SDKBase.UsersTempDirectory + "\\" + fileinf.Name, "dll");
                    files = null;
                    files = Directory.GetFiles(SDKBase.UsersTempDirectory + "\\" + fileinf.Name);
                    foreach (string file in files)
                    {
                        FileInfo dllinf = new FileInfo(file);
                        this.CopyDll(file, installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolderDLL + "\\" + scrinf.Title + "\\" + dllinf.Name);
                        //MessageBox.Show("hi6");
                    }
                    core.SetReferences(set, installfolder_scriptanddll + "\\" + ScrablerCore.ScriptsFolderDLL + "\\" + scrinf.Title, tscrfilename);
                }


                FileInfo fileinf2 = new FileInfo(script_Archfilename);

                string [] tfile = Directory.GetFiles(SDKBase.UsersTempDirectory + "\\" + fileinf2.Name);
                foreach (string file in tfile)
                {
                    File.Delete(file);
                }

                Directory.Delete(SDKBase.UsersTempDirectory + "\\" + fileinf2.Name);
            }



            catch (Exception e)
            {
                Program.Bugtracking(e);
            }
        }