1010using NETworkManager . Utilities ;
1111using NETworkManager . Models . PuTTY ;
1212using System . Windows . Input ;
13+ using MahApps . Metro . Controls . Dialogs ;
14+ using NETworkManager . Models . Settings ;
1315
1416namespace NETworkManager . Controls
1517{
@@ -26,14 +28,15 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
2628
2729 #region Variables
2830 private bool _initialized = false ;
31+ private IDialogCoordinator dialogCoordinator ;
2932
30- private PuTTYSessionInfo _puTTYSessionInfo ;
33+ private Models . PuTTY . PuTTYSessionInfo _puTTYSessionInfo ;
3134
3235 Process PuTTYProcess = null ;
3336 IntPtr AppWin ;
3437
3538 DispatcherTimer resizeTimer = new DispatcherTimer ( ) ;
36-
39+
3740 private bool _connected = true ;
3841 public bool Connected
3942 {
@@ -50,11 +53,13 @@ public bool Connected
5053 #endregion
5154
5255 #region Constructor, load
53- public PuTTYControl ( PuTTYSessionInfo info )
56+ public PuTTYControl ( Models . PuTTY . PuTTYSessionInfo info )
5457 {
5558 InitializeComponent ( ) ;
5659 DataContext = this ;
5760
61+ dialogCoordinator = DialogCoordinator . Instance ;
62+
5863 _puTTYSessionInfo = info ;
5964
6065 resizeTimer . Tick += ResizeTimer_Tick ;
@@ -92,39 +97,55 @@ private void ReconnectAction()
9297 #endregion
9398
9499 #region Methods
95- private void Connect ( )
100+ private async void Connect ( )
96101 {
102+
103+
97104 ProcessStartInfo info = new ProcessStartInfo
98105 {
99106 FileName = _puTTYSessionInfo . PuTTYLocation ,
100107 Arguments = PuTTY . BuildCommandLine ( _puTTYSessionInfo )
101108 } ;
102109
103- PuTTYProcess = Process . Start ( info ) ;
110+ try
111+ {
112+ PuTTYProcess = Process . Start ( info ) ;
104113
105- PuTTYProcess . EnableRaisingEvents = true ;
106- PuTTYProcess . Exited += PuTTYProcess_Exited ;
114+ PuTTYProcess . EnableRaisingEvents = true ;
115+ PuTTYProcess . Exited += PuTTYProcess_Exited ;
107116
108- PuTTYProcess . WaitForInputIdle ( ) ;
109-
110- // Embed putty window into panel, remove border etc.
111- AppWin = PuTTYProcess . MainWindowHandle ;
117+ PuTTYProcess . WaitForInputIdle ( ) ;
112118
113- NativeMethods . SetParent ( AppWin , puTTYHost . Handle ) ;
119+ // Embed putty window into panel, remove border etc.
120+ AppWin = PuTTYProcess . MainWindowHandle ;
114121
115- // Show window before set style and resize
116- NativeMethods . ShowWindow ( AppWin , NativeMethods . WindowShowStyle . Maximize ) ;
122+ NativeMethods . SetParent ( AppWin , puTTYHost . Handle ) ;
117123
118- // Remove border etc.
119- int style = ( int ) NativeMethods . GetWindowLong ( AppWin , NativeMethods . GWL_STYLE ) ;
120- style &= ~ ( NativeMethods . WS_BORDER | NativeMethods . WS_THICKFRAME ) ;
121- NativeMethods . SetWindowLongPtr ( AppWin , NativeMethods . GWL_STYLE , new IntPtr ( style ) ) ;
124+ // Show window before set style and resize
125+ NativeMethods . ShowWindow ( AppWin , NativeMethods . WindowShowStyle . Maximize ) ;
122126
123- // Resize embedded application & refresh
124- if ( PuTTYProcess != null )
125- ResizeEmbeddedPuTTY ( ) ;
127+ // Remove border etc.
128+ int style = ( int ) NativeMethods . GetWindowLong ( AppWin , NativeMethods . GWL_STYLE ) ;
129+ style &= ~ ( NativeMethods . WS_BORDER | NativeMethods . WS_THICKFRAME ) ;
130+ NativeMethods . SetWindowLongPtr ( AppWin , NativeMethods . GWL_STYLE , new IntPtr ( style ) ) ;
126131
127- Connected = true ;
132+ // Resize embedded application & refresh
133+ if ( PuTTYProcess != null )
134+ ResizeEmbeddedPuTTY ( ) ;
135+
136+ Connected = true ;
137+ }
138+ catch ( Exception ex )
139+ {
140+ MetroDialogSettings settings = AppearanceManager . MetroDialog ;
141+ settings . AffirmativeButtonText = Application . Current . Resources [ "String_Button_OK" ] as string ;
142+
143+ ConfigurationManager . Current . FixAirspace = true ;
144+
145+ await dialogCoordinator . ShowMessageAsync ( this , Application . Current . Resources [ "String_Header_Error" ] as string , ex . Message , MessageDialogStyle . Affirmative , settings ) ;
146+
147+ ConfigurationManager . Current . FixAirspace = false ;
148+ }
128149 }
129150
130151 private void PuTTYProcess_Exited ( object sender , EventArgs e )
0 commit comments