예제 #1
0
        //private void getWatchList(baseLogin site, string username, bool scraps)
        //{
        //    try
        //    {
        //        List<watchList> WatchList;      // The final watchlist
        //        List<watchList> DBWatchList;   // The watchlist in the db

        //        DBWatchList = datahandler.getWatchList(site.Name, username);

        //        bool notFinishedList = false;

        //        foreach(watchList user in DBWatchList)
        //        {
        //            if (user.done)
        //            {
        //                notFinishedList = true;
        //                break;
        //            }
        //        }

        //        if (notFinishedList)
        //        {
        //            DialogResult dialogResult = MessageBox.Show("Wish to continue old download first?", "Continue?", MessageBoxButtons.YesNoCancel);
        //            if (dialogResult == DialogResult.Yes)
        //            {
        //                WatchList = DBWatchList;
        //            }
        //            else if (dialogResult == DialogResult.No)
        //            {
        //                WatchList = getWatchList(username, site);
        //            }
        //            else
        //            {
        //                WatchList = null;
        //            }

        //        }
        //        else
        //        {
        //            WatchList = getWatchList(username, site);
        //        }


        //        // Find new watched users that differs from the database
        //        List<watchList> newWatchList = new List<watchList>();
        //        foreach(watchList user in WatchList)
        //        {
        //            if(DBWatchList.Contains(user))
        //            {
        //                continue;
        //            }
        //            else
        //            {
        //                newWatchList.Add(user);
        //            }
        //        }

        //        if(newWatchList.Any())
        //        {
        //            foreach(watchList user in newWatchList)
        //            {
        //                Console.WriteLine("User: "******" Site: " + user.site);
        //            }
        //        }


        //        // Download the watchlist
        //        if (WatchList != null)
        //        {
        //            foreach (watchList user in WatchList)
        //            {
        //                while (pauseDownloads)
        //                {
        //                    if (stopDownloads)
        //                        break;
        //                    Thread.Sleep(50);
        //                }

        //                if (stopDownloads)
        //                {
        //                    break;
        //                }
        //                getSubs(user.user, site, scraps);
        //                //if (scraps && !stopDownloads)
        //                //{
        //                //    getSubs(user, site, scraps);
        //                //}
        //                if (!stopDownloads)
        //                {
        //                    datahandler.updateWatchList(site.Name, user.user, user.watchlistUser);
        //                }
        //                else
        //                    break;
        //                Thread.Sleep(politeWait);

        //            }
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        Console.WriteLine(e);
        //    }
        //}

        private void getWatchList(Website site, string userToDownload, bool scraps)
        {
            try
            {
                string username = site.validateWatchlistUsername(userToDownload);

                watchList WatchList = new watchList();


                watchList DBWatchList   = datahandler.getWatchList(site.Name, username);
                bool      dbNotFinished = false;

                foreach (watchedUser user in DBWatchList.users)
                {
                    if (user.done == false)
                    {
                        dbNotFinished = true;
                        break;
                    }
                }

                if (dbNotFinished)
                {
                    DialogResult mssgbox = MessageBox.Show("Found unfinished download in database. Wish to finish?", "Finish", MessageBoxButtons.YesNoCancel);
                    if (mssgbox == DialogResult.Yes)
                    {
                        DialogResult mssgboxNew = MessageBox.Show("Do you want to find new watched users?", "Find new?", MessageBoxButtons.YesNo);
                        if (mssgboxNew == DialogResult.Yes)
                        {
                            //watchList newWatchList = new watchList();

                            //newWatchList.site = site.Name;
                            //newWatchList.watchlistUser = username;
                            //newWatchList.users = new List<watchedUser>();

                            //List<string> userStrings = site.getWatchList(username);

                            //foreach(string user in userStrings)
                            //{
                            //    watchedUser userW = new watchedUser{ user= user, done = false};
                            //    newWatchList.users.Add(userW);
                            //}
                            watchList newWatchList = makeWatchListFromUserStrings(site.getWatchList(username), site.Name, username);
                            WatchList = compareWatchList(newWatchList, DBWatchList);
                            datahandler.setWatchList(WatchList, false);
                        }
                        else
                        {
                            WatchList = DBWatchList;
                        }
                    }
                    else if (mssgbox == DialogResult.No)
                    {
                        if (DBWatchList.users.Any())
                        {
                            DialogResult msgbox = MessageBox.Show("Want to find new watched users only?", "New watches only?", MessageBoxButtons.YesNo);

                            watchList newWatchList = makeWatchListFromUserStrings(site.getWatchList(username), site.Name, username);

                            if (msgbox == DialogResult.Yes)
                            {
                                WatchList = compareWatchList(newWatchList, DBWatchList);
                                datahandler.setWatchList(WatchList, false);
                            }
                            else
                            {
                                WatchList = newWatchList;
                                datahandler.setWatchList(WatchList);
                            }
                        }
                    }
                    else if (mssgbox == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                else
                {
                    if (DBWatchList.users.Any())
                    {
                        DialogResult msgbox = MessageBox.Show("Want to find new watched users only?", "New watches only?", MessageBoxButtons.YesNo);

                        watchList newWatchList = makeWatchListFromUserStrings(site.getWatchList(username), site.Name, username);

                        if (msgbox == DialogResult.Yes)
                        {
                            WatchList = compareWatchList(newWatchList, DBWatchList);
                            datahandler.setWatchList(WatchList, false);
                        }
                        else
                        {
                            WatchList = newWatchList;
                            datahandler.setWatchList(WatchList);
                        }
                    }
                    else
                    {
                        WatchList = makeWatchListFromUserStrings(site.getWatchList(username), site.Name, username);
                        datahandler.setWatchList(WatchList);
                    }
                }

                if (WatchList.users != null && WatchList.users.Any())
                {
                    Console.WriteLine("Found {0} watched users on {1} for {2}", WatchList.users.Count(), site.Name, username);
                    foreach (watchedUser user in WatchList.users)
                    {
                        if (!user.done)
                        {
                            while (pauseDownloads)
                            {
                                if (stopDownloads)
                                {
                                    break;
                                }
                                Thread.Sleep(50);
                            }

                            if (stopDownloads)
                            {
                                break;
                            }
                            getSubs(user.user, site, scraps);
                            //if (scraps && !stopDownloads)
                            //{
                            //    getSubs(user, site, scraps);
                            //}
                            if (!stopDownloads)
                            {
                                datahandler.updateWatchList(site.Name, user.user, WatchList.watchlistUser);
                            }
                            else
                            {
                                break;
                            }

                            Thread.Sleep(politeWait);
                        }
                    }
                    Console.WriteLine("Watchlist for {0} on {1} has finished.", username, site.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }