Ejemplo n.º 1
0
        /// <summary>
        /// Executes a run of processing the stock data
        /// </summary>
        /// <param name="session">The session configuration</param>
        public static void Run(StockSession session)
        {
            // Set up the derived data sink
            var sourceData = session.SourceFile.GetSegments <StockDataSource>();
            var sinkData   = StockDataSetDerived <StockDataSink, StockDataSource> .Derive(sourceData, session.SinkFile, (data, idx) =>
            {
                var point = new StockDataSink();
                point.Update(data, idx);
                return(point);
            });

            session.SinkFile.SetSegments(sinkData);

            // Find when a stock increases by a certain amount
            PriceMonitor priceMonitor = new PriceMonitor(0.025);

            priceMonitor.MonitorDecrease = false;
            sinkData["AA"][0].Load();
            priceMonitor.Monitor("AA", sinkData["AA"][0][0].Price, (string stock, float startPrice, float endPrice, DateTime time) =>
            {
                System.Windows.Forms.MessageBox.Show(string.Format("{0} {1:C}->{2:C} @ {3}", stock, startPrice, endPrice, time));
                return(true);
            });

            // Load the first set of data
            foreach (var pair in sinkData)
            {
                foreach (var set in pair.Value)
                {
                    set.Load();
                    priceMonitor.Process(set, 0);
                }
            }
        }
Ejemplo n.º 2
0
        public static void RunWeek4Homework()
        {
            PriceWatch          myPriceWatch = new PriceWatch();
            PriceMonitor        monitor      = new PriceMonitor(myPriceWatch);
            PriceChangeNotifier auto         = new PriceChangeNotifier(myPriceWatch);

            Console.Clear();
            Console.WriteLine("This program uses the decorator program to calculate price and the");
            Console.WriteLine("observer pattern to watch the price of a boat.");
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("What is my budget to buy a boat?");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("$");

            bool haveBudget = false;

            do
            {
                string  userInput = Console.ReadLine();
                decimal userNumber;

                bool parsed = Decimal.TryParse(userInput, out userNumber);

                if (!parsed)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Please enter a number.");
                    Console.ForegroundColor = ConsoleColor.White;
                }

                else
                {
                    haveBudget = true;
                    myPriceWatch.CurrentBudget = userNumber;
                }
            } while (haveBudget == false);

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("What is the base price of the Boat?");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("$");

            bool haveBoatBasePrice = false;

            do
            {
                string  userInput = Console.ReadLine();
                decimal userBoatPrice;

                bool parsed = Decimal.TryParse(userInput, out userBoatPrice);

                if (!parsed)
                {
                    Console.WriteLine("Please enter a number.");
                }

                else
                {
                    haveBoatBasePrice         = true;
                    myPriceWatch.CurrentPrice = userBoatPrice;
                }
            } while (haveBoatBasePrice == false);

            IOrder myOrder = new Electronics(new Rigging(new Boat(new BoatOrder(), myPriceWatch.CurrentPrice)));

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("The total price of the boat with: ");
            Console.WriteLine(myOrder.GetOrder);
            Console.WriteLine("is $" + myOrder.Price + ".");
            Console.ForegroundColor = ConsoleColor.White;

            myPriceWatch.CurrentPrice = myOrder.Price;

            Console.WriteLine();
            Console.WriteLine("Let's try considering another boat.");
            Console.WriteLine();
            Console.WriteLine("What is the base price of the new Boat?");
            Console.Write("$");

            haveBoatBasePrice = false;

            do
            {
                string  userInput = Console.ReadLine();
                decimal userNumber;

                bool parsed = Decimal.TryParse(userInput, out userNumber);

                if (!parsed)
                {
                    Console.WriteLine("Please enter a number.");
                }

                else
                {
                    haveBoatBasePrice         = true;
                    myPriceWatch.CurrentPrice = userNumber;
                }
            } while (haveBoatBasePrice == false);

            IOrder myOrder2 = new Electronics(new Rigging(new Boat(new BoatOrder(), myPriceWatch.CurrentPrice)));

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("The total price of the boat with: ");
            Console.WriteLine(myOrder2.GetOrder);
            Console.WriteLine("is $" + myOrder2.Price + ".");

            myPriceWatch.CurrentPrice = myOrder2.Price;
        }