コード例 #1
0
 public void AccessingAndModifyingGlobalVariables1()
 {
     var engine = new Jurassic.ScriptEngine();
     engine.SetGlobalValue("interop", 15);
     engine.ExecuteFile(@"..\..\..\Unit Tests\Core\Sample Files\globals1.js");
     Assert.AreEqual(20, engine.GetGlobalValue<int>("interop"));
 }
コード例 #2
0
 public void AccessingAndModifyingGlobalVariables1()
 {
     var engine = new Jurassic.ScriptEngine();
     engine.SetGlobalValue("interop", 15);
     engine.ExecuteFile(Path.Combine (FilesDir, "globals1.js"));
     Assert.AreEqual(20, engine.GetGlobalValue<int>("interop"));
 }
コード例 #3
0
    // Executes a script (parameters are not supported yet!)
    // Returns the script result (parameter _result)
    // Returns true on success
    public bool executeScript <_T>(DynamicScript _script, ref _T _result)
        where _T : new()
    {
        // Local variables
        Type resultParamType = null;
        _T   defaultValueResultParam;
        bool hasResult = false;

        // Result required?
        if (_script.ResultName != null && _script.ResultName.Length > 0 && _script.ResultTypeName != null && _script.ResultTypeName.Length > 0)
        {
            // Get type for the result param
            resultParamType = Type.GetType(_script.ResultTypeName);
            if (resultParamType == null)
            {
                return(false);
            }
            if (resultParamType.IsValueType == false || Nullable.GetUnderlyingType(resultParamType) != null)
            {
                return(false);
            }

            // Get default parameter for the result type
            defaultValueResultParam = new _T();
            if (defaultValueResultParam == null)
            {
                return(false);
            }

            // Set global parameter for the result
            m_scriptEngine.SetGlobalValue(_script.ResultName, defaultValueResultParam);

            // Set flag
            hasResult = true;
        }

        // Execute script
        m_scriptEngine.Execute(_script.Code);

        // Get result
        if (hasResult)
        {
            _result = m_scriptEngine.GetGlobalValue <_T>(_script.ResultName);
        }

        return(true);
    }
コード例 #4
0
        public void AccessingAndModifyingGlobalVariables1()
        {
            var engine = new Jurassic.ScriptEngine();

            engine.SetGlobalValue("interop", 15);
            engine.ExecuteFile(Path.Combine(FilesDir, "globals1.js"));
            Assert.AreEqual(20, engine.GetGlobalValue <int>("interop"));
        }
コード例 #5
0
        public void AccessingAndModifyingGlobalVariables1()
        {
            var engine = new Jurassic.ScriptEngine();

            engine.SetGlobalValue("interop", 15);
            engine.ExecuteFile(@"..\..\..\Unit Tests\Core\Sample Files\globals1.js");
            Assert.AreEqual(20, engine.GetGlobalValue <int>("interop"));
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: axm-dave/AXMCMMUtil-VS2019
        //string connectionString = String.Empty;
        //MongoClient client = null;

        //public class Entity
        //{
        //    public ObjectId Id { get; set; }

        //    public string Name { get; set; }
        //}

        public Form1()
        {
            InitializeComponent();

            //fontName = "InspectionXpert GDT";
            fontName = "SOLIDWORKS GDT";
            //fontSize = "9.5";
            fontSize   = "8";
            fontFormat = "#,##0.000";
            ffontSize  = Convert.ToSingle(fontSize);
            newFont    = new System.Drawing.Font(fontName, ffontSize);

            Version version = null;

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                version = ApplicationDeployment.CurrentDeployment.CurrentVersion;
            }
            else
            {
                version = Assembly.GetExecutingAssembly().GetName().Version;
            }

            this.label10.Text = String.Format(this.label10.Text, version.Major, version.Minor, version.Build, version.Revision);

            var engine = new Jurassic.ScriptEngine();
            //engine.EnableDebugging = true;
            var result = engine.Evaluate("5 * 10 + 2");

            //engine.SetGlobalValue("console", new Jurassic.Library.FirebugConsole(engine));

            engine.ExecuteFile(@"test.js");
            var result1 = engine.GetGlobalValue <string>("s");
            var result2 = engine.GetGlobalValue <string>("word");
            var resultx = engine.GetGlobalValue <int>("x");
            var resulty = engine.GetGlobalValue <string>("y");

            int result3 = 0;

            try
            {
                result3 = engine.CallGlobalFunction <int>("test2", 50, 6 * 2);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }

            string resultTest3 = String.Empty;

            try
            {
                resultTest3 = engine.CallGlobalFunction <string>("test3", 50, 6 * 2);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }

            var result5 = engine.GetGlobalValue("z");
            var result4 = engine.GetGlobalValue <string>("z");

            foreach (var entry in result4)
            {
                int x = 0;
                x++;
            }

            var            json   = JSONObject.Stringify(engine, result4);
            var            json2  = JSONObject.Stringify(engine, result5);
            Object         xxxx   = JSONObject.Parse(engine, json2);
            JsonTextReader reader = new JsonTextReader(new StringReader(json2));

            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
                }
                else
                {
                    Console.WriteLine("Token: {0}", reader.TokenType);
                }
            }

            //var x = result4["sVal"];


            //int i = 0;

            //string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AXMCMMUtil.config");

            //if (File.Exists(configPath))
            //{
            //    Lua lua = new Lua();

            //    lua.DoFile(configPath);

            //    fontName = (string)lua["fontName"];
            //    double tempSize = (double)lua["fontSize"];
            //    fontSize = tempSize.ToString();
            //    fontFormat = (string)lua["fontFormat"];

            //    ffontSize = Convert.ToSingle(fontSize);
            //    newFont = new System.Drawing.Font(fontName, ffontSize);
            //}


            //connectionString = "mongodb://192.168.1.9";
            //client = new MongoClient(connectionString);
            //var server = client.GetServer();
            //var database = server.GetDatabase("test"); // "test" is the name of the database

            //// "entities" is the name of the collection
            //var collection = database.GetCollection<Entity>("entities");

            //var entity = new Entity { Name = "Tom" };
            //collection.Insert(entity);
            //var id = entity.Id; // Insert will set the Id if necessary (as it was in this example)

            //var query = Query<Entity>.EQ(e => e.Id, id);
            //entity = collection.FindOne(query);

            //entity.Name = "Dick";
            //collection.Save(entity);

            //var update = Update<Entity>.Set(e => e.Name, "Harry");
            //collection.Update(query, update);

            //collection.Remove(query);

            //var fileName = "D:\\Dropbox\\Dev\\AXMCMMUtil\\bin\\Debug\\Output.zip";
            //var newFileName = "D:\\Dropbox\\Dev\\AXMCMMUtil\\bin\\Debug\\OutputNew.zip";
            //using (var fs = new FileStream(fileName, FileMode.Open))
            //{
            //    var gridFsInfo = database.GridFS.Upload(fs, fileName);
            //    var fileId = gridFsInfo.Id;

            //    ObjectId oid = new ObjectId(fileId);
            //    ObjectId xxx = new ObjectId();
            //    var file = database.GridFS.FindOne(Query.EQ("_id", oid));

            //    //using (var stream = file.OpenRead())
            //    //{
            //    //    var bytes = new byte[stream.Length];
            //    //    stream.Read(bytes, 0, (int)stream.Length);
            //    //    using (var newFs = new FileStream(newFileName, FileMode.Create))
            //    //    {
            //    //        newFs.Write(bytes, 0, bytes.Length);
            //    //    }
            //   //}
            //}
        }