Beispiel #1
0
        public async Task <bool> ProcessEvent(byte[] data)
        {
            string jsonEvent = Encoding.UTF8.GetString(data);

            LockActivityCheck lockActivityCheck = JsonConvert.DeserializeObject <LockActivityCheck>(jsonEvent);

            return(await LockEventProcessHandler.Invoke(lockActivityCheck));
        }
Beispiel #2
0
        private async Task <bool> ProcessEvent(object lockEventpbj)
        {
            try
            {
                LockEvent      lockEvent      = (LockEvent)lockEventpbj;
                LockDeviceBson lockDeviceBson = new LockDeviceBson()
                {
                    IsActive       = true,
                    LastActiveTime = lockEvent.EventTime.ToDateTime(),
                    LockDeviceId   = lockEvent.LockDeviceId
                };

                await MongoDriver.MongoDbRepo.UpsertLockDeviceBson(lockDeviceBson);

                LockEventBson lockEventBson = new LockEventBson()
                {
                    DeviceEvent            = lockEvent.DeviceEvent,
                    EventTime              = lockEvent.EventTime.ToDateTime(),
                    LockDeviceBson         = lockDeviceBson,
                    RequestReferenceNumber = lockEvent.RequestReferenceNumber
                };
                await MongoDriver.MongoDbRepo.InsertLockEventBson(lockEventBson);

                if (lockEvent.DeviceEvent == LockEvent.Types.DeviceEventEnum.Open)
                {
                    //publish a msg for another queu to set lock to passive if spesified amount time is passed since last event
                    LockActivityCheck lockActivityCheck = new LockActivityCheck();
                    lockActivityCheck.LockDeviceId = lockDeviceBson.LockDeviceId;
                    lockActivityCheck.EventDate    = lockEventBson.EventTime;
                    string lockActivityCheckJson = JsonConvert.SerializeObject(lockActivityCheck);
                    byte[] binaryObject          = Encoding.UTF8.GetBytes(lockActivityCheckJson);
                    checkEventMqBroker.DelayedQueu($"Activity check event {lockDeviceBson.LockDeviceId}", binaryObject, 30 * 1000);
                }



                Console.WriteLine($"Event processed to be processed {lockEvent}");
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"err {e}");
            }
            return(false);
        }
Beispiel #3
0
        private async Task <bool> CheckEvent(object lockActivityCheckEventobj)
        {
            try
            {
                LockActivityCheck lockActivityCheckEvent = (LockActivityCheck)lockActivityCheckEventobj;
                //check if there is newer activity if no deactivate device
                var events = await MongoDriver.MongoDbRepo.GetLockEventBsonsByField("lockDevice.lockDeviceId", lockActivityCheckEvent.LockDeviceId);

                var lastEvent = events.OrderByDescending(a => a.EventTime).FirstOrDefault();
                if (lastEvent != null && lastEvent.EventTime <= lockActivityCheckEvent.EventDate)
                {
                    var lockDeviceList = await MongoDriver.MongoDbRepo.GetLockDeviceBsonsByField("lockDeviceId", lockActivityCheckEvent.LockDeviceId);

                    var lockDevice = lockDeviceList.FirstOrDefault();
                    if (lockDevice != null)
                    {
                        lockDevice.IsActive = false;
                        await MongoDriver.MongoDbRepo.UpsertLockDeviceBson(lockDevice);
                    }
                    else
                    {
                        //todo some error reportng
                    }
                }
                else
                {
                    //a newer event processed discard this check
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Activity check error for lockActivityCheckEvent, {e}");
            }

            return(false);
        }