Example #1
0
        static void Main(string[] args)
        {
            Microsoft.JScript.Vsa.VsaEngine eng = new Microsoft.JScript.Vsa.VsaEngine();
            var assembly = CompileScript(mSrc);

            var fst = assembly.CompiledAssembly.DefinedTypes.First();

            var entry = fst.DeclaredMethods.Skip(1).First();
            var pars  = entry.GetParameters();

            Console.WriteLine(entry.Invoke(eng, new object[] { new object(), eng }));

            // Console.WriteLine(assembly.CompiledAssembly.EntryPoint.Invoke(null, new object[] { new string[] { } }));

            /* var cnt = 0;
             *
             * foreach (var a in CodeDomProvider.GetAllCompilerInfo())
             * {
             *  Console.WriteLine($"{cnt++} compiler langs:");
             *
             *  foreach (var b in a.GetLanguages())
             *      Console.WriteLine($"\t {b}");
             *
             *  foreach (var b in a.GetExtensions())
             *      Console.WriteLine($"\t {b}");
             * } */
        }
Example #2
0
        public bool Run()
        {
            Debug.Assert(m_vsae != null);

            try {
                m_vsae.Run();

#if false
                Assembly     mbly    = m_vsae.Assembly;
                object       ob      = mbly.CreateInstance("script.Foo");
                Type[]       atyp    = mbly.GetTypes();
                Type         typMain = atyp[0];
                MemberInfo[] amthi   = typMain.GetMembers();
                foreach (MemberInfo mthi in amthi)
                {
                    MessageBox.Show(mthi.ToString());
                }
                object obT = mbly.CreateInstance(atyp[0].Name);
                MessageBox.Show(obT.ToString());
                obT  = null;
                atyp = null;
                mbly = null;
#endif

//			} catch (VsaException exVsa) {
//				return false;
            } finally {
                m_vsae.Close();
                m_vsae = null;
                OnScriptDone(EventArgs.Empty);
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// 字符对比替换,然后根据公式算出对应的值
        /// </summary>
        /// <param name="dicStr"></param>
        /// <param name="formula">公式</param>
        /// <returns></returns>
        public string ComputeValueByFormula(Dictionary <string, string> dicStr, string formula)
        {
            //筛选幂运算("^10^3^"-->10*10*10)
            if (formula.Contains('^'))
            {
                int a = formula.IndexOf('^') + 1;
                int b = formula.Substring(a).IndexOf('^') + 1;
                int c = formula.Substring(a + b).IndexOf('^');
                if (b == -1 || c == -1)
                {
                }
                else
                {
                    string v1 = formula.Substring(a, b - 1);
                    string v2 = formula.Substring(a + b, c);

                    double d1 = Convert.ToDouble(ComputeValueByFormula(dicStr, v1));
                    double d2 = Convert.ToDouble(ComputeValueByFormula(dicStr, v2));

                    formula = formula.Substring(0, a - 1) + Math.Pow(d1, d2).ToString() + formula.Substring(a + b + c + 1);
                }
            }

            //具体的计算公式(值已经替换过了如:strCompute ="4+5")
            string strCompute = string.Join("", formula.AsEnumerable().Select(c => dicStr.ContainsKey(c.ToString()) ? dicStr[c.ToString()] : c.ToString()));

            Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            //计算结果(如:result = 9)
            var result = Microsoft.JScript.Eval.JScriptEvaluate(strCompute, ve);

            return(result.ToString());
        }
Example #4
0
        /**
         * 计算产生式子的值
         * */
        public static object CalcByJs(string expression)
        {
            Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            object returnValue = Microsoft.JScript.Eval.JScriptEvaluate((object)expression, ve);

            return(returnValue);
        }
Example #5
0
        /// <summary> 计算公式 </summary>
        public static string ComputeFormula(this string formule)
        {
            Microsoft.JScript.Vsa.VsaEngine vsa
                = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();

            return(Microsoft.JScript.Eval.JScriptEvaluate(formule, vsa).ToString());
        }
Example #6
0
        /// <summary>
        /// 获取类的字符串形式
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public string GetClassString(string jsonStr)
        {
            Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            var m = Microsoft.JScript.Eval.JScriptEvaluate("(" + jsonStr + ")", ve);

            int index  = 0;
            var result = GetDicType((JSObject)m, ref index);

            StringBuilder content = new StringBuilder();

            foreach (var item in dataList)
            {
                content.AppendFormat("\tpublic class {0}\r\n", item.CLassName);
                content.AppendLine("\t{");
                foreach (var model in item.Dic)
                {
                    if (isAddGetSet)
                    {
                        content.AppendFormat("\t\tpublic {0} {1}", model.Value, model.Key);
                        content.Append(" { get; set; }\r\n");
                    }
                    else
                    {
                        content.AppendFormat("\t\tpublic {0} {1};\r\n", model.Value, model.Key);
                    }

                    content.AppendLine();
                }

                content.AppendLine("\t}");
                content.AppendLine();
            }

            return(content.ToString());
        }
        /// <summary>
        /// 将字符串形式的数学公式转换为计算公式并进行计算
        /// </summary>
        /// <param name="MathematicalFormate"></param>
        /// <returns></returns>
        public static double ConvertMathematicalCalculation(string MathematicalFormate)
        {
            //MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass();
            //sc.Language = "JavaScript";
            //return sc.Eval(MathematicalFormate).TryToDecimal();

            Microsoft.JScript.Vsa.VsaEngine Engine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            return(Microsoft.JScript.Eval.JScriptEvaluate(MathematicalFormate, Engine).TryToDouble());
        }
Example #8
0
        public bool Compile(string strScript)
        {
            if (m_vsae != null)
            {
                m_vsae.Close();
                m_vsae = null;
            }

            Init();

            m_vsaciScript.SourceText = WrapUserScript(strScript);
            return(m_vsae.Compile());
        }
Example #9
0
 /// <summary> 
    /// 由Microsoft.Eval对象计算表达式,需要引用Microsoft.JScript和Microsoft.Vsa名字空间。 
    /// </summary> 
    /// <param name="expression">表达式</param> 
    /// <returns></returns> 
 public static string CalcByJs(string expression)
 {
     try
     {
         Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
         object returnValue = Microsoft.JScript.Eval.JScriptEvaluate((object)expression, ve);
         return returnValue.ToString();
     }
     catch
     {
         return string.Empty;
     }           
 }
Example #10
0
        public EvaluatorEngine()
            : base(null)
        {
            vars = new Dictionary <string, object>();

            this.typeReflector = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(this.GetType()));

            engine        = new Microsoft.JScript.Vsa.VsaEngine();
            engine.doFast = false;
            output        = new StringBuilder();

            StringWriter sw = new StringWriter(output);

            engine.InitVsaEngine("executerjscript.net", new VsaSite(sw));

            imports = new List <string>();

            List <string> asses = new List <string>();

            foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    VsaReference reference = new VsaReference(engine, Path.GetFileNameWithoutExtension(assem.Location));
                    engine.Items.CreateItem(reference.AssemblyName, Microsoft.Vsa.VsaItemType.Reference, Microsoft.Vsa.VsaItemFlag.None);

                    if (Path.GetExtension(assem.EscapedCodeBase).Equals(".dll", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tmp = Path.GetFileNameWithoutExtension(assem.EscapedCodeBase);
                        if (!imports.Contains(tmp))
                        {
                            Import.JScriptImport(tmp, engine);
                        }
                    }

                    Import.JScriptImport("System.Net", engine);
                    Import.JScriptImport("System.IO", engine);
//using System;
//using System.IO;
//using System.Net;
//using System.Text;
                }
                catch { }
            }
        }
