Skip to content

fix(ssh): resize the PTY via public API, and cache DataGrid row-key lookups - #13

Open
xiaochengzjc wants to merge 2 commits into
masterfrom
fix/ssh-resize-and-datagrid-keys
Open

xiaochengzjc wants to merge 2 commits into
masterfrom
fix/ssh-resize-and-datagrid-keys

Conversation

@xiaochengzjc

Copy link
Copy Markdown
Collaborator

Summary

Two small, independent cleanups lifted out of #6 (thanks @heartacker). Both keep existing behaviour; neither touches the RDP bridge or persistence.

1. SSH terminal resize no longer uses reflection (Services/SshConnectionService.cs)

ResizeTerminal was reaching into SSH.NET's private _channel field and invoking the private SendWindowChangeRequest by reflection, with a hand-written error message when the internals did not match. ShellStream.ChangeWindowSize(columns, rows, pixelWidth, pixelHeight) is public API on the pinned SSH.NET 2026.0.1, takes the same arguments in the same order, and issues the same PTY window-change request — so this is a drop-in replacement that removes 34 lines and one using System.Reflection;.

The reflection path also cannot survive NativeAOT, so this is a prerequisite for any future AOT work.

2. DataGrid row-key properties are resolved once per item type (Controls/DataGridSourceAdapter.cs)

RebuildKeyMap runs on every selection query (TryGetItem, GetKey, GetSelectedItems, GetCurrentItem, SetSelectedItems), and for each row it scanned the item type for up to three nested key properties plus five direct ones — up to eight Type.GetProperty calls per row, per query. A 1,000-row session list meant thousands of redundant reflection lookups on every click.

The key plan (nested candidates, direct candidates, resolved Id property per nested type) is now cached in a ConcurrentDictionary keyed by runtime type. The generated key format is unchanged:

{type.FullName}:{propertyName}:{value}:{RuntimeHelpers.GetHashCode(item)}

so persisted/explicit row keys stay valid across the two implementations.

Verification

  • dotnet build -c Release: 0 warnings, 0 errors
  • dotnet test: 793 passed, 0 failed
  • Three new cases in CxShell.Tests/DataGridSourceAdapterTests.cs pin the nested-key, direct-key and no-key-fallback paths, each asserting that selecting one row returns exactly that row (the previous reflection scan and the cache must agree).

Not included

Everything else in #6 either already exists on master (H.264/AVC444, dirty-rect copy, CLIPRDR / LockClipboardData, RdpDpiPolicy, IME focus handling, the multi-tab workspace window, .NET 11) or is part of the NativeAOT refactor, which is being evaluated separately.

zhangruochu added 2 commits November 30, 2026 17:34
Reaching into SSH.NET's private _channel field and invoking SendWindowChangeRequest by reflection broke whenever the library reshaped its internals, and reflection is unavailable under NativeAOT. ShellStream exposes ChangeWindowSize publicly, so call it directly.
RebuildKeyMap runs on every selection query and scanned the item type with up to eight GetProperty calls per row, so selection cost grew with the number of properties rather than the number of rows. Resolve the nested and direct key properties once per type and reuse them, keeping the existing key format of type:property:value:instance-hash.

Adds coverage for the nested, direct and no-key fallbacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant