public string GetValue(string key) { string a = string.Empty; try { a = xd.Elements().DescendantsAndSelf("add").Attributes("key") .Where(x => String.Equals(x.Value, key)).First().Parent.Attribute("value").Value; } catch (InvalidOperationException) { Exceptions.ConfigFileBroken c = new Exceptions.ConfigFileBroken(Resources.AppconfigBroken + " Missing key: " + key); c.Data.Add("key", key); throw c; } return(a); }
Dictionary <object, object> GetDictionary(string name, Type KeyType, bool onlyKeyTypeKeys, Type ValueType, bool onlyValueTypeValues) { Dictionary <object, object> a = new Dictionary <object, object>(); try { XElement x = xd.Element("configuration").Element(Resources.StateSettingsConfigSection).Descendants(name).First(); foreach (XElement x1 in x.Elements()) { Type t1 = Type.GetType(x1.Element("key").Attribute("keytype").Value); Type t2 = Type.GetType(x1.Element("value").Attribute("valuetype").Value); if (!a.ContainsKey(Convert.ChangeType(x1.Element("key").Value, t1))) { if (!((onlyKeyTypeKeys && t1 != KeyType) || (onlyValueTypeValues && t2 != ValueType))) { a.Add(Convert.ChangeType(x1.Element("key").Value, t1) , Convert.ChangeType(x1.Element("value").Value, t2)); } } } } catch (Exception e) { if (e is InvalidOperationException || e is ArgumentNullException) { Exceptions.ConfigFileBroken c = new Exceptions.ConfigFileBroken(Resources.AppconfigBroken + " Bad/missing value in " + name); c.Data.Add("name", name); throw c; } else { throw; } } return(a); }
internal FormOptions() { InitializeComponent(); tabControl1.Visible = false; foreach (TreeNode n in treeView1.Nodes) { n.Expand(); } // populate login method opts comboBox1.Items.Add(Resources.SSPIConnection); comboBox1.Items.Add(Resources.UsernamePasswordConnection); foreach (DataGridViewColumn c1 in resultSetNamesGrid.Columns) { c1.HeaderCell.ToolTipText = Resources.TooltipResultNames; } toolStripStatusLabel1.Text = string.Empty; toolTip1.SetToolTip(label9, Resources.MaxSize); toolTip1.SetToolTip(textBox7, Resources.MaxSize); toolTip2.SetToolTip(label10, Resources.DupeKeyColumnsToolTip); toolTip2.AutoPopDelay = Settings1.Default.toolTipDelayBeforeFade; toolTip2.SetToolTip(textBox8, Resources.DupeKeyColumnsToolTip); ConfigManipulator c = new ConfigManipulator(); try { p = LoadOpts(); textBox1.Text = c.GetValue("Server"); textBox2.Text = c.GetValue("Database"); textBox3.Text = c.GetValue("ConnectionUsername"); textBox4.Text = c.GetValue("ConnectionPassword"); checkBox1.Checked = p.WriteEmptyResultSetColumns; checkBox2.Checked = p.AutoRewriteOverpunch; textBox5.Text = p.QueryTimeout.ToString(); textBox6.Text = p.MaxRowsPerSheet.ToString(); textBox9.Text = p.MaximumResultSetsPerWorkbook.ToString(); var p1 = p.ResultNames; int count = 0; foreach (object o in p1.Keys) { DataGridViewRow r = new DataGridViewRow(); resultSetNamesGrid.Rows.Add(); resultSetNamesGrid.Rows[count].Cells[0].Value = o; resultSetNamesGrid.Rows[count].Cells[1].Value = p1[(int)o]; count++; } if (String.Equals(c.GetValue("ExcelFileType"), Resources.FileTypeXml)) { comboBox3.SelectedIndex = 1; } else { comboBox3.SelectedIndex = 0; } if (String.Equals(c.GetValue("ConnectionMethod"), Resources.SSPIConnection)) { comboBox1.SelectedItem = Resources.SSPIConnection; } else { comboBox1.SelectedItem = Resources.UsernamePasswordConnection; } if (String.Equals(c.GetValue("NewResultSet"), Resources.NewResultSetWorksheet)) { radioButton1.Checked = true; radioButton2.Checked = false; } else { radioButton1.Checked = false; radioButton2.Checked = true; } textBox7.Text = Math.Round((double)p.MaxWorkBookSize / 1024 / 1024 / 1024, 3, MidpointRounding.AwayFromZero).ToString(); if (p.DupeKeysToDelayStartingNewWorksheet != null && p.DupeKeysToDelayStartingNewWorksheet.Length > 0) { textBox8.Text = string.Join(",", p.DupeKeysToDelayStartingNewWorksheet); } } catch (Exceptions.ConfigFileBroken e) { MessageBox.Show(e.Message); if (e.Data.Contains("key")) { toolStripStatusLabel1.Text = Resources.AppconfigBroken + " Missing key: " + (string)e.Data["key"]; } else { toolStripStatusLabel1.Text = Resources.AppconfigBroken; } panel7.Enabled = false; c1 = e; } }