예제 #1
0
            /// <summary>
            /// Event handler method
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            public void Notification(object sender, StockNotification e)
            {
                lock (ToLock)
                {
                    Console.WriteLine(brokerName.PadRight(12) + e.StockName.PadRight(12) + e.CurrentValue.ToString().PadRight(12) + e.NumberOfChanges.ToString().PadRight(12));
                }
                lock (ToLock)
                {
                    string directory = "/Users/brandontran/Projects/CECS475Lab3_2/CECS475Lab3_2";
                    string filename  = "stocks.txt";
                    string path      = directory + filename;

                    bool FileExists = File.Exists(path);

                    if (!File.Exists(path))
                    {
                        using (StreamWriter writer = File.CreateText(path))
                        {
                            writer.WriteLine("Broker".PadRight(12) + "Stock".PadRight(12) + "Value".PadRight(12) + "Changes".PadRight(12));
                            writer.WriteLine(e.StockName.PadRight(12) + e.CurrentValue.ToString().PadRight(12) + e.NumberOfChanges.ToString().PadRight(12) + e.InitialValue.ToString().PadRight(12));
                            writer.Flush();
                        }
                    }
                    else if (File.Exists(path))
                    {
                        using (StreamWriter writer = File.AppendText(path))
                        {
                            writer.WriteLine(brokerName.PadRight(12) + e.StockName.PadRight(12) + e.CurrentValue.ToString().PadRight(12) + e.NumberOfChanges.ToString().PadRight(12));
                            writer.Flush();
                        }
                    }
                }
            } //end of Notify method
예제 #2
0
        /// <summary>
        /// Method that raises an event if handler event in the class isn't null after being given data from eventdata
        /// </summary>
        /// <param name="e">Event dara</param>
        protected virtual void EventRaise(EventData e)
        {
            StockNotification handler = StockEvent;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #3
0
            public void ChangeStockValue()
            {
                // When the ChangeStockValue method is called upon, increase the number of changes towards the stock.
                _numOfChanges++;

                // Assume that you don't have to ask the user what value to change it to and apply a Random Number Generator
                Random RNG         = new Random();
                int    randomValue = RNG.Next(1, _maxChange);

                _currentValueOfStock += randomValue;


                if ((_currentValueOfStock - _initialValue) > _threshold)
                {
                    StockNotification args = new StockNotification(_stockName, _currentValueOfStock, _numOfChanges, _initialValue);
                    OnStockEvent(args);
                }
            }
예제 #4
0
        public void ProcessHelpStockNofification(string email, int productId, int productPriceId)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                return;
            }

            email = email.ToLower();

            var notification = _stockNotificationRepository.Table
                               .Where(x => x.Email.ToLower() == email)
                               .Where(x => x.ProductId == productId)
                               .Where(x => x.ProductPriceId == productPriceId)
                               .FirstOrDefault();

            if (notification != null)
            {
                notification.Notified      = false;
                notification.UpdatedOnDate = DateTime.Now;

                _stockNotificationRepository.Update(notification);
            }
            else
            {
                var newNotification = new StockNotification
                {
                    Email          = email,
                    ProductId      = productId,
                    ProductPriceId = productPriceId,
                    CreatedOnDate  = DateTime.Now,
                    UpdatedOnDate  = DateTime.Now
                };

                _stockNotificationRepository.Create(newNotification);
            }
        }
예제 #5
0
 public async void Notify(object sender, StockNotification e)
 {
     await writeFile((Stock)sender);
 }
예제 #6
0
 public void OnStockEvent(StockNotification e)
 {
     StockEvent?.Invoke(this, e);
 }