private void SetSubscription(string callbackEndpoint, string uvid, Identity identity,
                                     Common.Services.Internal.Interfaces.Notification notification, List <KeyValuePair <string, string> > paramList)
        {
            VisSubscription newSub = new VisSubscription();

            newSub.CallbackEndpoint          = callbackEndpoint;
            newSub.MessageID                 = uvid;
            newSub.MessageType               = _messageTypeService.Get(x => x.Name.ToLower() == "rtz").First();
            newSub.SubscriberIdentity        = identity;
            newSub.TimeOfSubscriptionRequest = DateTime.UtcNow;
            newSub.IsAuthorized              = true;
            _subscriptionService.Insert(newSub);

            // Send message to new subscriber
            var message = _publishedMessageService.Get(x => x.MessageID == uvid).FirstOrDefault();

            if (message != null)
            {
                _publishedMessageService.SendMessage(System.Text.Encoding.Default.GetString(message.Message),
                                                     uvid, newSub.CallbackEndpoint,
                                                     new Identity {
                    Name = identity.Name, UID = identity.UID
                });
            }

            // Save to DB
            _context.SaveChanges();

            _logEventService.LogSuccess(EventNumber.VIS_subscribeToVoyagePlan_response, EventDataType.Other,
                                        paramList,
                                        newSub.MessageID);
        }
Esempio n. 2
0
        private VisSubscription ConvertToEntity(SubscriptionObject subscriptionObject, string dataId)
        {
            var to = new VisSubscription();

            to.MessageID          = dataId;
            to.IsAuthorized       = true;
            to.CallbackEndpoint   = subscriptionObject.EndpointURL.ToString();
            to.MessageType        = _messageTypeService.Get(x => x.Name.ToLower() == "rtz").FirstOrDefault();
            to.SubscriberIdentity = _identityService.Get(x => x.UID == subscriptionObject.IdentityId).FirstOrDefault();
            return(to);
        }