コード例 #1
0
ファイル: ServerChannel.cs プロジェクト: guitcastro/lime
        /// <summary>
        /// Sends authentication roundtrip information
        /// to the connected node and awaits
        /// for the client authentication.
        /// </summary>
        /// <param name="authenticationRoundtrip">The authentication roundtrip data.</param>
        /// <returns>
        /// A autheticating session envelope with the authentication information.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">authenticationRoundtrip</exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public async Task<Session> AuthenticateSessionAsync(Authentication authenticationRoundtrip, CancellationToken cancellationToken)
        {
            if (authenticationRoundtrip == null)
            {
                throw new ArgumentNullException("authenticationRoundtrip");
            }

            if (base.State != SessionState.Authenticating)
            {
                throw new InvalidOperationException(string.Format("Cannot send an authentication roundtrip for a session in the '{0}' state", this.State));
            }

            var session = new Session()
            {
                Id = base.SessionId,
                From = base.LocalNode,
                State = base.State,
                Authentication = authenticationRoundtrip
            };

            await base.SendSessionAsync(session).ConfigureAwait(false);
            return await this.ReceiveSessionAsync(cancellationToken).ConfigureAwait(false);
        }
コード例 #2
0
ファイル: ClientChannel.cs プロジェクト: guitcastro/lime
        /// <summary>
        /// Send a authenticate session envelope
        /// to the server to establish
        /// an authenticated session and awaits
        /// for the response.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="identity"></param>
        /// <param name="authentication"></param>
        /// <param name="instance"></param>
        /// <param name="sessionMode"></param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">
        /// Cannot await for a session response since there's already a listener.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// identity
        /// or
        /// authentication
        /// </exception>
        public async Task<Session> AuthenticateSessionAsync(Identity identity, Authentication authentication, string instance, CancellationToken cancellationToken)
        {
            if (base.State != SessionState.Authenticating)
            {
                throw new InvalidOperationException(string.Format("Cannot authenticate a session in the '{0}' state", base.State));
            }

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

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

            var session = new Session()
            {
                Id = base.SessionId,
                From = new Node()
                {
                    Name = identity.Name,
                    Domain = identity.Domain,
                    Instance = instance
                },
                State = SessionState.Authenticating,
                Authentication = authentication
            };

            await base.SendSessionAsync(session).ConfigureAwait(false);
            return await this.ReceiveSessionAsync(cancellationToken).ConfigureAwait(false);
        }