本文整理汇总了C#中IMessage.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.GetType方法的具体用法?C# IMessage.GetType怎么用?C# IMessage.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessage
public void SendMessage(object sender, IMessage message, object context = null)
{
StartAction(() =>
{
if (sender != null)
{
if (_dictionary.ContainsKey(message.GetType()))
{
foreach (var actionInfo in _dictionary[message.GetType()])
{
if (context != null)
{
if (actionInfo.Context == context)
{
actionInfo.Handler.Invoke();
}
}
else
{
actionInfo.Handler.Invoke();
}
}
}
}
});
}
示例2: HandleMessage
/// <summary>
/// Accepts IMessage's sent to the GRoup
/// </summary>
/// <param name="message"></param>
/// <returns>true if successfully broadcasted to RelationshipType.MEMBER's</returns>
/// <remarks>
/// Overrides the default HandleMessage Behaviour for Group-like behaviour
/// </remarks>
public override bool HandleMessage(IMessage message)
{
// Check the message type
if (message.GetType() == typeof(StringMessage))
{
// pass the message on
Relationship members = new Relationship(RelationshipType.MEMBER);
// broadcast the message using Graph methods
Connections.Instance.SendMessageTo(this, members, message);
return true;
}
// if it's a connection message, try to learn about the connection
if (message.GetType() == typeof(ConnectionMessage))
{
// convert the message
ConnectionMessage msg = message as ConnectionMessage;
// pass the message
Learn(msg.Connection);
return true;
}
// didn't do anything.
return false;
}
示例3: GetConditionsForMessage
/// <summary>
/// Gets the list of conditions associated with a message.
/// </summary>
/// <param name="message">The message to get conditions for.</param>
/// <returns>A list of conditions that are associated with type of message provided.</returns>
public IList<Predicate<IMessage>> GetConditionsForMessage(IMessage message)
{
IList<Predicate<IMessage>> result = new List<Predicate<IMessage>>();
lock (this.locker)
if (this.messageTypeToConditionLookup.ContainsKey(message.GetType()))
foreach (Predicate<IMessage> condition in this.messageTypeToConditionLookup[message.GetType()])
result.Add(condition);
return result;
}
示例4: Dispatch
public void Dispatch(IMessage message, params object[] parameters)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
var handler = _messageHandlerFactory.Create(message.GetType(), parameters);
var dynamicDispatcher = GetDynamicDispatcher(message.GetType());
dynamicDispatcher(handler, message);
}
示例5: FindEventHandlersInAssemblies
public List<HandlerInfo> FindEventHandlersInAssemblies(IMessage message)
{
var result = new List<HandlerInfo>();
var methods = FindMethodsInAssemblyFromTypes(type => ((!type.IsInterface && !type.IsAbstract) &&
(type.GetInterfaces().SingleOrDefault(
x => IsEventHandler(x, message.GetType())) != null)), "Handle", type => new[] { message.GetType() });
foreach (var methodInfo in methods)
{
var declaringType = methodInfo.DeclaringType;
var staticAttribute = declaringType.GetCustomAttributes(typeof(StaticHandlerAttribute), true).SingleOrDefault();
result.Add(new HandlerInfo(methodInfo, staticAttribute != null));
}
return result;
}
示例6: OnMessageReceived
// OnMessageReceived - beim messageConsumer registrierte Callback-Methode,
// wird bei Empfang einer neuen Nachricht vom messageConsumer aufgerufen
public void OnMessageReceived(IMessage msg)
{
if (msg is ITextMessage)
{
ITextMessage tm = msg as ITextMessage;
//Console.WriteLine("TextMessage: ID=" + tm.GetType() + "\n" + tm.Text);
String s = tm.Text;
Console.WriteLine(s);
Schnorchel schnorchel = JsonConvert.DeserializeObject<Schnorchel>(s);
Console.WriteLine(schnorchel);
}
else if (msg is IMapMessage)
{
StringBuilder msgbuffer = new StringBuilder();
IMapMessage mm = msg as IMapMessage;
msgbuffer.AppendFormat("MapMessage: ID={0}\n", msg.GetType());
foreach (string key in mm.Properties.Keys)
{
msgbuffer.AppendFormat(" - Property '{0}' = {1}\n", key, mm.Properties[key]);
}
foreach (string key in mm.Body.Keys)
{
msgbuffer.AppendFormat(" - Eintrag '{0}' = {1}\n", key, mm.Body[key]);
}
Console.WriteLine(msgbuffer.ToString());
}
else
{
Console.WriteLine("\nAnderer Message-Typ: " + msg);
}
}
示例7: SerDesMessage
private static void SerDesMessage(IMessage message)
{
var b = CustomFormatter.Serialize(message);
var o = CustomFormatter.Deserialize(b);
Assert.AreEqual(o.GetType(), message.GetType());
AreEqual(message, o);
}
示例8: Remove
public void Remove(IMessage message)
{
if (message is Message)
_messages.Remove(message as Message);
else
throw new NotSupportedException("Cannot remove message of type '" + message.GetType() + "'");
}
示例9: CreateDelegate
public Delegate CreateDelegate(IMessage message, Func<IServiceBus> serviceBus)
{
var type = message.GetType();
if (!delegates.ContainsKey(type))
{
lock (lockObject)
{
if (!delegates.ContainsKey(type))
{
Type messageConvertor = typeof (Action<>).MakeGenericType(type);
var parameter = Expression.Parameter(type, "x");
delegates.Add(type,
Expression.Lambda(messageConvertor,
Expression.Call(Expression.Constant(serviceBus()),
typeof (IServiceBus).GetMethod("Publish").
MakeGenericMethod(type),
Expression.Constant(message, type)),
parameter).Compile());
}
}
}
return delegates[type];
}
示例10: PublishMessage
public Guid PublishMessage(IMessage message)
{
message.Created = DateTime.Now;
if (message.Identifier == Guid.Empty)
{
message.Identifier = Guid.NewGuid();
}
if (_channel.State != ChannelState.Open)
{
this.WriteDebugMessage("Publication to closed channel detected. Attempting to open channel.");
_channel.Open();
this.WriteDebugMessage("Channel has been opened, publication may proceed.");
}
var record = _publicationRegistry.PublishMessage(message);
_channel.Send(record);
this.WriteInfoMessage(
string.Format(
"Message {0} (record {1}) was successfully published via the channel {2}({3}).",
message.GetType().Name,
record.Identifier,
_channel.GetType().Name,
_channel.ChannelName));
return record.Identifier;
}
示例11: Publish
public void Publish(IMessage message, IMessageContext sender)
{
var messageTpye = message.GetType();
if (handlers.ContainsKey(messageTpye))
{
foreach (var handler in handlers[messageTpye])
{
dynamic instance = handlerFactory(handler);
try
{
if (HasResponse(message))
{
var result = instance.Handle((dynamic)(message.ToPublishedMessage(sender)));
sender.Respond(result);
}
else
instance.Handle((dynamic)(message.ToPublishedMessage(sender)));
}
catch (Exception ex)
{
sender.ErrorFormat("{0} , {1}", ex.Message, ex.StackTrace);
}
}
}
}
示例12: EnsureReliability
public void EnsureReliability(OutboundDisruptorEntry disruptorEntry, IMessage message, IEnumerable<MessageSubscription> concernedSubscriptions, MessageWireData messageData)
{
var messageOptions = _messageOptions[message.GetType().FullName];
if (messageOptions.ReliabilityLevel != ReliabilityLevel.FireAndForget)
foreach (var wireMessage in disruptorEntry.NetworkSenderData.WireMessages)
{
int seqNum;
if (!_endpointToSequenceNumber.TryGetValue(wireMessage.Endpoint, out seqNum))
{
_endpointToSequenceNumber.Add(wireMessage.Endpoint, 0);
seqNum = 0;
}
wireMessage.MessageData.SequenceNumber = seqNum;
_endpointToSequenceNumber[wireMessage.Endpoint] = seqNum + 1;
}
if (disruptorEntry.MessageTargetHandlerData.IsAcknowledgement)
{
SendAcknowledgementShadowMessages(message, concernedSubscriptions, disruptorEntry, messageData);
}
else
{
if (messageOptions.ReliabilityLevel == ReliabilityLevel.Persisted)
{
SendShadowMessages(concernedSubscriptions, messageData, disruptorEntry);
}
}
}
示例13: Get
/// <summary>
/// Gets a <see cref="MessageDescription"/> instance prepared for the
/// given message type.
/// </summary>
/// <param name="message">The message for which a <see cref="MessageDescription"/> should be obtained.</param>
/// <returns>
/// A <see cref="MessageDescription"/> instance.
/// </returns>
internal MessageDescription Get(IMessage message)
{
Contract.Requires(message != null);
Contract.Ensures(Contract.Result<MessageDescription>() != null);
ErrorUtilities.VerifyArgumentNotNull(message, "message");
return this.Get(message.GetType(), message.Version);
}
示例14: HandleMessage
public override bool HandleMessage(IMessage message)
{
if(message.GetType() == typeof(ConnectionMessage))
{
// pass on message to Entity handler
base.HandleMessage(message);
}
if (message.GetType() == typeof(StringMessage))
{
StringMessage msg = message as StringMessage;
gs.SetResponse(Responses.MESSAGE, "\"" + msg.Text + "\"");
}
return true;
}
示例15: Handle
public static void Handle(object handler, IMessage message)
{
Type messageType = message.GetType();
var method = handler.GetType()
.GetMethods(BindingFlags.Instance | BindingFlags.Public)
.Single(e => e.Name == "Handle" && e.GetParameters().Count() == 1 && e.GetParameters()[0].ParameterType == messageType);
method.Invoke(handler, new object[] { message });
}