本文整理汇总了C#中System.ServiceModel.Channels.BufferManager类的典型用法代码示例。如果您正苦于以下问题:C# BufferManager类的具体用法?C# BufferManager怎么用?C# BufferManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferManager类属于System.ServiceModel.Channels命名空间,在下文中一共展示了BufferManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message,
int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
String bodyContent = null;
lastMessage = message.Headers.Action;
XmlDictionaryReader reader = message.GetReaderAtBodyContents();
while (reader.Read())
{
if (reader.Name == "request")
{
bodyContent = reader.ReadElementContentAsString();
break;
}
}
reader.Close();
byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes(bodyContent);
int totalLength = messageBytes.Length + messageOffset;
byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
Array.Copy(messageBytes, 0,
totalBytes, messageOffset, messageBytes.Length);
ArraySegment<byte> buffer =
new ArraySegment<byte>(
totalBytes, messageOffset, messageBytes.Length);
return buffer;
}
开发者ID:gitlabuser,项目名称:warehouse,代码行数:31,代码来源:SerialMessageEncoder.cs
示例2: ReadMessage
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
var msgContents = new byte[buffer.Count];
Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
var message = new UTF8Encoding().GetString(msgContents);
var reader = XmlReader.Create(new MemoryStream(msgContents));
var xmlDocument = new XmlDocument();
xmlDocument.Load(reader);
var elementsByTagName = xmlDocument.GetElementsByTagName("Envelope", Soap11Namespace);
if (elementsByTagName.Count == 0)
throw new XmlException("Не найден узел Envelope");
var prefixOfNamespace = elementsByTagName[0].GetPrefixOfNamespace(Soap11Namespace);
if (string.IsNullOrEmpty(prefixOfNamespace))
throw new XmlException(string.Format("Не найден префикс пространста имен {0}", Soap11Namespace));
LogMessage(xmlDocument, true);
// Убираем actors из входящего сообщения
message = message.Replace(prefixOfNamespace + ":mustUnderstand=\"1\"", "");
message = message.Replace(prefixOfNamespace + ":actor=\"" + SmevActor + "\"", "");
var bytes = new UTF8Encoding().GetBytes(message.Replace(prefixOfNamespace + ":actor=\"" + RecipientActor + "\"", ""));
var length = bytes.Length;
var array = bufferManager.TakeBuffer(length);
Array.Copy(bytes, 0, array, 0, length);
buffer = new ArraySegment<byte>(array, 0, length);
return _innerEncoder.ReadMessage(buffer, bufferManager, contentType);
}
开发者ID:aanufriyev,项目名称:SmevWCFService,代码行数:25,代码来源:SMEVTextMessageEncoder.cs
示例3: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
ArraySegment<byte> messageBuffer;
byte[] writeBuffer = null;
int messageLength;
using (MemoryStream stream = new MemoryStream())
{
using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
{
message.WriteMessage(writer);
}
// TryGetBuffer is the preferred path but requires 4.6
//stream.TryGetBuffer(out messageBuffer);
writeBuffer = stream.ToArray();
messageBuffer = new ArraySegment<byte>(writeBuffer);
messageLength = (int)stream.Position;
}
int totalLength = messageLength + messageOffset;
byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
Array.Copy(messageBuffer.Array, 0, totalBytes, messageOffset, messageLength);
ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
return byteArray;
}
开发者ID:weshaggard,项目名称:wcf,代码行数:28,代码来源:CustomTextMessageEncoder.cs
示例4: FileRequestChannel
public FileRequestChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
FileRequestChannelFactory parent, Uri via)
: base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
{
this.via = via;
this.writeLock = new object();
}
开发者ID:dmetzgar,项目名称:custom-transport-channel,代码行数:7,代码来源:FileRequestChannel.cs
示例5: UdpSocketListener
// Listen sockets have been created.
public UdpSocketListener(List<Socket> listenSockets, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
{
this.listenSockets = listenSockets;
this.maxMessageSize = maxMessageSize;
this.bufferManager = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
this.dataReceivedCallback = dataReceivedCallback;
}
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:8,代码来源:UdpSocketListener.cs
示例6: ReadMessage
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
ArraySegment<byte> decompressedBuffer = DecompressBuffer(buffer, bufferManager);
Message returnMessage = _messageEncoder.ReadMessage(decompressedBuffer, bufferManager);
returnMessage.Properties.Encoder = this;
return returnMessage;
}
开发者ID:Nickymaco,项目名称:UwaySoftWCDMA,代码行数:7,代码来源:CompressionMessageEncoder.cs
示例7: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
ArraySegment<byte> buffer = innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
bindingElement.WriteCount++;
bindingElement.WriteBytes += buffer.Count;
return buffer;
}
开发者ID:JackFong,项目名称:GenericWcfServiceHostAndClient,代码行数:7,代码来源:CountingEncoder.cs
示例8: ReadMessage
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
Message message = this.innerEncoder.ReadMessage(buffer, bufferManager);
bindingElement.ReadCount++;
bindingElement.ReadBytes += buffer.Count;
return message;
}
开发者ID:JackFong,项目名称:GenericWcfServiceHostAndClient,代码行数:7,代码来源:CountingEncoder.cs
示例9: SizedTcpReplyChannel
public SizedTcpReplyChannel(MessageEncoder encoder, BufferManager bufferManager, Uri localAddress, Socket socket, ChannelManagerBase channelManager)
: base(encoder, bufferManager, channelManager)
{
this.localAddress = localAddress;
this.socket = socket;
this.InitializeSocket(socket);
}
开发者ID:GusLab,项目名称:WCFSamples,代码行数:7,代码来源:SizedTcpReplyChannel.cs
示例10: FileReplyChannel
public FileReplyChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
FileReplyChannelListener parent)
: base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
{
this.localAddress = address;
this.readLock = new object();
}
开发者ID:dmetzgar,项目名称:custom-transport-channel,代码行数:7,代码来源:FileReplyChannel.cs
示例11: MessageBusInputChannel
public MessageBusInputChannel(
BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
EndpointAddress localAddress,
IBus bus)
: base(bufferManager, encoder, parent)
{
_localAddress = localAddress;
_bus = bus;
_aLock = new object();
_tryReceiveDelegate = (TimeSpan timeout, out Message message) =>
{
message = null;
try
{
var requestMessage = _bus.Receive(true, null);
if (requestMessage != null)
{
message = GetWcfMessageFromString(requestMessage.Content);
OnAfterTryReceive(requestMessage);
}
}
catch (Exception ex)
{
throw new CommunicationException(ex.Message, ex);
}
return true;
};
_receiveDelegate = (TimeSpan timeout) =>
{
var requestMessage = _bus.Receive(false, ChannelID);
return GetWcfMessageFromString(requestMessage.Content);
};
}
开发者ID:shaunxu,项目名称:roma,代码行数:35,代码来源:MessageBusInputChannel.cs
示例12: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
if (message.Properties.ContainsKey(HttpRequestMessageProperty.Name))
{
HttpRequestMessageProperty httpMessage = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
if (httpMessage != null && httpMessage.Method == "POST")
{
ArraySegment<byte> innerMessage = _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
byte[] encodedMessage = Encoding.UTF8.GetBytes(String.Concat("xml=", HttpUtility.UrlEncode(Encoding.UTF8.GetString(innerMessage.Array, 0, innerMessage.Count))));
bufferManager.ReturnBuffer(innerMessage.Array);
byte[] buffer = bufferManager.TakeBuffer(encodedMessage.Length);
Array.Copy(encodedMessage, buffer, encodedMessage.Length);
bufferManager.ReturnBuffer(buffer);
return new ArraySegment<byte>(buffer, messageOffset, encodedMessage.Length);
}
else
{
return _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
}
}
else
{
return _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
}
}
开发者ID:Dozey,项目名称:XeroAPI,代码行数:32,代码来源:XeroMessageEncoder.cs
示例13: ReadMessage
/// <inheritdoc />
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
// Treat the alternate as native
if (IsAlternateContent(contentType))
{
// HACK: Should see if we have a declr or some xml
contentType = this.contentType;
}
var msgContents = new byte[buffer.Count];
Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
bufferManager.ReturnBuffer(buffer.Array);
// Most interoperable to include the xml declaration
writerSettings.OmitXmlDeclaration = false;
// Save the encoding for when we write the response
writerSettings.Encoding = msgContents.GetEncoding(contentType);
var xmlDeclEncoding = msgContents.GetXmlDeclEncoding(writerSettings.Encoding);
// Check if the two encodings align
if (xmlDeclEncoding != null && xmlDeclEncoding.WebName == writerSettings.Encoding.WebName)
{
// Need to recode
msgContents = Encoding.Convert(writerSettings.Encoding, xmlDeclEncoding, msgContents);
}
var stream = new MemoryStream(msgContents);
return ReadMessage(stream, int.MaxValue);
}
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:31,代码来源:CustomTextMessageEncoder.cs
示例14: WriteMessage
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
{
if (message == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
}
if (bufferManager == null)
{
throw TraceUtility.ThrowHelperError(new ArgumentNullException("bufferManager"), message);
}
if (maxMessageSize < 0)
{
throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize,
SR2.GetString(SR2.ValueMustBeNonNegative)), message);
}
if (messageOffset < 0 || messageOffset > maxMessageSize)
{
throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset,
SR2.GetString(SR2.JsonValueMustBeInRange, 0, maxMessageSize)), message);
}
ThrowIfMismatchedMessageVersion(message);
message.Properties.Encoder = this;
BufferedMessageWriter messageWriter = new WebScriptMetadataBufferedMessageWriter(this);
ArraySegment<byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);
if (MessageLogger.LogMessagesAtTransportLevel)
{
MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
}
if (System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoderIsEnabled() && messageData != null)
{
System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoder(EventTraceActivityHelper.TryExtractActivity(message), messageData.Count, this);
}
return messageData;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:35,代码来源:WebScriptMetadataMessageEncoderFactory.cs
示例15: Acceptor
public Acceptor(DistributorConfig config)
{
_bufferManager = BufferManager.CreateBufferManager(MaxBufferPoolSize, MaxBufferSize);
_config = config;
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_interactors = new Dictionary<Socket, Interactor>();
}
开发者ID:rob-blackbourn,项目名称:TopicBus,代码行数:7,代码来源:Acceptor.cs
示例16: SerialChannelBase
/// <summary>
/// SerialChannel Base
/// </summary>
/// <param name="bufferManager">
/// Buffer manager created by factory and listener</param>
/// <param name="encoderFactory">
/// Referece to encoder factory as returned by encoder element</param>
/// <param name="address">Remote address</param>
/// <param name="portNumber">COM port number</param>
/// <param name="parent">reference to factory/listener</param>
/// <param name="maxReceivedMessageSize">
/// Some settings for transport channel</param>
public SerialChannelBase(BufferManager bufferManager,
MessageEncoderFactory encoderFactory,
EndpointAddress address,
string portNumber,
ChannelManagerBase parent,
long maxReceivedMessageSize)
: base(parent)
{
this.address = address;
this.bufferManager = bufferManager;
this.encoder = encoderFactory.CreateSessionEncoder();
this.maxReceivedMessageSize = maxReceivedMessageSize;
this.portNumber = portNumber;
// Create port
serialPort = new SerialPort();
// Set the appropriate properties.
serialPort.PortName = this.portNumber;
//TODO: Read these settings from configuration file
serialPort.BaudRate = 9600;
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.Handshake = Handshake.None;
// Set the read/write timeouts
serialPort.ReadTimeout = 500;
serialPort.WriteTimeout = 500;
}
开发者ID:gitlabuser,项目名称:warehouse,代码行数:43,代码来源:SerialChannelBase.cs
示例17: ToFrameStreamObservable
public static IObservable<DisposableByteBuffer> ToFrameStreamObservable(this Stream stream, BufferManager bufferManager)
{
return Observable.Create<DisposableByteBuffer>(async (observer, token) =>
{
var headerBuffer = new byte[sizeof(int)];
try
{
while (!token.IsCancellationRequested)
{
if (await stream.ReadBytesCompletelyAsync(headerBuffer, headerBuffer.Length, token) != headerBuffer.Length)
break;
var length = BitConverter.ToInt32(headerBuffer, 0);
var buffer = bufferManager.TakeBuffer(length);
if (await stream.ReadBytesCompletelyAsync(buffer, length, token) != length)
break;
observer.OnNext(new DisposableByteBuffer(buffer, length, Disposable.Create(() => bufferManager.ReturnBuffer(buffer))));
}
observer.OnCompleted();
}
catch (Exception error)
{
observer.OnError(error);
}
});
}
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:29,代码来源:StreamExtensions.cs
示例18: MessageBusReplySessionChannel
public MessageBusReplySessionChannel(
BufferManager bufferManager, MessageEncoderFactory encoderFactory, ChannelManagerBase parent,
EndpointAddress localAddress,
IBus bus)
: base(bufferManager, encoderFactory, parent, localAddress, bus)
{
}
开发者ID:shaunxu,项目名称:roma,代码行数:7,代码来源:MessageBusReplySessionChannel.cs
示例19: Encode
public static ArraySegment<byte> Encode(Uri uri, ArraySegment<byte> messageBuffer, BufferManager bufferManager)
{
byte[] uriBuffer = UnicodeEncoding.Unicode.GetBytes(uri.ToString());
byte[] uriLengthBuffer = EncodeInt(uriBuffer.Length);
byte[] payloadLengthBuffer = EncodeInt(messageBuffer.Count);
// Encode the following fields:
// Uri length (4 bytes)
// Uri (size specified by uri length)
// Payload length (4 bytes)
// Payload (size specified by payload length)
byte[] buffer = bufferManager.TakeBuffer(uriLengthBuffer.Length + uriBuffer.Length +
payloadLengthBuffer.Length + messageBuffer.Count);
int destOffset = 0;
Buffer.BlockCopy(uriLengthBuffer, 0, buffer, destOffset, uriLengthBuffer.Length);
destOffset += uriLengthBuffer.Length;
Buffer.BlockCopy(uriBuffer, 0, buffer, destOffset, uriBuffer.Length);
destOffset += uriBuffer.Length;
Buffer.BlockCopy(payloadLengthBuffer, 0, buffer, destOffset, payloadLengthBuffer.Length);
destOffset += payloadLengthBuffer.Length;
Buffer.BlockCopy(messageBuffer.Array, messageBuffer.Offset, buffer, destOffset, messageBuffer.Count);
bufferManager.ReturnBuffer(messageBuffer.Array);
return new ArraySegment<byte>(buffer);
}
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:26,代码来源:FramingCodec.cs
示例20: HttpServer
public HttpServer(int maxAccept, int maxConnections, int bufferSize)
{
timeoutTimer = new System.Timers.Timer(Timeout);
timeoutTimer.Elapsed += timeoutTimer_Elapsed;
this.maxAccept = maxAccept;
this.maxConnections = maxConnections;
this.bufferSize = bufferSize;
this.enforceMaxClients = new Semaphore (maxConnections, maxConnections);
this.bufferManager = BufferManager.CreateBufferManager (maxConnections, maxConnections * bufferSize * 2);
for (int i = 0; i < maxAccept; i++) {
var acceptArgs = new SocketAsyncEventArgs ();
acceptArgs.Completed += HandleAcceptCompleted;
this.acceptPool.Push (acceptArgs);
}
for (int i = 0; i < maxConnections; i++) {
var readWriteArgs = new SocketAsyncEventArgs ();
var client = new HttpClient ();
readWriteArgs.UserToken = client;
readWriteArgs.SetBuffer (this.bufferManager.TakeBuffer (bufferSize), 0, bufferSize);
readWriteArgs.Completed += HandleReadWriteCompleted;
this.readWritePool.Push (readWriteArgs);
}
timeoutTimer.Start();
}
开发者ID:jacoblusk,项目名称:SAEA-HTTPD,代码行数:27,代码来源:HttpServer.cs
注:本文中的System.ServiceModel.Channels.BufferManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论