2017-06-12 20:19:18 +00:00
|
|
|
using System;
|
2017-06-13 07:03:01 +00:00
|
|
|
using System.Runtime.Serialization;
|
2017-06-13 03:31:47 +00:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Converters;
|
2017-06-12 20:19:18 +00:00
|
|
|
|
|
|
|
namespace Ooui
|
|
|
|
{
|
|
|
|
public class Message
|
|
|
|
{
|
2017-06-13 07:03:01 +00:00
|
|
|
[JsonProperty("m")]
|
2017-06-12 20:19:18 +00:00
|
|
|
public MessageType MessageType = MessageType.Nop;
|
2017-06-13 03:31:47 +00:00
|
|
|
|
|
|
|
[JsonProperty("id")]
|
2017-06-12 20:19:18 +00:00
|
|
|
public string TargetId = "";
|
2017-06-13 03:31:47 +00:00
|
|
|
|
|
|
|
[JsonProperty("k")]
|
|
|
|
public string Key = "";
|
|
|
|
|
2017-06-19 06:42:13 +00:00
|
|
|
[JsonProperty("v", NullValueHandling = NullValueHandling.Ignore)]
|
2017-06-15 09:39:19 +00:00
|
|
|
public object Value = null;
|
2017-06-13 07:51:24 +00:00
|
|
|
|
2017-06-16 04:27:15 +00:00
|
|
|
public static Message Call (string targetId, string method, params object[] args) => new Message {
|
|
|
|
MessageType = MessageType.Call,
|
|
|
|
TargetId = targetId,
|
|
|
|
Key = method,
|
|
|
|
Value = args,
|
|
|
|
};
|
|
|
|
|
2017-06-15 06:10:58 +00:00
|
|
|
public static Message Event (string targetId, string eventType) => new Message {
|
|
|
|
MessageType = MessageType.Event,
|
|
|
|
TargetId = targetId,
|
|
|
|
Key = eventType,
|
|
|
|
};
|
2017-06-12 20:19:18 +00:00
|
|
|
}
|
|
|
|
|
2017-06-13 07:03:01 +00:00
|
|
|
[JsonConverter (typeof (StringEnumConverter))]
|
2017-06-12 20:19:18 +00:00
|
|
|
public enum MessageType
|
|
|
|
{
|
2017-06-13 07:03:01 +00:00
|
|
|
[EnumMember(Value = "nop")]
|
2017-06-12 20:19:18 +00:00
|
|
|
Nop,
|
2017-06-13 07:03:01 +00:00
|
|
|
[EnumMember(Value = "create")]
|
2017-06-12 20:19:18 +00:00
|
|
|
Create,
|
2017-06-13 07:03:01 +00:00
|
|
|
[EnumMember(Value = "set")]
|
2017-06-12 20:45:27 +00:00
|
|
|
Set,
|
2017-06-13 07:03:01 +00:00
|
|
|
[EnumMember(Value = "call")]
|
2017-06-12 20:45:27 +00:00
|
|
|
Call,
|
2017-06-15 06:10:58 +00:00
|
|
|
[EnumMember(Value = "listen")]
|
|
|
|
Listen,
|
|
|
|
[EnumMember(Value = "event")]
|
|
|
|
Event,
|
2017-06-12 20:19:18 +00:00
|
|
|
}
|
|
|
|
}
|