public JsonHttpPacketClient(IJsonSerializationClientAdapter jc) { this.c = new Context(); this.jc = jc; jc.ClientEvent += (String CommandName, UInt32 CommandHash, String Parameters, Action <Exception> OnError) => { var jo = new JObject(); jo["commandName"] = new JValue(CommandName); jo["commandHash"] = new JValue(CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture)); jo["parameters"] = new JValue(Parameters); c.WriteBuffer.Add(jo); if (ClientMethod != null) { ClientMethod(OnError); } }; }
public JsonHttpClient(IJsonSerializationClientAdapter jc, String Prefix, String ServiceVirtualPath, Boolean UseJsonp, Boolean UseShortConnection) { if (!Prefix.EndsWith("/")) { throw new InvalidOperationException("PrefixNotEndWithSlash: '" + Prefix + "'"); } this.jc = jc; this.Prefix = Prefix; this.ServiceVirtualPath = ServiceVirtualPath; this.UseJsonp = UseJsonp; this.UseShortConnection = UseShortConnection; SessionId = null; CommandQueue = new Queue <Command>(); jc.ClientEvent += (CommandName, CommandHash, Parameters, OnError) => { var jo = new { commandName = CommandName, commandHash = CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture), parameters = Parameters }; SendWithHash(jo, jc.HandleResult); }; }
public JsonLinePacketClient(IJsonSerializationClientAdapter jc, IBinaryTransformer Transformer = null, int ReadBufferSize = 8 * 1024) { this.c = new Context(ReadBufferSize); this.jc = jc; this.Transformer = Transformer; jc.ClientEvent += (String CommandName, UInt32 CommandHash, String Parameters, Action <Exception> OnError) => { var Message = "/" + CommandName + "@" + CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture) + " " + Parameters + "\r\n"; var Bytes = System.Text.Encoding.UTF8.GetBytes(Message); if (Transformer != null) { Transformer.Transform(Bytes, 0, Bytes.Length); } c.WriteBuffer.Add(Bytes); if (this.ClientMethod != null) { ClientMethod(OnError); } }; }