コード例 #1
0
        protected internal virtual void InjectScriptLibraries(
            string workingDirectory,
            FilePreProcessorResult result,
            IDictionary <string, object> state
            )
        {
            Guard.AgainstNullArgument("result", result);
            Guard.AgainstNullArgument("state", state);

            if (state.ContainsKey(ScriptLibrariesInjected))
            {
                return;
            }

            var scriptLibrariesPreProcessorResult = LoadScriptLibraries(workingDirectory);

            if (scriptLibrariesPreProcessorResult != null)
            {
                result.Code = scriptLibrariesPreProcessorResult.Code + Environment.NewLine
                              + "Env.Initialize();" + Environment.NewLine
                              + result.Code;
                result.References.AddRange(scriptLibrariesPreProcessorResult.References);
                result.Namespaces.AddRange(scriptLibrariesPreProcessorResult.Namespaces);
            }
            else
            {
                result.Code = "Env.Initialize();" + Environment.NewLine + result.Code;
            }
            state.Add(ScriptLibrariesInjected, null);
        }
コード例 #2
0
ファイル: ScriptExecutor.cs プロジェクト: synnos/scriptcs
        protected internal virtual ScriptResult EngineExecute(
            string workingDirectory,
            string[] scriptArgs,
            FilePreProcessorResult result
            )
        {
            InjectScriptLibraries(workingDirectory, result, ScriptPackSession.State);
            var namespaces = Namespaces.Union(result.Namespaces);
            var references = References.Union(result.References);

            _log.Debug("Starting execution in engine");
            return(ScriptEngine.Execute(result.Code, scriptArgs, references, namespaces, ScriptPackSession));
        }
コード例 #3
0
        protected internal virtual void InjectScriptLibraries(
            string workingDirectory,
            FilePreProcessorResult result,
            IDictionary <string, object> state
            )
        {
            Guard.AgainstNullArgument("result", result);
            Guard.AgainstNullArgument("state", state);

            if (state.ContainsKey(ScriptLibrariesInjected))
            {
                return;
            }

            var scriptLibrariesPreProcessorResult = LoadScriptLibraries(workingDirectory);

            // script libraries should be injected just before the #line directive
            // if there is no #line directive, they can be injected at the beginning of code
            if (result.Code == null)
            {
                result.Code = string.Empty;
            }
            var safeInsertIndex = result.Code.IndexOf("#line");

            if (safeInsertIndex < 0)
            {
                safeInsertIndex = 0;
            }

            if (scriptLibrariesPreProcessorResult != null)
            {
                result.Code = result.Code.Insert(safeInsertIndex, scriptLibrariesPreProcessorResult.Code + Environment.NewLine
                                                 + "Env.Initialize();" + Environment.NewLine);
                result.References.AddRange(scriptLibrariesPreProcessorResult.References);
                result.Namespaces.AddRange(scriptLibrariesPreProcessorResult.Namespaces);
            }
            else
            {
                result.Code = result.Code.Insert(safeInsertIndex, "Env.Initialize();" + Environment.NewLine);
            }

            state.Add(ScriptLibrariesInjected, null);
        }
コード例 #4
0
ファイル: ScriptExecutor.cs プロジェクト: vbodurov/scriptcs
        protected internal virtual void InjectScriptLibraries(
            string workingDirectory,
            FilePreProcessorResult result,
            IDictionary <string, object> state
            )
        {
            if (state.ContainsKey(ScriptLibrariesInjected))
            {
                return;
            }

            var scriptLibrariesPreProcessorResult = LoadScriptLibraries(workingDirectory);

            if (scriptLibrariesPreProcessorResult != null)
            {
                result.Code = scriptLibrariesPreProcessorResult.Code + Environment.NewLine + result.Code;
                result.References.AddRange(scriptLibrariesPreProcessorResult.References);
                result.Namespaces.AddRange(scriptLibrariesPreProcessorResult.Namespaces);
            }
            state.Add(ScriptLibrariesInjected, null);
        }