예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <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));
            }
        }
예제 #3
0
        // 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)));
            }
        }
예제 #4
0
        /// <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();
            }
        }
예제 #5
0
        // 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;
            }
        }
예제 #6
0
 protected void OnMarket(object sender, StockEventArgs e)
 {
     StockEvent?.Invoke(sender, e);
 }
예제 #7
0
 protected virtual void stockEventChange(Stock stock)
 {
     // Invoke event and notify subscribers
     StockEvent?.Invoke(this, stock);
 }
예제 #8
0
 public void OnStockEvent(StockNotification e)
 {
     StockEvent?.Invoke(this, e);
 }
예제 #9
0
 protected virtual void OnStartTimer(StockEventArgs e)
 {
     StockEvent?.Invoke(this, e);
 }