Exemplo n.º 1
0
        /// <summary>
        /// Starts a scan using the given trade provider.
        /// </summary>
        /// <param name="currencies">currencies to scan for.</param>
        /// <param name="tradeProvider">provider</param>
        public async Task StartScan()
        {
            if (IsRunning)
            {
                return;
            }

            IsRunning = true;
            _logger.Info($"Initializing for League: {League}\n" +
                         $"Provider: {_tradeProvider.ProviderName()}({_tradeProvider.ProviderUrl()}).\n" +
                         $"Scan Cycle: {_scanCycleTime}. Result Limit: {_resultLimit}");
            _provider = _tradeProvider;
            _logger.Info("Starting Scan");


            InitializeScannerQueue(_currencies);
            // scan while we haven't called stop and we still have scanners to process.
            while (IsRunning && _scanQueue.Count > 0)
            {
                _logger.Info("Getting Scanner");
                var scanner = _scanQueue.Dequeue();

                if (OfferData.ContainsKey(scanner.BuyingType))
                {
                    _logger.Info($"Clearing offer data stored for {scanner.BuyingType}");
                    OfferData[scanner.BuyingType].Clear();
                }

                _logger.Info($"Getting Buy Offers for {scanner}");

                await Task.Run(async() => await CompileOfferData(scanner, _currencies));

                // exit so we don't wait on the last iteration
                if (_scanQueue.Count <= 0)
                {
                    continue;
                }

                _logger.Info($"Waiting {_scanCycleTime} to run next scanner.");
                await Task.Delay(_scanCycleTime);
            }

            _logger.Info("Completed scan.");
            Finished?.Invoke(this, EventArgs.Empty);
            IsRunning = false;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new offer
 /// </summary>
 /// <param name="buying">Currency being bought by the user</param>
 /// <param name="selling">Currency being sold by the user</param>
 /// <param name="username">the user selling the currency</param>
 /// <param name="league">the league of the user</param>
 public Offer(CurrencyItem buying,
              CurrencyItem selling,
              double currentStock,
              string username,
              string league,
              ITradeProvider provider)
 {
     Buying        = buying;
     Selling       = selling;
     CurrentStock  = currentStock;
     Username      = username;
     League        = league;
     TradeProvider = provider;
     _logger       = LogManager.GetCurrentClassLogger();
     _logger.Trace(
         $"Found Offer on {TradeProvider.ProviderName()}:[{Buying} => {Selling}] Stock: {CurrentStock}");
 }