public void CreateNewServerConfig(SCConnectionStringBuilder hostServerConfig) { hostServerConfig.ThrowIfNull(nameof(hostServerConfig)); string name = hostServerConfig.GetDisplayName(); string connectionstring = hostServerConfig.ConnectionString; CreateIsolatedStorage(); using (var userStorage = IsolatedStorageFile.GetUserStoreForAssembly()) { XmlDocument k2ConfDoc = null; using (var userStream = new IsolatedStorageFileStream(_k2ConfigFile, FileMode.Open, userStorage)) using (var cryptostreamLoad = new CryptoStream(userStream, Decryptor(), CryptoStreamMode.Read)) { k2ConfDoc = new XmlDocument(); k2ConfDoc.Load(cryptostreamLoad); } using (var userStream = new IsolatedStorageFileStream(_k2ConfigFile, FileMode.Create, userStorage)) using (var cryptostream = new CryptoStream(userStream, Encryptor(), CryptoStreamMode.Write)) { try { var connectionStringsElement = k2ConfDoc.SelectSingleNode("/configuration/connectionstrings"); var currentNode = connectionStringsElement.SelectSingleNode(string.Format("connectionstring[@name='{0}']", name)); if (currentNode != null) { connectionStringsElement.RemoveChild(currentNode); } var connStringNode = k2ConfDoc.CreateElement("connectionstring"); connectionStringsElement.PrependChild(connStringNode); connStringNode.SetAttribute("name", name); connStringNode.SetAttribute("connectionstring", connectionstring); k2ConfDoc.Save(cryptostream); userStream.Flush(); } finally { k2ConfDoc = null; } } } }
public void Remove(SCConnectionStringBuilder hostServerConfig) { hostServerConfig.ThrowIfNull(nameof(hostServerConfig)); string name = hostServerConfig.GetDisplayName(); CreateIsolatedStorage(); using (var userStorage = IsolatedStorageFile.GetUserStoreForAssembly()) { XmlDocument k2ConfDoc = null; using (var userStream = new IsolatedStorageFileStream(_k2ConfigFile, FileMode.Open, userStorage)) using (CryptoStream cryptostreamLoad = new CryptoStream(userStream, Decryptor(), CryptoStreamMode.Read)) { k2ConfDoc = new XmlDocument(); k2ConfDoc.Load(cryptostreamLoad); } var deleteNode = k2ConfDoc.SelectSingleNode(string.Format("//configuration/connectionstrings/connectionstring[@name='{0}']", name)); if (deleteNode != null) { var connectionstringsNode = k2ConfDoc.SelectSingleNode("//configuration/connectionstrings"); connectionstringsNode.RemoveChild(deleteNode); using (var userStream = new IsolatedStorageFileStream(_k2ConfigFile, FileMode.Create, userStorage)) using (var cryptostream = new CryptoStream(userStream, Encryptor(), CryptoStreamMode.Write)) { try { k2ConfDoc.Save(cryptostream); userStream.Flush(); } finally { k2ConfDoc = null; } } } } }
private void ChangeServerStatus() { var connectionStringBuilder = new SCConnectionStringBuilder(K2Client.Instance.K2Config.HostServerConnectionString); tssServer.Text = connectionStringBuilder.GetDisplayName(); }