本文整理汇总了C#中Message.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Message.GetType方法的具体用法?C# Message.GetType怎么用?C# Message.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public void Handle(Message msg)
{
if (msg.GetType().Equals(Message.MessageTypes.PLAYER_SPAWN))
{
String id = msg.get(1);
String screenName = msg.get(2);
float x_pos = float.Parse(msg.get(3));
float y_pos = float.Parse(msg.get(4));
float z_pos = float.Parse(msg.get(5));
PlayerInfo pi = new PlayerInfo(id, screenName, new Vector3f(x_pos, y_pos, z_pos));
for (int i = 0; i < ServerList.players.Count; i++)
{
if (!id.Equals(ServerList.players[i].GetID()))
{
parent.Send(int.Parse(id), new Message(Message.MessageTypes.PLAYER_SPAWN,
ServerList.players[i].GetID(), ServerList.players[i].GetScreenName(),
ServerList.players[i].GetPosition().x, ServerList.players[i].GetPosition().y,
ServerList.players[i].GetPosition().z));
}
}
ServerList.players.Add(pi);
parent.BroadcastExcept(int.Parse(pi.GetID()), msg); // broadcast
// that
// the
// player
// has
// spawned
}
else if (msg.GetType().Equals(Message.MessageTypes.PLAYER_MOVE))
{
String id = msg.get(1);
float x_pos = float.Parse(msg.get(3));
float y_pos = float.Parse(msg.get(4));
float z_pos = float.Parse(msg.get(5));
PlayerInfo p = PlayerWithID(ServerList.players, id);
if (p != null)
{
p.GetPosition().Set(new Vector3f(x_pos, y_pos, z_pos));
}
parent.Broadcast(msg);
}
else if (msg.getType().Equals(Message.MessageTypes.QUIT_MESSAGE))
{
String id = msg.get(1);
PlayerInfo p = PlayerWithID(ServerList.players, id);
if (p != null)
{
ServerList.players.Remove(p);
}
parent.Broadcast(msg);
}
else
{ // else, just broadcast the message
parent.Broadcast(msg);
}
}
示例2: construct
private static void construct(AggregateInfo aggregateInfo, Message creationMessage)
{
var creationConstructor = aggregateInfo.Type.GetConstructor(new[] {creationMessage.GetType()});
if (creationConstructor == null) throw new MissingMethodException(aggregateInfo.Type.FullName, "constructor");
creationConstructor.Invoke(aggregateInfo.Instance, new object[] {creationMessage});
}
示例3: CreateStreamCompleted
public static ResponseConfiguration CreateStreamCompleted(HttpResponseConfiguratorArgs entity, Message message, string eventStreamId)
{
Debug.Assert(message.GetType() == typeof(ClientMessage.CreateStreamCompleted));
var completed = message as ClientMessage.CreateStreamCompleted;
if (completed == null)
return InternalServerError();
switch (completed.Result)
{
case OperationResult.Success:
{
return new ResponseConfiguration(
HttpStatusCode.Created,
"Stream created",
null,
Encoding.UTF8,
new KeyValuePair<string, string>("Location",
HostName.Combine(entity.UserHostName,
"/streams/{0}",
Uri.EscapeDataString(eventStreamId))));
}
case OperationResult.PrepareTimeout:
case OperationResult.CommitTimeout:
case OperationResult.ForwardTimeout:
return InternalServerError("Create timeout");
case OperationResult.WrongExpectedVersion:
case OperationResult.StreamDeleted:
case OperationResult.InvalidTransaction:
return BadRequest(string.Format("Error code : {0}. Reason : {1}", completed.Result, completed.Message));
default:
throw new ArgumentOutOfRangeException();
}
}
示例4: OnMessage
public void OnMessage(Message message)
{
messageCount++;
LOG.Debug("Message listener count = " + messageCount);
TextMessage textMessage = message as TextMessage;
if (textMessage != null)
{
LOG.Info("Message Text = " + textMessage.Text);
} else
{
LOG.Warn("Can not process message of type " + message.GetType());
}
}
示例5: foreach
public SelectorInfo[] this[Message message]
{
get
{
var messageType = message.GetType();
if (!selectorsForMessage.ContainsKey(messageType))
{
foreach (
var assembly in
AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !selectorsForAssembly.ContainsKey(assembly)))
{
selectorsForAssembly[assembly] =
assembly
.GetTypes()
.Where(type => type.IsClass)
.Where(possibleSelector => typeof (SelectKeyForAggregate).IsAssignableFrom(possibleSelector))
.ToArray();
}
selectorsForMessage[messageType] =
selectorsForAssembly
.SelectMany(_ => _.Value)
.Select(
possibleSelectorType =>
new
{
PossibleSelectorType = possibleSelectorType,
Selectors =
possibleSelectorType
.GetInterfaces()
.Where(iface => typeof (SelectKeyForAggregate).IsAssignableFrom(iface))
.Where(selector => selector != typeof (SelectKeyForAggregate))
.Where(selector => selector.GetGenericArguments()[1].IsAssignableFrom(messageType))
})
.Where(possibleSelectors => possibleSelectors.Selectors.Any())
.SelectMany(
possibleSelectors => possibleSelectors.Selectors,
(possibleSelectors, selector) =>
new SelectorInfo(
selector.GetGenericArguments()[0],
(SelectKeyForAggregate)
Activator.CreateInstance(possibleSelectors.PossibleSelectorType)))
.ToArray();
}
return selectorsForMessage[messageType];
}
}
示例6: LogMessage
public static void LogMessage (MessageLogSourceKind sourceKind, ref Message msg, long maxMessageSize)
{
if (maxMessageSize > int.MaxValue)
throw new ArgumentOutOfRangeException ("maxMessageSize");
var mb = msg.CreateBufferedCopy ((int) maxMessageSize);
msg = mb.CreateMessage ();
LogMessage (new MessageLogTraceRecord (sourceKind, msg.GetType (), mb));
}
示例7: SendMessage
public void SendMessage(Message m, Action<JsonData> callback = null)
{
Debug.Log ("In send message");
var toSend = m.ToByteArray();
Debug.Log ("Got byte array");
Debug.Log(string.Format("{0}: sending {1} bytes", m.GetType(), toSend.Length));
m_socket.BeginSend (toSend, 0, toSend.Length, SocketFlags.None, SendMessageFinished, m);
if(callback != null) {
m_pendingCallback = callback;
m_hasCallback = true;
}
else {
m_pendingCallback = null;
m_hasCallback = false;
}
}
示例8: DispatchMessage
bool DispatchMessage(Message msg)
{
Action<User, ServerMessage> method;
if (s_handlerMap.TryGetValue(msg.GetType(), out method) == false)
return false;
method(this, (ServerMessage)msg);
return true;
}
示例9: Send
public void Send(Message message)
{
for (int i = 0; i < coroutines.Count; i++)
{
Coroutine coroutine = coroutines.ElementAt(i);
if (coroutine.mapper.mappedMessages.ContainsKey(message.GetType())) //if this coroutine contains the message
{
for (int j = 0; j < i; j++)//pop all child coroutines off the stack
{
coroutines.Pop();
}
MessageDelegate del;
coroutine.mapper.mappedMessages.TryGetValue(message.GetType(), out del);
del(message); //call function attached to mapped message
break;
}
}
}
示例10: ReadEventCompleted
public static ResponseConfiguration ReadEventCompleted(HttpResponseConfiguratorArgs entity, Message message)
{
Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventCompleted));
var completed = message as ClientMessage.ReadEventCompleted;
if (completed == null)
return InternalServerError();
switch (completed.Result)
{
case ReadEventResult.Success:
return OkCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, MaxPossibleAge);
case ReadEventResult.NotFound:
case ReadEventResult.NoStream:
return NotFound();
case ReadEventResult.StreamDeleted:
return Gone();
default:
throw new ArgumentOutOfRangeException();
}
}
示例11: HandleMessage
/// <summary>
/// Handles a message from the MessagePool
/// </summary>
/// <param name="msg"></param>
public virtual void HandleMessage(Message msg)
{
// Check we're enabled
if (!Enabled) return;
// Check we have a handler
var t = msg.GetType();
MethodInfo method;
if (!dctMessageHandlers.TryGetValue(t, out method)) return;
// Handle it!
tmp[0] = msg;
try
{
method.Invoke(this, tmp);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
示例12: Serialize
/// <summary>
/// Converts the given message to a JSON representation
/// </summary>
/// <param name="message">The message to be serialized</param>
/// <returns>The message in JSON form</returns>
public static string Serialize(Message message)
{
var dict = new Dictionary<string, Message>();
dict[message.GetType().Name.Replace("Message", "").FirstToLower()] = message;
return JsonConvert.SerializeObject(
dict,
Formatting.None,
new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
);
}
示例13: GetFreshStatsCompleted
public static ResponseConfiguration GetFreshStatsCompleted(HttpResponseConfiguratorArgs entity, Message message)
{
Debug.Assert(message.GetType() == typeof(MonitoringMessage.GetFreshStatsCompleted));
var completed = message as MonitoringMessage.GetFreshStatsCompleted;
if (completed == null)
return InternalServerError();
return completed.Success ? OkNoCache(entity.ResponseCodec.ContentType, Encoding.UTF8) : NotFound();
}
示例14: Send
public void Send(Message msg)
{
if (m_socket.Connected == false)
{
trace.TraceVerbose("[TX] socket not connected, skipping send");
return;
}
try
{
lock (m_sendLock)
{
trace.TraceVerbose("[TX] sending {0}", msg.GetType().Name);
var stream = m_netStream;
int len = stream.SentBytes;
NetSerializer.Primitives.WritePrimitive(stream, MAGIC);
Serializer.Serialize(stream, msg);
stream.Flush();
len = stream.SentBytes - len;
trace.TraceVerbose("[TX] sent {0} bytes", len);
if (m_netStatCollector != null)
m_netStatCollector.OnMessageSent(msg.GetType(), len);
}
}
catch (SocketException e)
{
var error = e.SocketErrorCode;
trace.TraceError("[TX]: socket error {0}", error);
}
}
示例15: Process
public Message Process(Message message)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
var pqlMessage = message as PqlMessage;
if (pqlMessage == null)
{
throw new Exception(string.Format("Invalid message type, expected {0}, got {1}",
typeof(PqlMessage).AssemblyQualifiedName, message.GetType().AssemblyQualifiedName));
}
try
{
// re-establish authentication context as it is on the client side
var authContext = AuthContextSerializer.GetObject(pqlMessage.AuthTicket);
PqlEngineSecurityContext.Set(authContext);
// get a processing manager from pool, start production
var holder = m_requestManagersPool.Take(m_cancellationTokenSource.Token);
try
{
var engine = m_enginesCache.GetEngine(authContext.TenantId, pqlMessage.ScopeId);
holder.Item.Attach((PqlMessage) message, engine, authContext);
engine.BeginExecution(holder.Item.ExecutionContext);
}
catch
{
holder.Item.ExecutionContext.Cancel(null);
holder.Dispose();
throw;
}
// return the message to WCF infrastructure
try
{
holder.Item.ExecutionContext.AttachRequestCompletion();
return new PqlMessage(
holder.Item,
new IDisposable[]
{
holder.Item.ExecutionContext.Completion,
holder
},
pqlMessage.AuthTicket, pqlMessage.ScopeId, m_protocolVersion);
}
catch (Exception e)
{
holder.Item.ExecutionContext.Cancel(e);
holder.Dispose();
throw;
}
}
catch (Exception e)
{
m_tracer.Exception(e);
return new PqlMessage(new PqlErrorDataWriter(1, e, true), null, pqlMessage.AuthTicket, pqlMessage.ScopeId, m_protocolVersion);
}
}