示例#1
0
        public void processOrder()
        {
            /*Calculate price based on the no of books and order timestamp.*/
            double book_price = order.Current_Price_order;

            book_price = book_price * (1.0 + tax);  //adding 10% tax to the price of book.
            Console.WriteLine("Verify credit card no...");
            /*Implement credit card validation function here*/


            Service1 myservice         = new Service1();
            String   encrypted_card_no = myservice.encryptCreditCard(order.CardNo.ToString());

            if (myservice.CheckValidTransaction(encrypted_card_no, order.No_of_books * book_price))
            {
                Console.WriteLine("Valid credit card for {0}", Thread.CurrentThread.Name);
                Console.WriteLine("The order details are : \n");
                Console.WriteLine("BookStore ID : " + order.BookstoreID);
                Console.WriteLine("Card no : " + order.CardNo);
                Console.WriteLine("No of books : " + order.No_of_books);
                Console.WriteLine("Timestamp : " + order.Timestamp);


                String confirmation_message = "Your order has been confirmed! Please store the receipt for your records:" +
                                              "\n -------------------------------------------\n" + "Order Number : " + local_order_num +
                                              " \nBookstore ID : " + order.BookstoreID + "\nNo of books : " +
                                              order.No_of_books + "\nPrice per book : " + book_price + "\nTotal Price : " + order.No_of_books * book_price +
                                              "\n------------------------------\n";
                Console.WriteLine(confirmation_message); /*Write confirmation message out to screen*/
            }

            else
            {
                Console.WriteLine("Invalid credit card for {0}", Thread.CurrentThread.Name);
            }
        }
示例#2
0
        //The main entry point for the application.

        static void Main(string[] args)
        {
            Service1 service1 = new Service1();

            service1.GetData();
            Bookstore b1 = new Bookstore();

            b1.GenerateCC();

            for (int i = 0; i < K; ++i)
            {
                Publisher publisher = new Publisher();
                publishers[i]     = publisher;
                p_threads[i]      = new Thread(publisher.Run);
                p_threads[i].Name = "Publisher: " + i;
                p_threads[i].Start();
                while (!p_threads[i].IsAlive)
                {
                    ;
                }
            }



            // Initialize the Bookstores
            for (int i = 0; i < N; ++i)
            {
                Bookstore bookstore = new Bookstore();

                // Bookstores Subscribe to the Price Cut event
                for (int j = 0; j < K; ++j)
                {
                    bookstore.Subscribe(publishers[j]);
                }

                b_threads[i]      = new Thread(bookstore.Run);
                b_threads[i].Name = i.ToString();
                b_threads[i].Start();
                while (!b_threads[i].IsAlive)
                {
                    ;
                }
            }

            // Wait for the publishers to max price cuts (20 in our case)
            for (int i = 0; i < K; ++i)
            {
                while (p_threads[i].IsAlive)
                {
                    ;
                }
            }

            // Bookstores are informed that publishers are not active
            for (int i = 0; i < N; ++i)
            {
                Bookstore.PublishersAlive = false;
            }

            //Wait for all the bookstore threads to terminate
            Console.WriteLine("Waiting for all the bookstore threads to terminate");
            for (int i = 0; i < N; ++i)
            {
                while (b_threads[i].IsAlive)
                {
                    ;
                }
            }

            Console.WriteLine("\n\nEnd of Program");


            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }