public IScriptCSSession GetOrCreate(string name, Cmdlet cmdlet)
        {
            var session = Get(name);

            if (null == session)
            {
                session = ScriptCSSession.Create(cmdlet);
                _map.Add(name, session);
            }

            return(session);
        }
Example #2
0
        static public ScriptCSSession Create(Cmdlet cmdlet)
        {
            ScriptCSSession session = null;
            var             logger  = new CurrentLogger();

            using (logger.CreateActiveLoggerSession(new CmdletLogger(cmdlet)))
            {
                IScriptHostFactory factory = new ScriptHostFactory();
                var engine = new RoslynScriptEngine(factory, logger);
                engine.BaseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var currentCmdletScriptPack = new CurrentCmdletScriptPack();
                var scriptPackSession       = new ScriptPackSession(new IScriptPack[] { currentCmdletScriptPack });
                scriptPackSession.InitializePacks();

                session = new ScriptCSSession(engine, scriptPackSession, currentCmdletScriptPack, logger);
            }

            return(session);
        }
        public static ScriptCSSession Create(Cmdlet cmdlet)
        {
            ScriptCSSession session = null;
            var logger = new CurrentLogger();

            using (logger.CreateActiveLoggerSession(new CmdletLogger(cmdlet)))
            {
                IScriptHostFactory factory = new ScriptHostFactory();
                var engine = new RoslynScriptEngine(factory, logger);
                engine.BaseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var currentCmdletScriptPack = new CurrentCmdletScriptPack();
                var scriptPackSession = new ScriptPackSession(new IScriptPack[] { currentCmdletScriptPack });
                scriptPackSession.InitializePacks();

                session = new ScriptCSSession( engine, scriptPackSession, currentCmdletScriptPack, logger );
            }

            return session;
        }