Exemplo n.º 1
0
        public void SetScript(string scriptText, string membersText, IEnumerable <string> openedNamespaces, IEnumerable <string> shortcuts)
        {
            GenerationError  = null;
            CompilationError = null;
            ExecutionError   = null;

            ScriptGenerationComplete  = false;
            ScriptCompilationComplete = false;
            ScriptExecutionComplete   = false;

            Ipr.Shortcuts.ResetShortcuts(shortcuts);
            OpenedNamespaces       = new List <string>(openedNamespaces);
            ScriptText             = scriptText;
            ScriptClassMembersText = membersText;
            ScriptCode             = String.Empty;
            _gmacScriptInstance    = null;

            this.ResetProgress();
        }
Exemplo n.º 2
0
        private bool CompileCSharpCode()
        {
            if (ScriptGenerationComplete == false)
            {
                return(false);
            }

            var progressId = this.ReportStart("Script Compilation", ScriptCode);

            try
            {
                CSScript.ShareHostRefAssemblies = true;

                CSScript.AssemblyResolvingEnabled = true;

                //var helper = new AsmHelper(CSScript.LoadCode(code, null, true));
                var helper = new AsmHelper(CSScript.LoadCode(ScriptCode));

                //the only reflection based call
                _gmacScriptInstance = (IGMacScript)helper.CreateObject("InteractiveScript");

                _gmacScriptInstance.Ipr = Ipr;

                this.ReportFinish(progressId, "", ProgressEventArgsResult.Success);

                return(true);
            }
            catch (Exception e)
            {
                CompilationError = e;

                this.ReportError(e);

                this.ReportFinish(progressId, "", ProgressEventArgsResult.Failure);

                return(false);
            }
        }