コード例 #1
0
        /// <summary>
        /// Gets the capture image parameters with Json web token credentials.
        /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token.
        /// </summary>
        /// <returns>
        ///  Byte array of image with transaction Id and image extension.
        /// </returns>
        public CaptureDto CaptureImage(Capture model)
        {
            var captureDto = new CaptureDto();

            Log.Information("[HCM][Capture Image][Req]" + "[" + JsonSerializer.Serialize(model) + "]");

            try
            {
                var(statusCode, errorResult) = LockerManagementValidator.PayloadValidator(LockerConfiguration, model.JwtCredentials.IsEnabled, model.JwtCredentials.Secret, model.JwtCredentials.Token, PayloadTypes.CaptureImage, model.LockerId, model.TransactionId, null, CaptureType.Photo);
                if (statusCode != StatusCode.Status200OK)
                {
                    return(CaptureMapper.ToError(new CaptureDto {
                        StatusCode = statusCode, Error = errorResult
                    }));
                }
                var result = LockerHelper.CapturePhoto(model, LockerConfiguration);
                captureDto = CaptureMapper.ToObject(result);
                Log.Information("[HCM][Capture Image][Res]" + "[Success]");
            }
            catch (Exception ex)
            {
                Log.Error("[HCM][Capture Image]" + "[" + ex + "]");
                return(CaptureMapper.ToError(new CaptureDto {
                    StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message)
                }));
            }

            return(captureDto);
        }
コード例 #2
0
        public void RecordRfidPropertyChange(Guid cabinetId, int lockerId, string newProperty)
        {
            var cabinet   = Cabinets.First(c => c.CabinetId == cabinetId);
            var locker    = cabinet.Lockers.First(l => l.LockerId == lockerId);
            var oldStatus = locker.ItemRfid;

            locker.ItemRfid = newProperty;
            Logger.LogMessage($"Update Rfid Status: Cabinet:{cabinet.CabinetId}, Locker:{locker.LockerId}, Old Status:{oldStatus}, New Status:{newProperty}");
            if (LockerHelper.ShouldStartCharging(locker))
            {
                var bill = Bills.First(b => b.CabinetId == cabinetId && b.LockerId == lockerId);
                bill.StartTime = DateTime.Now;
                Logger.LogMessage($"Start Timing: Bill Id: {bill.BillId},Start Time:{bill.StartTime}");
            }
        }
コード例 #3
0
        public void RecordGatePropertyChange(Guid cabinetId, int lockerId, bool newProperty)
        {
            var cabinet   = Cabinets.First(c => c.CabinetId == cabinetId);
            var locker    = cabinet.Lockers.First(l => l.LockerId == lockerId);
            var oldStatus = locker.GateOpened == true ? "Opened" : "Closed";

            locker.GateOpened = newProperty;
            var newStatus = newProperty == true ? "Opened" : "Closed";

            Logger.LogMessage($"Update Gate Status: Cabinet:{cabinet.CabinetId}, Locker:{locker.LockerId}, Old Status:{oldStatus}, New Status:{newStatus}");
            if (LockerHelper.ShouldStopCharging(locker))
            {
                var bill = Bills.First(b => b.CabinetId == cabinetId && b.LockerId == lockerId);
                bill.EndTime = DateTime.Now;
                bill.Cost    = 100;
                Logger.LogMessage($"Stop Timing: Bill Id: {bill.BillId},Start Time:{bill.StartTime}, End Time:{bill.EndTime}");
            }
        }
コード例 #4
0
        public Guid GetAvailableItemLocker(Guid cabinetId, string userId, Guid itemType, string TradeId)
        {
            var targetCabinet  = Cabinets.First(c => c.CabinetId == cabinetId);
            var targetCategory = targetCabinet.Categories.First(cat => cat.ItemType == itemType);

            if (targetCategory == null)
            {
                Logger.LogWarning($"No Available Category When Borrow, Cabinet Id :{targetCabinet.CabinetId}, Expect Item Type:{itemType}");
                return(new Guid());
            }
            var expectedAmount = targetCategory.Deposit;

            var paidAmount = BankHelper.CheckStatusAndAmount(TradeId);

            if (expectedAmount == paidAmount)
            {
                var lockerid = targetCabinet.Lockers.First(l => LockerHelper.IsLockerAvailable(l)).LockerId;
                targetCategory.AvailableLocker.Remove(lockerid);
                targetCategory.AvailableItem--;

                var id = Guid.NewGuid();
                Logger.LogMessage($"Assigned Locker:Cabinet Id :{cabinetId}, Locker Id:{lockerid}, Generated Bill:{id}");
                Bills.Add(new HiBoxBill()
                {
                    BillId      = id,
                    BillType    = Constants.BillType.Deposit,
                    CabinetId   = cabinetId,
                    DisplayName = targetCategory.DisplayName,
                    UserId      = userId,
                    ItemType    = itemType,
                    LockerId    = lockerid,
                    Rent        = targetCategory.Rent
                });

                Console.WriteLine("Opening Gate" + lockerid);
                return(id);
            }
            else
            {
                return(new Guid());
            }
        }
コード例 #5
0
 /// <summary>
 ///   Initialization information for locker configuration including Microcontroller board, Serial port and Communication port.
 ///</summary>
 public LockerManager(string configurationFilePath)
 {
     LockerConfiguration = LockerHelper.GetConfiguration(configurationFilePath);
     PortsHealthCheck    = LockerHelper.ComPortTest(LockerConfiguration);
     Log.Information("[HCM][Locker Manager][Initiated][Service initiated with scanner and logging.]");
 }