代码拉取完成,页面将自动刷新
#region S# License
/******************************************************************************************
NOTICE!!! This program and source code is owned and licensed by
StockSharp, LLC, www.stocksharp.com
Viewing or use of this code requires your acceptance of the license
agreement found at https://github.com/StockSharp/StockSharp/blob/master/LICENSE
Removal of this comment is a violation of the license agreement.
Project: StockSharp.Messages.Messages
File: ChannelMessageAdapter.cs
Created: 2015, 11, 11, 2:32 PM
Copyright 2010 by StockSharp, LLC
*******************************************************************************************/
#endregion S# License
namespace StockSharp.Messages
{
using System;
/// <summary>
/// Message adapter, forward messages through a transport channel <see cref="IMessageChannel"/>.
/// </summary>
public class ChannelMessageAdapter : MessageAdapterWrapper, IMessageSender
{
/// <summary>
/// Initializes a new instance of the <see cref="ChannelMessageAdapter"/>.
/// </summary>
/// <param name="innerAdapter">Underlying adapter.</param>
/// <param name="inputChannel">Incoming messages channel.</param>
/// <param name="outputChannel">Outgoing message channel.</param>
public ChannelMessageAdapter(IMessageAdapter innerAdapter, IMessageChannel inputChannel, IMessageChannel outputChannel)
: base(innerAdapter)
{
if (inputChannel == null)
throw new ArgumentNullException(nameof(inputChannel));
if (outputChannel == null)
throw new ArgumentNullException(nameof(outputChannel));
InputChannel = inputChannel;
OutputChannel = outputChannel;
InputChannel.NewOutMessage += InputChannelOnNewOutMessage;
OutputChannel.NewOutMessage += OutputChannelOnNewOutMessage;
}
/// <summary>
/// Adapter.
/// </summary>
public IMessageChannel InputChannel { get; }
/// <summary>
/// Adapter.
/// </summary>
public IMessageChannel OutputChannel { get; }
/// <summary>
/// Control the lifetime of the incoming messages channel.
/// </summary>
public bool OwnInputChannel { get; set; }
/// <summary>
/// Control the lifetime of the outgoing messages channel.
/// </summary>
public bool OwnOutputChannel { get; set; }
private void OutputChannelOnNewOutMessage(Message message)
{
RaiseNewOutMessage(message);
}
/// <summary>
/// Process <see cref="MessageAdapterWrapper.InnerAdapter"/> output message.
/// </summary>
/// <param name="message">The message.</param>
protected override void OnInnerAdapterNewOutMessage(Message message)
{
if (!OutputChannel.IsOpened)
OutputChannel.Open();
OutputChannel.SendInMessage(message);
}
private void InputChannelOnNewOutMessage(Message message)
{
InnerAdapter.SendInMessage(message);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public override void Dispose()
{
InputChannel.NewOutMessage -= InputChannelOnNewOutMessage;
OutputChannel.NewOutMessage -= OutputChannelOnNewOutMessage;
if (OwnInputChannel)
InputChannel.Dispose();
if (OwnOutputChannel)
OutputChannel.Dispose();
base.Dispose();
}
/// <summary>
/// Send message.
/// </summary>
/// <param name="message">Message.</param>
public override void SendInMessage(Message message)
{
if (!InputChannel.IsOpened)
InputChannel.Open();
InputChannel.SendInMessage(message);
}
/// <inheritdoc />
public void SendOutMessage(Message message)
{
if (!OutputChannel.IsOpened)
OutputChannel.Open();
OutputChannel.SendInMessage(message);
}
/// <summary>
/// Create a copy of <see cref="ChannelMessageAdapter"/>.
/// </summary>
/// <returns>Copy.</returns>
public override IMessageChannel Clone()
{
return new ChannelMessageAdapter(InnerAdapter, InputChannel.Clone(), OutputChannel.Clone());
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。