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


C# IConnection.Read方法代码示例

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


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

示例1: DecodeFramingFault

 public static void DecodeFramingFault(ClientFramingDecoder decoder, IConnection connection, Uri via, string contentType, ref TimeoutHelper timeoutHelper)
 {
     ValidateReadingFaultString(decoder);
     int offset = 0;
     byte[] buffer = DiagnosticUtility.Utility.AllocateByteArray(0x100);
     int size = connection.Read(buffer, offset, buffer.Length, timeoutHelper.RemainingTime());
     while (size > 0)
     {
         int num3 = decoder.Decode(buffer, offset, size);
         offset += num3;
         size -= num3;
         if (decoder.CurrentState == ClientFramingDecoderState.Fault)
         {
             ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime());
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(FaultStringDecoder.GetFaultException(decoder.Fault, via.ToString(), contentType));
         }
         if (decoder.CurrentState != ClientFramingDecoderState.ReadingFaultString)
         {
             throw Fx.AssertAndThrow("invalid framing client state machine");
         }
         if (size == 0)
         {
             offset = 0;
             size = connection.Read(buffer, offset, buffer.Length, timeoutHelper.RemainingTime());
         }
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException());
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:ConnectionUpgradeHelper.cs

示例2: ProcessNextRequestFrom

 // ----- Public methods
 public void ProcessNextRequestFrom(IConnection connection)
 {
     try {
         var request = connection.Read();
         var response = _clientRequestProcessor.Process(request);
         connection.Send(response);
     }
     catch (NoDataToReadFromConnectionException ex) {
         throw new NoRequestToProcessException("No request is available to process.", ex);
     }
 }
开发者ID:pierregillon,项目名称:ConnectUs,代码行数:12,代码来源:ClientRequestHandler.cs

示例3: Process

        public void Process(IConnection conn)
        {
            string message = conn.Read();

            try{
                MessageParser messageParser = new MessageParser(message);
                int port = messageParser.GetInt("port");
                string id = messageParser.GetString("id");
                m_DataCollector.AddArtifact (id, conn.RemoteIp, port);

                conn.Write("status=registered");
            }catch(Exception){
                conn.Write ("status=registration_failure");
            }
        }
开发者ID:romanthe,项目名称:HeatingSystemSimulator,代码行数:15,代码来源:RegistrationServer.cs

