Exemplo n.º 1
0
        protected override void OnApply(PageApplyEventArgs e)
        {
            base.OnApply(e);

            // On a non-64bit machine, bitness cannot be changed.
            if (!Environment.Is64BitOperatingSystem)
            {
                Bitness = BitnessOptions.DefaultToOperatingSystem;
                return;
            }

            if (_savedResetSession != ResetPowerShellSession)
            {
                var changed = ResetPowerShellSessionChanged;
                if (changed != null)
                {
                    changed(this, new EventArgs <bool>(ResetPowerShellSession));
                }
            }

            _savedResetSession = ResetPowerShellSession;

            if (_savedBitness != Bitness)
            {
                var changed = BitnessSettingChanged;
                if (changed != null)
                {
                    changed(this, new BitnessEventArgs(_savedBitness));
                }
            }
            _savedBitness = Bitness;
        }
Exemplo n.º 2
0
        /// <summary>
        /// These are the default settings for the dialog's options. This is called before LoadSettingsFromStorage/Xml, so the below will be overridden if persisted settings exist.
        /// </summary>
        private void InitializeSettings()
        {
            this.OverrideExecutionPolicyConfiguration = true;

            this.MultilineRepl = false;
            if (Environment.Is64BitOperatingSystem)
            {
                _savedBitness = Bitness;
            }
            else
            {
                Bitness = BitnessOptions.DefaultToOperatingSystem;
            }

            ResetPowerShellSessionChanged += PowerShellToolsPackage.Instance.ResetPowerShellSessionChanged;
            BitnessSettingChanged         += PowerShellToolsPackage.Instance.BitnessSettingChanged;

            this.ResetPowerShellSession = false;
            this.ShouldLoadProfiles     = true;
            this.ShowReleaseNotes       = true;
        }
        public static PowerShellHostProcess CreatePowerShellHostProcess(BitnessOptions bitness)
        {
            Log.DebugFormat("Starting host process. Bitness: {0}", bitness);
            PowerShellToolsPackage.DebuggerReadyEvent.Reset();

            Process powerShellHostProcess     = new Process();
            string  hostProcessReadyEventName = Constants.ReadyEventPrefix + Guid.NewGuid();

            EndPointGuid = Guid.NewGuid();

            string exeName;

            switch (bitness)
            {
            case BitnessOptions.x86:
                exeName = Constants.PowerShellHostExeNameForx86;
                break;

            case BitnessOptions.DefaultToOperatingSystem:
            default:
                exeName = Constants.PowerShellHostExeName;
                break;
            }
            string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path        = Path.Combine(currentPath, exeName);
            string hostArgs    = String.Format(CultureInfo.InvariantCulture,
                                               "{0}{1} {2}{3} {4}{5}",
                                               Constants.UniqueEndpointArg, EndPointGuid, // For generating a unique endpoint address
                                               Constants.VsProcessIdArg, Process.GetCurrentProcess().Id,
                                               Constants.ReadyEventUniqueNameArg, hostProcessReadyEventName);

            Log.DebugFormat("Host path: '{0}' Host arguments: '{1}'", path, hostArgs);

            powerShellHostProcess.StartInfo.Arguments = hostArgs;
            powerShellHostProcess.StartInfo.FileName  = path;

            powerShellHostProcess.StartInfo.CreateNoWindow = false;
            powerShellHostProcess.StartInfo.WindowStyle    = ProcessWindowStyle.Normal;

            powerShellHostProcess.StartInfo.UseShellExecute        = false;
            powerShellHostProcess.StartInfo.RedirectStandardInput  = true;
            powerShellHostProcess.StartInfo.RedirectStandardOutput = true;
            powerShellHostProcess.StartInfo.RedirectStandardError  = true;

            powerShellHostProcess.OutputDataReceived += PowerShellHostProcess_OutputDataReceived;
            powerShellHostProcess.ErrorDataReceived  += PowerShellHostProcess_ErrorDataReceived;

            EventWaitHandle readyEvent = new EventWaitHandle(false, EventResetMode.ManualReset, hostProcessReadyEventName);

            powerShellHostProcess.Start();
            powerShellHostProcess.EnableRaisingEvents = true;

            powerShellHostProcess.BeginOutputReadLine();
            powerShellHostProcess.BeginErrorReadLine();

            // Wait for ready signal from the host process.
            bool success = readyEvent.WaitOne(HostProcessSignalTimeout);

            readyEvent.Close();

            if (!success)
            {
                Log.Warn("Failed to start host!");
                int processId = powerShellHostProcess.Id;
                try
                {
                    powerShellHostProcess.Kill();
                }
                catch (Exception)
                {
                }

                if (powerShellHostProcess != null)
                {
                    powerShellHostProcess.Dispose();
                    powerShellHostProcess = null;
                }
                throw new PowerShellHostProcessException(String.Format(CultureInfo.CurrentCulture,
                                                                       Resources.ErrorFailToCreateProcess,
                                                                       processId.ToString()));
            }

            return(new PowerShellHostProcess(powerShellHostProcess, EndPointGuid));
        }
Exemplo n.º 4
0
 public void ProcessEventHandler(BitnessOptions bitness)
 {
     Log.DebugFormat("Bitness had been changed to {1}", bitness);
     EnsureCloseProcess();
 }
Exemplo n.º 5
0
 public BitnessEventArgs(BitnessOptions newBitness)
 {
     _newBitness = newBitness;
 }