public List <SelectListItem> GetBackups(string username, string database, ServerInfo server, string extension)
        {
            // Don't check if the directory doesn't exist.
            if (!VerifyBackupDirectory(username, false))
            {
                return(new List <SelectListItem>());
            }

            // Fetch data for the list.
            string[] backuppaths = Directory.GetFiles(HttpContext.Current.Server.MapPath("/Backups/" + username), "*." + extension);
            List <SelectListItem> backupfiles = new List <SelectListItem>();
            List <DatabaseInfo>   databases   = GetDatabases("Databases.ServerID", server.ServerID);
            string shortservername            = server.Hostname.Substring(0, server.Hostname.IndexOf('.'));

            // Compile a list of compatible backups.
            for (int i = 0; i < backuppaths.Length; i++)
            {
                string filename = Path.GetFileName(backuppaths[i]);

                // All MySQL files are compatible.
                if (extension.Equals("mysql", StringComparison.InvariantCultureIgnoreCase))
                {
                    backupfiles.Add(new SelectListItem {
                        Text = filename, Value = filename
                    });
                    continue;
                }
                // All backups of the exact same database are compatible.
                if (filename.Contains(database + "_" + shortservername + "_"))
                {
                    backupfiles.Add(new SelectListItem {
                        Text = filename, Value = filename
                    });
                    continue;
                }
                // Backups of old databases are compatible??????
                if (filename.Contains(shortservername))
                {
                    bool nomatch = true;
                    for (int j = 0; j < databases.Count; j++)
                    {
                        if (filename.Substring(0, filename.IndexOf('_')) == databases[j].Name)
                        {
                            nomatch = false;
                        }
                    }

                    if (nomatch)
                    {
                        backupfiles.Add(new SelectListItem {
                            Text = filename, Value = filename
                        });
                        continue;
                    }
                }
                // Backups from similar versions are compatible, if the server is different.
                if (filename.Contains("_" + server.Version + "_") && !filename.Contains("_" + shortservername + "_"))
                {
                    backupfiles.Add(new SelectListItem {
                        Text = filename, Value = filename
                    });
                    continue;
                }
            }

            return(backupfiles);
        }
        public ServerInfo GetServer(string serverID, string username = "")
        {
            // Compile SQL query and variables.
            string sql = "SELECT Servers.Hostname, Servers.Port, Protocols.ProtocolID, Protocols.Protocol, Protocols.Type, Protocols.Developer , Servers.Version, Servers.NewToDbMgr, Servers.AdminUsername, Servers.AdminPassword, Servers.Location " +
                         "FROM Servers " +
                         "INNER JOIN Protocols ON Servers.ProtocolID = Protocols.ProtocolID " +
                         "WHERE Servers.ServerID = '" + serverID + "';";
            string _hostname, _port, _protocolID, _protocol, _type, _developer, _version, _newtodbmgr, _adminusername, _adminpassword, _location;

            _hostname = _port = _protocolID = _protocol = _type = _developer = _version = _newtodbmgr = _adminusername = _adminpassword = _location = "";

            // Open connnection.
            try
            { OpenConnection(); }
            catch (Exception e)
            { throw e; }

            // Execute SQL query.
            SQLiteCommand    command = new SQLiteCommand(sql, sqliteConnection);
            SQLiteDataReader results = command.ExecuteReader();

            // Read SQL results.
            int rows_returned = 0;

            while (results.Read())
            {
                _hostname      = Convert.ToString(results["Hostname"]);
                _port          = Convert.ToString(results["Port"]);
                _protocolID    = Convert.ToString(results["ProtocolID"]);
                _protocol      = Convert.ToString(results["Protocol"]);
                _type          = Convert.ToString(results["Type"]);
                _developer     = Convert.ToString(results["Developer"]);
                _version       = Convert.ToString(results["Version"]);
                _newtodbmgr    = Convert.ToString(results["NewToDbMgr"]);
                _adminusername = Convert.ToString(results["AdminUsername"]);
                _adminpassword = Convert.ToString(results["AdminPassword"]);
                _location      = Convert.ToString(results["Location"]);
                rows_returned++;
            }

            // Close connection.
            try
            { CloseConnection(); }
            catch (Exception e)
            { throw e; }

            // Catch errors.
            if (rows_returned < 1)
            {
                HttpContext.Current.Session["ErrorMessage"] = "SERVER_NOT_FOUND";
                throw new Exception();
            }
            else if (rows_returned > 1)
            {
                HttpContext.Current.Session["ErrorMessage"] = "MULTIPLE_SERVERS";
                throw new Exception();
            }

            // Create basic server info.
            ServerInfo server = new ServerInfo(serverID, _hostname, _port, _protocolID, _protocol, _type, _developer, _version, _newtodbmgr, _adminusername, _adminpassword, _location);

            // Add advanced server info.
            List <DatabaseInfo> databases = new List <DatabaseInfo>();

            try
            { databases = GetDatabases("Databases.ServerID", serverID); }
            catch (Exception e)
            { throw e; }

            server.TotalDatabases = databases.Count;
            if (username != "")
            {
                for (int i = 0; i < databases.Count; i++)
                {
                    if (databases[i].Owner == username)
                    {
                        server.YourDatabases.Add(new DatabaseInfoLite(databases[i].DatabaseID, databases[i].Name));
                    }
                }
            }


            return(server);
        }