Exemplo n.º 1
0
        public Torrent[] getTorrents(int contributersThreshold, out int maxId, out int found)
        {
            Torrent[] torrents;

            mySqlConnection.Open();
            MySqlCommand maxIdQuery = mySqlConnection.CreateCommand();
            maxIdQuery.CommandText = "SELECT MAX(id) FROM `torrents` WHERE seeders + leechers >= ?count;";
            maxIdQuery.Parameters.Add("?count", MySqlDbType.Int32).Value = contributersThreshold;
            MySqlDataReader reader = maxIdQuery.ExecuteReader();

            reader.Read();

            maxId = reader.GetInt32("MAX(id)");

            reader.Close();
            mySqlConnection.Close();

            mySqlConnection.Open();
            MySqlCommand torrentsQuery = mySqlConnection.CreateCommand();
            torrentsQuery.CommandText = "SELECT `id`, `IMDBId`, `kickAssAffiliation` FROM `torrents` WHERE seeders + leechers >= ?count;";
            torrentsQuery.Parameters.Add("?count", MySqlDbType.Int32).Value = contributersThreshold;
            reader = torrentsQuery.ExecuteReader();

            found = 0;

            torrents = new Torrent[maxId + 1];

            while (reader.Read())
            {
                int id = reader.GetInt32("id");
                int IMDbId = reader.GetInt32("IMDbId");
                string kickAssAffiliation = reader.GetString("kickAssAffiliation");
                torrents[id] = new Torrent(id, IMDbId, kickAssAffiliation);
                found += 1;

                if (kickAssAffiliation != "")
                {
                    if (!kickAssToTorrentId.ContainsKey(kickAssAffiliation))
                    {
                        List<int> newList = new List<int>();
                        kickAssToTorrentId.Add(kickAssAffiliation, newList);
                    }
                    kickAssToTorrentId[kickAssAffiliation].Add(id);

                }
                if (IMDbId != 0)
                {
                    if (!IMDbToTorrentId.ContainsKey(IMDbId))
                    {
                        List<int> newList = new List<int>();
                        IMDbToTorrentId.Add(IMDbId, newList);
                    }
                    IMDbToTorrentId[IMDbId].Add(id);
                }

                if (IMDbId != 0 && kickAssAffiliation != "")
                {
                    if (!kickAssAffiliationToIMDbId.ContainsKey(kickAssAffiliation))
                    {
                        kickAssAffiliationToIMDbId.Add(kickAssAffiliation, IMDbId);
                    }
                    if (!IMDbIdToKickAssAffiliation.ContainsKey(IMDbId))
                    {
                        IMDbIdToKickAssAffiliation.Add(IMDbId, kickAssAffiliation);
                    }
                }
            }

            reader.Close();
            torrentsQuery.Dispose();
            maxIdQuery.Dispose();
            mySqlConnection.Close();

            return torrents;
        }