private void Close()
        {
            runspace.Close();
            runspace.Dispose();

            runspace      = null;
            host          = null;
            spoolerParams = null;
        }
        public PowershellAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String scriptContent)
            : base(contextLog, contextTask, contextJob, contextSpooler, scriptContent)
        {
            this.ParseScript();
            this.spoolerParams = new PowershellSpoolerParams(
                this.spooler_task, this.spooler, this.IsOrderJob, this.isShellMode);

            this.host = new PowershellAdapterPSHost(this.spooler_log);
            this.runspace = RunspaceFactory.CreateRunspace(this.host);
            this.runspace.Open();
            this.runspace.SessionStateProxy.SetVariable("spooler_log", this.spooler_log);
            this.runspace.SessionStateProxy.SetVariable("spooler_task", this.spooler_task);
            this.runspace.SessionStateProxy.SetVariable("spooler_job", this.spooler_job);
            this.runspace.SessionStateProxy.SetVariable("spooler", this.spooler);
            this.runspace.SessionStateProxy.SetVariable("spooler_params", this.spoolerParams);
        }
        public PowershellAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String contextStdErrLogLevel, String scriptContent)
            : base(contextLog, contextTask, contextJob, contextSpooler, contextStdErrLogLevel, scriptContent)
        {
            ParseScript();
            spoolerParams = new PowershellSpoolerParams(spooler_task, spooler, IsOrderJob, isShellMode);

            host     = new PowershellAdapterPSHost(spooler_task, spooler_log);
            runspace = RunspaceFactory.CreateRunspace(host);
            runspace.Open();
            runspace.SessionStateProxy.SetVariable("spooler_log", spooler_log);
            runspace.SessionStateProxy.SetVariable("spooler_task", spooler_task);
            runspace.SessionStateProxy.SetVariable("spooler_job", spooler_job);
            runspace.SessionStateProxy.SetVariable("spooler", spooler);
            runspace.SessionStateProxy.SetVariable("spooler_params", spoolerParams);

            InvokeDollarProfile();
        }
        private void Close()
        {
            this.runspace.Close();
            this.runspace.Dispose();

            this.runspace = null;
            this.host = null;
            this.spoolerParams = null;
        }