Example #11
0
        /// <summary>
        /// 运行一段JavaScript代码
        /// </summary>
        /// <param name="sCode">传入代码</param>
        /// <param name="sResult">返回内容</param>
        /// <returns>0执行正确/-1执行错误</returns>
        static public int JScriptEval(string sCode, out string sResult)
        {
            int nRet = 0;

            sResult = "";

            try
            {
                Microsoft.JScript.Vsa.VsaEngine vEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                sResult = Microsoft.JScript.Eval.JScriptEvaluate(sCode, vEngine).ToString();
            }
            catch (System.Exception ex)
            {
                nRet    = -1;
                sResult = ex.Message;
            }
            return(nRet);
        }
Example #12
0
        private static object Eval(string s, out bool err)
        {
            tmp.AppendLine(s);

            try
            {
                Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                object result = Microsoft.JScript.Eval.JScriptEvaluate(tmp.ToString(), ve);
                err = false;
                return(result);
            }
            catch (Exception ex)
            {
                tmp.Clear();
                err = true;
                return(ex.StackTrace);
            }
        }
Example #13
0
        //static Microsoft.JScript.Vsa.VsaEngine vEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
        public int Eval(string sCode, out string sResult)
        {
            int nRet = 0;

            //sResult = EvalMethod.Eval(sCode).ToString();

            Microsoft.JScript.Vsa.VsaEngine vEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            try
            {
                sResult = Microsoft.JScript.Eval.JScriptEvaluate(sCode, vEngine).ToString();
            }
            catch (System.Exception ex)
            {
                nRet    = -1;
                sResult = ex.Message;
            }
            GC.Collect();
            return(nRet);
        }
