/// <summary> /// Initialize the CryptoPack /// </summary> /// <param name="basePack">BasePack that will be copy</param> public CryptPack(BasePack basePack) : base(basePack) { this.encrypted = GetBool(1); this.readPosition = CID_POSITION + sizeof(int); this.writePosition = CID_POSITION + sizeof(int); }
public BaseAction(int ActionID, HttpGet HttpGet) { httpGet = HttpGet; _actionID = ActionID; basePack = new BasePack(); baseLog = new BaseLog(httpGet.param); }
/// <summary> /// Send a pack /// </summary> /// <param name="pack">Pack to be sender</param> /// <param name="host_name">Host's name</param> /// <param name="port">Host's port</param> public void SendPack(BasePack pack, string host_name, int port) { if (isEnable) { sender.Send(pack.Buffer, pack.Buffer.Length); } else { throw new ConnectionClosedException("Connection closed!"); } }
public void PutStringTestAndGetStringTest() { // Arrange string stringPut = "Test string."; BasePack basePack = new BasePack(); // Act basePack.PutString(stringPut); string stringGet = basePack.GetString(); // Assert Assert.AreEqual(stringPut, stringGet); }
public void PutFloatAtTheBeginningAndGetFloatFromTheBeginningTest() { // Arrange float floatPut = 123.4f; BasePack basePack = new BasePack(); // Act basePack.PutFloat(floatPut); float floatGet = basePack.GetFloat(); // Assert Assert.AreEqual(floatPut, floatGet); }
public void PutBoolAtTheBeginningAndGetBoolFromTheBeginningTest() { // Arrange bool boolPut = true; BasePack basePack = new BasePack(); // Act basePack.PutBool(boolPut); bool boolGet = basePack.GetBool(); // Assert Assert.AreEqual(boolPut, boolGet); }
public void PutByteAtTheBeginningAndGetByteFromTheBeginningTest() { // Arrange byte bytePut = 7; BasePack basePack = new BasePack(); // Act basePack.PutByte(bytePut); byte byteGet = basePack.GetByte(); // Assert Assert.AreEqual(bytePut, byteGet); }
public void PutCharAtTheBeginningAndGetCharFromTheBeginningTest() { // Arrange char charPut = 'a'; BasePack basePack = new BasePack(); // Act basePack.PutChar(charPut); char charGet = basePack.GetChar(); // Assert Assert.AreEqual(charPut, charGet); }
public void PutDoubleAtTheBeginningAndGetDoubleFromTheBeginningTest() { // Arrange double doublePut = 123.4; BasePack basePack = new BasePack(); // Act basePack.PutDouble(doublePut); double doubleGet = basePack.GetDouble(); // Assert Assert.AreEqual(doublePut, doubleGet); }
public void PutIntAtTheBeginningAndGetIntFromBeginningTest() { // Arrange int intPut = 123; BasePack basePack = new BasePack(); // Act basePack.PutInt(intPut); int intGet = basePack.GetInt(); // Assert Assert.AreEqual(intPut, intGet); }
public void ReadTestAreBuffersEqual() { // Arrange BasePack basePack = new BasePack(); byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; basePack.Write(buff, 0, buff.Length); // Act byte[] buffRead = new byte[buff.Length]; basePack.Read(buffRead, 0, buffRead.Length); // Assert CollectionAssert.AreEqual(buff, buffRead); }
public void ConversionFromByteArrayToBasePackTest() { // Arrange BasePack basePack = new BasePack(); byte[] byteArray = new byte[BasePack.packSize]; for (int i = 0; i < byteArray.Length; i++) byteArray[i] = (byte)(i % 256); // Act basePack = byteArray; // Assert for (int i = 0; i < byteArray.Length; i++) Assert.AreEqual(byteArray[i], basePack.Buffer[i]); }
/// <summary> /// Send a pack /// </summary> /// <param name="pack">Pack to be sender</param> /// <param name="ip">Address to send</param> public override void SendPack(BasePack pack, IPEndPoint ip = null) { if (isEnable) { if (ip == null) { throw new ArgumentNullException("IP cant be null!"); } sender.Send(pack.Buffer, pack.Buffer.Length, ip); } else { throw new ConnectionClosedException("Connection closed!"); } }
/// <summary> /// Send a pack /// </summary> /// <param name="pack">Pack to be sender</param> /// <param name="ip">Optional parameter used only by UDP protocol</param> public override void SendPack(BasePack pack, IPEndPoint ip = null) { if (isEnable) { try { input.Write(pack.Buffer, 0, pack.Buffer.Length); } catch (IOException e) { OnConnectionClosedCall(); Console.WriteLine(e.Message); Console.WriteLine("Connection closed! Host do not answer."); } } }
public void WriteTestAreBuffersEqual() { // Arrange BasePack basePack = new BasePack(); byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Act basePack.Write(buff, 0, buff.Length); // Assert - note that BasePack's buffer[0] is Pack's header, so written buffer is shifted by 1 to the right byte[] buffWritten = basePack.Buffer; for (int i = 0; i < buff.Length; i++) { Assert.AreEqual(buff[i], buffWritten[i + 1]); } }
public void ConversionFromByteArrayToBasePackTest() { // Arrange BasePack basePack = new BasePack(); byte[] byteArray = new byte[BasePack.packSize]; for (int i = 0; i < byteArray.Length; i++) { byteArray[i] = (byte)(i % 256); } // Act basePack = byteArray; // Assert for (int i = 0; i < byteArray.Length; i++) { Assert.AreEqual(byteArray[i], basePack.Buffer[i]); } }
/// <summary> /// Publish packs in pack_queue /// </summary> /// <exception cref="Exception"></exception> protected override void Publish() { byte[] buffer; while (isInputEnabled) { IPEndPoint info = null; try { buffer = listener.Receive(ref info); BasePack.PutString(buffer, info.Address.ToString(), 1); pack_queue.Enqueue(buffer); manualEvent.Set(); } catch (Exception e) { OnConnectionClosedCall(); Console.WriteLine(e.Message); Console.WriteLine("Connection closed! Host do not answer."); } } }
public override UDPPack PackFactory(BasePack pack) { return(new UDPPack(pack)); }
public override CryptPack PackFactory(BasePack pack) { return(new CryptPack(pack)); }
public UDPPack(BasePack basePack) : base(basePack) { this.readPosition += sizeof(int) + 15; }
public void WriteTestAreBuffersEqual() { // Arrange BasePack basePack = new BasePack(); byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Act basePack.Write(buff, 0, buff.Length); // Assert - note that BasePack's buffer[0] is Pack's header, so written buffer is shifted by 1 to the right byte[] buffWritten = basePack.Buffer; for (int i = 0; i < buff.Length; i++) Assert.AreEqual(buff[i], buffWritten[i + 1]); }
/// <summary> /// Send a pack /// </summary> /// <param name="pack">Pack to be sender</param> /// <param name="ip">Optional parameter used only by UDP protocol</param> public abstract void SendPack(BasePack pack, IPEndPoint ip = null);