示例4: InitiateUpgrade

 public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref IConnection connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref TimeoutHelper timeoutHelper)
 {
     for (string str = upgradeInitiator.GetNextUpgrade(); str != null; str = upgradeInitiator.GetNextUpgrade())
     {
         EncodedUpgrade upgrade = new EncodedUpgrade(str);
         connection.Write(upgrade.EncodedBytes, 0, upgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
         byte[] buffer = new byte[1];
         int count = connection.Read(buffer, 0, buffer.Length, timeoutHelper.RemainingTime());
         if (!ValidateUpgradeResponse(buffer, count, decoder))
         {
             return false;
         }
         ConnectionStream stream = new ConnectionStream(connection, defaultTimeouts);
         Stream stream2 = upgradeInitiator.InitiateUpgrade(stream);
         connection = new StreamConnection(stream2, stream);
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:ConnectionUpgradeHelper.cs

示例5: SendPreamble

 private IConnection SendPreamble(IConnection connection, ref TimeoutHelper timeoutHelper, ClientFramingDecoder decoder, out SecurityMessageProperty remoteSecurity)
 {
     connection.Write(this.Preamble, 0, this.Preamble.Length, true, timeoutHelper.RemainingTime());
     if (this.upgrade != null)
     {
         IStreamUpgradeChannelBindingProvider property = this.upgrade.GetProperty<IStreamUpgradeChannelBindingProvider>();
         StreamUpgradeInitiator upgradeInitiator = this.upgrade.CreateUpgradeInitiator(base.RemoteAddress, base.Via);
         if (!ConnectionUpgradeHelper.InitiateUpgrade(upgradeInitiator, ref connection, decoder, this, ref timeoutHelper))
         {
             ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper);
         }
         if ((property != null) && property.IsChannelBindingSupportEnabled)
         {
             this.channelBindingToken = property.GetChannelBinding(upgradeInitiator, ChannelBindingKind.Endpoint);
         }
         remoteSecurity = StreamSecurityUpgradeInitiator.GetRemoteSecurity(upgradeInitiator);
         connection.Write(ClientSingletonEncoder.PreambleEndBytes, 0, ClientSingletonEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime());
     }
     else
     {
         remoteSecurity = null;
     }
     byte[] buffer = new byte[1];
     int count = connection.Read(buffer, 0, buffer.Length, timeoutHelper.RemainingTime());
     if (!ConnectionUpgradeHelper.ValidatePreambleResponse(buffer, count, decoder, base.Via))
     {
         ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper);
     }
     return connection;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:StreamedFramingRequestChannel.cs

示例6: SendFault

        internal static void SendFault(IConnection connection, string faultString, byte[] drainBuffer, TimeSpan sendTimeout, int maxRead)
        {

            if (TD.ConnectionReaderSendFaultIsEnabled())
            {
                TD.ConnectionReaderSendFault(faultString);
            }

            EncodedFault encodedFault = new EncodedFault(faultString);
            TimeoutHelper timeoutHelper = new TimeoutHelper(sendTimeout);
            try
            {
                connection.Write(encodedFault.EncodedBytes, 0, encodedFault.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
                connection.Shutdown(timeoutHelper.RemainingTime());
            }
            catch (CommunicationException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                connection.Abort();
                return;
            }
            catch (TimeoutException e)
            {
                if (TD.SendTimeoutIsEnabled())
                {
                    TD.SendTimeout(e.Message);
                }
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                connection.Abort();
                return;
            }

            // make sure we read until EOF or a quota is hit
            int read = 0;
            int readTotal = 0;
            for (;;)
            {
                try
                {
                    read = connection.Read(drainBuffer, 0, drainBuffer.Length, timeoutHelper.RemainingTime());
                }
                catch (CommunicationException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                    connection.Abort();
                    return;
                }
                catch (TimeoutException e)
                {
                    if (TD.SendTimeoutIsEnabled())
                    {
                        TD.SendTimeout(e.Message);
                    }
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                    connection.Abort();
                    return;
                }

                if (read == 0)
                    break;

                readTotal += read;
                if (readTotal > maxRead || timeoutHelper.RemainingTime() <= TimeSpan.Zero)
                {
                    connection.Abort();
                    return;
                }
            }

            ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime());
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:71,代码来源:InitialServerConnectionReader.cs

示例7: SendPreamble

        IConnection SendPreamble(IConnection connection, ref TimeoutHelper timeoutHelper,
            ClientFramingDecoder decoder, out SecurityMessageProperty remoteSecurity)
        {
            connection.Write(Preamble, 0, Preamble.Length, true, timeoutHelper.RemainingTime());

            if (upgrade != null)
            {
                IStreamUpgradeChannelBindingProvider channelBindingProvider = upgrade.GetProperty<IStreamUpgradeChannelBindingProvider>();

                StreamUpgradeInitiator upgradeInitiator = upgrade.CreateUpgradeInitiator(this.RemoteAddress, this.Via);

                if (!ConnectionUpgradeHelper.InitiateUpgrade(upgradeInitiator, ref connection, decoder,
                    this, ref timeoutHelper))
                {
                    ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, Via, messageEncoder.ContentType, ref timeoutHelper);
                }

                if (channelBindingProvider != null && channelBindingProvider.IsChannelBindingSupportEnabled)
                {
                    this.channelBindingToken = channelBindingProvider.GetChannelBinding(upgradeInitiator, ChannelBindingKind.Endpoint);
                }

                remoteSecurity = StreamSecurityUpgradeInitiator.GetRemoteSecurity(upgradeInitiator);

                connection.Write(ClientSingletonEncoder.PreambleEndBytes, 0,
                    ClientSingletonEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime());
            }
            else
            {
                remoteSecurity = null;
            }

            // read ACK
            byte[] ackBuffer = new byte[1];
            int ackBytesRead = connection.Read(ackBuffer, 0, ackBuffer.Length, timeoutHelper.RemainingTime());
            if (!ConnectionUpgradeHelper.ValidatePreambleResponse(ackBuffer, ackBytesRead, decoder, this.Via))
            {
                ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, Via, messageEncoder.ContentType, ref timeoutHelper);
            }

            return connection;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:42,代码来源:StreamedFramingRequestChannel.cs


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