Example #14
0
        public static xblock GetCodeBlock(string code)
        {
            xblock ret = null;

            Microsoft.JScript.Vsa.VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine();
            StringWriter sw = new StringWriter();

            engine.InitVsaEngine("test", new VsaSite(sw));
            DocumentContext docContext = new DocumentContext("", engine);
            Context         context    = new Context(docContext, code);
            JSParser        parser     = new JSParser(context);
            Block           block      = parser.ParseEvalBody();

            ret = new xjscript.xblock(block);

            engine.Close();
            // MessageBox.Show(((Completion)block.Evaluate()).value.ToString());

            return(ret);
        }
Example #15
0
        private void _CreateEngine()
        {
            switch (this.Language)
            {
            case "VB":
            case "Visual Basic":
                this._VsaEngine    = new Microsoft.VisualBasic.Vsa.VsaEngine();
                this.vsaEngineType = VsaEngineType.VBEngine;
                break;

            case "JScript":
            case "JScript.NET":
                this._JScriptVsaEngine = new Microsoft.JScript.Vsa.VsaEngine();
                this.vsaEngineType     = VsaEngineType.JSEngine;
                break;

            default:
                throw new Exception("Unknown Engine");
            }
        }
Example #16
0
        private void run(string input, object sender, EventArgs e, RichTextBox richtextbox)
        {
            try
            {
                string          pattern = @"(?<!Math\.)(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2|abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)";
                MatchCollection mc      = Regex.Matches(input, pattern);
                foreach (Match m in mc)
                {
                    Regex rgx = new Regex(pattern);
                    input = rgx.Replace(input, "Math." + m);
                }
                switch (input.TrimEnd(' '))
                {
                case "help": helpToolStripMenuItem1_Click(sender, e); break;

                case "exit": exitToolStripMenuItem_Click(sender, e); break;

                case "save": saveToolStripMenuItem_Click(sender, e); break;

                case "statusbar": statusBarToolStripMenuItem_Click(sender, e); break;

                case "menubar": menuBarToolStripMenuItem_Click(sender, e); break;

                case "clear": MainrichTextBox.Clear(); break;

                default:
                    Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                    var result = Microsoft.JScript.Eval.JScriptEvaluate(input, ve);
                    richtextbox.AppendText("\n" + result.ToString());
                    break;
                }
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception er)
            {
                richtextbox.AppendText("\n" + er.Message);
            }
        }
Example #17
0
        public void Init()
        {
            // UNDONE: this is crap. The whole engine shouldn't have to be recreated and
            // reinitialized for each compile. Unfortunately it's the only way I've found
            // to work around the "Variable 'AED' has not been declared" problem.
            // A better solution needs to be found as this one seems to consume roughly
            // 240K of RAM each compile.

            m_vsae             = new Microsoft.JScript.Vsa.VsaEngine();
            m_vsae.RootMoniker = "com.spiffcode://script";
            m_vsae.Site        = this;
            m_vsae.InitNew();

            m_vsae.SetOption("print", true);                    // Enable the 'print' function for scripters
            m_vsae.SetOption("fast", false);                    // Enable legacy mode
            m_vsae.RootNamespace = "script";
            m_vsaciScript        = (IVsaCodeItem)m_vsae.Items.CreateItem("scriptspace",
                                                                         VsaItemType.Code, VsaItemFlag.None);

            m_vsae.Items.CreateItem("mscorlib.dll", VsaItemType.Reference, VsaItemFlag.None);
            m_vsae.Items.CreateItem("System.Windows.Forms.dll", VsaItemType.Reference, VsaItemFlag.None);
//			m_vsae.Items.CreateItem("System.dll", VsaItemType.Reference, VsaItemFlag.None);

            string[] astrNames = new String[m_htGlobals.Count];
            m_htGlobals.Keys.CopyTo(astrNames, 0);

            for (int i = 0; i < m_htGlobals.Count; i++)
            {
                IVsaGlobalItem vsagi = (IVsaGlobalItem)m_vsae.Items.CreateItem(astrNames[i],
                                                                               VsaItemType.AppGlobal, VsaItemFlag.None);
                // UNDONE: this doesn't seem to be working
                vsagi.ExposeMembers = true;
//				object obInstance = m_htGlobals[astrNames[i]];
//				vsagi.TypeString = obInstance.GetType().FullName;
            }
        }
