Exemplo n.º 1
0
        void OpenRunspace(bool sync)
        {
            // host and UI
            FarUI   = new FarUI();
            FarHost = new FarHost(FarUI);

            // initial state
            var state = InitialSessionState.CreateDefault();

            // can run scripts regadless of execution policy
            state.AuthorizationManager = new AuthorizationManager(Res.Me);

            // cmdlets
            Commands.BaseCmdlet.AddCmdlets(state);

            // apartment
            state.ApartmentState = Environment.GetEnvironmentVariable("PSF.ApartmentState") == "MTA" ? ApartmentState.MTA : ApartmentState.STA;

            // open/start runspace
            Runspace = RunspaceFactory.CreateRunspace(FarHost, state);
            Runspace.StateChanged += OnRunspaceStateEvent;
            if (sync)
            {
                Runspace.Open();
            }
            else
            {
                Runspace.OpenAsync();
            }
        }
Exemplo n.º 2
0
 void EnsureHost()
 {
     if (FarHost == null)
     {
         Editor.Closed       += delegate { CloseSession(); };
         Editor.CtrlCPressed += OnCtrlCPressed;
         FarUI   = new FarUI();
         FarHost = new FarHost(FarUI);
     }
 }
Exemplo n.º 3
0
        void OpenRunspace(bool sync)
        {
            // host and UI
            FarUI   = new FarUI();
            FarHost = new FarHost(FarUI);

            // initial state
            var state = InitialSessionState.CreateDefault();

            state.Variables.Add(new SessionStateVariableEntry[] {
                new SessionStateVariableEntry("Far", Far.Api, "Exposes FarNet.", ScopedItemOptions.AllScope | ScopedItemOptions.Constant),
                new SessionStateVariableEntry("Psf", this, "Exposes PowerShellFar.", ScopedItemOptions.AllScope | ScopedItemOptions.Constant),
                new SessionStateVariableEntry("LogEngineLifeCycleEvent", false, string.Empty),
                new SessionStateVariableEntry("LogProviderLifeCycleEvent", false, string.Empty),
            });

            // can run scripts regadless of execution policy
            state.AuthorizationManager = new AuthorizationManager(Res.Me);

            // cmdlets
            Commands.BaseCmdlet.AddCmdlets(state);

            // apartment
            //! cannot set different with PSThreadOptions.UseCurrentThread
            var myApartmentState = DefaultApartmentState();

            if (myApartmentState != ApartmentState.Unknown)
            {
                state.ApartmentState = myApartmentState;
            }

            // open/start runspace
            Runspace = RunspaceFactory.CreateRunspace(FarHost, state);
            Runspace.StateChanged += OnRunspaceStateEvent;
            if (myApartmentState == ApartmentState.Unknown)
            {
                Runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
            }
            if (sync)
            {
                Runspace.Open();
            }
            else
            {
                Runspace.OpenAsync();
            }
        }
Exemplo n.º 4
0
        void OpenRunspace(bool sync)
        {
            // host and UI
            FarUI   = new FarUI();
            FarHost = new FarHost(FarUI);

            // initial state
            var state = InitialSessionState.CreateDefault();

            // can run scripts regadless of execution policy
            state.AuthorizationManager = new AuthorizationManager(Res.Me);

            // cmdlets
            Commands.BaseCmdlet.AddCmdlets(state);

            // apartment
            //! cannot set different with PSThreadOptions.UseCurrentThread
            var myApartmentState = DefaultApartmentState();

            if (myApartmentState != ApartmentState.Unknown)
            {
                state.ApartmentState = myApartmentState;
            }

            // open/start runspace
            Runspace = RunspaceFactory.CreateRunspace(FarHost, state);
            Runspace.StateChanged += OnRunspaceStateEvent;
            if (myApartmentState == ApartmentState.Unknown)
            {
                Runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
            }
            if (sync)
            {
                Runspace.Open();
            }
            else
            {
                Runspace.OpenAsync();
            }
        }
Exemplo n.º 5
0
        internal void Disconnect()
        {
            //! do not unsubscribe _110301_164313
            //Console.CancelKeyPress -= CancelKeyPress; //_110128_075844

            // unsubscribe
            Far.Api.AnyEditor.Opened -= EditorKit.OnEditorOpened2;
            Far.Api.AnyEditor.Opened -= EditorKit.OnEditorOpened1;

            // kill menu
            UI.ActorMenu.Destroy();

            // kill remaining jobs
            //! after menus, before PS
            Job.StopJobsOnExit();

            // kill host
            if (FarHost != null)
            {
                try
                {
                    //! it may be still opening, but Far is already closing, ignore this case,
                    //! or we will see for a sec disappearing together with Far error message.
                    if (Runspace.RunspaceStateInfo.State == RunspaceState.Opened)
                        Runspace.Close();
                }
                finally
                {
                    // detach all
                    FarUI = null;
                    FarHost = null;
                    _engine_ = null;
                    Pipeline = null;
                    Runspace = null;
                }
            }
        }
Exemplo n.º 6
0
        void OpenRunspace(bool sync)
        {
            // host and UI
            FarUI = new FarUI();
            FarHost = new FarHost(FarUI);

            // initial state
            var state = InitialSessionState.CreateDefault();

            // can run scripts regadless of execution policy
            state.AuthorizationManager = new AuthorizationManager(Res.Me);

            // cmdlets
            Commands.BaseCmdlet.AddCmdlets(state);

            // apartment
            state.ApartmentState = Environment.GetEnvironmentVariable("PSF.ApartmentState") == "MTA" ? ApartmentState.MTA : ApartmentState.STA;

            // open/start runspace
            Runspace = RunspaceFactory.CreateRunspace(FarHost, state);
            Runspace.StateChanged += OnRunspaceStateEvent;
            if (sync)
                Runspace.Open();
            else
                Runspace.OpenAsync();
        }
Exemplo n.º 7
0
 void EnsureHost()
 {
     if (FarHost == null)
     {
         Editor.Closed += delegate { CloseSession(); };
         Editor.CtrlCPressed += OnCtrlCPressed;
         FarUI = new FarUI();
         FarHost = new FarHost(FarUI);
     }
 }