public static CollabPacket BuildCollabPacketMessageOnly(string message) { CollabPacket p = new CollabPacket { Message = message }; return p; }
public static CollabPacket BuildCollabPacket(string message, ImageData imageData) { CollabPacket p = new CollabPacket { Message = message, //ImgData = GetByteArrayFromImageData(imageData) }; return p; }
public void SendToAllExceptSender(CollabPacket.Packet p, Client sender) { byte[] toWrite = CollabPacket.ClassSerializer.SerializeClass(p); // Send to all connected clients except for the sender foreach (Client c in _connectedClients.Where(c => c != sender)) { Write(c.TcpClient, toWrite); } }
public static byte[] GetByteArrayFromCollabPacket(CollabPacket packetStruct) { // Get the size of our struct int size = Marshal.SizeOf(packetStruct); // Create a new byte array of that size byte[] array = new byte[size]; // Allocate memory for the struct in the heap IntPtr sPointer = Marshal.AllocHGlobal(size); // Convert the struct to a pointer Marshal.StructureToPtr(packetStruct, sPointer, false); // Copy the pointer into the byte array Marshal.Copy(sPointer, array, 0, size); // Free the sPointer we allocated above Marshal.FreeHGlobal(sPointer); // Return the data as a byte array return array; }
public static CollabPacket BuildCollabPacket(string message, string userData) { ImageData id = new ImageData { Data = new byte[5] { 45, 34, 23, 2, 12 }, Top = 1, Bottom = 245, Left = 35, Right = 2021 }; CollabPacket p = new CollabPacket { Message = message, UserData = userData, ImgData = id }; return p; }
public static CollabPacket GetCollabPacketFromByteArray(byte[] byteArray) { CollabPacket collabPacket = new CollabPacket(); // Get the size of ImageData struct and allocate memory on the heap for copying int size = Marshal.SizeOf(collabPacket); IntPtr sPointer = Marshal.AllocHGlobal(size); // Copy the byte array into the pointer to the ImageData structure Marshal.Copy(byteArray, 0, sPointer, size); // Assign the pointer to structure and cast as ImageData collabPacket = (CollabPacket)Marshal.PtrToStructure(sPointer, collabPacket.GetType()); // Free the memory allocated Marshal.FreeHGlobal(sPointer); return collabPacket; }
public DataReceivedArgs(CollabPacket.Packet p) { Packet = p; }
public void UpdateImage(CollabPacket.Packet packet) { Dispatcher.Invoke(new Action(() => { try { if (packet.ImageData != null) { _windowRect = packet.WindowRect; int height = (int) (packet.WindowRect.Bottom - packet.WindowRect.Top); int width = (int) (packet.WindowRect.Right - packet.WindowRect.Left); using (var ms = new MemoryStream(packet.ImageData)) { // Check if canvas is null, if so: populate it with the first image if (_canvas == null) { _canvas = new Bitmap( width, height, PixelFormat.Format32bppArgb); } if (height != _canvas.Height || width != _canvas.Width) { _canvas = new Bitmap( width, height, PixelFormat.Format32bppArgb); } Image source = Image.FromStream(ms); using (Graphics g = Graphics.FromImage(_canvas)) { g.DrawImage(source, (int) (packet.BoundingBox.Left), (int) (packet.BoundingBox.Top), (int) (packet.BoundingBox.Right - packet.BoundingBox.Left), (int) (packet.BoundingBox.Bottom - packet.BoundingBox.Top)); } IntPtr hBitmap = _canvas.GetHbitmap(); BitmapSource bms = Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(_canvas.Width, _canvas.Height)); WinApi.Gdi32.DeleteObject(hBitmap); CapImgBox.BeginInit(); CapImgBox.Source = bms; CapImgBox.EndInit(); CapImgBox.Width = bms.Width; CapImgBox.Height = bms.Height; Height = CapImgBox.Height + 40; Width = CapImgBox.Width + 20; // Update Statistics _totalBytes += packet.ImageData.Length; Title = String.Format("{0}'s {1} [Transfer: {2}]", _shareInfo.Sharer.FirstName + " " + _shareInfo.Sharer.LastName, _shareInfo.WindowTitle, Tools.FormatBytes(_totalBytes)); // Cleanup source.Dispose(); } } } catch(Exception ex) { Globals.DebugConsole.Log("Error updating Image control with data: " + ex.Message); } GC.Collect(); })); }
public Share(CollabPacket.ShareInfo shareInfo) { _shareInfo = shareInfo; InitializeComponent(); }
public ShareEventArgs(CollabPacket.Packet p) { Packet = p; }
public FriendReceivedEventArgs(CollabPacket.Packet p, bool isOnline) { Packet = p; IsOnline = isOnline; }