/// <summary> /// Changes the stock value and also raising the event of stock value changes /// </summary> public void ChangeStockValue() { var rand = new Random(); CurrentValue += rand.Next(0, MaxChange + 1); NumChanges++; if ((CurrentValue - InitialValue) > Threshold) { StockEvent?.Invoke(this, null); } }
/// <summary> /// Changes the stock value and also raising the event of stock value changes /// </summary> public void ChangeStockValue() { var rand = new Random(); CurrentValue += rand.Next((-1 * MaxChange), MaxChange); NumChanges++; if (Math.Abs((CurrentValue - InitialValue)) > Threshold) { StockEvent?.Invoke(this, new StockNotification(StockName, CurrentValue, NumChanges)); } }
// Change the stock value and invoke event to notify stock brokers when the threshold is reach private void ChangeStockValue() { // Generate a random number to within a range that stock can change every time unit and add it to the current stock's value Random rand = new Random(); CurrentValue += rand.Next(-MaxChange, MaxChange); // Increase the number of changes in value by 1 NumOfChanges++; // Check if the threshold is reached if (Math.Abs(CurrentValue - InitialValue) >= Threshold) { // Raise the events Parallel.Invoke(() => StockEvent?.Invoke(StockName, InitialValue, CurrentValue, NumOfChanges, DateTime.Now), () => StockEventData?.Invoke(this, new EventData(StockName, InitialValue, CurrentValue, NumOfChanges, DateTime.Now))); } }
/// <summary> /// Changes the stock value and also raising the event of stock value changes /// </summary> public void ChangeStockValue() { var rand = new Random(); CurrentValue += rand.Next(1, MaxChange + 1); NumChanges++; if ((CurrentValue - InitValue) > NotificationThreshold) { StockNotification args = new StockNotification(); //create event // Create event data args.StockName = Name; args.CurrentValue = CurrentValue; args.NumChanges = NumChanges; StockEvent?.Invoke(this, args); //raises event by invoking delegate StockChangeFile(); } }
// Change the stock value and invoke event to notify stock brokers when the threshold is reach private void ChangeStockValue() { /// Generate a random number to within a range that stock can change every time unit and add it to the current stock's value Random rand = new Random(); CurrentValue += rand.Next(-MaxChange, MaxChange); // Increase the number of changes in value by 1 NumOfChanges++; // Check if the threshold is reached if (Math.Abs(CurrentValue - InitialValue) >= Threshold) { // Subscribe to the StockEventData event _stockMarket.StockEventData += StockMarket_WriteToFile; // Invoke two events at the same time Parallel.Invoke(() => StockEvent?.Invoke(StockName, InitialValue, CurrentValue, NumOfChanges, DateTime.Now), () => _stockMarket.WriteToFile(StockName, InitialValue, CurrentValue, NumOfChanges, DateTime.Now)); // Unsubscribe the event after finishing write to file _stockMarket.StockEventData -= StockMarket_WriteToFile; } }
protected void OnMarket(object sender, StockEventArgs e) { StockEvent?.Invoke(sender, e); }
protected virtual void stockEventChange(Stock stock) { // Invoke event and notify subscribers StockEvent?.Invoke(this, stock); }
public void OnStockEvent(StockNotification e) { StockEvent?.Invoke(this, e); }
protected virtual void OnStartTimer(StockEventArgs e) { StockEvent?.Invoke(this, e); }