static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var ioConnectionInfo = new IOConnectionInfo() { Path = databasePath }; var key = new CompositeKey(); key.AddUserKey(new KcpPassword(databasePassword)); var pwDatabase = new PwDatabase(); pwDatabase.Open(ioConnectionInfo, key, null); var fieldMapper = new InMemoryFieldMapper() { HostAddress = "IP Address", ConnectionMethod = "OS" }; IPasswordChangerTreeNode treeNode = PasswordChangerTreeNode.Build(pwDatabase, fieldMapper); var pwChangerServiceFactory = new PasswordChangerServiceFactory( new PasswordDatabase(pwDatabase), new FakePasswordChangerExFactoryThatThrowsException() ); var formBatchPasswordChanger = new FormBatchPasswordChanger(treeNode, pwChangerServiceFactory); Application.Run(formBatchPasswordChanger); }
public override bool Initialize(IPluginHost pluginHost) { Debug.Assert(pluginHost != null); if (pluginHost == null) { return(false); } this.pluginHost = pluginHost; this.Settings = QuickConnectPluginSettings.Load(pluginHost, new PluginCustomConfigPropertyNameFormatter(PluginName)); this.fieldsMapper = new SettingsFieldMapper(this.Settings); pluginMenuItemOptions = new ToolStripMenuItem("Options..."); pluginMenuItemOptions.Click += new EventHandler( pluginMenuItemOptionsOnClickEventHandler = delegate(object obj, EventArgs ev) { List <String> fields = null; // Check if database is open. if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen) { fields = this.pluginHost.Database.GetAllFields(true).ToList(); fields.Sort(); } try { KeysHelper.UnregisterKeePassHotKeys(); using (FormOptions form = new FormOptions(Title, this.Settings, fields)) { form.ShowDialog(pluginHost.MainWindow); } } finally { KeysHelper.RegisterKeePassHotKeys(); } } ); pluginMenuItemBatchPasswordChanger = new ToolStripMenuItem("Batch Password Changer..."); pluginMenuItemBatchPasswordChanger.Click += new EventHandler( pluginMenuItemBatchPasswordChangerOnClickEventHandler = delegate(object obj, EventArgs ev) { IPasswordChangerTreeNode pwTreeNode = null; // Check if database is open. if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen) { pwTreeNode = PasswordChangerTreeNode.Build(pluginHost.Database, fieldsMapper); } else { pwTreeNode = new EmptyTreeNode("No database available."); } var pwChangerFactory = new DictionaryPasswordChangerExFactory(); if (QuickConnectUtils.IsVSpherePowerCLIInstalled()) { pwChangerFactory.Factories.Add(HostType.ESXi, new PasswordChangerExFactory(new ESXiPasswordChangerFactory())); } if (!String.IsNullOrEmpty(this.Settings.PsPasswdPath) && File.Exists(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath)) { pwChangerFactory.Factories.Add(HostType.Windows, new PasswordChangerExFactory(new WindowsPasswordChangerFactory( new PsPasswdWrapper(this.Settings.PsPasswdPath))) ); } pwChangerFactory.Factories.Add(HostType.Linux, new LinuxPasswordChangerExFactory(new LinuxPasswordChangerFactory())); var pwChangerServiceFactory = new PasswordChangerServiceFactory( new PasswordDatabase(this.pluginHost.Database), pwChangerFactory, new SystemClock() ); using (var form = new FormBatchPasswordChanger(pwTreeNode, pwChangerServiceFactory)) { form.ShowDialog(pluginHost.MainWindow); if (form.Changed) { refreshUI(); } } } ); pluginMenuItemAbout = new ToolStripMenuItem("About"); pluginMenuItemAbout.Click += new EventHandler( pluginMenuItemAboutOnClickEventHandler = delegate(object obj, EventArgs ev) { using (FormAbout form = new FormAbout()) { form.Text = form.Text.Replace("{title}", Title); form.ShowDialog(pluginHost.MainWindow); } } ); pluginMenuItem = new ToolStripMenuItem(String.Format("{0}", Title)); pluginMenuItem.DropDownItems.Add(pluginMenuItemBatchPasswordChanger); pluginMenuItem.DropDownItems.Add(pluginMenuItemOptions); pluginMenuItem.DropDownItems.Add(pluginMenuItemAbout); this.pluginHost.MainWindow.ToolsMenu.DropDownItems.Add(pluginMenuItem); // Add handlers. ContextMenuStrip entryContextMenu = pluginHost.MainWindow.EntryContextMenu; entryContextMenu.Opened += new EventHandler(entryContextMenu_Opened); entryContextMenu.Closed += new ToolStripDropDownClosedEventHandler(entryContextMenu_Closed); var control = FormsUtils.FindControlRecursive(pluginHost.MainWindow, KeePassListViewControl); var listViewControl = control as CustomListViewEx; if (listViewControl != null) { listViewControl.KeyUp += new KeyEventHandler(listViewControl_KeyUp); } return(true); }