Example #1
0
        public void Test()
        {
            inventory = new InventarioEfectivo();
            f56       = new F56(evnt, inventory);
            Thread.Sleep(2000);
            //jcm = new JCMIvizion(evnt, inventory);
            //jcm.StarCom();

            //Thread.Sleep(2000);

            //smrt = new SmartHopper(evnt, inventory);
            //smrt.StartThread();

            Thread.Sleep(2000);



            var _jcm   = jcm.getServiceStatus();
            var _f56   = f56.getServiceStatus();
            var _smart = smrt.getServiceStatus();
        }
Example #2
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);
                    }
                }
            }
        }