public static FlaggedResult<List<ItemSale>, KeyValuePair<ItemSale, string>> FindDealsFlagged(
			string steamid, DealsFilters filters, bool beep = false)
        {
            if (filters == null)
            {
                VersatileIO.Warning("Deals filters object was null. Setting to default.");
                filters = new DealsFilters();
            }

            VersatileIO.Info("Filters: " + filters);

            Price? max = GetMaxPrice();
            if (max == null)
            {
                return null;
            }
            Price min = GetMinPrice(max.Value);

            VersatileIO.Info("Price range: {0} - {1}.", min.ToString(), max.ToString());
            VersatileIO.WriteLine();

            List<ItemPricing> inRange = FindPricingsInRange(new PriceRange(min, max.Value), filters);

            List<ItemSale> relevant = FindRelevantClassifeids(inRange);

            var results = PickOutDealsFlagged(relevant, filters.DealsMinProfit);

            if (beep)
            {
                Console.Beep();
            }

            return results;
        }
        public ClassifiedsView()
        {
            InitializeComponent();

            ClassifiedsLoader = new BackgroundWorker();
            ClassifiedsLoader.DoWork += ClassifiedsLoader_DoWork;
            ClassifiedsLoader.RunWorkerCompleted += ClassifiedsLoader_RunWorkerCompleted;

            AvailableItems = new ObservableCollection<ItemViewModel>();
            ItemSearchResultList.ItemsSource = AvailableItems;

            Sellers = new ObservableCollection<ClassifiedsListingViewModel>();
            SellersList.ItemsSource = Sellers;

            Buyers = new ObservableCollection<ClassifiedsListingViewModel>();
            BuyersList.ItemsSource = Buyers;

            Filters = new DealsFilters();
            Filters.Qualities.Add(Quality.Unique);

            DealsLoader = new BackgroundWorker();
            DealsLoader.WorkerReportsProgress = true;
            DealsLoader.DoWork += DealsLoader_DoWork;
            DealsLoader.RunWorkerCompleted += DealsLoader_RunWorkerCompleted;
            DealsLoader.ProgressChanged += DealsLoader_ProgressChanged;

            DealFinder.OnProgressChanged += DealFinder_OnProgressChanged;

            DealsResults = new ObservableCollection<SaleViewModel>();
            DealsResultsList.ItemsSource = DealsResults;

            DealsExcluded = new ObservableCollection<DealExclusionViewModel>();
            DealsExcludedList.ItemsSource = DealsExcluded;
        }
        public void RunCommand(CommandHandler sender, List<string> args)
        {
            DealsFilters filters = new DealsFilters();

            string steamid = Settings.Instance.HomeSteamID64;

            foreach (string s in args)
            {
                if (!s.StartsWith("/"))
                {
                    steamid = s;
                    continue;
                }

                filters.HandleArg(s);
            }

            List<ItemSale> sales = DealFinder.FindDeals(steamid, filters);
            if (sales == null)
            {
                // already logged
                return;
            }

            sales.Sort((a, b) => a.Profit.TotalRefined.CompareTo(b.Profit.TotalRefined));

            VersatileIO.WriteLine();
            VersatileIO.Info("{0} deals found:", sales.Count);

            foreach (ItemSale s in sales)
            {
                VersatileIO.WriteComplex("  " + s.ToComplexString());
            }
        }
        public void RunCommand(CommandHandler sender, List<string> args)
        {
            if (args.Count < 2)
            {
                VersatileIO.Error("Syntax: " + Syntax);
                return;
            }

            Price min, max;
            if (!Price.TryParse(args[0], out min))
            {
                VersatileIO.Error("Invalid price: " + args[0]);
                return;
            }
            if (!Price.TryParse(args[1], out max))
            {
                VersatileIO.Error("Invalid price: " + args[1]);
            }
            PriceRange range = new PriceRange(min, max);

            DealsFilters filters = new DealsFilters();
            for (int i = 2; i < args.Count; i++)
            {
                filters.HandleArg(args[i]);
            }

            VersatileIO.Debug("Searching pricings...");
            List<ItemPricing> res = GetInRange(range, filters);
            foreach (ItemPricing p in res)
            {
                VersatileIO.WriteComplex("  " + p.Quality.GetColorCode() + p.ToUnpricedString() +
                    "&7 for " + p.GetPriceString());
            }

            VersatileIO.Info("{0} pricings matching filters [{1}].", res.Count, filters.ToString());
        }
 public static List<ItemPricing> GetInRange(PriceRange range, DealsFilters filters)
 {
     return DataManager.PriceData.Prices.FindAll((p) => filters.MatchesPricing(p) && range.Contains(p.Pricing));
 }
        public void PostLoad(MainWindow window)
        {
            MinPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_REF));
            MinPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_KEYS));
            MinPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_CASH));

            MaxPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_REF));
            MaxPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_KEYS));
            MaxPriceUnitCombo.Items.Add(new PriceUnitViewModel(Price.CURRENCY_CASH));

            Price min = new Price(Settings.Instance.RangeLastMinPrice);
            Price max = new Price(Settings.Instance.RangeLastMaxPrice);

            if (min.TotalKeys >= 2.0)
            {
                MinPriceBox.Text = min.TotalKeys.ToString();
                MinPriceUnitCombo.SelectedIndex = 1;
            }
            else
            {
                MinPriceBox.Text = min.TotalRefined.ToString();
                MinPriceUnitCombo.SelectedIndex = 0;
            }

            if (max.TotalKeys >= 2.0)
            {
                MaxPriceBox.Text = max.TotalKeys.ToString();
                MaxPriceUnitCombo.SelectedIndex = 1;
            }
            else
            {
                MaxPriceBox.Text = max.TotalRefined.ToString();
                MaxPriceUnitCombo.SelectedIndex = 0;
            }

            _loaded = true;

            OwnerWindow = window;

            Filters = new DealsFilters();

            _updateMinPrice();
            _updateMaxPrice();

            RunFilter();
        }
        public static List<ItemPricing> FindPricingsInRange(PriceRange range, DealsFilters filters)
        {
            List<ItemPricing> results = new List<ItemPricing>();

            VersatileIO.Info("Finding valid items in price range...");
            foreach (ItemPricing p in DataManager.PriceData.Prices) // get ALL the datas!
            {
                if (!range.Contains(p.Pricing))
                {
                    continue;
                }

                if (!filters.MatchesPricing(p))
                {
                    continue;
                }

                results.Add(p);
            }

            return results;
        }
        public static List<ItemPricing> FindPricingsInRange(PriceRange range, 
			List<Quality> qualitiesAllowed, List<ItemSlotPlain> slotsAllowed,
			bool? craftable = true, bool? halloween = null, bool? botkiller = null)
        {
            DealsFilters deals = new DealsFilters()
            {
                Qualities = qualitiesAllowed,
                Slots = slotsAllowed,
                Craftable = craftable,
                Halloween = halloween,
                Botkiller = botkiller,
            };

            return FindPricingsInRange(range, deals);
        }
 public static List<ItemSale> FindDeals(string steamid, DealsFilters filters, bool beep = false)
 {
     return FindDealsFlagged(steamid, filters, beep).Result;
 }