Example #18
0
 // Methods
 public static FunctionObject JScriptFunctionExpression(System.RuntimeTypeHandle handle, string name, string method_name, string[] formal_params, JSLocalField[] fields, bool must_save_stack_locals, bool hasArgumentsObject, string text, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
 // Constructors
 public GlobalScope(GlobalScope parent, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
Example #20
0
 private object Eval(string s)
 {
     Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
     return(Microsoft.JScript.Eval.JScriptEvaluate(s, ve));
 }
Example #21
0
 public static object JScriptEvaluate(object source, object unsafeOption, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
Example #22
0
 // Methods
 public static Namespace GetNamespace(string name, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
 public static object CallValue2(object val, object thisob, object[] arguments, bool construct, bool brackets, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
 // Methods
 public object Call(object[] arguments, bool construct, bool brackets, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
 // Methods
 public static Closure JScriptFunctionDeclaration(System.RuntimeTypeHandle handle, string name, string method_name, string[] formal_parameters, JSLocalField[] fields, bool must_save_stack_locals, bool hasArgumentsObject, string text, object declaringObject, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
Example #26
0
        public void Init()
        {
            // UNDONE: this is crap. The whole engine shouldn't have to be recreated and
            // reinitialized for each compile. Unfortunately it's the only way I've found
            // to work around the "Variable 'AED' has not been declared" problem.
            // A better solution needs to be found as this one seems to consume roughly
            // 240K of RAM each compile.

            m_vsae = new Microsoft.JScript.Vsa.VsaEngine();
            m_vsae.RootMoniker = "com.spiffcode://script";
            m_vsae.Site = this;
            m_vsae.InitNew();

            m_vsae.SetOption("print", true);	// Enable the 'print' function for scripters
            m_vsae.SetOption("fast", false);	// Enable legacy mode
            m_vsae.RootNamespace = "script";
            m_vsaciScript = (IVsaCodeItem)m_vsae.Items.CreateItem("scriptspace",
                    VsaItemType.Code, VsaItemFlag.None);

            m_vsae.Items.CreateItem("mscorlib.dll", VsaItemType.Reference, VsaItemFlag.None);
            m_vsae.Items.CreateItem("System.Windows.Forms.dll", VsaItemType.Reference, VsaItemFlag.None);
            //			m_vsae.Items.CreateItem("System.dll", VsaItemType.Reference, VsaItemFlag.None);

            string[] astrNames = new String[m_htGlobals.Count];
            m_htGlobals.Keys.CopyTo(astrNames, 0);

            for (int i = 0; i < m_htGlobals.Count; i++) {
                IVsaGlobalItem vsagi = (IVsaGlobalItem)m_vsae.Items.CreateItem(astrNames[i],
                        VsaItemType.AppGlobal, VsaItemFlag.None);
                // UNDONE: this doesn't seem to be working
                vsagi.ExposeMembers = true;
            //				object obInstance = m_htGlobals[astrNames[i]];
            //				vsagi.TypeString = obInstance.GetType().FullName;
            }
        }
Example #27
0
        private void _getGridOrigo(out double x0, out double y0, out double z0, out double dx, out double dy, out double dz, out double j, out double k, out double l, out double lat0, out double lon0)
        {
            x0 = 0; y0 = 0; z0 = 0; dx = 0; dy = 0; dz = 0; j = 0; k = 0; l = 0; lat0 = 0; lon0 = 0;
            object[] ncDims = _util.GetDimensions();

            List <double> interpolatedZVals = new List <double>();
            List <double> originalZVals     = new List <double>();

            ucar.nc2.Variable depthVar = null;
            foreach (object ncDim in ncDims)
            {
                string dimName = ((ucar.nc2.Dimension)ncDim).getName();
                if (_settings.XAxisName == dimName)
                {
                    ucar.nc2.Variable ncVar             = (ucar.nc2.Variable)_util.GetVariable(dimName);
                    List <double>     interpolatedYVals = new List <double>();
                    List <double>     originalYVals     = new List <double>();
                    _getMinAndInterval(ncVar, _settings.XLayer, out dx, out lon0, out interpolatedYVals, out originalYVals, false);
                    j  = originalYVals.Count;
                    x0 = 0;// originalYVals[0];

                    //overwrite dx, j
                    if (_settings.NumberXCells > 0)
                    {
                        j = _settings.NumberXCells;
                        //if (!double.TryParse(_settings.NumberXCells, out j))
                        //throw new Exception("Cannot convert " + _settings.NumberXCells + " to double");
                        _customDFSGrid = true;
                    }
                    if (_settings.DX > 0)
                    {
                        dx = _settings.DX;
                        //if (!double.TryParse(_settings.DX, out dx))
                        //throw new Exception("Cannot convert " + _settings.DX + " to double");
                        _customDFSGrid = true;
                    }

                    if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier))
                    {
                        Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                        double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine);
                        dx = dx * result;
                    }
                }
                else if (_settings.YAxisName == dimName)
                {
                    ucar.nc2.Variable ncVar             = (ucar.nc2.Variable)_util.GetVariable(dimName);
                    List <double>     interpolatedYVals = new List <double>();
                    List <double>     originalYVals     = new List <double>();
                    _getMinAndInterval(ncVar, _settings.YLayer, out dy, out lat0, out interpolatedYVals, out originalYVals, false);
                    k = originalYVals.Count;

                    y0 = 0;// originalYVals[0];

                    //overwrite dy, k
                    if (_settings.NumberYCells > 0)
                    {
                        k = _settings.NumberYCells;
                        //if (!double.TryParse(_settings.NumberYCells, out k))
                        //throw new Exception("Cannot convert " + _settings.NumberYCells + " to double");
                        _customDFSGrid = true;
                    }
                    if (_settings.DY > 0)
                    {
                        dy = _settings.DY;
                        //if (!double.TryParse(_settings.DY, out dy))
                        //throw new Exception("Cannot convert " + _settings.DY + " to double");
                        _customDFSGrid = true;
                    }

                    if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier))
                    {
                        Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                        double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine);
                        dy = dy * result;
                    }
                }
                else if (_settings.ZAxisName == dimName) //depth is y axis
                {
                    depthVar = (ucar.nc2.Variable)_util.GetVariable(dimName);

                    if (_settings.DZ == 0)
                    {
                        _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, false);
                        if (interpolatedZVals.Count != 0)
                        {
                            l        = interpolatedZVals.Count;
                            _zValues = interpolatedZVals;
                        }
                        else
                        {
                            l        = originalZVals.Count;
                            _zValues = originalZVals;
                        }
                        z0 = 0;
                    }
                    else
                    {
                        _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, true);
                        if (interpolatedZVals.Count != 0)
                        {
                            l        = interpolatedZVals.Count;
                            _zValues = interpolatedZVals;
                            z0       = interpolatedZVals[interpolatedZVals.Count - 1];
                        }
                        else
                        {
                            l        = originalZVals.Count;
                            _zValues = originalZVals;
                            z0       = originalZVals[originalZVals.Count - 1];
                        }
                        z0 = 0;
                    }
                }
            }

            if (_settings.OverwriteOriginX != -999 && _settings.OverwriteOriginX != -999)
            {
                lon0 = _settings.OverwriteOriginX;
                lat0 = _settings.OverwriteOriginY;
            }

            //calculate the size of the possible float array and limit it to _settings.MaxBlockSizeMB
            double floatArraySize = j * k * l * 4 / 1024 / 1024; //in mb

            if (floatArraySize > _settings.MaxBlockSizeMB)
            {
                _settings.DZ = (float)(originalZVals.Max() / (_settings.MaxBlockSizeMB / j / k / 4 * 1024 * 1024));
                _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, true);
                if (interpolatedZVals.Count != 0)
                {
                    l        = interpolatedZVals.Count;
                    _zValues = interpolatedZVals;
                }
                else
                {
                    l        = originalZVals.Count;
                    _zValues = originalZVals;
                }
                z0 = 0;
            }
        }
