public void ProcessStatusUpdate(IParkingSpotStatusUpdate parkingSpotStatusUpdate)
        {
            logger.LogInformation("BEGIN ProcessStatusUpdate");
            this.carparkProvider.ProcessStatusUpdate(parkingSpotStatusUpdate);
            Carpark carpark = this.carparkProvider.GetCarparkByName(parkingSpotStatusUpdate.Location);

            if (carpark == null)
            {
                logger.LogError($"No carpark found for {parkingSpotStatusUpdate.Location}");
                return;
            }

            ISpotUpdate spotUpdate = new SpotUpdateImpl()
            {
                CarparkId = carpark.Id,
                SpotId    = parkingSpotStatusUpdate.SpotId,
                Status    = parkingSpotStatusUpdate.Available ? SpotStatus.Available : SpotStatus.Unavailable,
                UpdatedOn = parkingSpotStatusUpdate.Timestamp,
                Source    = MessageSource.MessageBus
            };

            ProcessUpdate(spotUpdate);

            logger.LogInformation("END ProcessStatusUpdate");
        }
Ejemplo n.º 2
0
        private async Task UpdateSpotStatus(IParkingSpotStatusUpdate message)
        {
            var entity = new ParkingSpotStatusUpdateEntity(message.SpotId, message.Location, message.Timestamp);

            var insertOperation = TableOperation.InsertOrReplace(entity);

            await _heartbeats.ExecuteAsync(insertOperation);
        }
        public void ProcessStatusUpdate(IParkingSpotStatusUpdate parkingSpotStatusUpdate)
        {
            Carpark carpark = GetCarparkByName(parkingSpotStatusUpdate.Location);

            if (carpark != null)
            {
                carpark.SpotData[parkingSpotStatusUpdate.SpotId] = new ParkingSpotImpl
                {
                    SpotId      = parkingSpotStatusUpdate.SpotId,
                    LastUpdated = DateTime.Now,
                    SpotStatus  = parkingSpotStatusUpdate.Available ? SpotStatus.Available : SpotStatus.Unavailable
                };
            }
        }
        public async Task Store(IParkingSpotStatusUpdate parkingSpotStatusUpdate)
        {
            // Create a new customer entity.
            ParkingSpotMessage parkingSpot = new ParkingSpotMessage(parkingSpotStatusUpdate.SpotId, parkingSpotStatusUpdate.Location);

            parkingSpot.SpotId         = parkingSpotStatusUpdate.SpotId;
            parkingSpot.Timestamp      = parkingSpotStatusUpdate.Timestamp;
            parkingSpot.Available      = parkingSpotStatusUpdate.Available;
            parkingSpot.MetaData       = parkingSpotStatusUpdate.MetaData;
            parkingSpot.MetaDataString = JsonConvert.SerializeObject(parkingSpotStatusUpdate.MetaData);

            // Create the TableOperation object that inserts the customer entity.
            TableOperation insertOperation = TableOperation.Insert(parkingSpot);

            // Execute the insert operation.
            await _messageTable.ExecuteAsync(insertOperation);
        }
        public async Task <string> Store(IParkingSpotStatusUpdate update)
        {
            var fileName = $"{update.Timestamp.Ticks}-{Guid.NewGuid()}.json";

            _logger.LogInformation($"Uploading {fileName}");

            try
            {
                var            json           = JsonConvert.SerializeObject(update);
                CloudBlockBlob cloudBlockBlob = _cloudBlobContainer.GetBlockBlobReference(fileName);

                await cloudBlockBlob.UploadTextAsync(json);

                _logger.LogInformation($"Uploaded {fileName} @ {cloudBlockBlob.Uri}");

                return(cloudBlockBlob.Uri.ToString());
            }
            catch (Exception exception)
            {
                _logger.LogError($"Uploading {fileName} failed.", exception);
                return(string.Empty);
            }
        }
Ejemplo n.º 6
0
 public async Task Store(IParkingSpotStatusUpdate message)
 {
     await UpdateSpotStatus(message);
 }
        public async Task <string> Process(IParkingSpotStatusUpdate update)
        {
            _logger.LogInformation($"Processing spot {update.SpotId}.");

            return(await _repository.Store(update));
        }
 public async Task Process(IParkingSpotStatusUpdate update)
 {
     await _repository.Store(update);
 }