Ejemplo n.º 1
0
        static public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            // Create Evaluator
            evaluatorDefaultReportPrinter = new Mono.CSharp.ConsoleReportPrinter();
            var settings = new Mono.CSharp.CompilerSettings();

//                settings.AssemblyReferences = new List<string> {
//                    Assembly.GetExecutingAssembly().FullName
//                };
//                settings.LoadDefaultReferences = false;
            evaluatorCtx = new Mono.CSharp.CompilerContext(
                settings, evaluatorDefaultReportPrinter);
            evaluatorInstance = new Mono.CSharp.Evaluator(evaluatorCtx);

            ReferenceAllAssemblies();
            SetUsings();

            Log.Initialize();
            Inspector.Initialize();
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
        public CSharpParser CreateParser()
        {
            var settings = new Mono.CSharp.CompilerSettings();

            settings.Unsafe = AllowUnsafeBlocks;
            foreach (string define in PreprocessorDefines)
            {
                settings.AddConditionalSymbol(define);
            }
            return(new CSharpParser(settings));
        }
        internal Mono.CSharp.CompilerSettings ToMono()
        {
            var s = new Mono.CSharp.CompilerSettings();

            s.Unsafe            = allowUnsafeBlocks;
            s.Checked           = checkForOverflow;
            s.Version           = (Mono.CSharp.LanguageVersion)languageVersion.Major;
            s.WarningsAreErrors = treatWarningsAsErrors;
            s.WarningLevel      = warningLevel;
            foreach (int code in disabledWarnings)
            {
                s.SetIgnoreWarning(code);
            }
            foreach (int code in specificWarningsAsErrors)
            {
                s.AddWarningAsError(code);
            }
            foreach (string sym in conditionalSymbols)
            {
                s.AddConditionalSymbol(sym);
            }
            return(s);
        }
Ejemplo n.º 5
0
		internal Mono.CSharp.CompilerSettings ToMono()
		{
			var s = new Mono.CSharp.CompilerSettings();
			s.Unsafe = allowUnsafeBlocks;
			s.Checked = checkForOverflow;
			s.Version = (Mono.CSharp.LanguageVersion)languageVersion.Major;
			s.WarningsAreErrors = treatWarningsAsErrors;
			s.WarningLevel = warningLevel;
			foreach (int code in disabledWarnings)
				s.SetIgnoreWarning(code);
			foreach (int code in specificWarningsAsErrors)
				s.AddWarningAsError(code);
			foreach (string sym in conditionalSymbols)
				s.AddConditionalSymbol(sym);
			return s;
		}
Ejemplo n.º 6
0
		public CSharpParser CreateParser()
		{
			var settings = new Mono.CSharp.CompilerSettings();
			settings.Unsafe = AllowUnsafeBlocks;
			foreach (string define in PreprocessorDefines)
				settings.AddConditionalSymbol(define);
			return new CSharpParser(settings);
		}
Ejemplo n.º 7
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);
        }