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


C# IoSession.GetAttribute方法代码示例

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


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

示例1: SessionClosed

 /// <inheritdoc/>
 public override void SessionClosed(IoSession session)
 {
     IoSessionStream input = session.GetAttribute<IoSessionStream>(KEY_IN);
     IoSessionStream output = session.GetAttribute<IoSessionStream>(KEY_OUT);
     try
     {
         input.Close();
     }
     finally
     {
         output.Close();
     }
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:14,代码来源:StreamIoHandler.cs

示例2: ExceptionCaught

 public override void ExceptionCaught(INextFilter nextFilter, IoSession session, Exception cause)
 {
     Log.Error(ErrorCode.UnhandledExceptionCaught, cause);
     var counter = session.GetAttribute<int>(KeyName.SESSION_ERROR_COUNTER);
     if (counter >= MAX_UNCAUGHT_SESSION_ERROR_COUNT) session.Close(true);
     else
     {
         session.SetAttribute(KeyName.SESSION_ERROR_COUNTER, ++counter);
         base.ExceptionCaught(nextFilter, session, cause);
     }
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:11,代码来源:ExceptionCounterFilter.cs

示例3: GetSessionTasksQueue

        private SessionTasksQueue GetSessionTasksQueue(IoSession session)
        {
            SessionTasksQueue queue = session.GetAttribute<SessionTasksQueue>(TASKS_QUEUE);

            if (queue == null)
            {
                queue = new SessionTasksQueue();
                SessionTasksQueue oldQueue = (SessionTasksQueue)session.SetAttributeIfAbsent(TASKS_QUEUE, queue);
                if (oldQueue != null)
                    queue = oldQueue;
            }

            return queue;
        }
开发者ID:ettele,项目名称:Mina.NET,代码行数:14,代码来源:OrderedThreadPoolExecutor.cs

示例4: ExceptionCaught

 public override void ExceptionCaught(IoSession session, Exception cause)
 {
     IOException ioe = cause as IOException;
     if (ioe != null)
     {
         IoSessionStream input = session.GetAttribute<IoSessionStream>(KEY_IN);
         if (input != null)
         {
             input.Exception = ioe;
             return;
         }
     }
     Debug.WriteLine("Unexpected exception. {0}", cause);
     session.Close(true);
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:15,代码来源:StreamIoHandler.cs

示例5: ExceptionCaught

        /// <inheritdoc/>
        public override void ExceptionCaught(IoSession session, Exception cause)
        {
            IOException ioe = cause as IOException;
            if (ioe != null)
            {
                IoSessionStream input = session.GetAttribute<IoSessionStream>(KEY_IN);
                if (input != null)
                {
                    input.Exception = ioe;
                    return;
                }
            }

            if (log.IsWarnEnabled)
                log.Warn("Unexpected exception.", cause);
            session.Close(true);
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:18,代码来源:StreamIoHandler.cs

示例6: MessageReceived

        public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
        {
            List<String> phrases = session.GetAttribute<List<String>>("phrases");

            if (null == phrases)
            {
                phrases = new List<String>();
                session.SetAttribute("phrases", phrases);
            }

            phrases.Add((String)message);

            if (phrases.Count == 3)
            {
                session.RemoveAttribute("phrases");

                base.MessageReceived(nextFilter, session, new Haiku(phrases
                        .ToArray()));
            }
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:20,代码来源:ToHaikuIoFilter.cs

示例7: GetContext

 private Context GetContext(IoSession session)
 {
     Context ctx = session.GetAttribute<Context>(CONTEXT);
     if (ctx == null)
     {
         ctx = new Context(this);
         session.SetAttribute(CONTEXT, ctx);
     }
     return ctx;
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:10,代码来源:TextLineDecoder.cs

示例8: FilterClose

        public override void FilterClose(INextFilter nextFilter, IoSession session)
        {
            SslHandler handler = session.GetAttribute<SslHandler>(SSL_HANDLER);
            if (handler == null)
            {
                // The connection might already have closed, or
                // SSL might have not started yet.
                base.FilterClose(nextFilter, session);
                return;
            }

            IWriteFuture future = null;
            try
            {
                future = InitiateClosure(handler, nextFilter, session);
                future.Complete += (s, e) => base.FilterClose(nextFilter, session);
            }
            finally
            { 
                if (future == null)
                    base.FilterClose(nextFilter, session);
            }
        }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:23,代码来源:SslFilter.cs

示例9: MessageSent

 public override void MessageSent(IoSession session, Object message)
 {
     IoBuffer buffer = (IoBuffer)message;
     buffer.Rewind();
     Byte[] data = new Byte[buffer.Remaining];
     buffer.Get(data, 0, data.Length);
     StringBuilder sb = session.GetAttribute<StringBuilder>("sent");
     sb.Append(Encoding.ASCII.GetString(data));
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:9,代码来源:AbstractTrafficControlTest.cs

示例10: Decode

        /// <inheritdoc/>
        public override void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            if (!session.TransportMetadata.HasFragmentation)
            {
                while (input.HasRemaining)
                {
                    if (!DoDecode(session, input, output))
                        break;
                }

                return;
            }

            Boolean usingSessionBuffer = true;
            IoBuffer buf = session.GetAttribute<IoBuffer>(BUFFER);

            // If we have a session buffer, append data to that; otherwise
            // use the buffer read from the network directly.
            if (buf == null)
            {
                buf = input;
                usingSessionBuffer = false;
            }
            else
            {
                Boolean appended = false;
                // Make sure that the buffer is auto-expanded.
                if (buf.AutoExpand)
                {
                    try
                    {
                        buf.Put(input);
                        appended = true;
                    }
                    catch (InvalidOperationException)
                    {
                        // A user called derivation method (e.g. slice()),
                        // which disables auto-expansion of the parent buffer.
                    }
                    catch (OverflowException)
                    {
                        // A user disabled auto-expansion.
                    }
                }

                if (appended)
                {
                    buf.Flip();
                }
                else
                {
                    // Reallocate the buffer if append operation failed due to
                    // derivation or disabled auto-expansion.
                    buf.Flip();

                    IoBuffer newBuf = IoBuffer.Allocate(buf.Remaining + input.Remaining);
                    newBuf.AutoExpand = true;
                    newBuf.Order = buf.Order;
                    newBuf.Put(buf);
                    newBuf.Put(input);
                    newBuf.Flip();
                    buf = newBuf;

                    // Update the session attribute.
                    session.SetAttribute(BUFFER, buf);
                }
            }

            while (true)
            {
                Int32 oldPos = buf.Position;
                Boolean decoded = DoDecode(session, buf, output);
                if (decoded)
                {
                    if (buf.Position == oldPos)
                        throw new InvalidOperationException("DoDecode() can't return true when buffer is not consumed.");
                    if (!buf.HasRemaining)
                        break;
                }
                else
                {
                    break;
                }
            }

            // if there is any data left that cannot be decoded, we store
            // it in a buffer in the session and next time this decoder is
            // invoked the session buffer gets appended to
            if (buf.HasRemaining)
            {
                if (usingSessionBuffer && buf.AutoExpand)
                {
                    buf.Compact();
                }
                else
                {
                    StoreRemainingInSession(buf, session);
                }
            }
//.........这里部分代码省略.........
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:101,代码来源:CumulativeProtocolDecoder.cs

示例11: CanRead

 private Boolean CanRead(IoSession session)
 {
     Int32 pos = session.GetAttribute<Int32>("pos");
     Object sync = session.GetAttribute("lock");
     lock (sync)
     {
         Monitor.Wait(sync, 250);
     }
     String received = GetReceived(session);
     return pos < received.Length;
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:11,代码来源:AbstractTrafficControlTest.cs

示例12: MessageReceived

 public override void MessageReceived(IoSession session, Object message)
 {
     IoBuffer buffer = (IoBuffer)message;
     Byte[] data = new Byte[buffer.Remaining];
     buffer.Get(data, 0, data.Length);
     Object sync = session.GetAttribute("lock");
     lock (sync)
     {
         StringBuilder sb = session.GetAttribute<StringBuilder>("received");
         sb.Append(Encoding.ASCII.GetString(data));
         Monitor.PulseAll(sync);
     }
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:13,代码来源:AbstractTrafficControlTest.cs

示例13: GetReceived

 private String GetReceived(IoSession session)
 {
     return session.GetAttribute("received").ToString();
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:4,代码来源:AbstractTrafficControlTest.cs

示例14: GetDecoderOut

        private IProtocolDecoderOutput GetDecoderOut(IoSession session, INextFilter nextFilter)
        {
            IProtocolDecoderOutput output = session.GetAttribute<IProtocolDecoderOutput>(DECODER_OUT);

            if (output == null)
            {
                // Create a new instance, and stores it into the session
                output = new ProtocolDecoderOutputImpl();
                session.SetAttribute(DECODER_OUT, output);
            }

            return output;
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:13,代码来源:ProtocolCodecFilter.cs

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