public void publish_vehicle_signal_transactions_to_rabbitmq() { // PingVehicleInQueue pushes signals data to the queue. var vehiclesSignalData = _contextRepo.PingVehicleInQueue(_contextRepo.GenerateSignal()); Assert.IsNotNull(vehiclesSignalData); }
/// <summary> /// Sends checking signal to Customer's vehicle and enqueue the result using RabbitMQ. /// </summary> /// <param name="cid">Customer Id</param> public List <VehicleTransModel> PingVehiclesInQueue(int cid) { try { var vehicleTransList = new List <VehicleTransModel>(); // 1- ping vehicles of this customer/all and get signal statuses back. var vehiclesSignalStatuses = cid != 0 ? _vehicleContextRepo.GetAll().Where(v => v.CustomerId != null && v.CustomerId == cid) : _vehicleContextRepo.GetAll().Where(v => v.CustomerId != null); // 2- post to DB. foreach (var v in vehiclesSignalStatuses) { var vse = _genericsConnectionStatusRepo.GenerateSignal(); _genericsVehicleTransDbContextRepo.Add(new VehicleStatusTrans { PingTime = DateTime.Now, Status = vse.ToString(), VehicleId = v.Id }); _genericsVehicleTransDbContextRepo.SaveChanges(); vehicleTransList.Add(new VehicleTransModel { VehicleId = v.Id, VehicleCode = v.Code, VehicleRegistrationNumber = v.RegNumber, CustomerId = v.CustomerId, CustomerName = _genericsCustomerDbContextRepo.Find(v.CustomerId).Name, Status = vse.ToString() }); } // Publish list to EventBus queue. _serviceBusQueue.Publish("Customer_VehicleStatusTrans", vehicleTransList); return(vehicleTransList); } catch (NullReferenceException nullExp) { _logger.Log(LogLevel.Error, nullExp.Message, nullExp.Source); throw; } catch (ObjectDisposedException objectDisponseExp) { _logger.Log(LogLevel.Error, objectDisponseExp.Message, objectDisponseExp.Source); throw; } catch (NotSupportedException notSuppExp) { _logger.Log(LogLevel.Error, notSuppExp.Message, notSuppExp.Source); throw; } catch (Exception exp) { _logger.Log(LogLevel.Error, exp.Message, exp.Source); throw; } }