コード例 #1
0
        public void SubscribeTelemtry(Action <int, TelemetryKey, TelemetryValue> cb)
        {
            _tlmCallBack = cb;
            _eventSubscriptionWrapper.TelemetryBatchSubscription = new TelemetryBatchSubscription()
            {
                PollingPeriodMilliseconds          = POLLING_INTERVAL,
                PollingPeriodMillisecondsSpecified = true
            };

            SubscribeEventRequest requestEvent = new SubscribeEventRequest
            {
                ClientId = _connectionService.GetClientId(),

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

            if (responce.Exception != null)
            {
                throw responce.Exception;
            }
            if (responce.Value == null)
            {
                throw new InvalidOperationException("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, Enums.ModificationType> callBack)
        {
            var subscription = new ObjectModificationSubscription
            {
                ObjectType = "Vehicle"
            };

            _eventSubscriptionWrapper.ObjectModificationSubscription = subscription;

            SubscribeEventRequest requestEvent = new SubscribeEventRequest
            {
                ClientId = _connectionService.GetClientId(),

                Subscription = _eventSubscriptionWrapper
            };

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

            if (responce.Exception != null)
            {
                logger.Error(responce.Exception);
                throw new InvalidOperationException("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 == Sdk.Protocol.Encoding.ModificationType.MT_UPDATE || token == Sdk.Protocol.Encoding.ModificationType.MT_CREATE)
                {
                    var newCvd = new ClientVehicleDto()
                    {
                        VehicleId = vehicle.Id,
                        Name      = vehicle.Name
                    };
                    messageReceived(callBack, newCvd, Enums.ModificationType.UPDATED);
                }
                else
                {
                    var newCvd = new ClientVehicleDto()
                    {
                        VehicleId = vehicleId,
                        Name      = string.Empty
                    };
                    messageReceived(callBack, newCvd, Enums.ModificationType.DELETED);
                }
            }), _eventSubscriptionWrapper);

            _connectionService.NotificationListener.AddSubscription(st);
            tokens.Add(st);
        }