FreakOut.classes.Searcher.IntervallSearchFromDB C# (CSharp) Method

IntervallSearchFromDB() public method

public IntervallSearchFromDB ( int Intervall ) : void
Intervall int
return void
        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);
            }
        }

Usage Example

Example #1
0
        public MainWin(bool debug)
        {
            LogInstance = new Logger(debug);

            DBConnection = new DatabaseConnector(LogInstance);
            SearchInstance = new Searcher(LogInstance);

            LogInstance.WriteToFile(1, "Starting Application", LogSource);
            LogInstance.WriteToFile(1, "Initializing Cache", LogSource);
            DBConnection.InitializeCache();

            LogInstance.WriteToFile(1, "Fetching all PC-games from the DB", LogSource);
            CurGameList = DBConnection.AllGamesByPlatform("PC");

            //Start the searcher in it's own thread, it shouldn't interfere with anything
            LogInstance.WriteToFile(1, "Starting Searcher-Thread", LogSource);
            SearchThread = new Thread(() => { SearchInstance.IntervallSearchFromDB(30); });
            SearchThread.Start();

            LogInstance.WriteToFile(1, "Loading Form", LogSource);
            InitializeComponent();
            LogInstance.WriteToFile(1, "Welcome To FreakOut!", LogSource);
            btAddGame.Enabled = false;
            btAddGame.Visible = false;
            cBSearchResultPicker.Enabled = false;
            cBSearchResultPicker.Visible = false;
            bs_games.DataSource = DBConnection.FillDataTable();
            dataGridView1.DataSource = bs_games;
            dataGridView1.Refresh();

            if (CurGameList != null)
            {
                for (int x = 0; x < CurGameList.Count; x++)
                {
                    if (CurGameList[x] != null)
                        lboxGameList.Items.Add((x+1) + ". " + CurGameList[x].Name.Replace(":", "-") + " (ID: " + CurGameList[x].ID + ")");
                }
            }
            else
            {
                lblNameOfGame.Visible = false;
                lblPublisher.Visible = false;
                lblPlayers.Visible = false;
                lblCoOp.Visible = false;
                lblRelease.Visible = false;
                lblContent.Visible = false;
                lblYoutube.Visible = false;
                lblGenres.Visible = false;
                pbGamePic.Hide();
                lboxGameList.Items.Add("No games currently to display.");
            }

            this.FillPlatformBox();
            lboxGameList.SelectedIndex = 0;
        }