Exemple #1
0
        public static void Start()
        {
            System.Threading.Thread.Sleep(200);
            DocumentFileHelper[] orders = null;
            int sleepTime = 500;

            if (!Parser.TryInt(PosConfiguration.Get("SleepTime"), out sleepTime))
            {
                sleepTime = 500;
            }

            while (true)
            {
                if (Chassis.Engine.Terminate)
                {
                    break;
                }

                try
                {
                    orders = DocumentFileHelper.GetOpenOrders();
                }
                catch (Exception ex)
                {
                    Debugger.Instance().AppendLine("Order Error: " + ex.Message);
                }
                if (orders != null && orders.Length > 0)
                {
                    try
                    {
                        AutoLoadOrders(orders);
                    }
                    catch (Exception ex)
                    {
                        Debugger.Instance().AppendLine("Order Error: " + ex.Message);
                    }
                }
                else
                {
                    DisplayAdapter.Instance().LedOff(Leds.Order);
                }

                Thread.Sleep(sleepTime);
                while (cr.State == null)
                {
                    Thread.Sleep(200); //I wish this had a comment
                }
            }
        }
        public static void Start()
        {
            System.Threading.Thread.Sleep(200);
            DocumentFileHelper[] orders = null;
            int sleepTime = 5000;

            if (!Parser.TryInt(PosConfiguration.Get("SleepTime"), out sleepTime))
            {
                sleepTime = 5000;
            }

#if (!WindowsCE)
            tcpOrder = new TcpOrder();
#endif
            while (true)
            {
                if (Chassis.Engine.Terminate)
                {
                    break;
                }
                try
                {
                    CheckDataMessage();
                    cr.DataConnector.TransferOfflineData();

                    if (!isConnectionUp)
                    {
                        //CheckDataMessage() didnt throw exception
                        //means backoffice has become online
                        CashRegister.Log.Info("Network up");
                        isConnectionUp = true;
                        OnNetworkUp();
                    }
                }
                catch (BackOfficeUnavailableException bue)
                {
                    CashRegister.Log.Info("ARKA OFÝSE ULAÞILAMIYOR : " + bue.Message);
                    if (isConnectionUp)
                    {
                        isConnectionUp = false;
                        CashRegister.Log.Info("Network down");
                        if (OnNetworkDown != null)
                        {
                            OnNetworkDown();
                        }
                    }
                }
                catch (Exception e)
                {
                    cr.Log.Error("{0} on BackgroundWorker", e.GetType().ToString());
                }


                if (isConnectionUp)
                {
                    DisplayAdapter.Instance().LedOn(Leds.Online);
                }
                else
                {
                    DisplayAdapter.Instance().LedOff(Leds.Online);
                    DisplayAdapter.Instance().LedOff(Leds.Order);
                }

                try
                {
                    if (isConnectionUp && cr.DataConnector.CurrentSettings.GetProgramOption(Setting.FastPaymentControl) == PosConfiguration.ON)
                    {
                        orders = DocumentFileHelper.GetOpenOrders();
                    }
                    else if (orders != null)
                    {
                        orders = null;
                    }
                }
                catch (Exception ex)
                {
                    Debugger.Instance().AppendLine("Order Error: " + ex.Message);
                }
                if (orders != null && orders.Length > 0)
                {
                    DisplayAdapter.Instance().LedOn(Leds.Order);

                    if (PosConfiguration.Get("AutoOrderKey") == GetAutoOrderKey())
                    {
                        try
                        {
                            AutoLoadOrders(orders);
                        }
                        catch (Exception ex)
                        {
                            DisplayAdapter.Instance().LedOff(Leds.Order);
                            Debugger.Instance().AppendLine("Order Error: " + ex.Message);
                        }
                    }
                }
                else
                {
                    DisplayAdapter.Instance().LedOff(Leds.Order);
                }

                Thread.Sleep(sleepTime);
                while (cr.State == null)
                {
                    Thread.Sleep(200); //I wish this had a comment
                }
                TimeSpan ts = DateTime.Now - CashRegisterInput.lastKeyPressed;
                if (cr.State.IsIdle && cr.Document.IsEmpty)
                {
                    if (inactivityTimeout > 0 && ts.TotalSeconds > inactivityTimeout)
                    {
                        if (cr.State is States.Start && cr.CurrentCashier != null)
                        {
                            cr.Log.Info("Timeout occurred - logging out cashier id {0}.", cr.CurrentCashier.Id);
                            cr.State = States.Login.Instance();
                        }
                        //if (cr.IsDesktopWindows)
                        //    DisplayAdapter.Customer.ShowAdvertisement();
                        DisplayAdapter.Instance().Inactive = true;
                    }
                    //if (serverRequestQueue.Count == 0 && DisplayAdapter.Instance().Inactive)
                    //{
                    //    if (cr.DataConnector.CurrentSettings.IdleMessage.Length > 0)
                    //        DisplayAdapter.Customer.ShowAdvertisement();
                    //}
                    CheckMessageQueue();
                }
                else if (inactivityTimeout > 0 && ts.TotalSeconds > inactivityTimeout && cr.CurrentCashier != null)
                {
                    cr.Log.Info("Timeout occurred - logging out cashier id {0}.", cr.CurrentCashier.Id);
                    cr.State = States.Login.Instance();
                }
            }
        }