Exemplo n.º 1
0
 /* This function runs in a thread and will remain alive until all of the airline threads
  * have ended. The function checks whether or not a price drop event has occured by
  * checking the value of 'priceDropOccured'. If a price drop occurs then this function
  * creates an OrderObject and sends it to the MultiCellBuffer.
  */
 public void runAgency()
 {
     // Run the thread while the airline thread is still alive.
     while(airline.IsAlive)
     {
         if(priceDropOccured)
         {
             // Get the previous price and new price (used for calculating ticket need)
             int previousPrice = ((PriceDropEventArgs)currentEventArgs).getPrevious();
             int lowPrice = ((PriceDropEventArgs)currentEventArgs).getLow();
             int ticketNeed = calculateTicketNeed(previousPrice, lowPrice);
             OrderObject order = new OrderObject(agencyName, generateCreditNo(), ticketNeed, lowPrice);
             string encodedOrderString= Encoder.encodeOrder(order);
             lock (buffer)
             {
                 buffer.setOneCell(encodedOrderString);
             }
             // Reset the priceDropOccured data member once it's been handeled.
             priceDropOccured = false;
         }
     }
 }
Exemplo n.º 2
0
 public static string encodeOrder(OrderObject order)
 {
     string encodedOrderString = string.Format("{0}.{1}.{2}.{3}",
                                 order.getId(), order.getCardNo(), order.getAmount(), order.getUnitPrice());
     return encodedOrderString;
 }