public void StartPriceCheck()
        {
            this.Dispatcher.Invoke(() =>
            {
                startPriceCheck_btn.IsEnabled = false;
                startPriceCheck_btn.Content   = "Checking Prices...";
            });

            PriceChecker.CheckPrices(GetWatchItems());
        }
Beispiel #2
0
        private void CheckPrices(Object source, ElapsedEventArgs e)
        {
            if (!PriceChecker.CheckingPrices)
            {
                try
                {
                    List <AmazonWatchItem> itemList = Application.Current.Dispatcher.Invoke(() => ((MainWindow)Application.Current.MainWindow).GetWatchItems());
                    PriceChecker.CheckPrices(itemList);
                    CommonFunctions.UserSettings.SetNextScheduledPriceCheck(DateTime.Now.AddMilliseconds(this.MillisecondsUntilExecution));
                }
                catch (Exception ex)
                {
                    CommonFunctions.Log.Error("Error checking prices by scheduler", ex);
                }
            }
            else
            {
                try
                {
                    DisplayLogItem rescheduleLog = new DisplayLogItem();

                    //Manually was checking prices when scheduler tried to kicked off. Reschedule the scheduler to the settings time

                    switch (CommonFunctions.UserSettings.SchedulerOption)
                    {
                    case (Settings.ScheduleType.Hours):
                        rescheduleLog.LogText = DisplayLogItem.CreateLogText($"Price checker was already checking prices when the scheduler tried to begin.",
                                                                             $"Rescheduling for: {CommonFunctions.UserSettings.ScheduleTime} hours");
                        rescheduleLog.LogImage = DisplayLogItem.GetLogIcon(DisplayLogItem.LogIcon.Warning);
                        break;

                    case (Settings.ScheduleType.Days):
                        rescheduleLog.LogText = DisplayLogItem.CreateLogText($"Price checker was already checking prices when the scheduler tried to begin",
                                                                             $"Rescheduling for: {CommonFunctions.UserSettings.ScheduleTime} days");
                        rescheduleLog.LogImage = DisplayLogItem.GetLogIcon(DisplayLogItem.LogIcon.Warning);
                        break;
                    }

                    CommonFunctions.Log.Debug($"Rescheduling price checker for {this.MillisecondsUntilExecution} ms");
                    rescheduleLog.Log();
                    UpdateScheduleTime(this.MillisecondsUntilExecution);
                }
                catch (Exception rescheduleEx)
                {
                    CommonFunctions.Log.Error("Error rescheduling scheduler", rescheduleEx);
                }
            }
        }