Example #1
0
 private void ImagesPipeConnected(IAsyncResult e)
 {
     try
     {
         if (ImagesPipe != null)
         {
             ImagesPipe.EndWaitForConnection(e);
             ReadImagesPipe();
         }
     }
     catch (Exception exc)
     {
         Trace.TraceError("Failed to wait for connection on images pipe, remote session {0} ({1})", RemoteSession.Id, exc);
     }
 }
Example #2
0
        public void CreatePipes()
        {
            try
            {
                // close the pipes if already exist; they will be re-created below
                DeletePipes();

                // set the pipes access rights
                var pipeSecurity   = new PipeSecurity();
                var pipeAccessRule = new PipeAccessRule(AccountHelper.GetEveryoneGroupName(), PipeAccessRights.ReadWrite, AccessControlType.Allow);
                pipeSecurity.AddAccessRule(pipeAccessRule);

                // create the pipes
                _inputsPipe = new NamedPipeServerStream(
                    "remotesession_" + RemoteSession.Id + "_inputs",
                    PipeDirection.InOut,
                    1,
                    PipeTransmissionMode.Message,
                    PipeOptions.Asynchronous,
                    InputsPipeBufferSize,
                    InputsPipeBufferSize,
                    pipeSecurity);

                _imagesPipe = new NamedPipeServerStream(
                    "remotesession_" + RemoteSession.Id + "_outputs",
                    PipeDirection.InOut,
                    1,
                    PipeTransmissionMode.Message,
                    PipeOptions.Asynchronous,
                    ImagesPipeBufferSize,
                    ImagesPipeBufferSize,
                    pipeSecurity);

                // wait for client connection
                InputsPipe.BeginWaitForConnection(InputsPipeConnected, InputsPipe.GetHashCode());
                ImagesPipe.BeginWaitForConnection(ImagesPipeConnected, ImagesPipe.GetHashCode());
            }
            catch (Exception exc)
            {
                Trace.TraceError("Failed to create pipes, remote session {0} ({1})", RemoteSession.Id, exc);
            }
        }
Example #3
0
        private byte[] ReadImagesPipeMessage()
        {
            try
            {
                var memoryStream = new MemoryStream();
                var buffer       = new byte[ImagesPipeBufferSize];

                do
                {
                    memoryStream.Write(buffer, 0, ImagesPipe.Read(buffer, 0, buffer.Length));
                } while (ImagesPipe != null && ImagesPipe.IsConnected && ImagesPipe.CanRead && !ImagesPipe.IsMessageComplete);

                return(memoryStream.ToArray());
            }
            catch (Exception exc)
            {
                Trace.TraceError("Failed to read images pipe message, remote session {0} ({1})", RemoteSession.Id, exc);
                return(null);
            }
        }