コード例 #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;
            }
        }
コード例 #3
0
            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);
            }
コード例 #4
0
            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;
            }
コード例 #5
0
 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);
        }
コード例 #7
0
        public ScreenshotContent CreateWindowScreenshot(IntPtr hWnd, ScreenshotContent existingScreenshot = null)
        {
            bool isInForeground;

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