Пример #1
0
        static private void SetUsings()
        {
//		Mono.CSharp.Evaluator.Run("using uREPL;");
//		Mono.CSharp.Evaluator.Run("using System;");
//		Mono.CSharp.Evaluator.Run("using UnityEngine;");
            evaluatorInstance.Run("using uREPL;");
            evaluatorInstance.Run("using System;");
            evaluatorInstance.Run("using UnityEngine;");
            // #if UNITY_EDITOR
            // Mono.CSharp.Evaluator.Run("using UnityEditor;");
            // #endif
        }
Пример #2
0
        public ScriptEvaluator Compile ()
        { 
            Message = null;
            HasError = false;

            var reportWriter = new System.IO.StringWriter ();
                        
            try
            {
                var settings = new Mono.CSharp.CompilerSettings ();
                settings.GenerateDebugInfo = false;
                settings.LoadDefaultReferences = true;
                settings.Optimize = true;
                settings.WarningsAreErrors = false;  
                
                var reporter = new Mono.CSharp.ConsoleReportPrinter (reportWriter);

                var ctx = new Mono.CSharp.CompilerContext (settings, reporter);

                var scriptEngine = new Mono.CSharp.Evaluator (ctx);

                AddReference (this.GetType ());

                // add assemblies
                for (int i = 0; i < _assemblies.Count; i++)
                {
                    scriptEngine.ReferenceAssembly (_assemblies[i]);   
                }
                
                if (String.IsNullOrWhiteSpace (Script))
                    throw new ArgumentNullException ("Expression");
                
                if (!scriptEngine.Run (Script))
                    throw new Exception (reportWriter.ToString ());

                if (reporter.ErrorsCount > 0)
                {
                    throw new Exception (reportWriter.ToString ());
                }

                _createMethod = scriptEngine.Compile ("new " + MainClassName + "()");

                if (reporter.ErrorsCount > 0)
                {
                    throw new Exception (reportWriter.ToString ());
                }
                if (_createMethod == null)
                {
                    throw new Exception ("script method could be created");
                }
            }
            catch (Exception e)
            {                
                Message = e.Message;
                HasError = true;
            }
            return this;
        }
Пример #3
0
        public ScriptEvaluator CompileAndCreateModel()
        {
            Message  = null;
            HasError = false;
            Result   = false;

            var reportWriter = new System.IO.StringWriter();

            try
            {
                var settings = new Mono.CSharp.CompilerSettings();
                settings.GenerateDebugInfo     = false;
                settings.LoadDefaultReferences = true;
                settings.Optimize          = true;
                settings.WarningsAreErrors = false;

                var reporter = new Mono.CSharp.ConsoleReportPrinter(reportWriter);

                var ctx = new Mono.CSharp.CompilerContext(settings, reporter);

                var scriptEngine = new Mono.CSharp.Evaluator(ctx);

                scriptEngine.ReferenceAssembly(this.GetType().Assembly);
                scriptEngine.ReferenceAssembly(typeof(BigDataPipeline.Interfaces.Record).Assembly);
                scriptEngine.ReferenceAssembly(typeof(Newtonsoft.Json.JsonConvert).Assembly);

                scriptEngine.ReferenceAssembly(typeof(System.Data.Common.DbConnection).Assembly);
                scriptEngine.ReferenceAssembly(typeof(Dapper.SqlMapper).Assembly);
                scriptEngine.ReferenceAssembly(typeof(Npgsql.NpgsqlConnection).Assembly);
                scriptEngine.ReferenceAssembly(typeof(Amazon.S3.AmazonS3Client).Assembly);


                if (String.IsNullOrWhiteSpace(Script))
                {
                    throw new ArgumentNullException("Expression");
                }


                if (!scriptEngine.Run(Script))
                {
                    throw new Exception(reportWriter.ToString());
                }

                if (reporter.ErrorsCount > 0)
                {
                    throw new Exception(reportWriter.ToString());
                }

                object model = scriptEngine.Evaluate("new EvaluatorDynamicScript();");

                if (reporter.ErrorsCount > 0)
                {
                    throw new Exception(reportWriter.ToString());
                }

                Model = model as IAWSRedshiftPluginDynamicScript;

                //Mono.CSharp.CompiledMethod method = scriptEngine.Compile ("myClass.Test1 ();");

                //if (reporter.ErrorsCount > 0)
                //{
                //    throw new Exception (reportWriter.ToString ());
                //}
                //if (method == null)
                //{
                //    throw new Exception ("script method not found");
                //}

                // execute method
                //object result = null;
                //method (ref result);

                //// check result
                //if (result is bool)
                //    Result = (bool)result;
                //else
                //    Result = false;
            }
            catch (Exception e)
            {
                Message  = e.Message;
                HasError = true;
            }
            return(this);
        }