示例#1
0
        public void Handle(EventMessage message)
        {
            if (message == null)
            {
                return;
            }

            var attendanceLog = JsonConvert.DeserializeObject <AttendanceLog>(message.Content);

            // Check attendance log.
            if (!EnsureUniqueAttendanceLog(attendanceLog))
            {
                _logger.InfoFormat("SyncToWebHandler:attendance log (id:{id}) exists", attendanceLog.Id);
                return;
            }

            // Check worker.
            var workerId = EnsureCurrentWorker(attendanceLog);

            if (string.Empty == workerId)
            {
                _logger.InfoFormat("SyncToWebHandler:No map between {workerId} and {enrollNumber}", workerId, attendanceLog.UserId);
                return;
            }

            switch (attendanceLog.DeviceType)
            {
            case DeviceType.In:
                EnsureCheckIn(attendanceLog, workerId);
                break;

            case DeviceType.Out:
                EnsureCheckOut(attendanceLog, workerId);
                break;

            case DeviceType.InOut:
                EnsureCheckInOrCheckOut(attendanceLog, workerId);
                break;

            default:
                _logger.ErrorFormat("Not support device type:{@attendance}", attendanceLog);
                break;
            }

            _db.Dequeue(message.Id);
        }