diff --git a/Protocols/PowerShell/PowerShellConnectionForm.Designer.cs b/Protocols/PowerShell/PowerShellConnectionForm.Designer.cs index badc196..7ed4576 100644 --- a/Protocols/PowerShell/PowerShellConnectionForm.Designer.cs +++ b/Protocols/PowerShell/PowerShellConnectionForm.Designer.cs @@ -29,13 +29,18 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this._terminal = new WalburySoftware.TerminalControl(); + this._statusStrip = new System.Windows.Forms.StatusStrip(); + this._statusStripSpacerLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this._progressLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this._progressBar = new System.Windows.Forms.ToolStripProgressBar(); + this._statusStrip.SuspendLayout(); this.SuspendLayout(); // // _terminal // - this._terminal.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this._terminal.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this._terminal.AuthType = Poderosa.ConnectionParam.AuthType.Password; this._terminal.BackColor = System.Drawing.Color.Navy; this._terminal.ForeColor = System.Drawing.Color.White; @@ -45,25 +50,62 @@ private void InitializeComponent() this._terminal.Method = WalburySoftware.ConnectionMethod.Telnet; this._terminal.Name = "_terminal"; this._terminal.Password = ""; - this._terminal.Size = new System.Drawing.Size(715, 522); + this._terminal.Size = new System.Drawing.Size(715, 500); this._terminal.TabIndex = 0; this._terminal.UserName = ""; // + // _statusStrip + // + this._statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this._statusStripSpacerLabel, + this._progressLabel, + this._progressBar}); + this._statusStrip.Location = new System.Drawing.Point(0, 496); + this._statusStrip.Name = "_statusStrip"; + this._statusStrip.Size = new System.Drawing.Size(713, 22); + this._statusStrip.SizingGrip = false; + this._statusStrip.TabIndex = 1; + // + // _statusStripSpacerLabel + // + this._statusStripSpacerLabel.Name = "_statusStripSpacerLabel"; + this._statusStripSpacerLabel.Size = new System.Drawing.Size(513, 17); + this._statusStripSpacerLabel.Spring = true; + // + // _progressLabel + // + this._progressLabel.Name = "_progressLabel"; + this._progressLabel.Size = new System.Drawing.Size(52, 17); + this._progressLabel.Text = " "; + // + // _progressBar + // + this._progressBar.Name = "_progressBar"; + this._progressBar.Size = new System.Drawing.Size(100, 16); + // // PowerShellConnectionForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(713, 518); + this.Controls.Add(this._statusStrip); this.Controls.Add(this._terminal); this.Name = "PowerShellConnectionForm"; this.Text = "PowerShellConnectionForm"; + this._statusStrip.ResumeLayout(false); + this._statusStrip.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private WalburySoftware.TerminalControl _terminal; + private System.Windows.Forms.StatusStrip _statusStrip; + private System.Windows.Forms.ToolStripStatusLabel _statusStripSpacerLabel; + private System.Windows.Forms.ToolStripStatusLabel _progressLabel; + private System.Windows.Forms.ToolStripProgressBar _progressBar; } } \ No newline at end of file diff --git a/Protocols/PowerShell/PowerShellConnectionForm.cs b/Protocols/PowerShell/PowerShellConnectionForm.cs index ab74c34..4d714e0 100644 --- a/Protocols/PowerShell/PowerShellConnectionForm.cs +++ b/Protocols/PowerShell/PowerShellConnectionForm.cs @@ -125,6 +125,9 @@ public override void Connect() { GEnv.Options.Font = Connection.Font; + _progressBar.Value = 0; + _progressLabel.Text = ""; + // This is not strictly a network connection: we're relaying information that we receive from the runspace to the terminal over a local stream // (a StreamConnection in this case) TerminalParam terminalParam = TCPTerminalParam.Fake; @@ -147,7 +150,7 @@ public override void Connect() _terminal.TerminalPane.SendShiftTab = true; _terminal.SetPaneColors(Connection.TextColor, Connection.BackgroundColor); - _powerShellHost = new PowerShellHost(this, _terminal, ExecuteQuiet); + _powerShellHost = new PowerShellHost(this, _terminal, ExecuteQuiet, _progressBar, _progressLabel); // Create the host and runspace instances for this interpreter. If we're connecting to the local host, don't bother with the connection info. // ReSharper disable StringCompareIsCultureSpecific.3 diff --git a/Protocols/PowerShell/PowerShellConnectionForm.resx b/Protocols/PowerShell/PowerShellConnectionForm.resx index 29dcb1b..2b980ff 100644 --- a/Protocols/PowerShell/PowerShellConnectionForm.resx +++ b/Protocols/PowerShell/PowerShellConnectionForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Protocols/PowerShell/PowerShellHost.cs b/Protocols/PowerShell/PowerShellHost.cs index f8fdfac..f948b37 100644 --- a/Protocols/PowerShell/PowerShellHost.cs +++ b/Protocols/PowerShell/PowerShellHost.cs @@ -6,6 +6,7 @@ using System.Management.Automation.Runspaces; using System.Reflection; using System.Threading; +using System.Windows.Forms; using WalburySoftware; namespace EasyConnect.Protocols.PowerShell @@ -51,10 +52,12 @@ public class PowerShellHost : PSHost, IHostSupportsInteractiveSession /// The connection form that will display the PowerShell console. /// Terminal control that will display the PowerShell console. /// Method used to execute PowerShell commands within the current session. - public PowerShellHost(PowerShellConnectionForm parentForm, TerminalControl terminal, Func> executeHelper) + /// Progress bar UI element to update when writing progress records. + /// Label UI element to update when writing progress records. + public PowerShellHost(PowerShellConnectionForm parentForm, TerminalControl terminal, Func> executeHelper, ToolStripProgressBar progressBar, ToolStripStatusLabel progressLabel) { _parentForm = parentForm; - _powerShellHostUi = new PowerShellHostUi(terminal, executeHelper); + _powerShellHostUi = new PowerShellHostUi(terminal, executeHelper, progressBar, progressLabel); } /// diff --git a/Protocols/PowerShell/PowerShellHostUi.cs b/Protocols/PowerShell/PowerShellHostUi.cs index a3a30a3..b13200c 100644 --- a/Protocols/PowerShell/PowerShellHostUi.cs +++ b/Protocols/PowerShell/PowerShellHostUi.cs @@ -9,7 +9,10 @@ using System.Security; using System.Text; using System.Threading; +using System.Timers; +using System.Windows.Forms; using WalburySoftware; +using Timer = System.Timers.Timer; namespace EasyConnect.Protocols.PowerShell { @@ -59,7 +62,7 @@ public class PowerShellHostUi : PSHostUserInterface, IHostUISupportsMultipleChoi protected Dictionary> _intellisenseParameters = new Dictionary>(); /// - /// Thread that is retrieving intellisense commands. + /// Thread that is retrieving Intellisense commands. /// protected Thread _intellisenseThread = null; @@ -89,16 +92,35 @@ public class PowerShellHostUi : PSHostUserInterface, IHostUISupportsMultipleChoi /// protected Stack _upCommandHistory = new Stack(); + /// + /// Progress bar UI element to update when writing progress records. + /// + protected ToolStripProgressBar _progressBar; + + /// + /// Label UI element to update when writing progress records. + /// + protected ToolStripStatusLabel _progressLabel; + + /// + /// Timer to use for asynchronous UI events. + /// + protected Timer _timer = new Timer(); + /// /// Default constructor. /// /// Terminal control that will display the PowerShell console. /// Method used to execute PowerShell commands within the current session. - public PowerShellHostUi(TerminalControl terminal, Func> executeHelper) + /// Progress bar UI element to update when writing progress records. + /// Label UI element to update when writing progress records. + public PowerShellHostUi(TerminalControl terminal, Func> executeHelper, ToolStripProgressBar progressBar, ToolStripStatusLabel progressLabel) { _terminal = terminal; _powerShellRawUi = new PowerShellRawUi(terminal); _executeHelper = executeHelper; + _progressBar = progressBar; + _progressLabel = progressLabel; } /// @@ -868,6 +890,35 @@ public override void WriteLine(string value) /// A ProgressReport object. public override void WriteProgress(long sourceId, ProgressRecord record) { + _progressLabel.Text = String.IsNullOrEmpty(record.Activity) + ? "" + : record.Activity + (String.IsNullOrEmpty(record.CurrentOperation) + ? "" + : ": ") + record.CurrentOperation; + _progressBar.Value = record.PercentComplete; + + // If we've completed, leave it in its current state for one second and then clear the progress data + if (_progressBar.Value == 100) + { + _timer.Enabled = true; + _timer.Interval = 1000; + _timer.Elapsed += _timer_Elapsed; + _timer.Start(); + } + } + + /// + /// Handler method that's called when ticks. Clears the progress data from the UI and stops the timer. + /// + /// Object from which this event originated, in this case. + /// Arguments associated with this event. + void _timer_Elapsed(object sender, ElapsedEventArgs e) + { + _progressLabel.Text = ""; + _progressBar.Value = 0; + + _timer.Elapsed -= _timer_Elapsed; + _timer.Stop(); } ///