internal void InitializeForSend(Converter converter, uint cmd, uint flags, object payload) { Packet header = new Packet { Seq = _sequenceId, Cmd = cmd, Flags = flags }; Raw = new MessageRaw(); Base = new MessageBase { Header = header, Payload = payload }; if (payload != null) { Raw.Payload = converter.Serialize(payload); Base.Header.Size = (uint)Raw.Payload.Length; Base.Header.CrcData = CRC.ComputeCRC(Raw.Payload, 0); } }
protected override void Execute(TContext model) { var ev = model.Event; var eventId = ev.ExtendedDatas()[Constants.EventId].GetValue(model).ToString(); var taskId = ev.ExtendedDatas()[Constants.TaskUuid].GetValue(model).ToString(); if (model.Workflow.GetEvent(Guid.Parse(eventId), out Event e)) { if (e.GetAction(Guid.Parse(taskId), out PushedAction a)) { a.Change = ChangeEnum.New; var i = model.IncomingEvent; var m = new MessageRaw(); var body = new MessageBlock() .Add(nameof(i.CreationDate), i.CreationDate.ToString()) .Add(nameof(i.EventDate), i.EventDate.ToString()) ; foreach (var item in i.ExtendedDatas().Items) { body.Add(item.Key, item.Value.GetValue(model)); } m.Body = body; a.ResultMessage = m; } } }
private void Xmpp_OnMessage(object sender, Message msg) { Friend friend; if (friends.TryGetValue(msg.From.User, out friend)) { OnMessage(new ChatMessage(msg.From.User, msg, false)); } else { MessageRaw?.Invoke(this, msg); } }
public async Task <int> Fetch(ITargetBlock <MessageRaw> buffer, long fromPosition, int limit, CancellationToken cancellationToken = default(CancellationToken)) { using (var cnn = new SqlConnection(_connectionString)) { var cmd = cnn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = spuReadAllStreamsForward; cmd.AddInputParam(limitParamName, SqlDbType.Int, limit); cmd.AddInputParam(fromPositionParamName, SqlDbType.Int, fromPosition); await cnn.OpenAsync(cancellationToken).NotOnCapturedContext(); var rows = 0; using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult, cancellationToken).NotOnCapturedContext()) { while (await reader.ReadAsync(cancellationToken).NotOnCapturedContext()) { var raw = new MessageRaw { StreamId = reader.GetString(colIndexForStreamName), MessageContractName = reader.GetString(colIndexForContractName), CorrelationId = reader.GetGuid(colIndexForCorrelationId), Timestamp = reader.GetDateTime(colIndexForTimestamp), MessageId = reader.GetGuid(colIndexForMessageId), MessageVersion = reader.GetInt32(colIndexForMessageVersion), MessagePosition = reader.GetInt64(colIndexForMessagePosition), MessagePayload = reader.GetStream(colIndexForMessagePayload), MessageMetadataPayload = reader.IsDBNull(colIndexForMessageMetadataPayload) ? null : reader.GetStream(colIndexForMessageMetadataPayload) }; await buffer.SendAsync(raw, cancellationToken).NotOnCapturedContext(); rows++; } } return(rows); } }
internal void InitializeForSend( IController parent, Converter converter, uint cmd, uint flags, object payload ) { Packet header = parent.NewPacket(); header.m_cmd = cmd; header.m_flags = flags; m_parent = parent; m_raw = new MessageRaw (); m_base = new MessageBase(); m_base.m_header = header; m_base.m_payload = payload; if(payload != null) { m_raw.m_payload = converter.Serialize( payload ); m_base.m_header.m_size = (uint)m_raw.m_payload.Length; m_base.m_header.m_crcData = CRC.ComputeCRC( m_raw.m_payload, 0 ); } }
internal void InitializeForSend(IController parent, Converter converter, uint cmd, uint flags, object payload) { Packet header = parent.NewPacket(); header.m_cmd = cmd; header.m_flags = flags; m_parent = parent; m_raw = new MessageRaw(); m_base = new MessageBase(); m_base.m_header = header; m_base.m_payload = payload; if (payload != null) { m_raw.m_payload = converter.Serialize(payload); m_base.m_header.m_size = (uint)m_raw.m_payload.Length; m_base.m_header.m_crcData = CRC.ComputeCRC(m_raw.m_payload, 0); } }
public IncomingMessage(IController parent, MessageRaw raw, MessageBase messageBase) { _parent = parent; _raw = raw; _base = messageBase; }
public IncomingMessage( IController parent, MessageRaw raw, MessageBase messageBase) { m_parent = parent; m_raw = raw; m_base = messageBase; }
public static JToken Serialize(this MessageRaw self) { return(visitor.VisitMessageRaw(self)); }
public abstract T VisitMessageRaw(MessageRaw m);
public static void SendMessage(BinaryWriter stream, INetMessage msg) { var msgRaw = new MessageRaw(msg); msgRaw.WriteTo(stream); }
static INetMessage OnReceivedMessage(MessageRaw msg, Side side) { if (messageTypes.TryGetValue(msg.type, out var msgType)) { var netMsg = (INetMessage)Activator.CreateInstance(msgType); netMsg.Side = side; using (var ms = new MemoryStream(msg.data)) { var subId = -1; try { netMsg.OnDeserialize(new BinaryReader(ms)); if (netMsg is Msg82NetModule netModule) { subId = netModule.moduleId; if (subId == 1) { if (netMsg.Side == Side.Server) { Console.WriteLine($"<{netMsg.Side}> : {((NetworkText)netModule.moduleValue["text"]).text}"); } } } } catch (NotImplementedException e) { throw e; } catch (Exception e) { throw new Exception($"(SubPackage:{subId}) Failed to deserialize message\n" + e.ToString()); } //Console.WriteLine($"Reveiced msg {msg.type} from " + netMsg.Side.ToString()); if (ms.Position != ms.Length) { throw new Exception($"(SubPackage:{subId}) Part of the data is not read"); } // check whether the serialized result is same byte[] data = null; using (var memorystream = new MemoryStream()) using (var testWriter = new BinaryWriter(memorystream)) { netMsg.OnSerialize(testWriter); memorystream.Seek(0, SeekOrigin.Begin); data = new byte[memorystream.Length]; memorystream.Read(data, 0, (int)memorystream.Length); } for (var i = 0; i < data.Length; ++i) { if (data[i] != msg.data[i]) { Console.WriteLine($"Warning: (SubPackage:{subId}) Serialized result is not same with the original one"); break; } } } return(netMsg); } else { Console.WriteLine($"Unknown msg {msg.type}"); } return(null); }
static Task StartForward(NetworkStream from, NetworkStream to) { var task = new Task(() => { while (serverConnection.Connected && playerConnection.Connected) { MessageRaw msg; try { var reader = new BinaryReader(from); msg = new MessageRaw(reader); } catch { break; } INetMessage netMessage = null; try { if (from == serverStream) { netMessage = OnReceivedMessage(msg, Side.Server); } else { netMessage = OnReceivedMessage(msg, Side.Client); } } catch (NotImplementedException) { Console.WriteLine($"An not implemented message {msg.type}"); netMessage = null; } catch (Exception e) { Console.WriteLine($"Failed to read net message {msg.type} because {e.Message}"); netMessage = null; } try { if (netMessage != null) { try { using (var memoryStream = new MemoryStream()) { if (msg.type == Msg10SendSection.ID) { var sectionData = (Msg10SendSection)netMessage; foreach (var tile in sectionData.tiles) { tile.Value.wall = 0; } } if (msg.type == Msg16PlayerHP.ID) { var playerHp = (Msg16PlayerHP)netMessage; playerHp.maxHp = 1000; playerHp.hp = 1000; } using (var writer = new BinaryWriter(memoryStream)) { netMessage.OnSerialize(writer); var message = new MessageRaw(); message.type = msg.type; message.length = (short)(memoryStream.Length + 3); message.data = memoryStream.GetBuffer(); var netWriter = new BinaryWriter(to); message.WriteTo(netWriter); } } } catch (Exception e) { Console.WriteLine($"Failed to serialize net message {msg.type} because {e.Message}"); var writer = new BinaryWriter(to); msg.WriteTo(writer); } } else { var writer = new BinaryWriter(to); msg.WriteTo(writer); } } catch (Exception e) { break; } } }); task.Start(); return(task); }