示例#1
0
        public bool WaitSealingCompleted(out SealingCompleteMessage sealingResult, int timeout = Timeout.Infinite)
        {
            //   Log.Info("WaitSealingCompleted");
            ManualResetEvent[]      waitHandle       = new ManualResetEvent[] { new ManualResetEvent(false), new ManualResetEvent(false) };
            SealingCompleteMessage  completeResponse = null;
            SealingErrorMessage     errorResponse    = null;
            SealingCompleteReceived completeAction   = delegate(SealingCompleteMessage msg) {
                completeResponse = msg;
                waitHandle[0].Set();
            };
            SealingErrorReceived errorAction = delegate(SealingErrorMessage msg) {
                errorResponse = msg;
                waitHandle[1].Set();
            };

            try {
                SealingCompleteEvent += completeAction;
                SealingErrorEvent    += errorAction;
                int result = EventWaitHandle.WaitAny(waitHandle, timeout);
                if (result == 0)
                {
                    sealingResult = completeResponse;
                    Log.Info("WaitSealingComplete;{0}", completeResponse);
                    return(true);
                }
                else if (result == 1)
                {
                    Log.Warn("WaitSealingComplete;{0}", errorResponse);
                    throw new SealingErrorException(errorResponse.ErrorCode, errorResponse.ProgramNumber, errorResponse.SelectedSealerBar);
                }
                else
                {
                    sealingResult = null;
                    Log.Warn("WaitSealingComplete;Timeout");
                    return(false);
                }
            } catch (Exception ex) {
                Log.Error("WaitSealingComplete;Exception:{0}", ex.ToString());
                LastException = ex;
                throw;
            } finally {
                SealingCompleteEvent -= completeAction;
                SealingErrorEvent    -= errorAction;
            }
        }
示例#2
0
        public bool IsSeallerError()
        {
            SealingErrorMessage  errorResponse = null;
            SealingErrorReceived errorAction   = delegate(SealingErrorMessage msg) {
                errorResponse = msg;
            };

            try
            {
                if (errorResponse != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }