public void Update(object sender, StockEventArgs eventArgs) { Console.WriteLine( eventArgs.Euro > 40 ? $"Bank {this.Name} sells euros; Euro rate:{eventArgs.Euro}" : $"Bank {this.Name} is buying euros; Euro rate: {eventArgs.Euro}"); }
public void Update(object sender, StockEventArgs eventArgs) { Console.WriteLine( eventArgs.USD > 30 ? $"Broker {this.Name} sells dollars; Dollar rate: {eventArgs.USD}" : $"Broker {this.Name} buys dollars; Dollar rate: {eventArgs.USD}"); }
public void Update(object sender, StockEventArgs e) { StockInfo stockInfo = e.Info; Console.WriteLine( stockInfo.USD > 30 ? $"Broker {this.Name} sells dollars; Dollar rate: {stockInfo.USD}" : $"Broker {this.Name} buys dollars; Dollar rate: {stockInfo.USD}"); }
/// <summary> /// Update StockInfo. /// </summary> /// <param name="sender"> /// Event sender. /// </param> /// <param name="e"> /// StockEventArgs object. /// </param> public void Update(object sender, StockEventArgs e) { StockInfo stockInfo = e.StockInfo; Console.WriteLine( stockInfo.Euro > 40 ? $"Bank {this.Name} sells euros; Euro rate:{stockInfo.Euro}" : $"Bank {this.Name} is buying euros; Euro rate: {stockInfo.Euro}"); }
private StockEventArgs GetNewCurrency() { Random random = new Random(); StockEventArgs newCurrency = new StockEventArgs() { Euro = random.Next(2, 3), USD = random.Next(1, 5), }; return(newCurrency); }
public void Market() { for (int i = 0; i < measurePeriodSeconds / intervaMeasurelSeconds; i++) { Console.WriteLine($"\nNew currency data...\n"); StockEventArgs newData = GetNewCurrency(); OnCurrencyChanged(this, newData); Console.WriteLine(new string('-', 70)); Thread.Sleep(intervaMeasurelSeconds * 1000); } }
void Run() { Random rnd = new Random(); for (int days = 0; days < 5; days++) { StockEventArgs stocksInfo = new StockEventArgs(); stocksInfo.USD = rnd.Next(20, 40); stocksInfo.Euro = rnd.Next(30, 50); OnNewStockData(this, stocksInfo); Thread.Sleep(2000); } }
protected void OnMarket(object sender, StockEventArgs e) { StockEvent?.Invoke(sender, e); }
public Stock() { stocksInfo = new StockEventArgs(); }
private void Message(object sender, StockEventArgs eventArgs) { currentCurrency = eventArgs ?? throw new ArgumentNullException($"Incorrect data of {nameof(eventArgs)}"); Console.WriteLine("Bank report message:"); Console.WriteLine("Usd = {0}, Euro = {1}\n", eventArgs.USD, eventArgs.Euro); }
protected virtual void OnNewStockData(object sender, StockEventArgs e) { StockData?.Invoke(this, e); }
protected virtual void OnCurrencyChanged(object sender, StockEventArgs e) { CurrencyChanged?.Invoke(this, e); }
public Stock(int measurePeriodSeconds, int intervalSeconds) { currentCurrency = new StockEventArgs(); this.intervaMeasurelSeconds = intervalSeconds; this.measurePeriodSeconds = measurePeriodSeconds; }
protected virtual void OnStartTimer(StockEventArgs e) { StockEvent?.Invoke(this, e); }
protected virtual void OnNewInfo(object sender, StockEventArgs e) { NewInfo?.Invoke(this, e); }