Пример #1
0
        public void SubscribeTelemtry(Action <int, bool> downlinkCallback)
        {
            _downlinkCb = downlinkCallback;
            _eventSubscriptionWrapper.TelemetryBatchSubscription = new TelemetryBatchSubscription()
            {
                PollingPeriodMilliseconds          = POLLING_INTERVAL,
                PollingPeriodMillisecondsSpecified = true
            };

            SubscribeEventRequest requestEvent = new SubscribeEventRequest();

            requestEvent.ClientId = _connectionService.ClientId;

            requestEvent.Subscription = _eventSubscriptionWrapper;
            var responce = _connectionService.Submit <SubscribeEventResponse>(requestEvent);

            if (responce.Exception != null)
            {
                throw responce.Exception;
            }
            if (responce.Value == null)
            {
                throw new System.Exception("Server return empty response on SubscribeTelemtry event");
            }
            var subscribeEventResponse = responce.Value;

            SubscriptionToken st = new SubscriptionToken(subscribeEventResponse.SubscriptionId, _getTelemetryNotificationHandler(
                                                             (telemetry) =>
            {
                _onTelemetryBatchReceived(telemetry);
            }), _eventSubscriptionWrapper);

            _connectionService.NotificationListener.AddSubscription(st);
        }
Пример #2
0
        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);
        }