public static void Serialize(DataResponse.Type type, Stream data, Stream result) { BinaryWriter writer = new BinaryWriter(result); writer.Write(NetworkProtocol.NETWORK_PROTOCOL_VERSION); writer.Write((UInt32)data.Length); writer.Write((UInt32)type); long position = data.Position; data.Seek(0, SeekOrigin.Begin); data.CopyTo(result); data.Seek(position, SeekOrigin.Begin); }
private bool ApplyResponse(DataResponse response) { if (response.Version >= NetworkProtocol.NETWORK_PROTOCOL_MIN_VERSION) { //SaveTestResponse(response); switch (response.ResponseType) { case DataResponse.Type.ReportProgress: Int32 length = response.Reader.ReadInt32(); StatusText.Text = new String(response.Reader.ReadChars(length)); break; case DataResponse.Type.NullFrame: RaiseEvent(new CancelConnectionEventArgs()); StatusText.Visibility = System.Windows.Visibility.Collapsed; lock (frames) { frames.Flush(); ScrollToEnd(); } break; case DataResponse.Type.Handshake: TracerStatus status = (TracerStatus)response.Reader.ReadUInt32(); KeyValuePair <string, string> warning; if (statusToError.TryGetValue(status, out warning)) { RaiseEvent(new ShowWarningEventArgs(warning.Key, warning.Value)); } if (response.Version >= NetworkProtocol.NETWORK_PROTOCOL_VERSION_23) { Platform.Connection connection = new Platform.Connection() { Address = response.Source.Address.ToString(), Port = response.Source.Port }; Platform.Type target = Platform.Type.Unknown; String targetName = Utils.ReadBinaryString(response.Reader); Enum.TryParse(targetName, true, out target); connection.Target = target; connection.Name = Utils.ReadBinaryString(response.Reader); RaiseEvent(new NewConnectionEventArgs(connection)); } break; default: lock (frames) { frames.Add(response); //ScrollToEnd(); } break; } } else { RaiseEvent(new ShowWarningEventArgs("Invalid NETWORK_PROTOCOL_VERSION", String.Empty)); return(false); } return(true); }
public static DataResponse Create(String base64) { MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64)); return(DataResponse.Create(stream)); }
private void SaveTestResponse(DataResponse response) { if (!testResponses.ContainsKey(response.ResponseType)) testResponses.Add(response.ResponseType, 0); int count = testResponses[response.ResponseType]++; String data = response.SerializeToBase64(); String path = response.ResponseType.ToString() + "_" + String.Format("{0:000}", count) + ".bin"; File.WriteAllText(path, data); }
private bool ApplyResponse(DataResponse response) { if (response.Version == NetworkProtocol.NETWORK_PROTOCOL_VERSION) { //SaveTestResponse(response); switch (response.ResponseType) { case DataResponse.Type.ReportProgress: Int32 length = response.Reader.ReadInt32(); StatusText.Text = new String(response.Reader.ReadChars(length)); break; case DataResponse.Type.NullFrame: lock (frames) { frames.Flush(); if (frames.Count > 0) { frameList.SelectedItem = frames[frames.Count - 1]; ScrollToEnd(); } } break; case DataResponse.Type.Handshake: ETWStatus status = (ETWStatus)response.Reader.ReadUInt32(); KeyValuePair<string, string> warning; if (statusToError.TryGetValue(status, out warning)) { ShowWarning(warning.Key, warning.Value); } break; default: StatusText.Visibility = System.Windows.Visibility.Collapsed; lock (frames) { frames.Add(response.ResponseType, response.Reader); //ScrollToEnd(); } break; } } else { MessageBox.Show("Invalid NETWORK_PROTOCOL_VERSION"); return false; } return true; }