public void SubscribeVehicle(System.Action <ClientVehicleDTO, ModificationTypeDTO> callBack) { var subscription = new ObjectModificationSubscription(); subscription.ObjectType = "Vehicle"; _eventSubscriptionWrapper.ObjectModificationSubscription = subscription; SubscribeEventRequest requestEvent = new SubscribeEventRequest(); requestEvent.ClientId = _connectionService.ClientId; requestEvent.Subscription = _eventSubscriptionWrapper; var responce = _connectionService.Submit <SubscribeEventResponse>(requestEvent); if (responce.Exception != null) { logger.Error(responce.Exception); throw new Exception("Failed to subscribe on vehicle modifications. Try again or see log for more details."); } var subscribeEventResponse = responce.Value; SubscriptionToken st = new SubscriptionToken(subscribeEventResponse.SubscriptionId, _getObjectNotificationHandler <Vehicle>( (token, vehicleId, vehicle) => { if (token == ModificationType.MT_UPDATE || token == ModificationType.MT_CREATE) { var newCvd = new ClientVehicleDTO() { VehicleId = vehicle.Id, Name = vehicle.Name, TailNumber = vehicle.SerialNumber }; _messageReceived(callBack, newCvd, ModificationTypeDTO.UPDATED); } else { var newCvd = new ClientVehicleDTO() { VehicleId = vehicleId, Name = string.Empty, TailNumber = string.Empty }; _messageReceived(callBack, newCvd, ModificationTypeDTO.DELETED); } }), _eventSubscriptionWrapper); _connectionService.NotificationListener.AddSubscription(st); tokens.Add(st); }
private void refreshVehicle(ClientVehicleDTO vehicle, ModificationTypeDTO mtd) { bool update = false; if (!_vehicles.ContainsKey(vehicle.VehicleId)) { update = true; } _vehicles.AddOrUpdate(vehicle.VehicleId, vehicle, (key, oldValue) => { if (vehicle.Name != oldValue.Name) { update = true; } return(vehicle); }); if (update && OnVehicleUpdated != null) { OnVehicleUpdated(vehicle); } }
private void _messageReceived(System.Action <ClientVehicleDTO, ModificationTypeDTO> callback, ClientVehicleDTO vehicle, ModificationTypeDTO mtd) { callback(vehicle, mtd); }