Ejemplo n.º 1
0
        private void HandlePaymentCash(int quantity)
        {
            current_status = status_cash.waiting;

            mach_status           = machine_status.receiving;
            CompletedTransaction  = false;
            BufferPaymentReceived = 0;
            PaymentExpected       = quantity;
            evnt.GetEvent <Enable_Cash>().Publish(true);
            timer1.Enabled = true;
        }
Ejemplo n.º 2
0
        private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                evnt.GetEvent <Disable_Cash>().Publish(true);
                current_status = status_cash.time_out;

                mach_status = machine_status.idle;

                /////////INICIAR DEVOLUCION DE DINERO ADQUIRIDO;


                List <Efectivo> dev = CalcularDevuelta(BufferPaymentReceived);

                evnt.GetEvent <Devol_Cash>().Publish(dev);

                BufferPaymentReceived = 0;
                timer1.Enabled        = false;
            }catch (SystemException E)
            {
                log.Error(E.Message);
            }
        }
Ejemplo n.º 3
0
        public void CashReceived(int value)
        {
            timer1.Stop();
            timer1.Start();
            BufferPaymentReceived += value;
            if (BufferPaymentReceived == PaymentExpected)
            {
                ////DEJAR DE RECIBIR DINERO Y PROCEDER A DEVOLVER SI ES EL CASO;
                evnt.GetEvent <Disable_Cash>().Publish(true);
                current_status        = status_cash.ok;
                mach_status           = machine_status.idle;
                BufferPaymentReceived = 0;
                timer1.Enabled        = false;


                inventory.UploadInventory(ComClass.operation_types.purchase.ToString("g"), null);

                /////
            }
            else if (BufferPaymentReceived > PaymentExpected)
            {
                current_status = status_cash.ok;
                mach_status    = machine_status.idle;
                evnt.GetEvent <Disable_Cash>().Publish(true);
                int Devuelta = BufferPaymentReceived - PaymentExpected;

                List <Efectivo> dev = CalcularDevuelta(Devuelta);
                // UpdateDevuelta(dev);
                evnt.GetEvent <Devol_Cash>().Publish(dev);

                CompletedTransaction  = true;
                BufferPaymentReceived = 0;
                timer1.Enabled        = false;
                inventory.UploadInventory(ComClass.operation_types.purchase.ToString("g"), null);
            }
        }
Ejemplo n.º 4
0
        public void process()
        {
            //this.CalcularDevuelta(1670);

            inventory = new InventarioEfectivo();

            f56 = new F56(evnt, inventory);
            log.Debug("F56 Started");

            Thread.Sleep(1000);

            jcm = new JCMIvizion(evnt, inventory);
            jcm.StarCom();
            log.Debug("JCM Started");
            Thread.Sleep(1000);

            smrt = new SmartHopper(evnt, inventory);
            smrt.StartThread();
            log.Debug("smrt Started");
            Thread.Sleep(1000);



            //



            var _jcm   = jcm.getServiceStatus();
            var _f56   = f56.getServiceStatus();
            var _smart = smrt.getServiceStatus();

            evnt.GetEvent <Disable_Cash>().Publish(true);


            if (_jcm.error.HasError || _f56.error.HasError || _smart.error.HasError)
            {
                mach_status = machine_status.error;
            }
            if (_jcm.IsDone && _f56.IsDone)
            {
                mach_status = machine_status.idle;
            }
            log.Debug("Service started Started");
            using (var listener = new SocketListener(1337)) // Start listening
            {
                log.Debug("Socket Started");

                for (;;)
                {
                    try
                    {
                        using (var remote = listener.Accept()) // Accepts a connection (blocks execution)
                        {
                            var      data = remote.Receive();  // Receives data (blocks execution)
                            ComClass deserializedProduct = JsonConvert.DeserializeObject <ComClass>(data);


                            if (deserializedProduct.funciones == ComClass.function.cash_handling)
                            {
                                if (mach_status == machine_status.idle)
                                {
                                    HandlePaymentCash(deserializedProduct.Value);
                                    deserializedProduct.result = ComClass.status_cash.ok;
                                }
                                else
                                {
                                    deserializedProduct.result = ComClass.status_cash.fail;
                                }
                            }
                            else if (deserializedProduct.funciones == function.set_money)
                            {
                                this.SetMoney(deserializedProduct.Inventario, deserializedProduct.user);
                                deserializedProduct.result = status_cash.ok;
                            }
                            else if (deserializedProduct.funciones == function.add_money)
                            {
                                this.AddMoney(deserializedProduct.Inventario, deserializedProduct.user);
                                deserializedProduct.result = status_cash.ok;
                            }
                            else if (deserializedProduct.funciones == ComClass.function.system_status)
                            {
                                deserializedProduct.status = mach_status;
                            }
                            else if (deserializedProduct.funciones == function.get_devices_status)
                            {
                                deserializedProduct.DeviceStatus = new List <Common.ServiceStatus>();
                                deserializedProduct.DeviceStatus.Add(f56.getServiceStatus());
                                deserializedProduct.DeviceStatus.Add(smrt.getServiceStatus());
                                deserializedProduct.DeviceStatus.Add(jcm.getServiceStatus());
                            }
                            else if (deserializedProduct.funciones == ComClass.function.operation_status)
                            {
                                deserializedProduct.result = current_status;
                            }
                            else if (deserializedProduct.funciones == ComClass.function.get_money)
                            {
                                deserializedProduct.Inventario = inventory.GetInventario();
                            }
                            else if (deserializedProduct.funciones == ComClass.function.remove_money)
                            {
                                this.RemoveMoney(deserializedProduct.Inventario, deserializedProduct.user);
                                deserializedProduct.result = status_cash.ok;
                            }
                            remote.Send(JsonConvert.SerializeObject(deserializedProduct)); // Sends the received data back
                        }
                    }catch (SystemException E)
                    {
                        log.Error(E.Message);
                    }
                }
            }
        }