예제 #1
0
        protected override void OnPackageReceived(ServerSideClient client, Package package)
        {
            switch ((Commands)package.Command)
            {
            // Broadcast messages to all clients.
            case Commands.InstantMessage:
                var message = InstantMessageContent.Deserialize(package.Content);
                messages.Add(message);
                Pusher.Push(message);
                BroadcastPackageAsync(package);
                break;

            // Send screenshot specific client.
            case Commands.Screenshot:
                var screenshot = ScreenshotContent.Deserialize(package.Content);
                ServerSideClient destClient = Clients.FirstOrDefault(c => c.Name == screenshot.RecieverName);
                destClient?.SendPackageAsync(package);
                break;

            // Send cursor to all clients. Does not need to be deserialized because
            // the contents of the package do not need to be analyzed.
            case Commands.CursorPosition:
                BroadcastPackageAsync(package);
                break;
            }
        }
예제 #2
0
        protected override void OnPackageReceived(Package package)
        {
            base.OnPackageReceived(package);

            switch ((Commands)package.Command)
            {
            case Commands.InstantMessage:
                Pusher.Push(InstantMessageContent.Deserialize(package.Content));
                break;

            case Commands.Screenshot:
                Pusher.Push(ScreenshotContent.Deserialize(package.Content));
                break;

            case Commands.CursorPosition:
                var args = ClientCursorContent.Deserialize(package.Content);
                var find = clientCursorPositions.FirstOrDefault(c => c.ClientName == args.ClientName);

                if (find == null)
                {
                    clientCursorPositions.Add(args);
                }
                else
                {
                    int index = clientCursorPositions.IndexOf(find);

                    if (index != -1)
                    {
                        clientCursorPositions[index] = args;
                    }
                }
                break;
            }
        }
            public static ScreenshotContent Create(
                WindowPosition pos,
                ScreenshotContent existingScreenshot = null)
            {
                // Try to reuse the existing screenshot's bitmap, if it has the same size.
                if (existingScreenshot != null && !(existingScreenshot.Size.Width == pos.Size.Width &&
                                                    existingScreenshot.Size.Height == pos.Size.Height))
                {
                    // We cannot use the existing screenshot, so dispose of it.
                    existingScreenshot.Dispose();
                    existingScreenshot = null;
                }

                if (existingScreenshot == null)
                {
                    existingScreenshot = new ScreenshotContent(pos);
                }
                else
                {
                    // The window could have been moved, so refresh the position.
                    existingScreenshot.WindowPosition = pos;
                }

                existingScreenshot.FillScreenshot();
                return(existingScreenshot);
            }
            public static ScreenshotContent Create(WindowPosition pos, 
                ScreenshotContent existingScreenshot = null)
            {
                // Try to reuse the existing screenshot's bitmap, if it has the same size.
                if (existingScreenshot != null && !(existingScreenshot.Size.Width == pos.Size.Width
                    && existingScreenshot.Size.Height == pos.Size.Height))
                {
                    // We cannot use the existing screenshot, so dispose of it.
                    existingScreenshot.Dispose();
                    existingScreenshot = null;
                }

                if (existingScreenshot == null)
                    existingScreenshot = new ScreenshotContent(pos);
                else
                    // The window could have been moved, so refresh the position.
                    existingScreenshot.WindowPosition = pos; 

                existingScreenshot.FillScreenshot();
                return existingScreenshot;
            }
 public ScreenshotContent CreateWindowScreenshot(IntPtr hWnd, ScreenshotContent existingScreenshot = null) =>
     ScreenshotContent.Create(GetWindowPosition(hWnd), existingScreenshot);
예제 #6
0
        /// <summary>
        /// Sends a screenshot asynchronously.
        /// </summary>
        /// <param name="image">The image to send.</param>
        /// <param name="toClient">The client to send to.</param>
        /// <returns>How much data, in bytes, successfully sent.</returns>
        public void SendScreenAsync(Bitmap image, string toClient)
        {
            var screenshot = new ScreenshotContent((Png)image, Name, toClient);

            SendPackageTaskAsyncBase((int)Commands.Screenshot, screenshot);
        }
        public ScreenshotContent CreateWindowScreenshot(IntPtr hWnd, ScreenshotContent existingScreenshot = null)
        {
            bool isInForeground;

            return(ScreenshotContent.Create(GetWindowPosition(hWnd, out isInForeground), existingScreenshot));
        }