Example #28
0
 static CodeEvaluator()
 {
     sEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
 }
Example #29
0
        public bool Compile(string strScript)
        {
            if (m_vsae != null) {
                m_vsae.Close();
                m_vsae = null;
            }

            Init();

            m_vsaciScript.SourceText = WrapUserScript(strScript);
            return m_vsae.Compile();
        }
 // Methods
 public static void JScriptPackage(string rootName, Microsoft.JScript.Vsa.VsaEngine engine)
 {
 }
Example #31
0
        public bool Run()
        {
            Debug.Assert(m_vsae != null);

            try {
                m_vsae.Run();

            #if false
                Assembly mbly = m_vsae.Assembly;
                object ob = mbly.CreateInstance("script.Foo");
                Type[] atyp = mbly.GetTypes();
                Type typMain = atyp[0];
                MemberInfo[] amthi = typMain.GetMembers();
                foreach (MemberInfo mthi in amthi) {
                    MessageBox.Show(mthi.ToString());
                }
                object obT = mbly.CreateInstance(atyp[0].Name);
                MessageBox.Show(obT.ToString());
                obT = null;
                atyp = null;
                mbly = null;
            #endif

            //			} catch (VsaException exVsa) {
            //				return false;
            } finally {
                m_vsae.Close();
                m_vsae = null;
                OnScriptDone(EventArgs.Empty);
            }
            return true;
        }
 public static ArrayObject splice(object thisob, Microsoft.JScript.Vsa.VsaEngine engine, double start, double deleteCnt, object[] args)
 {
 }
