public void Serialize(Guid connectionId, IConnectionEvent eventObject, Stream output) { var serializer = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; UserConnection user; ConnectionManager._connections.TryGetValue(connectionId, out user); if (user != null) { var json = JObject.FromObject(eventObject, serializer); json.Add("type", new JValue(eventObject.GetType().Name)); json.Remove("connectionId"); var jsonString = json.ToString(); var utfJson = Encoding.Default.GetBytes(jsonString); jsonString = Encoding.UTF8.GetString(utfJson); if (user.AesShook) { var keybytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesKey)); var iv = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesIv)); var encrpytedJson = UlteriusAes.Encrypt(jsonString, keybytes, iv); using (var writer = new BinaryWriter(output, Encoding.UTF8, true)) { writer.Write(encrpytedJson); } } else { using (var writer = new StreamWriter(output, Encoding.UTF8, 4096, true)) { writer.Write(jsonString); } } } }
public void Serialize(IConnectionEvent eventObject, Stream output) { JsonSerializer serializer = new JsonSerializer(); serializer.ContractResolver = new CamelCasePropertyNamesContractResolver(); var json= JObject.FromObject(eventObject, serializer); json.Add("type", new JValue(eventObject.GetType().Name)); json.Remove("connectionId"); using (var writer = new StreamWriter(output, Encoding.UTF8,4096,true)) using( var jwriter = new JsonTextWriter(writer)) { json.WriteTo(jwriter); } }
public void Serialize(IConnectionEvent eventObject, Stream output) { JsonSerializer serializer = new JsonSerializer(); serializer.ContractResolver = new CamelCasePropertyNamesContractResolver(); var json = JObject.FromObject(eventObject, serializer); json.Add("type", new JValue(eventObject.GetType().Name)); json.Remove("connectionId"); using (var writer = new StreamWriter(output, Encoding.UTF8, 4096, true)) using (var jwriter = new JsonTextWriter(writer)) { json.WriteTo(jwriter); } }
public void Serialize(Guid connectionId, IConnectionEvent eventObject, Stream output) { var serializer = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; UserConnection user; ConnectionManager._connections.TryGetValue(connectionId, out user); if (user != null) { var json = JObject.FromObject(eventObject, serializer); json.Add("type", new JValue(eventObject.GetType().Name)); json.Remove("connectionId"); var jsonString = json.ToString().UnicodeUtf8(); Console.WriteLine(jsonString); if (user.AesShook) { var keybytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesKey)); var iv = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesIv)); var encrpytedJson = UlteriusAes.Encrypt(Encoding.UTF8.GetBytes(jsonString), keybytes, iv); using (var memoryStream = new MemoryStream()) { using (var binaryWriter = new BinaryWriter(memoryStream, Encoding.UTF8)) { var Endpoint = "terminal"; binaryWriter.Write(Endpoint.Length); binaryWriter.Write(Encoding.UTF8.GetBytes(Endpoint)); binaryWriter.Write(Encoding.UTF8.GetBytes(UlteriusAes.EncryptionType.CBC.ToString())); binaryWriter.Write(encrpytedJson); } using (var writer = new BinaryWriter(output, Encoding.UTF8, true)) { writer.Write(memoryStream.ToArray()); } } } else { using (var writer = new StreamWriter(output, Encoding.UTF8, 4096, true)) { writer.Write(jsonString); } } } }
public void Serialize(Guid connectionId, IConnectionEvent eventObject, Stream output) { var serializer = new JsonSerializer {ContractResolver = new CamelCasePropertyNamesContractResolver()}; UserConnection user; ConnectionManager._connections.TryGetValue(connectionId, out user); if (user != null) { var json = JObject.FromObject(eventObject, serializer); json.Add("type", new JValue(eventObject.GetType().Name)); json.Remove("connectionId"); var jsonString = json.ToString().UnicodeUtf8(); if (user.AesShook) { var keybytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesKey)); var iv = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(user.AesIv)); var encrpytedJson = UlteriusAes.Encrypt(Encoding.UTF8.GetBytes(jsonString), keybytes, iv); using (var memoryStream = new MemoryStream()) { using (var binaryWriter = new BinaryWriter(memoryStream, Encoding.UTF8)) { var Endpoint = "terminal"; binaryWriter.Write(Endpoint.Length); binaryWriter.Write(Encoding.UTF8.GetBytes(Endpoint)); binaryWriter.Write(Encoding.UTF8.GetBytes(UlteriusAes.EncryptionType.CBC.ToString())); binaryWriter.Write(encrpytedJson); } using (var writer = new BinaryWriter(output, Encoding.UTF8, true)) { writer.Write(memoryStream.ToArray()); } } } else { using (var writer = new StreamWriter(output, Encoding.UTF8, 4096, true)) { writer.Write(jsonString); } } } }
public void Push(IConnectionEvent evt) { evt.ConnectionId = this.ConnectionId; _bus.Queue.Publish(evt, evt.GetType()); }
public void Push(IConnectionEvent evt) { evt.ConnectionId = ConnectionId; _bus.Queue.Publish(evt, evt.GetType()); }