void password_Click(object sender, RoutedEventArgs e) { try { ContextMenu cm = (ContextMenu)ContextMenu.ItemsControlFromItemContainer((MenuItem)e.OriginalSource); CEc2Instance ins = (CEc2Instance)((FrameworkElement)(((Panel)(cm.PlacementTarget)).Children[0])).DataContext; if (ins != null) { //check key file string keyFile = CAwsConfig.Instance.getKeyFilePath(ins.keyPairName); if (string.IsNullOrEmpty(keyFile) == true || File.Exists(keyFile) == false) { KeyFileInputDlg kfInput = new KeyFileInputDlg(ins.keyPairName); kfInput.ShowDialog(); keyFile = CAwsConfig.Instance.getKeyFilePath(ins.keyPairName); if (string.IsNullOrEmpty(keyFile) == true || File.Exists(keyFile) == false) { MessageBox.Show("Cannot find the key file.", "Get Password", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } FetchPassword pw = new FetchPassword(ins); pw.ShowDialog(); } else { MessageBox.Show("Cannot fetch the password for this instance."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void password_Click(object sender, RoutedEventArgs e) { try { ContextMenu cm = (ContextMenu)ContextMenu.ItemsControlFromItemContainer((MenuItem)e.OriginalSource); CEc2Instance ins = (CEc2Instance)((FrameworkElement)(((Panel)(cm.PlacementTarget)).Children[0])).DataContext; if (ins != null) { //check key file string keyFile = CAwsConfig.Instance.getKeyFilePath(ins.keyPairName); if (string.IsNullOrEmpty(keyFile) == true || File.Exists(keyFile) == false) { KeyFileInputDlg kfInput = new KeyFileInputDlg(ins.keyPairName); kfInput.ShowDialog(); keyFile = CAwsConfig.Instance.getKeyFilePath(ins.keyPairName); if (string.IsNullOrEmpty(keyFile) == true || File.Exists(keyFile) == false) { MessageBox.Show("Cannot find the key file.", "Get Password", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } FetchPassword pw = new FetchPassword(ins); pw.ShowDialog(); } else { MessageBox.Show("Cannot fetch the password for this instance."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }