Example #1
0
        private NotificationHandler _getObjectNotificationHandler <T>(ObjectChangeSubscriptionCallback <T> callback) where T : class, IIdentifiable
        {
            string invariantName = InvariantNames.GetInvariantName <T>();

            return(notification =>
            {
                ObjectModificationEvent @event = notification.Event.ObjectModificationEvent;

                callback(@event.ModificationType, @event.ObjectId,
                         @event.ModificationType == ModificationType.MT_DELETE ?
                         null : (T)@event.Object.Get(invariantName));
            });
        }
Example #2
0
        private Vehicle getVehicleById(int id)
        {
            var getVehicleResp = _connectionService.Execute <GetObjectResponse>(
                new GetObjectRequest
            {
                ClientId   = _connectionService.GetClientId(),
                ObjectType = InvariantNames.GetInvariantName <Vehicle>(),
                ObjectId   = id
            });

            var vehicle = getVehicleResp.Object?.Vehicle;

            return(vehicle);
        }
Example #3
0
        /// <summary>
        /// Create subscribtion to change the selected vehicle
        /// </summary>
        /// <param name="handler">Handler for new vehicle tail number</param>
        /// <returns>Returns subscription id or null if error is raised</returns>
        public int SubscribeSelectedVehicleChange(System.Action <ClientVehicleDto> handler)
        {
            //get selected vehicle id from mission preferences
            ObjectModificationSubscription missionPrefSubscription = new ObjectModificationSubscription
            {
                ObjectType = InvariantNames.GetInvariantName <MissionPreference>()
            };

            EventSubscriptionWrapper subscriptionWrapper = new EventSubscriptionWrapper
            {
                ObjectModificationSubscription = missionPrefSubscription
            };

            var response = _connectionService.Execute <SubscribeEventResponse>(
                new SubscribeEventRequest()
            {
                ClientId     = _connectionService.GetClientId(),
                Subscription = subscriptionWrapper,
            });

            _connectionService.NotificationListener.AddSubscription(new SubscriptionToken(response.SubscriptionId,
                                                                                          (notif) =>
            {
                var prefs = notif.Event.ObjectModificationEvent.Object.MissionPreference;
                if (prefs.Name.Equals(PREF_NAME))
                {
                    int?id = missionPreferenceToVehicleId(prefs, _connectionService.GetUser().Id);
                    if (id != null)
                    {
                        var v = getVehicleById(id.Value);
                        if (v != null)
                        {
                            handler(new ClientVehicleDto()
                            {
                                Name      = v.Name,
                                VehicleId = v.Id
                            });
                            return;
                        }
                    }
                    handler(null);
                }
            },
                                                                                          subscriptionWrapper));
            return(response.SubscriptionId);
        }
Example #4
0
        private string getVehicleTailNumberById(int id)
        {
            var getVehicleResp = _connectionService.Execute <GetObjectResponse>(
                new GetObjectRequest
            {
                ClientId   = _connectionService.ClientId,
                ObjectType = InvariantNames.GetInvariantName <Vehicle>(),
                ObjectId   = id
            });


            var vehicle = getVehicleResp.Object?.Vehicle;

            if (vehicle != null)
            {
                return(getTailNumberFromVehicle(vehicle));
            }
            return(null);
        }
Example #5
0
        /// <summary>
        /// Create subscribtion to change the selected vehicle
        /// </summary>
        /// <param name="handler">Handler for new vehicle tail number</param>
        /// <returns>Returns subscription id or null if error is raised</returns>
        public int SubscribeSelectedVehicleChange(System.Action <string> handler)
        {
            //get selected vehicle id from mission preferences
            int result = 0;
            ObjectModificationSubscription missionPrefSubscription = new ObjectModificationSubscription();

            missionPrefSubscription.ObjectType = InvariantNames.GetInvariantName <MissionPreference>();

            EventSubscriptionWrapper subscriptionWrapper = new EventSubscriptionWrapper();

            subscriptionWrapper.ObjectModificationSubscription = missionPrefSubscription;

            var response = _connectionService.Execute <SubscribeEventResponse>(
                new SubscribeEventRequest()
            {
                ClientId     = _connectionService.ClientId,
                Subscription = subscriptionWrapper,
            });

            result = response.SubscriptionId;
            _connectionService.NotificationListener.AddSubscription(new SubscriptionToken(response.SubscriptionId,
                                                                                          (notif) =>
            {
                var prefs = notif.Event.ObjectModificationEvent.Object.MissionPreference;
                int?id    = missionPreferenceToVehicleId(prefs, _connectionService.User.Id);
                if (id != null)
                {
                    string tailNum = getVehicleTailNumberById(id.Value);
                    if (tailNum != null)
                    {
                        handler(tailNum);
                    }
                }
            },
                                                                                          subscriptionWrapper));
            return(response.SubscriptionId);
        }