/// <summary>
        /// Testing method for the encoder and decode functions.
        /// </summary>
        public static void EncodeDecodeTest()
        {
            DateTime  now       = new DateTime();
            Publisher p         = new Publisher(1);
            Random    rdm       = new Random();
            Bookstore bookstore = new Bookstore(1);

            for (int i = 0; i < 20; i++)
            {
                now = DateTime.Now;
                OrderObject o = new OrderObject
                                (
                    i,                                 //senderId
                    (Int32)(rdm.NextDouble() * 10000), //cardNo
                    i,                                 //receiverId
                    (Int32)(rdm.NextDouble() * 200),   //amount
                    (Int32)(rdm.NextDouble() * 100),   //unitPrice
                    now,                               //timestamp,
                    DateTime.Now.Millisecond
                                );
                string str = bookstore.Encoder(o);
                Console.WriteLine("The OrderObject's actual contents were: " + o.getBookStoreId() + "," + o.getCardNo().ToString() + ","
                                  + o.getPublisherId() + "," + o.getAmount().ToString() + "," + o.getUnitPrice().ToString() + "," + o.getTimestamp().ToString());
                Console.WriteLine("The string created by the encoder was: " + str);

                o = p.getDecoder().decode(str);
                Console.WriteLine("The Decoder created another OrderObject from the string created by the encoder whose contents were: \n"
                                  + o.getBookStoreId() + "," + o.getCardNo().ToString() + ","
                                  + o.getPublisherId() + "," + o.getAmount().ToString() + ","
                                  + o.getUnitPrice().ToString() + "," + o.getTimestamp().ToString() + "\n");

                System.Threading.Thread.Sleep(50);
            }
        }
        /// <summary>
        /// Main program for Project 2
        ///
        /// The creates the multicell buffer, publishers, and Retail stores.
        ///     There are 2 publisher threads
        ///     There are 5 retailer threads
        ///     There is one Multicell buffer.
        ///     As long as either publisher thread is running, the retail store threads will stay active.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            const Int32 NumStores = 5;


            // create the multi cell buffer
            mcb = new MultiCellBuffer(3);

            Publisher publisher1 = new Publisher(1);
            Publisher publisher2 = new Publisher(2);


            // start the publisher threads
            Thread P1 = new Thread(new ThreadStart(publisher1.runPublisher));
            Thread P2 = new Thread(new ThreadStart(publisher2.runPublisher));

            P1.Start();
            P2.Start();

            // Subscribe to events



            Thread[] retailStores = new Thread[NumStores];
            for (int i = 0; i < NumStores; i++)
            {
                // start n retail stores
                Bookstore bs = new Bookstore(i);
                Publisher.priceCutEvent       += new PriceCut(bs.BookSale);
                OrderProcessing.orderComplete += new OrderProcessed(bs.CompletedSale);
                retailStores[i] = new Thread(new ThreadStart(bs.BookStoreFunc));
                retailStores[i].Start();
            }


            while (P1.IsAlive || P2.IsAlive)
            {
                Thread.Sleep(1000);
            }
            BookStoreThreadRunning = false;

            //TestBookStore();

            //TestPricingModel();

            //EncodeDecodeTest();

            //Console.Read();
        }
        public static MultiCellBuffer mcb; // multicell buffer

        /// <summary>
        /// Test Bookstore Code -- function to test the bookstore class
        /// </summary>
        public static void TestBookStore()

        {
            Random rnd = new Random();



            Bookstore bs  = new Bookstore(1);
            Bookstore bs1 = new Bookstore(2);

            // set initial book prices
            GV.set_Pub1_Price(rnd.NextDouble() * (200 - 20) + 20);
            GV.set_Pub2_Price(rnd.NextDouble() * (200 - 20) + 20);


            // Start the BookStore Thread

            Thread BookStoreThread = new Thread(new ThreadStart(bs.BookStoreFunc));

            BookStoreThread.Name = "1";
            BookStoreThread.Start();

            Thread BookStoreThread1 = new Thread(new ThreadStart(bs1.BookStoreFunc));

            BookStoreThread1.Name = "2";
            BookStoreThread1.Start();



            // test the bookstore demand thread.
            for (int i = 0; i < 10; i++)
            {
                GV.set_Pub1_Price(rnd.NextDouble() * (200 - 20) + 20);
                GV.set_Pub2_Price(rnd.NextDouble() * (200 - 20) + 20);

                System.Threading.Thread.Sleep(1500);

                String p1s = mcb.getOneCell(1);
                Console.WriteLine("\t\t\t\t\t getoneCell(1) : {0}", p1s);
                p1s = mcb.getOneCell(1);
                Console.WriteLine("\t\t\t\t\t getoneCell(1) : {0}", p1s);
                String p2s = mcb.getOneCell(2);
                Console.WriteLine("\t\t\t\t\t getoneCell(2) : {0}", p2s);
                p2s = mcb.getOneCell(2);
                Console.WriteLine("\t\t\t\t\t getoneCell(2) : {0}", p2s);
            }
            BookStoreThreadRunning = false; // shut off threads
        }