public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

            if (sessionViewModel == null)
            {
                throw new ArgumentNullException("sessionViewModel");
            }

            var message = envelopeViewModel.Envelope as Message;

            if (message != null &&
                message.Id != Guid.Empty)
            {
                var notification = new Notification()
                {
                    Id = message.Id,
                    To = message.From,
                    Event = Event.Consumed
                };

                var notificationEnvelopeViewModel = new EnvelopeViewModel()
                {
                    Envelope = notification
                };

                sessionViewModel.InputJson = notificationEnvelopeViewModel.Json;
                
                if (sessionViewModel.SendCommand.CanExecute(null))
                {
                    await sessionViewModel.SendCommand.ExecuteAsync(null);
                }
            }
        }
Esempio n. 2
0
 private void ProcessNotification(Notification notification)
 {
     foreach (var contactViewModel in Contacts)
     {
         if (contactViewModel.Conversation != null)
         {                    
             contactViewModel.Conversation.ReceiveNotification(notification);                    
         }
     }         
 }
Esempio n. 3
0
        private async Task ReceiveMessagesAsync(IChannel channel, CancellationToken cancellationToken)
        {
            while (channel.State == SessionState.Established)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var message = await channel.ReceiveMessageAsync(cancellationToken);

                IDictionary<string, Guid> instanceSessionDictionary;

                if (message.To == null)
                {
                    var notification = new Notification()
                    {
                        Id = message.Id,
                        Event = Event.Failed,
                        Reason = new Reason()
                        {
                            Code = ReasonCodes.VALIDATION_INVALID_RECIPIENTS,
                            Description = "Invalid destination"
                        }
                    };

                    await channel.SendNotificationAsync(notification);
                }
                else if (!_identityInstanceSessionIdDictionary.TryGetValue(message.To.ToIdentity(), out instanceSessionDictionary) ||
                         !instanceSessionDictionary.Any())
                {
                    var notification = new Notification()
                    {
                        Id = message.Id,
                        Event = Event.Failed,
                        Reason = new Reason()
                        {
                            Code = ReasonCodes.ROUTING_DESTINATION_NOT_FOUND,
                            Description = "Destination not found"
                        }
                    };

                    await channel.SendNotificationAsync(notification);
                }
                else 
                {
                    Guid destinationSessionId;

                    if (!instanceSessionDictionary.TryGetValue(message.To.Instance, out destinationSessionId))
                    {
                        destinationSessionId = instanceSessionDictionary.First().Value;
                    }

                    IServerChannel destinationChannel;

                    if (_serverConnectedNodesDictionary.TryGetValue(destinationSessionId, out destinationChannel))
                    {
                        await destinationChannel.SendMessageAsync(message);
                    }
                    else
                    {
                        var notification = new Notification()
                        {
                            Id = message.Id,
                            Event = Event.Failed,
                            Reason = new Reason()
                            {
                                Code = ReasonCodes.DISPATCH_ERROR,
                                Description = "Destination session is unavailable"
                            }
                        };

                        await channel.SendNotificationAsync(notification);
                    }
                }

            }
        }        
Esempio n. 4
0
 internal void ReceiveNotification(Notification notification)
 {
     var message = Messages.FirstOrDefault(m => m.Id == notification.Id);
     if (message != null)
     {
         message.LastEvent = notification.Event;
     }
 }
Esempio n. 5
0
        private async Task ReceiveMessagesAsync(IChannel channel, CancellationToken cancellationToken)
        {
            while (channel.State == SessionState.Established)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var message = await channel.ReceiveMessageAsync(cancellationToken);

                IDictionary <string, Guid> instanceSessionDictionary;

                if (message.To == null)
                {
                    var notification = new Notification()
                    {
                        Id     = message.Id,
                        Event  = Event.Failed,
                        Reason = new Reason()
                        {
                            Code        = ReasonCodes.VALIDATION_INVALID_RECIPIENTS,
                            Description = "Invalid destination"
                        }
                    };

                    await channel.SendNotificationAsync(notification);
                }
                else if (!_identityInstanceSessionIdDictionary.TryGetValue(message.To.ToIdentity(), out instanceSessionDictionary) ||
                         !instanceSessionDictionary.Any())
                {
                    var notification = new Notification()
                    {
                        Id     = message.Id,
                        Event  = Event.Failed,
                        Reason = new Reason()
                        {
                            Code        = ReasonCodes.ROUTING_DESTINATION_NOT_FOUND,
                            Description = "Destination not found"
                        }
                    };

                    await channel.SendNotificationAsync(notification);
                }
                else
                {
                    Guid destinationSessionId;

                    if (!instanceSessionDictionary.TryGetValue(message.To.Instance, out destinationSessionId))
                    {
                        destinationSessionId = instanceSessionDictionary.First().Value;
                    }

                    IServerChannel destinationChannel;

                    if (_serverConnectedNodesDictionary.TryGetValue(destinationSessionId, out destinationChannel))
                    {
                        await destinationChannel.SendMessageAsync(message);
                    }
                    else
                    {
                        var notification = new Notification()
                        {
                            Id     = message.Id,
                            Event  = Event.Failed,
                            Reason = new Reason()
                            {
                                Code        = ReasonCodes.DISPATCH_ERROR,
                                Description = "Destination session is unavailable"
                            }
                        };

                        await channel.SendNotificationAsync(notification);
                    }
                }
            }
        }