/// <see cref="ITrace.WriteFork"/> public void WriteFork(RCThread newThread, RCThread parentThread) { if (newThread == null) { throw new ArgumentNullException("newThread"); } if (parentThread == null) { throw new ArgumentNullException("parentThread"); } RCPackage packageToWrite = RCPackage.CreateCustomDataPackage(RCL_FORK_FORMAT); packageToWrite.WriteInt(0, newThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(1, newThread.Name); packageToWrite.WriteInt(2, parentThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(3, parentThread.Name); packageToWrite.WriteLong(4, timer.ElapsedMilliseconds); byte[] buffer = new byte[packageToWrite.PackageLength]; packageToWrite.WritePackageToBuffer(buffer, 0); this.outputWriter.Write(buffer); this.outputWriter.Flush(); this.outputStream.Flush(); }
/// <see cref="ITrace.WriteLine"/> public void WriteLine(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } string strToWrite = obj.ToString(); if (strToWrite == null) { strToWrite = string.Empty; } RCPackage packageToWrite = RCPackage.CreateCustomDataPackage(RCL_EVENT_FORMAT); packageToWrite.WriteInt(0, RCThread.CurrentThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(1, RCThread.CurrentThread.Name); packageToWrite.WriteLong(2, timer.ElapsedMilliseconds); packageToWrite.WriteString(3, strToWrite); byte[] buffer = new byte[packageToWrite.PackageLength]; packageToWrite.WritePackageToBuffer(buffer, 0); this.outputWriter.Write(buffer); this.outputWriter.Flush(); this.outputStream.Flush(); }
/// <see cref="ITrace.WriteJoin"/> public void WriteJoin(RCThread runningThread, RCThread waitingThread) { if (runningThread == null) { throw new ArgumentNullException("runningThread"); } if (waitingThread == null) { throw new ArgumentNullException("waitingThread"); } RCPackage packageToWrite = RCPackage.CreateCustomDataPackage(RCL_JOIN_FORMAT); packageToWrite.WriteInt(0, runningThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(1, runningThread.Name); packageToWrite.WriteInt(2, waitingThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(3, waitingThread.Name); packageToWrite.WriteLong(4, timer.ElapsedMilliseconds); byte[] buffer = new byte[packageToWrite.PackageLength]; packageToWrite.WritePackageToBuffer(buffer, 0); this.outputWriter.Write(buffer); this.outputWriter.Flush(); this.outputStream.Flush(); }
/// <see cref="ITrace.WriteLine"/> public void WriteException(Exception ex, bool isFatal) { if (ex == null) { throw new ArgumentNullException("ex"); } string strToWrite = ex.ToString(); if (strToWrite == null) { strToWrite = string.Empty; } RCPackage packageToWrite = RCPackage.CreateCustomDataPackage(RCL_EXCEPTION_FORMAT); packageToWrite.WriteInt(0, RCThread.CurrentThread.WrappedThread.ManagedThreadId); packageToWrite.WriteString(1, RCThread.CurrentThread.Name); packageToWrite.WriteLong(2, timer.ElapsedMilliseconds); packageToWrite.WriteByte(3, isFatal ? (byte)0x01 : (byte)0x00); packageToWrite.WriteString(4, strToWrite); byte[] buffer = new byte[packageToWrite.PackageLength]; packageToWrite.WritePackageToBuffer(buffer, 0); this.outputWriter.Write(buffer); this.outputWriter.Flush(); this.outputStream.Flush(); }
public static RCPackage GenerateRandomPackage() { int rndType = rnd.Next(0, 3); int rndFormat = rnd.Next(0, 3); RCPackage retPack = null; if (rndType == 0) { retPack = RCPackage.CreateNetworkPingPackage(); return(retPack); } else if (rndType == 1) { retPack = RCPackage.CreateCustomDataPackage(rndFormat); } else if (rndType == 2) { retPack = RCPackage.CreateNetworkCustomPackage(rndFormat); } RCPackageFormat format = RCPackageFormat.GetPackageFormat(rndFormat); for (int i = 0; i < format.NumOfFields; i++) { RCPackageFieldType datatype = format.GetFieldType(i); if (datatype == RCPackageFieldType.BYTE) { retPack.WriteByte(i, (byte)rnd.Next(byte.MinValue, byte.MaxValue)); } else if (datatype == RCPackageFieldType.SHORT) { retPack.WriteShort(i, (short)rnd.Next(short.MinValue, short.MaxValue)); } else if (datatype == RCPackageFieldType.INT) { retPack.WriteInt(i, (int)rnd.Next(int.MinValue, int.MaxValue)); } else if (datatype == RCPackageFieldType.LONG) { retPack.WriteLong(i, (long)rnd.Next(int.MinValue, int.MaxValue)); } else if (datatype == RCPackageFieldType.STRING) { int strIdx = rnd.Next(0, 10); retPack.WriteString(i, strCollection[strIdx]); } else if (datatype == RCPackageFieldType.BYTE_ARRAY) { int arrLen = rnd.Next(0, 10); byte[] arr = new byte[arrLen]; rnd.NextBytes(arr); retPack.WriteByteArray(i, arr); } else if (datatype == RCPackageFieldType.SHORT_ARRAY) { int arrLen = rnd.Next(0, 10); short[] arr = new short[arrLen]; for (int j = 0; j < arrLen; ++j) { arr[j] = (short)rnd.Next(short.MinValue, short.MaxValue); } retPack.WriteShortArray(i, arr); } else if (datatype == RCPackageFieldType.INT_ARRAY) { int arrLen = rnd.Next(0, 10); int[] arr = new int[arrLen]; for (int j = 0; j < arrLen; ++j) { arr[j] = (int)rnd.Next(int.MinValue, int.MaxValue); } retPack.WriteIntArray(i, arr); } else if (datatype == RCPackageFieldType.LONG_ARRAY) { int arrLen = rnd.Next(0, 10); long[] arr = new long[arrLen]; for (int j = 0; j < arrLen; ++j) { arr[j] = (long)rnd.Next(int.MinValue, int.MaxValue); } retPack.WriteLongArray(i, arr); } else if (datatype == RCPackageFieldType.STRING_ARRAY) { int arrLen = rnd.Next(0, 10); string[] arr = new string[arrLen]; for (int j = 0; j < arrLen; ++j) { int strIdx = rnd.Next(0, 10); arr[j] = strCollection[strIdx]; } retPack.WriteStringArray(i, arr); } else { throw new NetworkingSystemException("Unknown datatype"); } } return(retPack); }