当前位置: 首页>>代码示例>>C#>>正文


C# IoSession.ContainsAttribute方法代码示例

本文整理汇总了C#中IoSession.ContainsAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IoSession.ContainsAttribute方法的具体用法?C# IoSession.ContainsAttribute怎么用?C# IoSession.ContainsAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IoSession的用法示例。


在下文中一共展示了IoSession.ContainsAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SessionIdle

        /// <inheritdoc/>
        public override void SessionIdle(INextFilter nextFilter, IoSession session, IdleStatus status)
        {
            if (status == _interestedIdleStatus)
            {
                if (!session.ContainsAttribute(WAITING_FOR_RESPONSE))
                {
                    Object pingMessage = _messageFactory.GetRequest(session);
                    if (pingMessage != null)
                    {
                        nextFilter.FilterWrite(session, new DefaultWriteRequest(pingMessage));
                        //session.Write(pingMessage);

                        // If policy is OFF, there's no need to wait for
                        // the response.
                        if (_requestTimeoutHandler != KeepAliveRequestTimeoutHandler.DeafSpeaker)
                        {
                            MarkStatus(session);
                            if (_interestedIdleStatus == IdleStatus.BothIdle)
                            {
                                session.SetAttribute(IGNORE_READER_IDLE_ONCE);
                            }
                        }
                        else
                        {
                            ResetStatus(session);
                        }
                    }
                }
                else
                {
                    HandlePingTimeout(session);
                }
            }
            else if (status == IdleStatus.ReaderIdle)
            {
                if (session.RemoveAttribute(IGNORE_READER_IDLE_ONCE) == null)
                {
                    if (session.ContainsAttribute(WAITING_FOR_RESPONSE))
                    {
                        HandlePingTimeout(session);
                    }
                }
            }

            if (_forwardEvent)
                nextFilter.SessionIdle(session, status);
        }
开发者ID:zesus19,项目名称:c5.v1,代码行数:48,代码来源:KeepAliveFilter.cs

示例2: MessageReceived

 public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
 {
     using (var scope = ObjectHost.Host.BeginLifetimeScope())
     {
         var commandMessage = message as DuplexMessage;
         if (commandMessage != null)
         {
             if (commandMessage.Header.CommandCode == CommandCode.Authentication)
             {
                 var school = metaRepository
                     .GetAllSchools()
                     .ByIdentifier(commandMessage.Header.Identifier);
                 if (school != null && school.UniqueToken.Equals(
                     commandMessage.GetContent<AuthInfo>().Mac, StringComparison.OrdinalIgnoreCase))
                 {
                     session.SetAttributeIfAbsent(KeyName.SESSION_IDENTIFIER, commandMessage.Header.Identifier);
                     identifierManager.SetSessonIdentifier(commandMessage.Header.Identifier, session);
                     nextFilter.FilterWrite(session,
                         new DefaultWriteRequest(
                             DuplexMessage.CreateCallbackMessage(commandMessage)));
                 }
                 else
                 {
                     nextFilter.FilterWrite(session, 
                         new DefaultWriteRequest(
                             DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.AuthenticationFailed)));
                 }
             }
             else if (
                 commandMessage.Header.CommandCode == CommandCode.Register ||
                 commandMessage.Header.CommandCode == CommandCode.Heartbeat)
             {
                 nextFilter.MessageReceived(session, message);
             }
             else
             {
                 if (!session.ContainsAttribute(KeyName.SESSION_IDENTIFIER))
                 {
                     nextFilter.FilterWrite(session, new DefaultWriteRequest(
                         DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.UnauthorizedCommand)));
                 }
                 else
                 {
                     var identifier = session.GetAttribute<string>(KeyName.SESSION_IDENTIFIER);
                     if (identifier.Equals(commandMessage.Header.Identifier))
                         nextFilter.MessageReceived(session, message);
                     else
                     {
                         nextFilter.FilterWrite(session, new DefaultWriteRequest(
                             DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.UnauthorizedCommand)));
                     }
                 }
                 
             }
         }
         else
         {
             nextFilter.FilterWrite(session, new DefaultWriteRequest(
                 DuplexMessage.CreateAckMessage(
                     Guid.NewGuid().ToByteArray().ToBase64(), 
                     MessageVersion.V1, 
                     CommandCode.UnAssigned, 
                     ErrorCode.IllegalCommandRequest)));
         }
     }
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:66,代码来源:AuthenticationValidationFilter.cs


注:本文中的IoSession.ContainsAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。