private static void OnAttemptConnect(IAsyncResult ar) { try { Status = true; s_socket.EndConnect(ar); //notify the server the connection was established succefully MessageStructure msgToSend = new MessageStructure { Command = Command.AttemptLogin, Color = HexConverter.Convert(Client.Color), ClientName = Client.Name, UserName = Client.UserName }; byte[] msgToSendByte = msgToSend.ToByte(); // Ssend the login credinails of the established connection to the server //s_socket.BeginSend(msgToSendByte, 0, msgToSendByte.Length, SocketFlags.None, OnSend, null); s_socket.Send(msgToSendByte, 0, msgToSendByte.Length, SocketFlags.None); s_byteMessage = new byte[2097152]; s_socket.BeginReceive(s_byteMessage, 0, s_byteMessage.Length, SocketFlags.None, OnReceive, null); } catch (Exception ex) { if (ClientNetworkEngineAttemptLoginErrorEvent != null) { ClientNetworkEngineAttemptLoginErrorEvent.Invoke(ex.Message); } //MessageBox.Show(ex.Message + @" -> OnAttemptConnect", @"Chat: ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static bool HasHex(this XmlElement xml, string attribute, out long value) { value = 0; if (!xml.HasAttribute(attribute)) { return(false); } return(HexConverter.Convert(xml.Attributes[attribute], ref value)); }
public static void NameChange(string clientNameNew) { try { MessageStructure msgToSend = new MessageStructure { Command = Command.NameChange, UserName = Client.UserName, ClientName = Client.Name, Color = HexConverter.Convert(Client.Color), Message = clientNameNew }; byte[] msgToSendByte = msgToSend.ToByte(); s_socket.BeginSend(msgToSendByte, 0, msgToSendByte.Length, SocketFlags.None, OnSend, null); } catch (Exception ex) { MessageBox.Show(ex.Message + @" -> NameChange", @"Chat: " + Client.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void ChangeColor(Color color) { try { //string colorHex = GenericStatic.HexConverter(ColorPicker.Color); //ClientConnection.Color = colorHex; MessageStructure msgToSend = new MessageStructure { Command = Command.ColorChanged, UserName = Client.UserName, ClientName = Client.Name, Color = HexConverter.Convert(color) }; byte[] msgToSendByte = msgToSend.ToByte(); s_socket.BeginSend(msgToSendByte, 0, msgToSendByte.Length, SocketFlags.None, OnSend, null); } catch (Exception ex) { MessageBox.Show(ex.Message + @" -> ChangeColor", @"Chat: " + Client.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void ConvertStringToByteArrayGivesProperResult() { var hexByteAry = _converter.Convert(_expectedHexString); Assert.IsTrue(hexByteAry.SequenceEqual(_expectedHexByteArray)); }
public void HexConverter_Convert() { IValueConverter converter; object actualValue; Type expectedType; converter = new HexConverter(); expectedType = typeof(string); // // Test with null. // try { converter.Convert(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect type. // try { converter.Convert("true"); Assert.Fail("Expected ArgumentException to be thrown."); } catch (ArgumentException) { } // // Test with 0. // actualValue = converter.Convert(0); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("0000", actualValue, "Converted value is incorrect."); // // Test with negative value. // actualValue = converter.Convert(-1); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("FFFFFFFF", actualValue, "Converted value is incorrect."); // // Test with positive value. // actualValue = converter.Convert(1024); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("0400", actualValue, "Converted value is incorrect."); }