本文整理汇总了C#中IConnection.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Write方法的具体用法?C# IConnection.Write怎么用?C# IConnection.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.Write方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
}
示例2: ExecuteOverride
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response)
{
var commandName = input.Get<string>("command");
var cmd = Game.Current.Commands.FindCommandInternal(commandName);
if (cmd == null)
{
response.Invalidate(CommonResources.HelpNotFoundFormat, commandName);
return;
}
connection.Write(NotificationMessage.Heading(CommonResources.HelpName), NotificationMessage.Normal(cmd.Metadata.Name));
connection.Write(NotificationMessage.Heading(CommonResources.HelpDescription), NotificationMessage.Normal(cmd.Metadata.Description));
connection.Write(NotificationMessage.Heading(CommonResources.HelpSynopsis), NotificationMessage.Normal(cmd.Metadata.Synopsis));
connection.Write(NotificationMessage.Heading(CommonResources.HelpAliases), NotificationMessage.Normal(string.Join(",", cmd.Metadata.Aliases)));
}
示例3: Execute
/// <summary>
/// Executes the specified command for the specified connection.
/// </summary>
/// <param name="input">The IInput containing the command information to execute.</param>
/// <param name="connection">The IConnection executing the command.</param>
public void Execute(IInput input, IConnection connection)
{
// Find the command from the input.
var cmd = FindCommandInternal(input.CommandName);
if (cmd == null)
{
InvalidateResponse(input, connection, CommonResources.CommandInvalidFormat, input.CommandName);
return;
}
string errorMessage;
if (!cmd.Value.ValidateArguments(input, out errorMessage))
{
InvalidateResponse(input, connection, errorMessage);
return;
}
if (cmd.Value.RequiresUser && connection.User == null)
{
InvalidateResponse(input, connection, CommonResources.CommandRequiresUser);
return;
}
if (cmd.Value.RequiresCharacter && connection.Character == null)
{
InvalidateResponse(input, connection, CommonResources.CommandRequiresCharacter);
return;
}
var response = cmd.Value.Execute(input, connection);
connection.Write(response);
}
示例4: WriteMessage
public static void WriteMessage(Message message, IConnection connection, bool isRequest, IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper)
{
byte[] envelopeEndFramingEndBytes = null;
if (message != null)
{
bool flag;
MessageEncoder encoder = settings.MessageEncoderFactory.Encoder;
byte[] envelopeStartBytes = SingletonEncoder.EnvelopeStartBytes;
if (isRequest)
{
envelopeEndFramingEndBytes = SingletonEncoder.EnvelopeEndFramingEndBytes;
flag = TransferModeHelper.IsRequestStreamed(settings.TransferMode);
}
else
{
envelopeEndFramingEndBytes = SingletonEncoder.EnvelopeEndBytes;
flag = TransferModeHelper.IsResponseStreamed(settings.TransferMode);
}
if (flag)
{
connection.Write(envelopeStartBytes, 0, envelopeStartBytes.Length, false, timeoutHelper.RemainingTime());
Stream stream = new StreamingOutputConnectionStream(connection, settings);
Stream stream2 = new TimeoutStream(stream, ref timeoutHelper);
encoder.WriteMessage(message, stream2);
}
else
{
ArraySegment<byte> segment = SingletonEncoder.EncodeMessageFrame(encoder.WriteMessage(message, 0x7fffffff, settings.BufferManager, envelopeStartBytes.Length + 5));
Buffer.BlockCopy(envelopeStartBytes, 0, segment.Array, segment.Offset - envelopeStartBytes.Length, envelopeStartBytes.Length);
connection.Write(segment.Array, segment.Offset - envelopeStartBytes.Length, segment.Count + envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager);
}
}
else if (isRequest)
{
envelopeEndFramingEndBytes = SingletonEncoder.EndBytes;
}
if (envelopeEndFramingEndBytes != null)
{
connection.Write(envelopeEndFramingEndBytes, 0, envelopeEndFramingEndBytes.Length, true, timeoutHelper.RemainingTime());
}
}
示例5: 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;
}
示例6: 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
示例7: 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());
}
示例8: 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;
}
示例9: WriteMessage
public static void WriteMessage(Message message, IConnection connection, bool isRequest,
IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper)
{
byte[] endBytes = null;
if (message != null)
{
MessageEncoder messageEncoder = settings.MessageEncoderFactory.Encoder;
byte[] envelopeStartBytes = SingletonEncoder.EnvelopeStartBytes;
bool writeStreamed;
if (isRequest)
{
endBytes = SingletonEncoder.EnvelopeEndFramingEndBytes;
writeStreamed = TransferModeHelper.IsRequestStreamed(settings.TransferMode);
}
else
{
endBytes = SingletonEncoder.EnvelopeEndBytes;
writeStreamed = TransferModeHelper.IsResponseStreamed(settings.TransferMode);
}
if (writeStreamed)
{
connection.Write(envelopeStartBytes, 0, envelopeStartBytes.Length, false, timeoutHelper.RemainingTime());
Stream connectionStream = new StreamingOutputConnectionStream(connection, settings);
Stream writeTimeoutStream = new TimeoutStream(connectionStream, timeoutHelper.RemainingTime());
messageEncoder.WriteMessage(message, writeTimeoutStream);
}
else
{
ArraySegment<byte> messageData = messageEncoder.WriteMessage(message,
int.MaxValue, settings.BufferManager, envelopeStartBytes.Length + IntEncoder.MaxEncodedSize);
messageData = SingletonEncoder.EncodeMessageFrame(messageData);
Buffer.BlockCopy(envelopeStartBytes, 0, messageData.Array, messageData.Offset - envelopeStartBytes.Length,
envelopeStartBytes.Length);
connection.Write(messageData.Array, messageData.Offset - envelopeStartBytes.Length,
messageData.Count + envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager);
}
}
else if (isRequest) // context handles response end bytes
{
endBytes = SingletonEncoder.EndBytes;
}
if (endBytes != null)
{
connection.Write(endBytes, 0, endBytes.Length,
true, timeoutHelper.RemainingTime());
}
}
示例10: InvalidateResponse
private static void InvalidateResponse(IInput input, IConnection connection, string format, params object[] args)
{
var response = new ResponseMessage(input);
response.Invalidate(format, args);
connection.Write(response);
}