示例#1
0
        private void buttonDownload_Click(object sender, EventArgs e)
        {
            this.listBoxLog.Items.Clear();

            this.buttonDownload.Enabled = false;
            this.progressBar.Value      = 0;

            ChestsDownloaderSettings settings = new ChestsDownloaderSettings();

            settings.GetAllFusesCollection = this.cbAllFuses.Checked;
            settings.GetAllMaxedCollection = this.cbAllMaxed.Checked;
            settings.GetCurrentCollection  = this.cbCurrCards.Checked;
            settings.LookForPlayerGuild    = this.cbLookUpForGuild.Checked;

            if (this.cbLevel1.Checked)
            {
                settings.AddBlocklevel(1);
            }

            if (this.cbLevel2.Checked)
            {
                settings.AddBlocklevel(2);
            }

            if (this.cbLevel3.Checked)
            {
                settings.AddBlocklevel(3);
            }

            if (this.cbLevel4.Checked)
            {
                settings.AddBlocklevel(4);
            }

            if (this.cbLevel5.Checked)
            {
                settings.AddBlocklevel(5);
            }

            if (this.cbLevel6.Checked)
            {
                settings.AddBlocklevel(6);
            }

            this.backgroundWorker1.RunWorkerAsync(settings);
        }
示例#2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ChestsDownloaderSettings settings = e.Argument as ChestsDownloaderSettings;

                if (settings == null)
                {
                    settings = new ChestsDownloaderSettings();
                }


                int progress = 0;
                this.backgroundWorker1.ReportProgress(progress, "Приступаем к обработке Дек");


                SiteDataManager manager = new SiteDataManager("russia", "mother", this.CurrentCredential.Password);
                this.backgroundWorker1.ReportProgress(progress, "Подключаемся к сайту");

                var chests = manager.SiteChestsManager.UserChestsDescriptions;
                this.backgroundWorker1.ReportProgress(progress, "Получена коллекция сундуков");

                String currentCardsFolder    = this.CurrentCredential.Engine.ChestsManager.GetCurrentCardsFolderpath();
                String maxedCardsCardsFolder = this.CurrentCredential.Engine.ChestsManager.GetMaxedCardsFolderpath();
                String allFusesCardsFolder   = this.CurrentCredential.Engine.ChestsManager.GetAllFusesCardsFolderpath();

                int step = 100 / chests.Count;

                foreach (UserChestDescription chestDescription in chests)
                {
                    this.backgroundWorker1.ReportProgress(progress, "Обрабатываем: " + chestDescription.Name);

                    int tries = 10;
                    while (tries-- > 0)
                    {
                        try
                        {
                            Console.WriteLine("Обрабатываем: " + chestDescription.Name);
                            var chest = manager.SiteChestsManager.FillChest(chestDescription);

                            String guild = "";

                            if (settings.LookForPlayerGuild)
                            {
                                try
                                {
                                    guild = manager.SiteDeckManager.GetGuildByPlayer(chestDescription.Name) + ".";
                                }
                                catch
                                {
                                    //this.backgroundWorker1.ReportProgress(progress, "Произошла ошибка: Не удалось определить гильдию игрока. " + ex.ToString());
                                }
                            }

                            var fname = MakeSafeName(guild + chestDescription.Name);

                            using (var f = System.IO.File.CreateText(currentCardsFolder + "\\" + fname + ".txt"))
                            {
                                foreach (String card in chest.IOwnerCards)
                                {
                                    if (settings.CheckFilterCard(card))
                                    {
                                        f.WriteLine(card);
                                    }
                                }
                            }

                            if (settings.GetAllMaxedCollection)
                            {
                                using (var f = File.CreateText(maxedCardsCardsFolder + "\\" + fname + ".txt"))
                                {
                                    foreach (String card in chest.IOwnerCardsMaxed)
                                    {
                                        f.WriteLine(card);
                                    }
                                }
                            }


                            if (settings.GetAllFusesCollection)
                            {
                                using (var f = File.CreateText(allFusesCardsFolder + "\\" + fname + ".txt"))
                                {
                                    foreach (String card in chest.IPossibleCard)
                                    {
                                        f.WriteLine(card);
                                    }
                                }
                            }
                            tries = 0;

                            progress = progress + step;
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            this.backgroundWorker1.ReportProgress(progress, "Произошла ошибка: " + ex.ToString());
                            this.backgroundWorker1.ReportProgress(progress, "Осталось попыток: " + tries);
                        }
                        catch (Exception ex)
                        {
                            this.backgroundWorker1.ReportProgress(progress, "Произошла ошибка: " + ex.ToString());
                            this.backgroundWorker1.ReportProgress(progress, "Осталось попыток: " + tries);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.backgroundWorker1.ReportProgress(-1, ex.Message);
            }
        }