Example #33
0
        private void _getGridOrigo(out double x0, out double y0, out double dx, out double dy, out double j, out double k, out double lat0, out double lon0)
        {
            x0 = 0; y0 = 0; dx = 0; dy = 0; j = 0; k = 0; lat0 = 0; lon0 = 0;
            object[] ncVars = _util.GetVariables();
            foreach (object ncVar in ncVars)
            {
                ucar.nc2.Variable var     = (ucar.nc2.Variable)ncVar;
                string            varName = var.getFullName();

                if (_settings.XAxisName == varName)
                {
                    _getMinAndInterval(var, _settings.XLayer, out dx, out lon0, out j);
                    x0 = 0;

                    //overwrite dx, j
                    if (_settings.NumberXCells > 0)
                    {
                        j = _settings.NumberXCells;
                        //if (!double.TryParse(_settings.NumberXCells, out j))
                        //throw new Exception("Cannot convert " + _settings.NumberXCells + " to double");
                        _customDFSGrid = true;
                    }
                    if (_settings.DX > 0)
                    {
                        dx = _settings.DX;
                        //if (!double.TryParse(_settings.DX, out dx))
                        //throw new Exception("Cannot convert " + _settings.DX + " to double");
                        _customDFSGrid = true;
                    }

                    if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier))
                    {
                        Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                        double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine);
                        dx = dx * result;
                    }
                }
                else if (_settings.YAxisName == varName)
                {
                    _getMinAndInterval(var, _settings.YLayer, out dy, out lat0, out k);
                    y0 = 0;

                    //overwrite dy, k
                    if (_settings.NumberYCells > 0)
                    {
                        k = _settings.NumberYCells;
                        //if (!double.TryParse(_settings.NumberYCells, out k))
                        //throw new Exception("Cannot convert " + _settings.NumberYCells + " to double");
                        _customDFSGrid = true;
                    }
                    if (_settings.DY > 0)
                    {
                        dy = _settings.DY;
                        //if (!double.TryParse(_settings.DY, out dy))
                        //throw new Exception("Cannot convert " + _settings.DY + " to double");
                        _customDFSGrid = true;
                    }

                    if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier))
                    {
                        Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
                        double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine);
                        dy = dy * result;
                    }
                }
            }
            if (_settings.OverwriteOriginX != -999 && _settings.OverwriteOriginX != -999)
            {
                lon0 = _settings.OverwriteOriginX;
                lat0 = _settings.OverwriteOriginY;
            }
        }
Example #34
0
 static CodeEvaluator()
 {
     sEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
 }