Example #1
0
 private void UpdatesPipeConnected(IAsyncResult e)
 {
     try
     {
         if (UpdatesPipe != null)
         {
             UpdatesPipe.EndWaitForConnection(e);
             ReadUpdatesPipe();
         }
     }
     catch (Exception exc)
     {
         Trace.TraceError("Failed to wait for connection on updates 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);

                _updatesPipe = new NamedPipeServerStream(
                    "remotesession_" + RemoteSession.Id + "_updates",
                    PipeDirection.InOut,
                    1,
                    PipeTransmissionMode.Message,
                    PipeOptions.Asynchronous,
                    UpdatesPipeBufferSize,
                    UpdatesPipeBufferSize,
                    pipeSecurity);

                // wait for client connection
                InputsPipe.BeginWaitForConnection(InputsPipeConnected, InputsPipe.GetHashCode());
                UpdatesPipe.BeginWaitForConnection(UpdatesPipeConnected, UpdatesPipe.GetHashCode());
            }
            catch (Exception exc)
            {
                Trace.TraceError("Failed to create pipes, remote session {0} ({1})", RemoteSession.Id, exc);
            }
        }
        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(RemoteSession.Manager.Client.GetProcessIdentity(), PipeAccessRights.FullControl, AccessControlType.Allow);
                pipeSecurity.AddAccessRule(pipeAccessRule);

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

                _updatesPipe = new NamedPipeServerStream(
                    "remotesession_" + RemoteSession.Id + "_updates",
                    PipeDirection.InOut,
                    1,
                    PipeTransmissionMode.Byte,
                    PipeOptions.Asynchronous,
                    0,
                    0,
                    pipeSecurity);

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

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

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