diff --git a/VAR.Toolbox/Code/Logger.cs b/VAR.Toolbox/Code/Logger.cs index 2ae7f30..809bfa9 100644 --- a/VAR.Toolbox/Code/Logger.cs +++ b/VAR.Toolbox/Code/Logger.cs @@ -17,7 +17,7 @@ namespace VAR.Toolbox.Code string path = Path.GetDirectoryName(location); string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location); - string fileOut = String.Format("{0}/{1}.{2}.txt", path, filenameWithoutExtension, + string fileOut = string.Format("{0}/{1}.{2}.txt", path, filenameWithoutExtension, DateTime.UtcNow.ToString("yyyy-MM")); return File.AppendText(fileOut); } diff --git a/VAR.Toolbox/Code/ProxyCmdExecutorFactory.cs b/VAR.Toolbox/Code/ProxyCmdExecutorFactory.cs index 813ae3a..687aa4e 100644 --- a/VAR.Toolbox/Code/ProxyCmdExecutorFactory.cs +++ b/VAR.Toolbox/Code/ProxyCmdExecutorFactory.cs @@ -1,14 +1,21 @@ -namespace VAR.Toolbox.Code +using System; + +namespace VAR.Toolbox.Code { public class ProxyCmdExecutorFactory { public static IProxyCmdExecutor CreateFromConfig(string config) { - if (string.IsNullOrEmpty(config)) + if (string.IsNullOrEmpty(config) || config.StartsWith("Dummy:")) { return new ProxyCmdExecutorDummy(); } - return new ProxyCmdExecutorThroughSQLServer(config); + if (config.StartsWith("SqlServer:")) + { + string configSqlServer = config.Substring("SqlServer:".Length); + return new ProxyCmdExecutorThroughSQLServer(configSqlServer); + } + throw new NotImplementedException(string.Format("Cant create IProxyCmdExecutor with this config: {0}", config)); } } } diff --git a/VAR.Toolbox/Properties/Settings.Designer.cs b/VAR.Toolbox/Properties/Settings.Designer.cs deleted file mode 100644 index 394f062..0000000 --- a/VAR.Toolbox/Properties/Settings.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace VAR.Toolbox.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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("Data Source=SRV7;Initial Catalog=master;Integrated Security=True")] - public string ProxyCmdConfig { - get { - return ((string)(this["ProxyCmdConfig"])); - } - set { - this["ProxyCmdConfig"] = value; - } - } - } -} diff --git a/VAR.Toolbox/Properties/Settings.settings b/VAR.Toolbox/Properties/Settings.settings deleted file mode 100644 index f241a87..0000000 --- a/VAR.Toolbox/Properties/Settings.settings +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - Data Source=SRV7;Initial Catalog=master;Integrated Security=True - - - \ No newline at end of file diff --git a/VAR.Toolbox/UI/FrmProxyCmd.Designer.cs b/VAR.Toolbox/UI/FrmProxyCmd.Designer.cs index 70db630..4e46845 100644 --- a/VAR.Toolbox/UI/FrmProxyCmd.Designer.cs +++ b/VAR.Toolbox/UI/FrmProxyCmd.Designer.cs @@ -31,6 +31,8 @@ this.splitMain = new System.Windows.Forms.SplitContainer(); this.txtOutput = new System.Windows.Forms.TextBox(); this.txtInput = new System.Windows.Forms.TextBox(); + this.ddlCurrentConfig = new System.Windows.Forms.ComboBox(); + this.btnConfig = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.splitMain)).BeginInit(); this.splitMain.Panel1.SuspendLayout(); this.splitMain.Panel2.SuspendLayout(); @@ -39,9 +41,11 @@ // // splitMain // + this.splitMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.splitMain.BackColor = System.Drawing.SystemColors.ControlDark; - this.splitMain.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitMain.Location = new System.Drawing.Point(0, 0); + this.splitMain.Location = new System.Drawing.Point(0, 28); this.splitMain.Name = "splitMain"; this.splitMain.Orientation = System.Windows.Forms.Orientation.Horizontal; // @@ -52,8 +56,8 @@ // splitMain.Panel2 // this.splitMain.Panel2.Controls.Add(this.txtInput); - this.splitMain.Size = new System.Drawing.Size(392, 369); - this.splitMain.SplitterDistance = 313; + this.splitMain.Size = new System.Drawing.Size(413, 418); + this.splitMain.SplitterDistance = 353; this.splitMain.SplitterWidth = 10; this.splitMain.TabIndex = 3; this.splitMain.TabStop = false; @@ -69,7 +73,7 @@ this.txtOutput.Name = "txtOutput"; this.txtOutput.ReadOnly = true; this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtOutput.Size = new System.Drawing.Size(392, 313); + this.txtOutput.Size = new System.Drawing.Size(413, 353); this.txtOutput.TabIndex = 1; this.txtOutput.TabStop = false; // @@ -83,15 +87,40 @@ this.txtInput.Multiline = true; this.txtInput.Name = "txtInput"; this.txtInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtInput.Size = new System.Drawing.Size(392, 46); + this.txtInput.Size = new System.Drawing.Size(413, 55); this.txtInput.TabIndex = 0; this.txtInput.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtInput_KeyDown); // + // ddlCurrentConfig + // + this.ddlCurrentConfig.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ddlCurrentConfig.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.ddlCurrentConfig.FormattingEnabled = true; + this.ddlCurrentConfig.Location = new System.Drawing.Point(0, 1); + this.ddlCurrentConfig.Name = "ddlCurrentConfig"; + this.ddlCurrentConfig.Size = new System.Drawing.Size(342, 21); + this.ddlCurrentConfig.TabIndex = 4; + this.ddlCurrentConfig.SelectedIndexChanged += new System.EventHandler(this.ddlCurrentConfig_SelectedIndexChanged); + // + // btnConfig + // + this.btnConfig.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnConfig.Location = new System.Drawing.Point(348, 1); + this.btnConfig.Name = "btnConfig"; + this.btnConfig.Size = new System.Drawing.Size(65, 23); + this.btnConfig.TabIndex = 5; + this.btnConfig.Text = "Config"; + this.btnConfig.UseVisualStyleBackColor = true; + this.btnConfig.Click += new System.EventHandler(this.btnConfig_Click); + // // FrmProxyCmd // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(392, 369); + this.ClientSize = new System.Drawing.Size(413, 446); + this.Controls.Add(this.btnConfig); + this.Controls.Add(this.ddlCurrentConfig); this.Controls.Add(this.splitMain); this.Name = "FrmProxyCmd"; this.Text = "ProxyCmd"; @@ -110,5 +139,7 @@ private System.Windows.Forms.SplitContainer splitMain; private System.Windows.Forms.TextBox txtOutput; private System.Windows.Forms.TextBox txtInput; + private System.Windows.Forms.ComboBox ddlCurrentConfig; + private System.Windows.Forms.Button btnConfig; } } \ No newline at end of file diff --git a/VAR.Toolbox/UI/FrmProxyCmd.cs b/VAR.Toolbox/UI/FrmProxyCmd.cs index 55ffc4f..dfac5cb 100644 --- a/VAR.Toolbox/UI/FrmProxyCmd.cs +++ b/VAR.Toolbox/UI/FrmProxyCmd.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Threading; using System.Windows.Forms; using VAR.Toolbox.Code; @@ -7,16 +9,27 @@ namespace VAR.Toolbox.UI { public partial class FrmProxyCmd : Form, IOutputHandler { - public FrmProxyCmd() - { - InitializeComponent(); - } - + #region Declarations + private object _executionLock = new object(); private List _cmdHistory = new List(); private int _currentHistoryIndex = -1; + #endregion Declarations + + #region Life cycle + + public FrmProxyCmd() + { + InitializeComponent(); + LoadConfig(); + } + + #endregion Life cycle + + #region UI events + private void txtInput_KeyDown(object sender, KeyEventArgs e) { if (Monitor.IsEntered(_executionLock)) @@ -35,6 +48,7 @@ namespace VAR.Toolbox.UI Application.DoEvents(); txtInput.Text = string.Empty; OutputLine(cmd); + PrepareProxyCmdExecutor(); new Thread(() => ExecuteCmd(cmd)).Start(); } return; @@ -88,14 +102,45 @@ namespace VAR.Toolbox.UI } } + private void ddlCurrentConfig_SelectedIndexChanged(object sender, EventArgs e) + { + CleanProxyCmdExecutor(); + } + + private void btnConfig_Click(object sender, EventArgs e) + { + throw new NotImplementedException("Implement btnConfig_Click"); + } + + #endregion UI events + + #region ProxyCmdExecutor + private IProxyCmdExecutor _proxyCmdExecutor = null; - private void ExecuteCmd(string cmdString) + private void PrepareProxyCmdExecutor() { if (_proxyCmdExecutor == null) { - _proxyCmdExecutor = ProxyCmdExecutorFactory.CreateFromConfig(Properties.Settings.Default.ProxyCmdConfig); + _proxyCmdExecutor = ProxyCmdExecutorFactory.CreateFromConfig(GetCurrentConfig()); } + } + private void CleanProxyCmdExecutor() + { + IDisposable disposableProxyCmdExecutor = _proxyCmdExecutor as IDisposable; + if (disposableProxyCmdExecutor !=null) + { + disposableProxyCmdExecutor.Dispose(); + } + _proxyCmdExecutor = null; + } + + #endregion ProxyCmdExecutor + + #region Private methods + + private void ExecuteCmd(string cmdString) + { Monitor.Enter(_executionLock); try { @@ -120,5 +165,83 @@ namespace VAR.Toolbox.UI Application.DoEvents(); })); } + + #endregion Private methods + + #region Config + + public void LoadConfig() + { + CleanProxyCmdExecutor(); + string configFile = GetConfigFileName(); + string[] config = null; + if (File.Exists(configFile) == false) + { + config = new string[] { "Dummy|Dummy:" }; + } + else + { + config = File.ReadAllLines(configFile); + } + SetLoadedConfig(config); + } + + private void SetLoadedConfig(string[] configLines) + { + string previousSelectedName = null; + ProxyCmdConfigItem selectedConfig = ddlCurrentConfig.SelectedItem as ProxyCmdConfigItem; + if (selectedConfig != null) { previousSelectedName = selectedConfig.Name; } + + ddlCurrentConfig.Items.Clear(); + foreach (string configLine in configLines) + { + int idxSplit = configLine.IndexOf('|'); + if(idxSplit < 0) { continue; } + string configName = configLine.Substring(0, idxSplit); + string configData = configLine.Substring(idxSplit + 1); + + ddlCurrentConfig.Items.Add(new ProxyCmdConfigItem { Name = configName, Config = configData, }); + } + if (string.IsNullOrEmpty(previousSelectedName)) + { + ddlCurrentConfig.SelectedIndex = 0; + return; + } + + foreach(ProxyCmdConfigItem configItem in ddlCurrentConfig.Items) + { + if(configItem.Name == previousSelectedName) + { + ddlCurrentConfig.SelectedItem = configItem; + break; + } + } + } + + private string GetConfigFileName() + { + string location = System.Reflection.Assembly.GetEntryAssembly().Location; + string path = Path.GetDirectoryName(location); + string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location); + + string configFile = string.Format("{0}/{1}.ProxyCmd.cfg", path, filenameWithoutExtension); + return configFile; + } + + private string GetCurrentConfig() + { + ProxyCmdConfigItem selectedConfig = ddlCurrentConfig.SelectedItem as ProxyCmdConfigItem; + if (selectedConfig == null) { return null; } + return selectedConfig.Config; + } + + #endregion Config + } + + public class ProxyCmdConfigItem + { + public string Name { get; set; } + public string Config { get; set; } + public override string ToString() { return Name; } } } diff --git a/VAR.Toolbox/VAR.Toolbox.csproj b/VAR.Toolbox/VAR.Toolbox.csproj index a98502c..9df82f7 100644 --- a/VAR.Toolbox/VAR.Toolbox.csproj +++ b/VAR.Toolbox/VAR.Toolbox.csproj @@ -157,11 +157,6 @@ - - True - True - Settings.settings - Form @@ -183,12 +178,7 @@ - - - SettingsSingleFileGenerator - Settings.Designer.cs - diff --git a/VAR.Toolbox/app.config b/VAR.Toolbox/app.config deleted file mode 100644 index 68ec9d4..0000000 --- a/VAR.Toolbox/app.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - -
- - - - - - Data Source=SRV7;Initial Catalog=master;Integrated Security=True - - - - \ No newline at end of file