本文整理汇总了C#中IMessage.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.Copy方法的具体用法?C# IMessage.Copy怎么用?C# IMessage.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.Copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPushEnd
/*
void OnPushEnd(IAsyncResult result)
{
EndPushMessageToClients(result);
}
*/
/// <summary>
/// Pushes a message to the specified clients (subscribers).
/// </summary>
/// <param name="subscribers">Collection of subscribers.</param>
/// <param name="message">The Message to push to the subscribers.</param>
/// <remarks>
/// The Collection of subscribers is a collection of client Id strings.
/// </remarks>
public void PushMessageToClients(ICollection subscribers, IMessage message)
{
MessageDestination destination = GetDestination(message) as MessageDestination;
SubscriptionManager subscriptionManager = destination.SubscriptionManager;
if( subscribers != null && subscribers.Count > 0 )
{
IMessage messageClone = message.Copy() as IMessage;
/*
if( subscribers.Count > 1 )
{
messageClone.SetHeader(MessageBase.DestinationClientIdHeader, BinaryMessage.DestinationClientGuid);
messageClone.clientId = BinaryMessage.DestinationClientGuid;
//Cache the message
MemoryStream ms = new MemoryStream();
AMFSerializer amfSerializer = new AMFSerializer(ms);
//TODO this should depend on endpoint settings
amfSerializer.UseLegacyCollection = false;
amfSerializer.WriteData(ObjectEncoding.AMF3, messageClone);
amfSerializer.Flush();
byte[] cachedContent = ms.ToArray();
ms.Close();
BinaryMessage binaryMessage = new BinaryMessage();
binaryMessage.body = cachedContent;
//binaryMessage.Prepare();
messageClone = binaryMessage;
}
*/
foreach(string clientId in subscribers)
{
MessageClient client = subscriptionManager.GetSubscriber(clientId);
if( client == null )
continue;
if (log.IsDebugEnabled)
{
if( messageClone is BinaryMessage )
log.Debug(__Res.GetString(__Res.MessageServicePushBinary, message.GetType().Name, clientId));
else
log.Debug(__Res.GetString(__Res.MessageServicePush, message.GetType().Name, clientId));
}
IEndpoint endpoint = _messageBroker.GetEndpoint(client.EndpointId);
if (endpoint != null)
endpoint.Push(messageClone, client);
else
{
//We should never get here
if( log.IsErrorEnabled)
log.Error(string.Format("Missing endpoint for message client {0}", client.ClientId));
}
}
}
}
示例2: Push
public override void Push(IMessage message, MessageClient messageClient)
{
IEndpointPushHandler handler = messageClient.Client.GetEndpointPushHandler(this.Id);
if (handler != null)
{
IMessage messageClone = message.Copy() as IMessage;
messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
messageClone.clientId = messageClient.ClientId;
handler.PushMessage(messageClone);
}
/*
IMessage messageClone = message.Clone() as IMessage;
messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
messageClone.clientId = messageClient.ClientId;
messageClient.AddMessage(messageClone);
*/
}
示例3: Push
public override void Push(IMessage message, MessageClient messageClient)
{
if (this.ChannelDefinition.Properties.IsPollingEnabled)
{
IEndpointPushHandler handler = messageClient.Client.GetEndpointPushHandler(this.Id);
if (handler != null)
{
IMessage messageClone = message.Copy() as IMessage;
messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
messageClone.clientId = messageClient.ClientId;
handler.PushMessage(messageClone);
}
/*
IMessage messageClone = message.Clone() as IMessage;
messageClone.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
messageClone.clientId = messageClient.ClientId;
messageClient.AddMessage(messageClone);
*/
}
else
{
if (log.IsWarnEnabled)
log.Warn("Push request received for the non-polling AMF endpoint '" + this.Id + "'");
}
}