FreakOut.classes.DatabaseConnector.GameIsDownloaded C# (CSharp) Method

GameIsDownloaded() public method

public GameIsDownloaded ( int GameID ) : bool
GameID int
return bool
        public bool GameIsDownloaded(int GameID)
        {
            //Return wether a game is downloaded (= true) or not (= false)
            LogInstance.WriteToFile(1, "Asking for download-status of the game with the ID " + GameID + ".", LogSource);
            if (!connectionopen)
            {
                DBConnector.Open();
                connectionopen = true;
            }
            FbTransaction DBTransaction = DBConnector.BeginTransaction();
            FbCommand DBCommand = new FbCommand("SELECT downloaded from games WHERE ID = " + GameID, DBConnector, DBTransaction);
            FbDataReader DBReader = DBCommand.ExecuteReader();

            while (DBReader.Read())
            {
                if (DBReader.GetInt32(0) == 0)
                {
                    DBConnector.Close();
                    connectionopen = false;
                    return false;
                }
                else
                {
                    DBConnector.Close();
                    connectionopen = false;
                    return true;
                }
            }

            //In case the DBReader cannot find a valid result, we'll return false (this will be when the game isn't there...)
            //Have to implement this everywhere - not done yet though...
            LogInstance.WriteToFile(3, "No such game with the ID " + GameID + "! This is CRITICAL and may indicate database-corruption!", LogSource);
            return false;
        }

Usage Example

Exemplo n.º 1
0
        public void IntervallSearchFromDB(int Intervall)
        {
            DatabaseConnector SearchConnector = new DatabaseConnector(SearchLog);
            List<string> providerlist = SearchConnector.GetProviderList;
            ProviderInterface RSSSearch = new ProviderInterface(providerlist, SearchLog);
            bool sabenabled;

            if (SearchConnector.GetSettingByName("sabnzbdenabled") == "True")
                sabenabled = true;
            else
                sabenabled = false;

            nzbhandler sabnzbd = new nzbhandler(SearchLog);
            bool exc = false;

            while (!_stopped)
            {
                List<Game> Result = SearchConnector.AllGames();

                if (Result != null && providerlist != null)
                {
                    foreach (Game GameToSearch in Result)
                    {
                        if (GameToSearch == null)
                            break;

                        List<string> RSSResults = RSSSearch.Search(GameToSearch, 1000);

                        if (RSSResults == null)
                            break;

                        #region Checking
                        for (int i = 0; i < RSSResults.Count; i++)
                        {
                            string ResultName = RSSResults[i].Split(new Char[] {';'})[0];
                            string ResultLink = RSSResults[i].Split(new Char[]{';'})[1];

                            if (ResultName.Contains(GameToSearch.Name.Replace(" ", ".")) && !ResultName.Contains("Update") && !ResultName.Contains("Patch") && !SearchConnector.GameIsDownloaded(GameToSearch.ID))
                            {
                                if (SearchConnector.GetExceptions != null)
                                {
                                    foreach (string exception in SearchConnector.GetExceptions)
                                    {
                                        if (ResultName.Contains(exception))
                                        {
                                            exc = true;
                                            SearchLog.WriteToFile(1, "Found exception for " + GameToSearch.Name + "! Exception match: " + exception, LogSource);
                                        }
                                    }

                                    if (!exc)
                                    {
                                        SearchConnector.MarkGameSnatched(GameToSearch.ID);
                                        SearchConnector.MarkGameUnwanted(GameToSearch.ID);
                                        if (sabenabled)
                                        {
                                            SearchLog.WriteToFile(1, "Downloading game " + GameToSearch.Name + " via sabnzbd.", LogSource);
                                            sabnzbd.SendNZB(ResultLink, SearchConnector.GetSettingByName("sabnzbdurl"), SearchConnector.GetSettingByName("sabnzbdapi"));
                                            break;
                                        }
                                        else
                                        {
                                            SearchLog.WriteToFile(1, "Not sending DL for " + GameToSearch.Name + " to sabnzbd. Check your config!", LogSource);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    if (sabenabled)
                                    {
                                        SearchLog.WriteToFile(1, "Downloading game " + GameToSearch.Name + " via sabnzbd.", LogSource);
                                        sabnzbd.SendNZB(ResultLink, SearchConnector.GetSettingByName("sabnzbdurl"), SearchConnector.GetSettingByName("sabnzbdapi"));
                                        break;
                                    }
                                    else
                                    {
                                        SearchLog.WriteToFile(1, "Not sending DL for " + GameToSearch.Name + " to sabnzbd. Check your config!", LogSource);
                                        break;
                                    }
                                }

                                exc = false;
                            }
                        }
                        #endregion
                    }
                }
                System.Threading.Thread.Sleep(Intervall * 60000);
            }
        }