public static void getDesktopResponse(ClientMosaique client, GetDesktopResponse packet)
        {
            if (client.value == null || client.value.frmRdp == null)
            {
                return;
            }

            Image desktop;

            using (MemoryStream ms = new MemoryStream(packet.image))
            {
                desktop = Image.FromStream(ms);
            }

            if (client.value != null)
            {
                client.value.frmRdp.updateRdp(desktop);
            }


            packet.image = null;

            if (client.value != null && client.value.frmRdp != null && client.value.frmRdp.stopRdp != true)
            {
                new GetDesktop(85, packet.monitor).Execute(client);
            }
        }
예제 #2
0
        private void Execute(ISender client, GetDesktopResponse message)
        {
            lock (_syncLock)
            {
                if (!IsStarted)
                {
                    return;
                }

                if (_codec == null || _codec.ImageQuality != message.Quality || _codec.Monitor != message.Monitor || _codec.Resolution != message.Resolution)
                {
                    _codec?.Dispose();
                    _codec = new UnsafeStreamCodec(message.Quality, message.Monitor, message.Resolution);
                }

                using (MemoryStream ms = new MemoryStream(message.Image))
                {
                    // create deep copy & resize bitmap to local resolution
                    OnReport(new Bitmap(_codec.DecodeData(ms), LocalResolution));
                }

                message.Image = null;

                client.Send(new GetDesktop {
                    Quality = message.Quality, DisplayIndex = message.Monitor
                });
            }
        }
예제 #3
0
        public static void HandleGetDesktopResponse(Client client, GetDesktopResponse packet)
        {
            if (client.Value == null ||
                client.Value.FrmRdp == null ||
                client.Value.FrmRdp.IsDisposed ||
                client.Value.FrmRdp.Disposing)
            {
                return;
            }

            if (packet.Image == null)
            {
                return;
            }

            if (client.Value.StreamCodec == null)
            {
                client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
            }

            if (client.Value.StreamCodec.ImageQuality != packet.Quality ||
                client.Value.StreamCodec.Monitor != packet.Monitor ||
                client.Value.StreamCodec.Resolution != packet.Resolution)
            {
                if (client.Value.StreamCodec != null)
                {
                    client.Value.StreamCodec.Dispose();
                }

                client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
            }

            using (MemoryStream ms = new MemoryStream(packet.Image))
            {
                client.Value.FrmRdp.UpdateImage(client.Value.StreamCodec.DecodeData(ms), true);
            }

            packet.Image = null;

            if (client.Value != null && client.Value.FrmRdp != null && client.Value.FrmRdp.IsStarted)
            {
                new GetDesktop(packet.Quality, packet.Monitor).Execute(client);
            }
        }
예제 #4
0
        public static void HandleGetDesktopResponse(Client client, GetDesktopResponse packet)
        {
            if (client.Value.FrmRdp == null)
            {
                return;
            }

            if (packet.Image == null)
            {
                if (client.Value.FrmRdp != null)
                {
                    client.Value.FrmRdp.UpdateImage(client.Value.LastDesktop);
                }

                client.Value.LastDesktop     = null;
                client.Value.LastDesktopSeen = true;

                return;
            }

            // we can not dispose all bitmaps here, cause they are later used again in `client.Value.LastDesktop`
            if (client.Value.LastDesktop == null)
            {
                if (client.Value.StreamCodec != null)
                {
                    client.Value.StreamCodec.Dispose();
                }

                client.Value.StreamCodec = new UnsafeStreamCodec();
                if (client.Value.LastQuality != packet.Quality || client.Value.LastMonitor != packet.Monitor)
                {
                    client.Value.LastQuality = packet.Quality;
                    client.Value.LastMonitor = packet.Monitor;
                }

                using (MemoryStream ms = new MemoryStream(packet.Image))
                {
                    Bitmap newScreen = client.Value.StreamCodec.DecodeData(ms);

                    client.Value.LastDesktop = newScreen;

                    if (client.Value.FrmRdp != null)
                    {
                        client.Value.FrmRdp.UpdateImage(newScreen, true);
                    }

                    newScreen = null;
                }
            }
            else
            {
                using (MemoryStream ms = new MemoryStream(packet.Image))
                {
                    lock (client.Value.StreamCodec)
                    {
                        if (client.Value.LastQuality != packet.Quality || client.Value.LastMonitor != packet.Monitor)
                        {
                            if (client.Value.StreamCodec != null)
                            {
                                client.Value.StreamCodec.Dispose();
                            }

                            client.Value.StreamCodec = new UnsafeStreamCodec();
                            client.Value.LastQuality = packet.Quality;
                            client.Value.LastMonitor = packet.Monitor;
                        }

                        Bitmap newScreen = client.Value.StreamCodec.DecodeData(ms);

                        client.Value.LastDesktop = newScreen;

                        if (client.Value.FrmRdp != null)
                        {
                            client.Value.FrmRdp.UpdateImage(newScreen, true);
                        }

                        newScreen = null;
                    }
                }
            }

            packet.Image = null;
            client.Value.LastDesktopSeen = true;
        }