コード例 #1
0
        public void agencyFunc()
        {
            Int32 currentThreadName = Convert.ToInt32(Thread.CurrentThread.Name);

            hotel.registerCreditCardNumber(currentThreadName);
            Event[currentThreadName] = new AutoResetEvent(false);

            while (true)
            {
                int   eventIndex;
                Int32 threadName, _orderIds;
                int.TryParse(Thread.CurrentThread.Name, out eventIndex);
                Event[eventIndex].WaitOne();
                OrderClass orderObj = new OrderClass();

                amountOfRoom = calculateRoomAmount();
                threadName   = Convert.ToInt32(Thread.CurrentThread.Name);
                _orderIds    = ++orderIdsOfAgency[threadName];
                orderObj.setAmt(amountOfRoom);
                orderObj.setCardNo(threadName + 7000);
                orderObj.setSenderId(threadName);
                orderObj.setOrderId(_orderIds);
                orderObj.setSenderTime(DateTime.Now);
//                Thread.Sleep(1000);
                orderObj.setUnitPrice(roomPrice.price);
                String str = Coder.encoder(orderObj);

                Program.mcb.setOneCell(str);
            }
        }
コード例 #2
0
        public static OrderClass decoder(String encodedString)
        {
            if (encodedString != null)
            {
                HotelBookingSystem.CryptService.ServiceClient decrypt = new HotelBookingSystem.CryptService.ServiceClient();
                String decodedString = decrypt.Decrypt(encodedString);
                int    index         = 0;
                String str           = "";
                while (decodedString[index] != '&')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                Int32 orderId = Convert.ToInt32(str);
                str.Remove(0);
                str = "";
                index++;

                while (decodedString[index] != '#')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                Int32 senderId = Convert.ToInt32(str);
                str.Remove(0);
                str = "";
                index++;

                while (decodedString[index] != '$')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                Int32 cardNo = Convert.ToInt32(str);
                str.Remove(0);
                str = "";
                index++;

                while (decodedString[index] != '?')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                Double unitPrice = Convert.ToDouble(str);
                str.Remove(0);
                str = "";
                index++;

                while (decodedString[index] != '%')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                Int32 amountOfRoom = Convert.ToInt32(str);
                str.Remove(0);
                str = "";
                index++;

                while (decodedString[index] != '@')
                {
                    str += decodedString[index].ToString();
                    index++;
                }
                DateTime senderTime = Convert.ToDateTime(str);
                //              Console.WriteLine("OrderId: {0} SenderId: {1} CardNo: {2} Amount: {3} Date: {4}", orderId, senderId, cardNo, amountOfRoom, senderTime);
                OrderClass order = new OrderClass();
                order.setOrderId(orderId);
                order.setSenderId(senderId);
                order.setCardNo(cardNo);
                order.setUnitPrice(unitPrice);
                order.setAmt(amountOfRoom);
                order.setSenderTime(senderTime);
                return(order);
            }
            else
            {
                Console.WriteLine("Null string!");
                return(null);
            }
        }