From e2acf1a5d0313aaac0b46a356ca598aa748c15bc Mon Sep 17 00:00:00 2001 From: swagner Date: Mon, 13 Sep 2010 22:18:12 +0000 Subject: [PATCH] Implemented !ClientFactory and username / password management (#1187) git-svn-id: https://src.heuristiclab.com/svn/core/trunk/sources@4387 2abd9481-f8db-48e9-bd25-06bc13291c1b --- HeuristicLab.Clients.Common/3.3/ClientFactory.cs | 58 +++++++ .../3.3/HeuristicLab.Clients.Common-3.3.csproj | 21 ++- .../3.3/PasswordDialog.Designer.cs | 176 +++++++++++++++++++++ HeuristicLab.Clients.Common/3.3/PasswordDialog.cs | 48 ++++++ .../3.3/Properties/Settings.Designer.cs | 62 ++++++++ .../3.3/Properties/Settings.settings | 15 ++ HeuristicLab.Clients.Common/3.3/app.config | 21 +++ .../3.3/HeuristicLab.Optimizer-3.3.csproj | 5 + .../3.3/HeuristicLabOptimizerPlugin.cs.frame | 1 + .../3.3/MenuItems/AboutMenuItem.cs | 2 +- ...boutMenuItem.cs => UsernamePasswordMenuItem.cs} | 21 +-- HeuristicLab/3.3/MergeConfigs.cmd | 1 + 12 files changed, 419 insertions(+), 12 deletions(-) create mode 100644 HeuristicLab.Clients.Common/3.3/ClientFactory.cs create mode 100644 HeuristicLab.Clients.Common/3.3/PasswordDialog.Designer.cs create mode 100644 HeuristicLab.Clients.Common/3.3/PasswordDialog.cs create mode 100644 HeuristicLab.Clients.Common/3.3/Properties/Settings.Designer.cs create mode 100644 HeuristicLab.Clients.Common/3.3/Properties/Settings.settings create mode 100644 HeuristicLab.Clients.Common/3.3/app.config copy HeuristicLab.Optimizer/3.3/MenuItems/{AboutMenuItem.cs => UsernamePasswordMenuItem.cs} (65%) diff --git a/HeuristicLab.Clients.Common/3.3/ClientFactory.cs b/HeuristicLab.Clients.Common/3.3/ClientFactory.cs new file mode 100644 index 0000000000..23976ab163 --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/ClientFactory.cs @@ -0,0 +1,58 @@ +#region License Information +/* HeuristicLab + * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) + * + * This file is part of HeuristicLab. + * + * HeuristicLab is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * HeuristicLab is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HeuristicLab. If not, see . + */ +#endregion + +using System; +using System.ServiceModel; +using HeuristicLab.Clients.Common.Properties; + +namespace HeuristicLab.Clients.Common { + public static class ClientFactory { + public static I CreateClient() + where T : ClientBase, I + where I : class { + return CreateClient(null, null); + } + public static I CreateClient(string endpointConfigurationName) + where T : ClientBase, I + where I : class { + return CreateClient(endpointConfigurationName, null); + } + public static I CreateClient(string endpointConfigurationName, string remoteAddress) + where T : ClientBase, I + where I : class { + T client; + if (string.IsNullOrEmpty(endpointConfigurationName)) { + client = Activator.CreateInstance(); + } else { + client = (T)Activator.CreateInstance(typeof(T), endpointConfigurationName); + } + + if (!string.IsNullOrEmpty(remoteAddress)) { + client.Endpoint.Address = new EndpointAddress(remoteAddress); + } + + client.ClientCredentials.UserName.UserName = Settings.Default.UserName; + client.ClientCredentials.UserName.Password = Settings.Default.Password; + client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + return (I)client; + } + } +} diff --git a/HeuristicLab.Clients.Common/3.3/HeuristicLab.Clients.Common-3.3.csproj b/HeuristicLab.Clients.Common/3.3/HeuristicLab.Clients.Common-3.3.csproj index ee6f955b62..1d3d8fcb35 100644 --- a/HeuristicLab.Clients.Common/3.3/HeuristicLab.Clients.Common-3.3.csproj +++ b/HeuristicLab.Clients.Common/3.3/HeuristicLab.Clients.Common-3.3.csproj @@ -104,16 +104,35 @@ + + + - + + + Form + + + PasswordDialog.cs + + + True + True + Settings.settings + + + + SettingsSingleFileGenerator + Settings.Designer.cs + diff --git a/HeuristicLab.Clients.Common/3.3/PasswordDialog.Designer.cs b/HeuristicLab.Clients.Common/3.3/PasswordDialog.Designer.cs new file mode 100644 index 0000000000..e9c29848d2 --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/PasswordDialog.Designer.cs @@ -0,0 +1,176 @@ +#region License Information +/* HeuristicLab + * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) + * + * This file is part of HeuristicLab. + * + * HeuristicLab is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * HeuristicLab is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HeuristicLab. If not, see . + */ +#endregion + +namespace HeuristicLab.Clients.Common { + partial class PasswordDialog { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.usernameLabel = new System.Windows.Forms.Label(); + this.usernameTextBox = new System.Windows.Forms.TextBox(); + this.passwordLabel = new System.Windows.Forms.Label(); + this.passwordTextBox = new System.Windows.Forms.TextBox(); + this.savePasswordCheckBox = new System.Windows.Forms.CheckBox(); + this.savePasswordLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.okButton.Location = new System.Drawing.Point(163, 89); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 23); + this.okButton.TabIndex = 6; + this.okButton.Text = "&OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(244, 89); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 7; + this.cancelButton.Text = "&Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // usernameLabel + // + this.usernameLabel.AutoSize = true; + this.usernameLabel.Location = new System.Drawing.Point(12, 15); + this.usernameLabel.Name = "usernameLabel"; + this.usernameLabel.Size = new System.Drawing.Size(58, 13); + this.usernameLabel.TabIndex = 0; + this.usernameLabel.Text = "&Username:"; + // + // usernameTextBox + // + this.usernameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.usernameTextBox.Location = new System.Drawing.Point(102, 12); + this.usernameTextBox.Name = "usernameTextBox"; + this.usernameTextBox.Size = new System.Drawing.Size(217, 20); + this.usernameTextBox.TabIndex = 1; + // + // passwordLabel + // + this.passwordLabel.AutoSize = true; + this.passwordLabel.Location = new System.Drawing.Point(12, 41); + this.passwordLabel.Name = "passwordLabel"; + this.passwordLabel.Size = new System.Drawing.Size(56, 13); + this.passwordLabel.TabIndex = 2; + this.passwordLabel.Text = "&Password:"; + // + // passwordTextBox + // + this.passwordTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.passwordTextBox.Location = new System.Drawing.Point(102, 38); + this.passwordTextBox.Name = "passwordTextBox"; + this.passwordTextBox.PasswordChar = '*'; + this.passwordTextBox.Size = new System.Drawing.Size(217, 20); + this.passwordTextBox.TabIndex = 3; + // + // savePasswordCheckBox + // + this.savePasswordCheckBox.AutoSize = true; + this.savePasswordCheckBox.Checked = true; + this.savePasswordCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.savePasswordCheckBox.Location = new System.Drawing.Point(102, 64); + this.savePasswordCheckBox.Name = "savePasswordCheckBox"; + this.savePasswordCheckBox.Size = new System.Drawing.Size(15, 14); + this.savePasswordCheckBox.TabIndex = 5; + this.savePasswordCheckBox.UseVisualStyleBackColor = true; + // + // savePasswordLabel + // + this.savePasswordLabel.AutoSize = true; + this.savePasswordLabel.Location = new System.Drawing.Point(12, 64); + this.savePasswordLabel.Name = "savePasswordLabel"; + this.savePasswordLabel.Size = new System.Drawing.Size(84, 13); + this.savePasswordLabel.TabIndex = 4; + this.savePasswordLabel.Text = "&Save Password:"; + // + // PasswordDialog + // + this.AcceptButton = this.okButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(331, 124); + this.Controls.Add(this.savePasswordCheckBox); + this.Controls.Add(this.passwordTextBox); + this.Controls.Add(this.usernameTextBox); + this.Controls.Add(this.savePasswordLabel); + this.Controls.Add(this.passwordLabel); + this.Controls.Add(this.usernameLabel); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "PasswordDialog"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Set Username / Password"; + this.Load += new System.EventHandler(this.PasswordDialog_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Label usernameLabel; + private System.Windows.Forms.TextBox usernameTextBox; + private System.Windows.Forms.Label passwordLabel; + private System.Windows.Forms.TextBox passwordTextBox; + private System.Windows.Forms.CheckBox savePasswordCheckBox; + private System.Windows.Forms.Label savePasswordLabel; + } +} \ No newline at end of file diff --git a/HeuristicLab.Clients.Common/3.3/PasswordDialog.cs b/HeuristicLab.Clients.Common/3.3/PasswordDialog.cs new file mode 100644 index 0000000000..093acc2ec1 --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/PasswordDialog.cs @@ -0,0 +1,48 @@ +#region License Information +/* HeuristicLab + * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) + * + * This file is part of HeuristicLab. + * + * HeuristicLab is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * HeuristicLab is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HeuristicLab. If not, see . + */ +#endregion + +using System; +using System.Windows.Forms; +using HeuristicLab.Clients.Common.Properties; + +namespace HeuristicLab.Clients.Common { + public partial class PasswordDialog : Form { + public PasswordDialog() { + InitializeComponent(); + } + + private void PasswordDialog_Load(object sender, EventArgs e) { + usernameTextBox.Text = Settings.Default.UserName; + passwordTextBox.Text = Settings.Default.Password; + savePasswordCheckBox.Checked = Settings.Default.SavePassword; + } + + private void okButton_Click(object sender, EventArgs e) { + Settings.Default.UserName = usernameTextBox.Text; + Settings.Default.SavePassword = savePasswordCheckBox.Checked; + Settings.Default.Password = string.Empty; + Settings.Default.Save(); + Settings.Default.Password = passwordTextBox.Text; + if (savePasswordCheckBox.Checked) + Settings.Default.Save(); + } + } +} diff --git a/HeuristicLab.Clients.Common/3.3/Properties/Settings.Designer.cs b/HeuristicLab.Clients.Common/3.3/Properties/Settings.Designer.cs new file mode 100644 index 0000000000..62529ef506 --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/Properties/Settings.Designer.cs @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace HeuristicLab.Clients.Common.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("anonymous")] + public string UserName { + get { + return ((string)(this["UserName"])); + } + set { + this["UserName"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("anonymous")] + public string Password { + get { + return ((string)(this["Password"])); + } + set { + this["Password"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool SavePassword { + get { + return ((bool)(this["SavePassword"])); + } + set { + this["SavePassword"] = value; + } + } + } +} diff --git a/HeuristicLab.Clients.Common/3.3/Properties/Settings.settings b/HeuristicLab.Clients.Common/3.3/Properties/Settings.settings new file mode 100644 index 0000000000..8c76087f1f --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/Properties/Settings.settings @@ -0,0 +1,15 @@ + + + + + + anonymous + + + anonymous + + + True + + + \ No newline at end of file diff --git a/HeuristicLab.Clients.Common/3.3/app.config b/HeuristicLab.Clients.Common/3.3/app.config new file mode 100644 index 0000000000..70701f7af6 --- /dev/null +++ b/HeuristicLab.Clients.Common/3.3/app.config @@ -0,0 +1,21 @@ + + + + +
+ + + + + + anonymous + + + anonymous + + + True + + + + \ No newline at end of file diff --git a/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj b/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj index f01e7888fe..d195d30f1e 100644 --- a/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj +++ b/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj @@ -120,6 +120,7 @@ + @@ -173,6 +174,10 @@ + + {730A9104-D4D1-4360-966B-E49B7571DDA3} + HeuristicLab.Clients.Common-3.3 + {0E27A536-1C4A-4624-A65E-DC4F4F23E3E1} HeuristicLab.Common.Resources-3.3 diff --git a/HeuristicLab.Optimizer/3.3/HeuristicLabOptimizerPlugin.cs.frame b/HeuristicLab.Optimizer/3.3/HeuristicLabOptimizerPlugin.cs.frame index fd9d57072d..9e648d6c82 100644 --- a/HeuristicLab.Optimizer/3.3/HeuristicLabOptimizerPlugin.cs.frame +++ b/HeuristicLab.Optimizer/3.3/HeuristicLabOptimizerPlugin.cs.frame @@ -26,6 +26,7 @@ namespace HeuristicLab.Optimizer { [Plugin("HeuristicLab.Optimizer", "3.3.0.$WCREV$")] [PluginFile("HeuristicLab.Optimizer-3.3.dll", PluginFileType.Assembly)] [PluginDependency("HeuristicLab.Persistence", "3.3")] + [PluginDependency("HeuristicLab.Clients.Common", "3.3")] [PluginDependency("HeuristicLab.Common", "3.3")] [PluginDependency("HeuristicLab.Common.Resources", "3.3")] [PluginDependency("HeuristicLab.Core", "3.3")] diff --git a/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs b/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs index ecf0d1c9ca..619bce7ff3 100644 --- a/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs +++ b/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs @@ -29,7 +29,7 @@ namespace HeuristicLab.Optimizer.MenuItems { private AboutDialog aboutDialog; public override string Name { - get { return "&About"; } + get { return "&About..."; } } public override IEnumerable Structure { get { return new string[] { "&Help" }; } diff --git a/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs b/HeuristicLab.Optimizer/3.3/MenuItems/UsernamePasswordMenuItem.cs similarity index 65% copy from HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs copy to HeuristicLab.Optimizer/3.3/MenuItems/UsernamePasswordMenuItem.cs index ecf0d1c9ca..a5731602dc 100644 --- a/HeuristicLab.Optimizer/3.3/MenuItems/AboutMenuItem.cs +++ b/HeuristicLab.Optimizer/3.3/MenuItems/UsernamePasswordMenuItem.cs @@ -21,27 +21,28 @@ using System.Collections.Generic; using System.Windows.Forms; +using HeuristicLab.Clients.Common; using HeuristicLab.MainForm; -using HeuristicLab.PluginInfrastructure.Starter; namespace HeuristicLab.Optimizer.MenuItems { - internal class AboutMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider { - private AboutDialog aboutDialog; - + internal class UserNamePasswordMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider { public override string Name { - get { return "&About"; } + get { return "Set &Username / Password..."; } } public override IEnumerable Structure { - get { return new string[] { "&Help" }; } + get { return new string[] { "&Services" }; } } public override int Position { - get { return 9100; } + get { return 4100; } + } + public override string ToolTipText { + get { return "Set username and password for accessing HeuristicLab services"; } } public override void Execute() { - if (aboutDialog == null) - aboutDialog = new AboutDialog(); - aboutDialog.ShowDialog((IWin32Window)MainFormManager.MainForm); + using (PasswordDialog dialog = new PasswordDialog()) { + dialog.ShowDialog((IWin32Window)MainFormManager.MainForm); + } } } } diff --git a/HeuristicLab/3.3/MergeConfigs.cmd b/HeuristicLab/3.3/MergeConfigs.cmd index 9edac5df74..f3d0bed6cb 100644 --- a/HeuristicLab/3.3/MergeConfigs.cmd +++ b/HeuristicLab/3.3/MergeConfigs.cmd @@ -1,4 +1,5 @@ ConfigMerger "%SolutionDir%\HeuristicLab.PluginInfrastructure\3.3\%Outdir%\HeuristicLab.PluginInfrastructure-3.3.dll.config" "HeuristicLab 3.3.exe.config" +ConfigMerger "%SolutionDir%\HeuristicLab.Clients.Common\3.3\%Outdir%\HeuristicLab.Clients.Common-3.3.dll.config" "HeuristicLab 3.3.exe.config" ConfigMerger "%SolutionDir%\HeuristicLab.Optimizer\3.3\%Outdir%\HeuristicLab.Optimizer-3.3.dll.config" "HeuristicLab 3.3.exe.config" ConfigMerger "%SolutionDir%\HeuristicLab.Persistence\3.3\%Outdir%\HeuristicLab.Persistence-3.3.dll.config" "HeuristicLab 3.3.exe.config" ConfigMerger "%SolutionDir%\HeuristicLab.Tracing\3.3\%Outdir%\HeuristicLab.Tracing-3.3.dll.config" "HeuristicLab 3.3.exe.config" \ No newline at end of file -- 2.11.4.GIT