Ejemplo n.º 1
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

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

            var session = envelopeViewModel.Envelope as Session;

            if (session != null)
            {
                sessionViewModel.LastSessionState = session.State;

                if (session.State == SessionState.Established)
                {
                    sessionViewModel.LocalNode = session.To;
                    sessionViewModel.RemoteNode = session.From;
                }
            }

            return Task.FromResult<object>(null);
        }
Ejemplo n.º 2
0
        public MainViewModel()
        {
            SelectedSession = new SessionViewModel();

            Title = string.Format(
                "Lime Test Console v{0}",
                Assembly.GetEntryAssembly().GetName().Version);

            ClosingCommand = new RelayCommand(Closing);
            ClosedCommand  = new RelayCommand(Closed);
        }
Ejemplo n.º 3
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

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

            var notification = envelopeViewModel.Envelope as Notification;

            if (notification != null)
            {
                sessionViewModel.LastNotificationEvent = notification.Event;
            }

            return Task.FromResult<object>(null);
        }
Ejemplo n.º 4
0
        public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

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

            var session = envelopeViewModel.Envelope as Session;

            if (session != null &&
                new[] { SessionState.Finished, SessionState.Failed }.Contains(session.State) &&
                sessionViewModel.CloseTransportCommand.CanExecute(null))
            {
                await sessionViewModel.CloseTransportCommand.ExecuteAsync(null);
            }
        }
Ejemplo n.º 5
0
        public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

            if (sessionViewModel == null)
            {
                throw new ArgumentNullException("sessionViewModel");
            }
            
            var session = envelopeViewModel.Envelope as Session;
            var transport = sessionViewModel.Transport;

            if (session != null &&
                session.State == SessionState.Negotiating &&
                session.Compression.HasValue &&
                session.Encryption.HasValue &&
                transport != null)
            {
                var cancellationToken = TimeSpan.FromSeconds(15).ToCancellationToken();

                if (transport.Compression != session.Compression.Value)
                {
                    await transport.SetCompressionAsync(session.Compression.Value, cancellationToken);
                }

                if (transport.Encryption != session.Encryption.Value)
                {
                    await transport.SetEncryptionAsync(session.Encryption.Value, cancellationToken);

                    if (session.Encryption.Value != SessionEncryption.None)
                    {
                        sessionViewModel.CanSendAsRaw = false;
                    }

                }
            }
        }
Ejemplo n.º 6
0
        public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

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

            var command = envelopeViewModel.Envelope as Command;

            if (command != null &&
                command.Status == CommandStatus.Pending &&
                command.Uri != null &&
                command.Uri.Path.Equals(UriTemplates.PING))
            {
                var commandResponse = new Command()
                {
                    Id = command.Id,
                    Status = CommandStatus.Success,
                    To = command.From,
                    Resource = new Ping()
                };

                var commandEnvelopeViewModel = new EnvelopeViewModel()
                {
                    Envelope = commandResponse
                };

                sessionViewModel.InputJson = commandEnvelopeViewModel.Json;

                if (sessionViewModel.SendCommand.CanExecute(null))
                {
                    await sessionViewModel.SendCommand.ExecuteAsync(null);
                }
            }
        }
Ejemplo n.º 7
0
        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);
                }
            }
        }
Ejemplo n.º 8
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

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

            var session = envelopeViewModel.Envelope as Session;

            if (session != null &&
                session.Id != Guid.Empty)
            {
                var sessionIdVariableViewModel = sessionViewModel
                    .Variables
                    .FirstOrDefault(v => v.Name.Equals("sessionId"));

                if (sessionIdVariableViewModel == null)
                {
                    sessionIdVariableViewModel = new VariableViewModel()
                    {
                        Name = "sessionId"
                    };

                    sessionViewModel.Variables.Add(sessionIdVariableViewModel);
                }

                sessionIdVariableViewModel.Value = session.Id.ToString();
            }

            return Task.FromResult<object>(null);
        }