private void ProcessConfig(string configFile, ProjectItem configItem) { XDocument xdoc = XDocument.Load(configFile); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } foreach (XElement cs in csNode.Elements()) { if (!cs.Name.LocalName.Equals("add")) { continue; } ConnectionStringEntry entry = new ConnectionStringEntry(); entry.ConfigFile = configItem.Name; entry.ConfigPath = configFile; entry.ProjectName = configItem.ContainingProject.Name; entry.ConnectionName = cs.Attribute(XName.Get("name")).Value; entry.ConnectionString = cs.Attribute(XName.Get("connectionString")).Value; entry.ProjectItem = configItem; _foundConnections.Add(entry); } }
protected virtual void _view_TestConnection(ConnectionStringEntry entry, bool silent) { var result = ConnectionHelper.ValidateConnection(entry); if (result) { View.SetMessage("Success!"); } else { View.SetError("Failed!"); } }
private void AddConnectionToConfig(ConnectionStringEntry entry) { try { PrepareConfigFile(entry); XDocument xdoc = XDocument.Load(entry.ConfigPath); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } XElement newNode = new XElement(XName.Get("add")); newNode.SetAttributeValue(XName.Get("name"), entry.ConnectionName); newNode.SetAttributeValue(XName.Get("connectionString"), entry.ConnectionString); csNode.AddFirst(newNode); xdoc.Save(entry.ConfigPath); _model.Entries.Add(entry); } catch (UnauthorizedAccessException accessEx) { _view.SetError("Unable to access the configuration file.\nReason: " + accessEx.Message); } }
void _view_SaveConnection(ConnectionStringEntry entry, bool silent) { ProfileHelper ph = new ProfileHelper(); ph.SaveNewConnection(entry); _view.RefreshView(); }
private void tsEdit_Click(object sender, EventArgs e) { ConnectionStringEntry entry = GetSelectedEntry(); if (entry == ConnectionStringEntry.Empty) { return; } ConnectionStringEditor editor = new ConnectionStringEditor(); GenericConnectionPresenter presenter = new GenericConnectionPresenter(editor); if (editor.ShowDialog(entry.ConnectionName, entry.ConnectionString) == System.Windows.Forms.DialogResult.Cancel) { return; } string connectionName = entry.ConnectionName; entry.ConnectionString = editor.ConnectionString; entry.ConnectionName = editor.ConnectionName; lstConnectionStrings.SelectedItems[0].SubItems[2].Text = entry.ConnectionName; lstConnectionStrings.SelectedItems[0].SubItems[3].Text = entry.ConnectionString; if (this.UpdateConnection != null) { this.UpdateConnection.Invoke(connectionName, entry, false); } }
private ConnectionStringEntry GetSelectedEntry() { if (lstConnectionStrings.SelectedIndices.Count < 1) { return(ConnectionStringEntry.Empty); } ConnectionStringEntry entry = lstConnectionStrings.SelectedItems[0].Tag as ConnectionStringEntry; return(entry); }
public void SaveNewConnection(ConnectionStringEntry entry) { string connKey = string.Format("{0}_{1}", entry.ProjectName, entry.ConnectionName); SavedConnection newConn = new SavedConnection() { ConnectionString = entry.ConnectionString, Name = connKey }; SaveNewConnection(newConn); }
public void SaveNewConnection(ConnectionStringEntry entry) { string connKey = string.Format("{0}_{1}", entry.ProjectName, entry.ConnectionName); SavedConnection newConn = new SavedConnection() { ConnectionString = entry.ConnectionString, Name = connKey }; SaveNewConnection(newConn); }
protected virtual void _view_TestConnection(ConnectionStringEntry entry, bool silent) { var result = ConnectionHelper.ValidateConnection(entry); if (result) { View.SetMessage("Success!"); } else { View.SetError("Failed!"); } }
private static void PrepareConfigFile(ConnectionStringEntry entry) { if (!entry.ProjectItem.IsOpen) { entry.ProjectItem.Open(Constants.vsViewKindCode); } FileAttributes attributes = File.GetAttributes(entry.ConfigPath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { attributes = attributes & ~FileAttributes.ReadOnly; File.SetAttributes(entry.ConfigPath, attributes); } }
private void OpenConfigFile() { ConnectionStringEntry entry = GetSelectedEntry(); if (entry == ConnectionStringEntry.Empty) { return; } if (this.OpenContainingConfig != null) { this.OpenContainingConfig(entry, false); } }
private void _view_TestConnection(ConnectionStringEntry entry, bool silent) { var result = ConnectionHelper.ValidateConnection(entry); if (!silent && result) { _view.SetMessage("Success!"); } if (!silent && !result) { _view.SetError("Failed!"); } _view.RefreshView(); }
private static void PrepareConfigFile(ConnectionStringEntry entry) { if (!entry.ProjectItem.IsOpen) { entry.ProjectItem.Open(Constants.vsViewKindCode); } FileAttributes attributes = File.GetAttributes(entry.ConfigPath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { attributes = attributes & ~FileAttributes.ReadOnly; File.SetAttributes(entry.ConfigPath, attributes); } }
private void SetupConnectionTest(ConnectionStringEntry entry, bool silent) { try { this.Cursor = Cursors.WaitCursor; if (this.TestConnection != null) { this.TestConnection.Invoke(entry, silent); } } finally { this.Cursor = Cursors.Default; } }
public static bool ValidateConnection(ConnectionStringEntry entry) { try { SqlConnection conn = new SqlConnection(entry.ConnectionString); conn.Open(); conn.Close(); entry.Status = ConnectionStatus.Valid; return(true); } catch { entry.Status = ConnectionStatus.Invalid; return(false); } }
public static bool ValidateConnection(ConnectionStringEntry entry) { try { SqlConnection conn = new SqlConnection(entry.ConnectionString); conn.Open(); conn.Close(); entry.Status = ConnectionStatus.Valid; return true; } catch { entry.Status = ConnectionStatus.Invalid; return false; } }
private void WriteConfigChanges(string connectionName, ConnectionStringEntry entry) { try { PrepareConfigFile(entry); XDocument xdoc = XDocument.Load(entry.ConfigPath); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } foreach (XElement cs in csNode.Elements()) { if (!cs.Name.LocalName.Equals("add")) { continue; } if (!cs.Attribute(XName.Get("name")).Value.Equals(connectionName)) { continue; } cs.Attribute(XName.Get("name")).Value = entry.ConnectionName; cs.Attribute(XName.Get("connectionString")).Value = entry.ConnectionString; } xdoc.Save(entry.ConfigPath); } catch (UnauthorizedAccessException accessEx) { _view.SetError("Unable to access the configuration file.\nReason: " + accessEx.Message); } }
private void tsAddConnection_Click(object sender, EventArgs e) { foreach (var itm in chkLstConfigs.CheckedItems) { ConnectionStringEntry conn = itm as ConnectionStringEntry; if (!string.IsNullOrEmpty(txtConnectionName.Text) && !string.IsNullOrEmpty(txtConnStr.Text)) { NewConnections.Add(new ConnectionStringEntry() { ConnectionName = txtConnectionName.Text, ConnectionString = txtConnStr.Text, ConfigPath = conn.ConfigPath, ConfigFile = conn.ConfigFile, ProjectName = conn.ProjectName, ProjectItem = conn.ProjectItem }); } foreach (var savedIitm in chkLstSavedConnections.CheckedItems) { SavedConnection savedConn = savedIitm as SavedConnection; NewConnections.Add(new ConnectionStringEntry() { ConnectionName = savedConn.Name, ConnectionString = savedConn.ConnectionString, ConfigPath = conn.ConfigPath, ConfigFile = conn.ConfigFile, ProjectName = conn.ProjectName, ProjectItem = conn.ProjectItem }); } } this.DialogResult = System.Windows.Forms.DialogResult.OK; }
void _view_ChangeConnection(ConnectionStringEntry entry, SavedConnection savedConn, bool silent) { entry.ConnectionString = savedConn.ConnectionString; WriteConfigChanges(entry.ConnectionName, entry); _view.RefreshView(); }
private void _view_DeleteConnection(ConnectionStringEntry entry, bool silent) { RemoveConnectionFromConfig(entry); _view.ConnectionStrings = _model.Entries; }
private void _view_AddConnection(ConnectionStringEntry entry, bool silent) { AddConnectionToConfig(entry); _view.ConnectionStrings = _model.Entries; }
private void _view_UpdateConnection(string connectionName, ConnectionStringEntry entry, bool silent) { WriteConfigChanges(connectionName, entry); }
private void _view_OpenContainingConfig(ConnectionStringEntry entry, bool silent) { OpenConfigInIDE(entry); }
private void _view_AddConnection(ConnectionStringEntry entry, bool silent) { AddConnectionToConfig(entry); _view.ConnectionStrings = _model.Entries; }
private void AddConnectionToConfig(ConnectionStringEntry entry) { try { PrepareConfigFile(entry); XDocument xdoc = XDocument.Load(entry.ConfigPath); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } XElement newNode = new XElement(XName.Get("add")); newNode.SetAttributeValue(XName.Get("name"), entry.ConnectionName); newNode.SetAttributeValue(XName.Get("connectionString"), entry.ConnectionString); csNode.AddFirst(newNode); xdoc.Save(entry.ConfigPath); _model.Entries.Add(entry); } catch (UnauthorizedAccessException accessEx) { _view.SetError("Unable to access the configuration file.\nReason: " + accessEx.Message); } }
private void _view_UpdateConnection(string connectionName, ConnectionStringEntry entry, bool silent) { WriteConfigChanges(connectionName, entry); }
private static void OpenConfigInIDE(ConnectionStringEntry entry) { var file = entry.ProjectItem.Open(Constants.vsViewKindCode); file.Visible = true; }
void _view_SaveConnection(ConnectionStringEntry entry, bool silent) { ProfileHelper ph = new ProfileHelper(); ph.SaveNewConnection(entry); _view.RefreshView(); }
private void _view_TestConnection(ConnectionStringEntry entry, bool silent) { var result = ConnectionHelper.ValidateConnection(entry); if (!silent && result) { _view.SetMessage("Success!"); } if (!silent && !result) { _view.SetError("Failed!"); } _view.RefreshView(); }
private void _view_OpenContainingConfig(ConnectionStringEntry entry, bool silent) { OpenConfigInIDE(entry); }
private void _view_DeleteConnection(ConnectionStringEntry entry, bool silent) { RemoveConnectionFromConfig(entry); _view.ConnectionStrings = _model.Entries; }
void _view_ChangeConnection(ConnectionStringEntry entry, SavedConnection savedConn, bool silent) { entry.ConnectionString = savedConn.ConnectionString; WriteConfigChanges(entry.ConnectionName, entry); _view.RefreshView(); }
private void SetupConnectionTest(ConnectionStringEntry entry, bool silent) { try { this.Cursor = Cursors.WaitCursor; if (this.TestConnection != null) { this.TestConnection.Invoke(entry, silent); } } finally { this.Cursor = Cursors.Default; } }
private static void OpenConfigInIDE(ConnectionStringEntry entry) { var file = entry.ProjectItem.Open(Constants.vsViewKindCode); file.Visible = true; }
private void WriteConfigChanges( string connectionName, ConnectionStringEntry entry) { try { PrepareConfigFile(entry); XDocument xdoc = XDocument.Load(entry.ConfigPath); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } foreach (XElement cs in csNode.Elements()) { if (!cs.Name.LocalName.Equals("add")) { continue; } if (!cs.Attribute(XName.Get("name")).Value.Equals(connectionName)) { continue; } cs.Attribute(XName.Get("name")).Value = entry.ConnectionName; cs.Attribute(XName.Get("connectionString")).Value = entry.ConnectionString; } xdoc.Save(entry.ConfigPath); } catch (UnauthorizedAccessException accessEx) { _view.SetError("Unable to access the configuration file.\nReason: " + accessEx.Message); } }
private void ProcessConfig(string configFile, ProjectItem configItem) { XDocument xdoc = XDocument.Load(configFile); var csNode = xdoc.Descendants(XName.Get("connectionStrings")).FirstOrDefault(); if (csNode == null) { return; } foreach (XElement cs in csNode.Elements()) { if (!cs.Name.LocalName.Equals("add")) { continue; } ConnectionStringEntry entry = new ConnectionStringEntry(); entry.ConfigFile = configItem.Name; entry.ConfigPath = configFile; entry.ProjectName = configItem.ContainingProject.Name; entry.ConnectionName = cs.Attribute(XName.Get("name")).Value; entry.ConnectionString = cs.Attribute(XName.Get("connectionString")).Value; entry.ProjectItem = configItem; _foundConnections.Add(entry); } }