public bool injectIntoProcess(Process process, bool x64, bool runtime40, string sourceCodeFile)
		{
		 	//fixedCourceCode.showInCodeViewer();
		 	var compileEngine = new CompileEngine(runtime40 ? "v4.0" : "v3.5") { useCachedAssemblyIfAvailable = false };		 	
			//var compiledAssembly = compileEngine.compileSourceCode(fixedCourceCode);			
			var compiledAssembly = compileEngine.compileSourceFile(sourceCodeFile);			
			return injectIntoProcess(process,x64, runtime40,compiledAssembly);
		}
示例#2
0
        /*public O2_Start RegisterO2Extensions()
        {

            var versionName      = o2PlatformConfig.Version_Name;
            var h2Logo           = o2PlatformConfig.Folder_Scripts.pathCombine(@"_DataFiles\_Images\H2Logo.ico");
            var o2Logo           = o2PlatformConfig.Folder_Scripts.pathCombine(@"_DataFiles\_Images\O2Logo.ico");
            RegisterWindowsExtension_WinForms.register_CurrentApplication(".h2", versionName, h2Logo);
            RegisterWindowsExtension_WinForms.register_CurrentApplication(".o2", versionName, o2Logo);
            return this;
        }*/
        public Assembly compileScript(string o2Script)
        {
            var compileEngine = new CompileEngine();
            var assembly = compileEngine.compileSourceFile(o2Script.local());
            if (assembly.isNull())
                MessageBox.Show(compileEngine.sbErrorMessage.str(), @"Compilation error in Start_O2:");
            return assembly;
        }
        public static Assembly compileCodeSnippet(this string snippet, Action<string> onCompileOk, Action<string> onCompileFail)
        {
            try
            {
                var codeFile = createCSharpFileFromCodeSnippet(snippet);

                var compileEngine = new CompileEngine();
                var assembly = compileEngine.compileSourceFile(codeFile);
                if (assembly.notNull())
                {
                    onCompileOk("[compileAndExecuteCodeSnippet] Snippet assembly created OK: {0}".format(assembly.location()));
                    return assembly;
                }
                onCompileFail("[compileAndExecuteCodeSnippet] Compilation failed: ".line() + compileEngine.sbErrorMessage.str());
            }
            catch (Exception ex)
            {
                ex.log("[compileAndExecuteCodeSnippet]");
            }
            return null;
        }
        public void onCompileScript(IStep step)
        {
            O2Thread.mtaThread(
                ()=>
                    {
                        step.clear();
                        //var panel = step.FirstControl; 
                        step.add_Label("Compiling Script:" +  scriptToExecute);

                        var compileEngine = new CompileEngine();
                        var compiledAssembly = compileEngine.compileSourceFile(scriptToExecute);
                        if (compiledAssembly != null)					
                        {
                            var label = step.add_Label("Compilation was ok", 20);
                            label.ForeColor = Color.DarkGreen;
                            step.add_Label("Which method to you want to execute?", 40);
                            var top = 40;
                            foreach(var method in PublicDI.reflection.getMethods(compiledAssembly))
                            {
                                if (PublicDI.reflection.getParameters(method).Count ==0 && 
                                    method.Name.Contains(">b") == false)
                                {
                                    var methodToExecute = method;
                                    step.add_Link(method.Name , top+=20 ,10 ,
                                                  ()=> PublicDI.reflection.invoke(methodToExecute));
                                };
                            }							
                        }
                        else
                        {
                            var label = step.add_Label("Compilation Failed", 20);
                            label.ForeColor = Color.DarkRed;
                            step.add_Label(compileEngine.sbErrorMessage.ToString(), 40);                            
                        }
						
                    });			   
        }
        public Assembly compileCSSharpFile()
        {
            enableCodeComplete();
            compiledAssembly = null;
            var compileEngine = new CompileEngine();
            if (getSourceCode() != "")
            {
                saveSourceCode();
                // always save before compiling
                compileEngine.compileSourceFile(sPathToFileLoaded);
                compiledAssembly = compileEngine.compiledAssembly;
                if (compiledAssembly.notNull() && o2CodeCompletion.notNull() && compileEngine.cpCompilerParameters.notNull())
                    o2CodeCompletion.addReferences(compileEngine.cpCompilerParameters.ReferencedAssemblies.toList());
            }

            var state = compiledAssembly == null && compileEngine.sbErrorMessage != null;
            //btShowHideCompilationErrors.visible(state);
            //btShowHideCompilationErrors.prop("Visible",state);
            btShowHideCompilationErrors.visible(state);
            tvCompilationErrors.visible(state);
            lbCompilationErrors.visible(state);
            //lbCompilationErrors.prop("Visible", state);

            clearBookmarksAndMarkers();
            // if there isn't a compiledAssembly, show errors
            if (compiledAssembly == null)
            {
                CompileEngine_WinForms.addErrorsListToTreeView(tvCompilationErrors, compileEngine.sbErrorMessage);
                showErrorsInSourceCodeEditor(compileEngine.sbErrorMessage.str());
            }
             /*   else
            {
                if (compiledFileAstData.notNull())
                    compiledFileAstData.Dispose();
                compiledFileAstData = new O2MappedAstData(sPathToFileLoaded);
            }*/

            return compiledAssembly;
        }
 public static List<String> compileAllFilesIndividually(List<String> filesToCompile, Action<string> currentTask, Action<int> numberOfStepsToPerform, Action onStepEvent)
 {
     currentTask("Compiling all rules individualy (one file at the time)");
     numberOfStepsToPerform(filesToCompile.Count);
     var compileEngine = new CompileEngine();
     PublicDI.log.info("Compiling All XRules source code files ONE at the time");
     var results = new List<String>();
     foreach (var fileToCompile in filesToCompile)
     {
         var assembly = compileEngine.compileSourceFile(fileToCompile);
         if (assembly != null)
             results.Add(assembly.Location);
         else
             PublicDI.log.error("In XRules_Execution.compileAllFilesIndividually, could not compile file: {0}", fileToCompile);
         onStepEvent();
     }
     return results;
 }