Пример #1
0
    def send_transactions(self, productdata, member_id, queue):
        """ Send transaction requests to the server """
        self.logger.info("Sending transactions")

        message = Message()

        for (barcode, count) in productdata:
            packet = Packet(PacketTypes.Transaction, {"barcode":barcode, "memberid":member_id, "count":count})
            message.add_packet(packet)

        self.send_queue.put( MessagingQueueItem(PacketTypes.Transaction, message.get_xml(), queue) )
Пример #2
0
    def send_transactions(self, productdata, member_id, queue):
        """ Send transaction requests to the server """
        self.logger.info("Sending transactions")

        message = Message()

        for (barcode, count) in productdata:
            packet = Packet(PacketTypes.Transaction, {
                "barcode": barcode,
                "memberid": member_id,
                "count": count
            })
            message.add_packet(packet)

        self.send_queue.put(
            MessagingQueueItem(PacketTypes.Transaction, message.get_xml(),
                               queue))
Пример #3
0
    def process_packets(self, packets):
        """ Process a list of packets """
        
        reply = Message() ## The reply starts as an empty message

        for packet in packets:

            self.logger.info("Handling '%s' packet..." % packet.type)

            if packet.type == PacketTypes.Ping:
                reply.add_packet( Packet(PacketTypes.PingReply) )
            elif packet.type == PacketTypes.GetProduct:
                reply.add_packet( self.get_product_from_data(packet.data) )
            elif packet.type == PacketTypes.GetUser:
                reply.add_packet( self.get_user_from_data(packet.data) )
            elif packet.type == PacketTypes.Transaction:
                reply.add_packet( self.apply_transaction_from_data(packet.data) )
            elif packet.type == PacketTypes.AddProduct:
                reply.add_packet ( self.add_product_from_data(packet.data) )
            elif packet.type == PacketTypes.AddCredit:
                reply.add_packet( self.add_credit_from_data(packet.data) )
            elif packet.type == PacketTypes.GetRandomProduct:
                reply.add_packet( self.get_random_product_packet() )
            elif packet.type == PacketTypes.PingReply:
                pass # No action required for ping reply
            else:
                self.logger.warning("Unknown packet '%s'" % packet.type)

        return reply.get_xml()
Пример #4
0
    def process_packets(self, packets):
        """ Process a list of packets """

        reply = Message()  ## The reply starts as an empty message

        for packet in packets:

            self.logger.info("Handling '%s' packet..." % packet.type)

            if packet.type == PacketTypes.Ping:
                reply.add_packet(Packet(PacketTypes.PingReply))
            elif packet.type == PacketTypes.GetProduct:
                reply.add_packet(self.get_product_from_data(packet.data))
            elif packet.type == PacketTypes.GetUser:
                reply.add_packet(self.get_user_from_data(packet.data))
            elif packet.type == PacketTypes.Transaction:
                reply.add_packet(self.apply_transaction_from_data(packet.data))
            elif packet.type == PacketTypes.AddProduct:
                reply.add_packet(self.add_product_from_data(packet.data))
            elif packet.type == PacketTypes.AddCredit:
                reply.add_packet(self.add_credit_from_data(packet.data))
            elif packet.type == PacketTypes.GetRandomProduct:
                reply.add_packet(self.get_random_product_packet())
            elif packet.type == PacketTypes.PingReply:
                pass  # No action required for ping reply
            else:
                self.logger.warning("Unknown packet '%s'" % packet.type)

        return reply.get_xml()