Exemplo n.º 1
0
        // Message recieved and process it to save in database
        internal static void Terminal_MessageRecieved(MessageReceivedEventArgs MessageArgs)
        {
            DAL.BMDevice.TADataReceiverDAL DataReceiverDALObj = new DAL.BMDevice.TADataReceiverDAL();
            var res = DataReceiverDALObj.SaveEmployeeAttendanceDetail(MessageArgs.Message);

            if (res != null && res.ExecutionResult == Model.eExecutionResult.CommitedSucessfuly)
            {
                MessageArgs.ProcessAcknowledgement = true;
                frmLogStatus.LogMessage(new Model.BMDevice.LogViewModel(MessageArgs.Message)
                {
                    LogMessage = "Saved." + (!String.IsNullOrWhiteSpace(res.MessageAfterSave) ? ": " + res.MessageAfterSave : "")
                });
                if (!String.IsNullOrWhiteSpace(res.MessageAfterSave))
                {
                    DataReceiverDALObj.SaveDataReceiverErrorLog("Save with Validation Error", res.MessageAfterSave);

                    Program.NotifyApplicationIcon.ApplicationIcon.ShowBalloonTip(10000, "Saved with Validation Error", res.MessageAfterSave, System.Windows.Forms.ToolTipIcon.Warning);
                }
            }
            else
            {
                string ErrorMessage = (res != null ?
                                       (res.ExecutionResult == Model.eExecutionResult.ErrorWhileExecuting ?
                                        (res.Exception != null ? res.Exception.Message : "") :
                                        (res.ExecutionResult == Model.eExecutionResult.ValidationError ? res.ValidationError : "")) : "");

                frmLogStatus.LogMessage(new Model.BMDevice.LogViewModel(MessageArgs.Message)
                {
                    LogMessage = "Error while saving : " + ErrorMessage,
                });

                DataReceiverDALObj.SaveDataReceiverErrorLog("Error while saving attendance data", ErrorMessage);

                if (!String.IsNullOrWhiteSpace(ErrorMessage))
                {
                    Program.NotifyApplicationIcon.ApplicationIcon.ShowBalloonTip(10000, "Vision : Error while saving attendance.", ErrorMessage, System.Windows.Forms.ToolTipIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        public static void OnReceive(IAsyncResult iar)
        {
            Terminal term = (Terminal)iar.AsyncState;

            if (term == null)
            {
                return;
            }
            int rcv;

            try
            {
                if (term == null)
                {
                    return;
                }
                try
                {
                    rcv = term.stream.EndRead(iar);
                }
                catch (ObjectDisposedException)
                {
                    return;
                }
                if (rcv <= 0)
                {
                    return;
                    //throw new Exception("connection closed");
                }

                if (term == null)
                {
                    return;
                }
                // Accumulate message
                Array.Copy(term.message, 0,
                           term.messageAccumulated, term.messageAccumulatedLen, rcv);
                term.messageAccumulatedLen += rcv;

                while (term.messageAccumulatedLen > 0)
                {
                    if (term == null)
                    {
                        return;
                    }
                    int consumed;

                    // Process stream
                    if (!term.ProcStream(out consumed))
                    {
                        throw new Exception("handle failed");
                    }

                    // Trim consumed stream
                    if (consumed > 0)
                    {
                        term.messageAccumulatedLen -= consumed;
                        Array.Copy(term.messageAccumulated,
                                   consumed, term.messageAccumulated,
                                   0, term.messageAccumulatedLen);
                    }
                    else
                    {
                        break;
                    }
                }
                if (term == null)
                {
                    return;
                }
                // Restart alive timer
                term.RestartAliveTimer();
                if (term == null)
                {
                    return;
                }
                term.stream.BeginRead(term.message, 0, MaxMessageSize,
                                      new AsyncCallback(Terminal.OnReceive), term);
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                ex = DAL.CommonFunctions.GetFinalError(ex);

                DAL.BMDevice.TADataReceiverDAL DALObj = new DAL.BMDevice.TADataReceiverDAL();
                DALObj.SaveDataReceiverErrorLog((term != null ? term.RawMessage : null), ex.Message);

                frmLogStatus.LogMessage(new Model.BMDevice.LogViewModel()
                {
                    LogMessage = "Error while processing recieved data.\r\n" + ex.Message
                });

                if (Program.NotifyApplicationIcon != null && Program.NotifyApplicationIcon.ApplicationIcon != null)
                {
                    Program.NotifyApplicationIcon.ApplicationIcon.ShowBalloonTip(10000, "Vision : Error while processing recieved data.", ex.Message, System.Windows.Forms.ToolTipIcon.Error);
                }

                term.Dispose();
            }
        }