Beispiel #1
0
        /// <summary>
        /// retrieve the mouse cursor from the rdp session and send it to the browser
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(
            object sender,
            EventArgs e)
        {
            // if cookies are enabled, the http session id is added to the http request headers; otherwise, it's added to the http request url
            // in both cases, the given http session is automatically bound to the current http context

            RemoteSessionManager remoteSessionManager = null;

            try
            {
                // retrieve the remote session manager for the current http session
                remoteSessionManager = (RemoteSessionManager)HttpContext.Current.Session[HttpSessionStateVariables.RemoteSessionManager.ToString()];
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to retrieve the remote session manager for the http session {0}, ({1})", HttpContext.Current.Session.SessionID, exc);
                return;
            }

            try
            {
                // retrieve params
                var imgIdx = int.Parse(HttpContext.Current.Request.QueryString["imgIdx"]);

                // retrieve image data
                var img     = remoteSessionManager.GetCachedUpdate(imgIdx);
                var imgData = img != null?Convert.FromBase64String(img.Base64Data) : null;

                if (imgData != null && imgData.Length > 0)
                {
                    var imgStream = new MemoryStream(imgData);
                    var bitmap    = new Bitmap(imgStream);

                    //var cursor = CreateCursor(bitmap, img.PosX, img.PosY);
                    // TODO: find a way to save a cursor as .cur file? using .ico instead...

                    var icon = Icon.FromHandle(bitmap.GetHicon());

                    // TODO: IE
                    // IE does support .ico files for cursors, but an icon doesn't have an hotspot and there is no way to define it in IE...
                    // problem is, the user thinks clicking a specific spot and, in fact, isn't...
                    // also, the cursor blinks when it changes, and stays invisible as long as the user doesn't move the mouse...
                    // for these reasons, IE won't display custom cursors...

                    var iconStream = new MemoryStream();
                    icon.Save(iconStream);
                    var iconData = iconStream.ToArray();

                    // write the output
                    HttpContext.Current.Response.OutputStream.Write(iconData, 0, iconData.Length);
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to get mouse cursor, remote session {0} ({1})", remoteSessionManager.RemoteSession.Id, exc);
            }
        }
Beispiel #2
0
        /// <summary>
        /// retrieve an image update (region or fullscreen) from the rdp session and send it to the browser
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(
            object sender,
            EventArgs e)
        {
            // if cookies are enabled, the http session id is added to the http request headers; otherwise, it's added to the http request url
            // in both cases, the given http session is automatically bound to the current http context

            RemoteSessionManager remoteSessionManager = null;

            try
            {
                // retrieve the remote session manager for the current http session
                remoteSessionManager = (RemoteSessionManager)HttpContext.Current.Session[HttpSessionStateVariables.RemoteSessionManager.ToString()];
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to retrieve the remote session manager for the http session {0}, ({1})", HttpContext.Current.Session.SessionID, exc);
                return;
            }

            try
            {
                // retrieve params
                var imgIdx = int.Parse(HttpContext.Current.Request.QueryString["imgIdx"]);

                // retrieve image data
                var img     = remoteSessionManager.GetCachedUpdate(imgIdx);
                var imgData = img != null?Convert.FromBase64String(img.Base64Data) : null;

                if (imgData != null && imgData.Length > 0)
                {
                    // write the output
                    HttpContext.Current.Response.OutputStream.Write(imgData, 0, imgData.Length);
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.TraceError("Failed to get display update, remote session {0} ({1})", remoteSessionManager.RemoteSession.Id, exc);
            }
        }