// Corresponds to "File/Save As..." private void SaveAs_Click(object sender, RoutedEventArgs e) { var board = ((BoardFile)this.DataContext); if (board == null) { return; } var saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Fortune Street Board (.frb) | *.frb"; saveFileDialog.DefaultExt = "frb"; if (saveFileDialog.ShowDialog() != true) { return; } currentFileName = saveFileDialog.FileName; loneFileName = saveFileDialog.SafeFileName; using (var stream = saveFileDialog.OpenFile()) { MiscUtil.IO.EndianBinaryWriter binWriter = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, stream); board.WriteToStream(binWriter); } UpdateTitle(); }
public StreamInspector(int bufferSize, TcpClient source, TcpClient destination) { BufferSize = bufferSize; Source = source; Destination = destination; var sourceStream = source.GetStream(); var destinationStream = destination.GetStream(); Action<Stream, Stream, Action<byte[]>> move = (src, dst, callback) => { MiscUtil.IO.EndianBinaryReader br = new MiscUtil.IO.EndianBinaryReader(MiscUtil.Conversion.EndianBitConverter.Big, src); MiscUtil.IO.EndianBinaryWriter bw = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, dst); while (true) { int len = br.ReadInt32(); var packet = br.ReadBytes(len); callback(packet); bw.Write(len); bw.Write(packet); } }; SourceThread = new Thread((o) => move(sourceStream, destinationStream, OnSend)); SourceThread.Start(); DestinationThread = new Thread((o) => move(destinationStream, sourceStream, OnReceive)); DestinationThread.Start(); }
public override void SerializePayload(MiscUtil.IO.EndianBinaryWriter writer) { writer.Write(slaveAddress); writer.Write((byte)writeLen); writer.Write(readLen); writer.Write(writeData, 0, writeLen); }
protected override void Send(MiscUtil.IO.EndianBinaryWriter writer) { writer.Write((int)ProtocolVersion); WriteString16(writer, Username); writer.Write((long)Unused1); writer.Write((int)Unused2); writer.Write((sbyte)Unused3); writer.Write((sbyte)Unused4); writer.Write((sbyte)Unused5); writer.Write((sbyte)Unused6); }
internal static MemoryStream GeneratePayload(NotificationPayload payload, ILogger logger) { try { //convert Devide token to HEX value. byte[] deviceToken = new byte[payload.DeviceToken.Length / 2]; for (int i = 0; i < deviceToken.Length; i++) { deviceToken[i] = byte.Parse(payload.DeviceToken.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber); } var frameMemStream = new MemoryStream(); var endianWriter = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, frameMemStream); //item 1, device token endianWriter.Write((byte)1); endianWriter.Write((UInt16)32); frameMemStream.Write(deviceToken, 0, 32); //item 2, Payload string apnMessage = payload.ToJson(); endianWriter.Write((byte)2); endianWriter.Write((UInt16)apnMessage.Length); frameMemStream.Write(Encoding.UTF8.GetBytes(apnMessage), 0, apnMessage.Length); //item 3, Identifier endianWriter.Write((byte)3); endianWriter.Write((UInt16)4); endianWriter.Write((UInt32)payload.PayloadId); //item 4, Expiry date DateTime concreteExpireDateUtc = (DateTime.UtcNow.AddMonths(1)).ToUniversalTime(); TimeSpan epochTimeSpan = concreteExpireDateUtc - UNIX_EPOCH; var expiryTimeStamp = (int)epochTimeSpan.TotalSeconds; endianWriter.Write((byte)4); endianWriter.Write((UInt16)4); endianWriter.Write((UInt32)expiryTimeStamp); //item5 endianWriter.Write((byte)5); endianWriter.Write((UInt16)1); frameMemStream.WriteByte(5); return(frameMemStream); } catch (Exception ex) { logger.Error("Unable to generate payload - " + ex.Message); return(null); } }
protected async Task PartialSendAsync(NetPeer peer, byte[] bytes) { var parts = DataUtil.SplitBytes(bytes, Global.Config.MAX_PACKET_SIZE); var partialId = Basic.GenID64(); var totalPartNum = parts.Count(); if (totalPartNum > 256) { Log.Error("send_bytes_too_long", peer.ConnId, totalPartNum); return; } for (short i = 0; i < parts.Count(); ++i) { var part = parts.ElementAt(i); using (var m = new MemoryStream()) { using (var writer = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Little, m)) { writer.Write(OpCode.PARTIAL); writer.Write(partialId); writer.Write(i); writer.Write(parts.Count()); writer.Write(part); peer.Send(m.ToArray()); await Task.Delay(1); Log.Info("send_part", i, parts.Count(), part.Length); } } //var partialBuf = Unpooled.DirectBuffer(); //partialBuf.WriteIntLE((int)OpCode.PARTIAL); //partialBuf.WriteLongLE((long)partialId); //partialBuf.WriteByte(i); //partialBuf.WriteByte(parts.Count()); //partialBuf.WriteBytes(part); //peer.Send(partialBuf); ////partialBuf.Release(); //await Task.Delay(10); //Log.Info("send_part", i, parts.Count(), part.Length); } }
public void Register() { //var buffer = Unpooled.DirectBuffer(); //buffer.WriteIntLE((int)OpCode.REGISTER_REQ); //buffer.WriteLongLE((long)Global.Host.Id); //buffer.WriteBytes(Encoding.UTF8.GetBytes(Global.Host.UniqueName)); using (var m = new MemoryStream()) { using (var writer = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Little, m)) { writer.Write(OpCode.REGISTER_REQ); writer.Write(Global.Host.Id); writer.Write(Encoding.UTF8.GetBytes(Global.Host.UniqueName)); this.Send(m.ToArray()); } } //this.Send(buffer); //buffer.Release(); }
// Corresponds to "File/Save" private void Save_Click(object sender, RoutedEventArgs e) { var board = ((BoardFile)this.DataContext); if (board == null) { return; } if (currentFileName == null) { SaveAs_Click(sender, e); return; } using (var stream = new FileStream(currentFileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None)) { MiscUtil.IO.EndianBinaryWriter binWriter = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, stream); board.WriteToStream(binWriter); } UpdateTitle(); }
public override byte[] Pack() { //var buf = Unpooled.DirectBuffer(); //buf.WriteIntLE((int)this.ProtoCode); //buf.WriteLongLE((long)this.Id); //buf.WriteLongLE((long)this.FromActorId); //buf.WriteLongLE((long)this.ToActorId); //buf.WriteBytes(this.Payload); //var bytes = buf.ToArray(); //buf.Release(); //return bytes; using (var m = new MemoryStream()) { using (var writer = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Little, m)) { writer.Write(this.ProtoCode); writer.Write(this.Id); writer.Write(this.FromActorId); writer.Write(this.ToActorId); writer.Write(this.Payload); return(m.ToArray()); } } //using (var m = new MemoryStream()) //{ // using (BinaryWriter writer = new BinaryWriter(m)) // { // writer.Write(this.ProtoCode); // writer.Write(this.Id); // writer.Write(this.FromActorId); // writer.Write(this.ToActorId); // writer.Write(this.Payload); // } // return m.ToArray(); //} }
private void DoStart() { tcpListener = new TcpListener(Configuration.RemotePort); tcpListener.Start(); while (!exit) { tcpClient = tcpListener.AcceptTcpClient(); tcpListener.BeginAcceptTcpClient() var stream = tcpClient.GetStream(); var endianStream = new MiscUtil.IO.EndianBinaryWriter(Configuration.EndianBitConverter, stream, Configuration.Encoding); try { while (!exit) { var pack = PacketGenerator.GetDefaultPacket(); var buffer = PacketGenerator.BuildPacket(pack); endianStream.Write((uint)Networking.Packets.PacketType.LicensePlate); endianStream.Write(buffer.Length); stream.Write(buffer, 0, buffer.Length); } } catch (System.Exception ex) { HandleException(ex); } } }
public void Send(QVariant qvariant) { MiscUtil.IO.EndianBinaryWriter bw = new MiscUtil.IO.EndianBinaryWriter(MiscUtil.Conversion.EndianBitConverter.Big, ns); MemoryStream ms = new MemoryStream(); QTypeManager.Serialize(ms, qvariant); ms.Seek(0, SeekOrigin.Begin); bw.Write((int)ms.Length); QTypeManager.Serialize(ns, qvariant); ns.Flush(); }
protected override void Prepare(MiscUtil.IO.EndianBinaryWriter w) { WriteVarInt(w, MaxSize); }