public static void Add(ServerInfo serverInfo) { var servers = GetAll(); if (servers.Any(s => s.Name == serverInfo.Name && ((serverInfo.Credential != null) ? (s.Credential != null && s.Credential.Username == serverInfo.Credential.Username && s.Credential.Password == serverInfo.Credential.Password) : s.Credential == null))) throw new DuplicateNameException(string.Format("Server '{0}' already exists.", serverInfo.Name)); var rootElement = Document.Element("Servers"); if (rootElement == null) throw new NullReferenceException("Root element 'Servers' does not exist."); if (serverInfo.Credential == null) rootElement.Add(new XElement("Server", serverInfo.Name)); else rootElement.Add(new XElement("Server", serverInfo.Name, new XAttribute("Username", serverInfo.Credential.Username), new XAttribute("Password", serverInfo.Credential.Password))); Document.Save(FileName); }
public Machine(ServerInfo serverInfo) { _serverInfo = serverInfo; }