Esempio n. 1
0
        private async void FetchData()
        {
            GetFrequency();
            ApiAdapter.GenerateUri();
            await this.Dispatcher.Invoke(async() =>
            {
                await ApiAdapter.GetItems();
            });

            currentData.CheckActives();
            SetOpacity();
        }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            NETAutoupdater.InitializeAutoupdater(AppVersion);

            if (!string.IsNullOrEmpty(Settings.Default.FilterChangeSoundFileLocation) && !FilterSoundLocationDialog.Content.Equals("Default Sound"))
            {
                Data.Player.Open(new Uri(Settings.Default.FilterChangeSoundFileLocation));
            }
            else
            {
                Data.Player.Open(new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Sounds\filterchanged.mp3")));
            }

            if (!string.IsNullOrEmpty(Settings.Default.ItemPickupSoundFileLocation) && !ItemPickupLocationDialog.Content.Equals("Default Sound"))
            {
                Data.PlayerSet.Open(new Uri(Settings.Default.ItemPickupSoundFileLocation));
            }
            else
            {
                Data.PlayerSet.Open(new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Sounds\itemsPickedUp.mp3")));
            }

            //TESTING SETTINGS RESET
            //if (Debugger.IsAttached)
            //    Properties.Settings.Default.Reset();

            // initialize stash tabs
            //DataContext = stashTabsModel;

            // Populate the league dropdown
            if (Settings.Default.MainLeague)
            {
                MainLeagueComboBox.ItemsSource = ApiAdapter.GetAllLeagueNames();
            }

            InitializeColors();
            InitializeHotkeys();
            InitializeTray();
            LoadModeVisibility();

            // add Action to MouseHook
            MouseHook.MouseAction += Coordinates.Event;
        }
        private async void FetchData()
        {
            MainWindow.overlay.WarningMessage           = "";
            MainWindow.overlay.ShadowOpacity            = 0;
            MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Hidden;
            //aTimer.Stop();
            CalculationActive = true;
            this.Dispatcher.Invoke(() =>
            {
                IsIndeterminate = true;
            });
            await this.Dispatcher.Invoke(async() =>
            {
                GetFrequency();
                if (await ApiAdapter.GenerateUri())
                {
                    if (await ApiAdapter.GetItems())
                    {
                        try
                        {
                            await Task.Run(() =>
                            {
                                Data.CheckActives();
                                SetOpacity();

                                //ChaosRecipeEnhancer.aTimer.Enabled = true;
                                Trace.WriteLine("timer enabled");
                                aTimer.Enabled    = true;
                                CalculationActive = false;
                                this.Dispatcher.Invoke(() =>
                                {
                                    IsIndeterminate = false;
                                });
                            }, Data.ct);
                        }
                        catch (OperationCanceledException ex) when(ex.CancellationToken == Data.ct)
                        {
                            Trace.WriteLine("abort");
                            CalculationActive = false;
                            this.Dispatcher.Invoke(() =>
                            {
                                IsIndeterminate = false;
                            });
                        }
                    }
                }
                if (RateLimit.RateLimitExceeded)
                {
                    // TODO: show rate limit exceeded in ui
                    MainWindow.overlay.WarningMessage           = "Rate Limit Exceeded! Waiting...";
                    MainWindow.overlay.ShadowOpacity            = 1;
                    MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible;
                    aTimer.Enabled = false;
                    await Task.Delay(RateLimit.GetSecondsToWait() * 1000);
                    RateLimit.RequestCounter    = 0;
                    RateLimit.RateLimitExceeded = false;
                    aTimer.Enabled = true;
                }
                if (RateLimit.BanTime > 0)
                {
                    MainWindow.overlay.WarningMessage           = "Temporary Ban! Waiting...";
                    MainWindow.overlay.ShadowOpacity            = 1;
                    MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible;
                    aTimer.Enabled = false;
                    await Task.Delay(RateLimit.BanTime * 1000);
                    RateLimit.BanTime = 0;
                    aTimer.Enabled    = true;
                }
            });
        }
        private async void FetchData()
        {
            if (FetchingActive)
            {
                return;
            }
            if (!Properties.Settings.Default.ChaosRecipe && !Properties.Settings.Default.RegalRecipe && !Properties.Settings.Default.ExaltedRecipe)
            {
                MessageBox.Show("No recipes are enabled. Please pick a recipe.", "No Recipes", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DisableWarnings();
            FetchingActive    = true;
            CalculationActive = true;

            this.Dispatcher.Invoke(() =>
            {
                IsIndeterminate    = true;
                FetchButtonEnabled = false;
                FetchButtonColor   = Brushes.DimGray;
            });
            await this.Dispatcher.Invoke(async() =>
            {
                if (await ApiAdapter.GenerateUri())
                {
                    if (await ApiAdapter.GetItems())
                    {
                        try
                        {
                            await Task.Run(async() =>
                            {
                                await Data.CheckActives();
                                SetOpacity();
                                CalculationActive = false;
                                this.Dispatcher.Invoke(() =>
                                {
                                    IsIndeterminate = false;
                                });
                            }, Data.ct);
                            await Task.Delay(fetchCooldown * 1000).ContinueWith(_ =>
                            {
                                Trace.WriteLine("waited fetchcooldown");
                                //FetchButtonEnabled = true;
                                //FetchButtonColor = Brushes.Green;
                                //FetchingActive = false;
                            });
                        }
                        catch (OperationCanceledException ex) when(ex.CancellationToken == Data.ct)
                        {
                            Trace.WriteLine("abort");
                        }
                    }
                }
                if (RateLimit.RateLimitExceeded)
                {
                    MainWindow.overlay.WarningMessage           = "Rate Limit Exceeded! Waiting...";
                    MainWindow.overlay.ShadowOpacity            = 1;
                    MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible;
                    await Task.Delay(RateLimit.GetSecondsToWait() * 1000);
                    RateLimit.RequestCounter    = 0;
                    RateLimit.RateLimitExceeded = false;
                }
                if (RateLimit.BanTime > 0)
                {
                    MainWindow.overlay.WarningMessage           = "Temporary Ban! Waiting...";
                    MainWindow.overlay.ShadowOpacity            = 1;
                    MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible;
                    await Task.Delay(RateLimit.BanTime * 1000);
                    RateLimit.BanTime = 0;
                }
            });


            CalculationActive = false;
            FetchingActive    = false;
            this.Dispatcher.Invoke(() =>
            {
                IsIndeterminate    = false;
                FetchButtonEnabled = true;
                FetchButtonColor   = Brushes.Green;
                FetchingActive     = false;
            });
            Trace.WriteLine("end of fetch function reached");
        }