Beispiel #1
0
        protected override void PreProcess()
        {
            try
            {
                lastKeyPressed = DateTime.Now;
                KeyMap.Load();
                Debugger.Instance().AppendLine("Started Display: " + DateTime.Now.ToLongTimeString());

                DisplayAdapter.Instance();
                DisplayAdapter.Both.Show(PosMessage.PLEASE_WAIT);
                Application.DoEvents();
                Debugger.Instance().AppendLine("Finished Display" + DateTime.Now.ToLongTimeString());

                if (PosConfiguration.Get("BarcodeComPort") != "")
                {
                    ConnectBarcode();
                }

                //Console.CancelKeyPress += new ConsoleCancelEventHandler(pos_OnClosed);

                CashRegister.Instance();
                CashRegister.Printer.DateTimeChanged += new EventHandler(Printer_DateTimeChanged);

                Debugger.Instance().AppendLine("Started BackgroundWorker: " + DateTime.Now.ToLongTimeString());
                Thread thread = new Thread(new ThreadStart(BackgroundWorker.Start));
                thread.Name         = "BackgroundWorker";
                thread.IsBackground = true;
                thread.Priority     = ThreadPriority.BelowNormal;
                thread.Start();
            }
            catch (UnauthorizedAccessException ex)
            {
                throw ex;
            }
        }
Beispiel #2
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
                }
            }
        }
        private static void CheckMessageQueue()
        {
            while (serverRequestQueue.Count > 0)
            {
                System.Threading.Thread nThread = new Thread(new ThreadStart(BlinkLed));
                blinkOn = true;
                nThread.Start();

                IState currentState = cr.State;
                cr.State = WaitingState.Instance();
                try
                {
                    String request = serverRequestQueue.Dequeue();

                    cr.DataConnector.SendWaitingMessage("Ýþleminiz yapýlýyor...");

                    if (!DisplayAdapter.Cashier.Inactive)
                    {
                        DisplayAdapter.Cashier.Show("ARKA OFÝS\nÝÞLEMÝ YAPILIYOR...");
                    }

                    int success = cr.DataConnector.ProcessRequest(request);

                    if (success == 0)//Data.dll is not responsible for request
                    {
                        String failResponse = String.Empty;
                        success = -1;
                        try
                        {
                            ProcessServerRequest(request);
                            success = 1;
                        }
                        catch (PowerFailureException pfe)
                        {
                            try  { Recover.RecoverPowerFailure(pfe); }
                            catch { };
                            Error err = new Error(pfe);
                            failResponse = err.Message.Replace('\n', '·');
                        }
                        catch (LimitExceededOrZRequiredException le)
                        {
                            cr.Log.Warning(le);
                            failResponse = PosMessage.LOGO_DEPARTMENT_CHANGE_Z_REPORT_REQUIRED.Replace('\n', '·');
                        }
                        catch (Exception ex)
                        {
                            Error err = new Error(ex);
                            failResponse = err.Message.Replace('\n', '·');
                        }

                        try
                        {
                            //1 : success, -1 fail
                            if (success == 1)
                            {
                                cr.DataConnector.SendMessage(true, "ÝÞLEM BAÞARIYLA TAMAMLANMIÞTIR.");
                                cr.Log.Success("Office request \"{0}\" completed", request.TrimEnd('0', '\n', '\r'));
                            }
                            else
                            {
                                cr.DataConnector.SendMessage(false, failResponse);
                                cr.Log.Error("Office request \"{0}\" failed: {1}", request.TrimEnd('0', '\n', '\r'), failResponse);
                            }
                        }
                        catch { }
                    }
                    if (!DisplayAdapter.Instance().Inactive)
                    {
                        if (success == -1)
                        {
                            DisplayAdapter.Cashier.Show("ARKA OFÝS ÝÞLEMÝ\nBAÞARISIZ OLDU!..");
                        }
                        else
                        {
                            DisplayAdapter.Cashier.Show("ARKA OFÝS ÝÞLEMÝ\nBAÞARIYLA TAMAMLANDI");
                        }
                    }
                }
                finally
                {
                    if (!(cr.State is ElectronicJournalError))
                    {
                        if (cr.State is States.Login)
                        {
                            currentState = States.Login.Instance();
                        }
                        else
                        {
                            cr.State = States.Start.Instance();
                        }
                        if (!(currentState is WaitingState))
                        {
                            cr.State = currentState;
                        }
                    }
                }
            }
            blinkOn = false;
        }
Beispiel #4
0
        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();
                }
            }
        }