public RosterConversationViewModel(RosterViewModel roster) : base(new Uri("/Pages/RosterConversation.xaml", UriKind.Relative)) { if (roster == null) { throw new ArgumentNullException(nameof(roster)); } _roster = roster; _roster.PropertyChanged += Roster_PropertyChanged; }
public async Task LoginAsync() { IClientChannel client = null; ITraceWriter traceWriter = null; if (ShowTraceWindow) { traceWriter = Owner.TraceViewModel; base.MessengerInstance.Send <OpenWindowMessage>( new OpenWindowMessage() { WindowName = "Trace", DataContext = Owner.TraceViewModel }); } IsBusy = true; this.ErrorMessage = string.Empty; try { var cancellationToken = _loginTimeout.ToCancellationToken(); var transport = new TcpTransport(traceWriter: traceWriter); await transport.OpenAsync(_serverAddressUri, cancellationToken); client = new ClientChannel( transport, _sendTimeout, fillEnvelopeRecipients: true, autoReplyPings: true, autoNotifyReceipt: true); if (RegisterUser) { var guestSessionResult = await client.EstablishSessionAsync( compressionOptions => compressionOptions.First(), encryptionOptions => SessionEncryption.TLS, new Identity() { Name = Guid.NewGuid().ToString(), Domain = _userNameNode.Domain }, (schemeOptions, roundtrip) => new GuestAuthentication(), null, cancellationToken ); if (guestSessionResult.State == SessionState.Established) { // Creates the account var account = new Account() { Password = this.Password.ToBase64() }; await client.SetResourceAsync <Account>( LimeUri.Parse(UriTemplates.ACCOUNT), account, _userNameNode, cancellationToken); await client.SendFinishingSessionAsync(); await client.ReceiveFinishedSessionAsync(cancellationToken); client.DisposeIfDisposable(); transport = new TcpTransport(traceWriter: traceWriter); await transport.OpenAsync(_serverAddressUri, cancellationToken); client = new ClientChannel( transport, _sendTimeout, fillEnvelopeRecipients: true, autoReplyPings: true, autoNotifyReceipt: true); } else if (guestSessionResult.Reason != null) { this.ErrorMessage = guestSessionResult.Reason.Description; } else { this.ErrorMessage = "Could not establish a guest session with the server"; } } var authentication = new PlainAuthentication(); authentication.SetToBase64Password(this.Password); var sessionResult = await client.EstablishSessionAsync( compressionOptions => compressionOptions.First(), encryptionOptions => SessionEncryption.TLS, new Identity() { Name = _userNameNode.Name, Domain = _userNameNode.Domain }, (schemeOptions, roundtrip) => authentication, _userNameNode.Instance, cancellationToken); if (sessionResult.State == SessionState.Established) { var rosterViewModel = new RosterViewModel(client, this); base.Owner.ContentViewModel = rosterViewModel; } else if (sessionResult.Reason != null) { this.ErrorMessage = sessionResult.Reason.Description; } else { this.ErrorMessage = "Could not connect to the server"; } } catch (Exception ex) { ErrorMessage = ex.Message; client.DisposeIfDisposable(); } finally { IsBusy = false; } }
public async Task LoginAsync() { IClientChannel client = null; ITraceWriter traceWriter = null; if (ShowTraceWindow) { traceWriter = Owner.TraceViewModel; base.MessengerInstance.Send<OpenWindowMessage>( new OpenWindowMessage() { WindowName = "Trace", DataContext = Owner.TraceViewModel }); } IsBusy = true; this.ErrorMessage = string.Empty; try { var cancellationToken = _loginTimeout.ToCancellationToken(); var transport = new TcpTransport(traceWriter: traceWriter); await transport.OpenAsync(_serverAddressUri, cancellationToken); client = new ClientChannel( transport, _sendTimeout, fillEnvelopeRecipients: true, autoReplyPings: true, autoNotifyReceipt: true); if (RegisterUser) { var guestSessionResult = await client.EstablishSessionAsync( compressionOptions => compressionOptions.First(), encryptionOptions => SessionEncryption.TLS, new Identity() { Name = Guid.NewGuid().ToString(), Domain = _userNameNode.Domain }, (schemeOptions, roundtrip) => new GuestAuthentication(), null, cancellationToken ); if (guestSessionResult.State == SessionState.Established) { // Creates the account var account = new Account() { Password = this.Password.ToBase64() }; await client.SetResourceAsync<Account>( LimeUri.Parse(UriTemplates.ACCOUNT), account, _userNameNode, cancellationToken); await client.SendFinishingSessionAsync(); await client.ReceiveFinishedSessionAsync(cancellationToken); client.DisposeIfDisposable(); transport = new TcpTransport(traceWriter: traceWriter); await transport.OpenAsync(_serverAddressUri, cancellationToken); client = new ClientChannel( transport, _sendTimeout, fillEnvelopeRecipients: true, autoReplyPings: true, autoNotifyReceipt: true); } else if (guestSessionResult.Reason != null) { this.ErrorMessage = guestSessionResult.Reason.Description; } else { this.ErrorMessage = "Could not establish a guest session with the server"; } } var authentication = new PlainAuthentication(); authentication.SetToBase64Password(this.Password); var sessionResult = await client.EstablishSessionAsync( compressionOptions => compressionOptions.First(), encryptionOptions => SessionEncryption.TLS, new Identity() { Name = _userNameNode.Name, Domain = _userNameNode.Domain }, (schemeOptions, roundtrip) => authentication, _userNameNode.Instance, cancellationToken); if (sessionResult.State == SessionState.Established) { var rosterViewModel = new RosterViewModel(client, this); base.Owner.ContentViewModel = rosterViewModel; } else if (sessionResult.Reason != null) { this.ErrorMessage = sessionResult.Reason.Description; } else { this.ErrorMessage = "Could not connect to the server"; } } catch (Exception ex) { ErrorMessage = ex.Message; client.DisposeIfDisposable(); } finally { IsBusy = false; } }