/// <summary>
        /// Publish objects so that the host can use it, and then block indefinitely (until the input stream is open).
        /// 
        /// Note that we should publish only one object, and then have other objects be accessible from it. Publishing
        /// multiple objects can cause problems if the client does a call like "remoteProxy1(remoteProxy2)" as remoting
        /// will not be able to know if the server object for both the proxies is on the same server.
        /// </summary>
        /// <param name="remoteRuntimeChannelName">The IPC channel that the remote console expects to use to communicate with the ScriptEngine</param>
        /// <param name="scope">A intialized ScriptScope that is ready to start processing script commands</param>
        internal static void StartServer(string remoteRuntimeChannelName, ScriptScope scope) {
            Debug.Assert(ChannelServices.GetChannel(remoteRuntimeChannelName) == null);

            IpcChannel channel = CreateChannel("ipc", remoteRuntimeChannelName);

            LifetimeServices.LeaseTime = GetSevenDays();
            LifetimeServices.LeaseManagerPollTime = GetSevenDays();
            LifetimeServices.RenewOnCallTime = GetSevenDays();
            LifetimeServices.SponsorshipTimeout = GetSevenDays();

            ChannelServices.RegisterChannel(channel, false);

            try {
                RemoteCommandDispatcher remoteCommandDispatcher = new RemoteCommandDispatcher(scope);
                RemotingServices.Marshal(remoteCommandDispatcher, CommandDispatcherUri);

                // Let the remote console know that the startup output (if any) is complete. We use this instead of
                // a named event as we want all the startup output to reach the remote console before it proceeds.
                Console.WriteLine(RemoteCommandDispatcher.OutputCompleteMarker);

                // Block on Console.In. This is used to determine when the host process exits, since ReadLine will return null then.
                string input = System.Console.ReadLine();
                Debug.Assert(input == null);
            } finally {
                ChannelServices.UnregisterChannel(channel);
            }
        }
        /// <summary>
        /// Publish objects so that the host can use it, and then block indefinitely (until the input stream is open).
        ///
        /// Note that we should publish only one object, and then have other objects be accessible from it. Publishing
        /// multiple objects can cause problems if the client does a call like "remoteProxy1(remoteProxy2)" as remoting
        /// will not be able to know if the server object for both the proxies is on the same server.
        /// </summary>
        /// <param name="remoteRuntimeChannelName">The IPC channel that the remote console expects to use to communicate with the ScriptEngine</param>
        /// <param name="scope">A intialized ScriptScope that is ready to start processing script commands</param>
        internal static void StartServer(string remoteRuntimeChannelName, ScriptScope scope)
        {
            Debug.Assert(ChannelServices.GetChannel(remoteRuntimeChannelName) == null);

            IpcChannel channel = CreateChannel("ipc", remoteRuntimeChannelName);

            LifetimeServices.LeaseTime            = GetSevenDays();
            LifetimeServices.LeaseManagerPollTime = GetSevenDays();
            LifetimeServices.RenewOnCallTime      = GetSevenDays();
            LifetimeServices.SponsorshipTimeout   = GetSevenDays();

            ChannelServices.RegisterChannel(channel, false);

            try {
                RemoteCommandDispatcher remoteCommandDispatcher = new RemoteCommandDispatcher(scope);
                RemotingServices.Marshal(remoteCommandDispatcher, CommandDispatcherUri);

                // Let the remote console know that the startup output (if any) is complete. We use this instead of
                // a named event as we want all the startup output to reach the remote console before it proceeds.
                Console.WriteLine(RemoteCommandDispatcher.OutputCompleteMarker);

                // Block on Console.In. This is used to determine when the host process exits, since ReadLine will return null then.
                string input = System.Console.ReadLine();
                Debug.Assert(input == null);
            } finally {
                ChannelServices.UnregisterChannel(channel);
            }
        }
        private void InitializeRemoteScriptEngine()
        {
            StartRemoteRuntimeProcess();

            _remoteCommandDispatcher = GetRemoteObject <RemoteCommandDispatcher>(RemoteRuntimeServer.CommandDispatcherUri);

            _scriptScope = _remoteCommandDispatcher.ScriptScope;
            Engine       = _scriptScope.Engine;

            // Register a channel for the reverse direction, when the remote runtime process wants to fire events
            // or throw an exception
            string clientChannelName = _channelName.Replace("RemoteRuntime", "RemoteConsole");

            _clientChannel = RemoteRuntimeServer.CreateChannel(clientChannelName, clientChannelName);
            ChannelServices.RegisterChannel(_clientChannel, false);
        }
 internal RemoteConsoleCommandDispatcher(RemoteCommandDispatcher remoteCommandDispatcher, AutoResetEvent remoteOutputReceived)
 {
     _remoteCommandDispatcher = remoteCommandDispatcher;
     _remoteOutputReceived = remoteOutputReceived;
 }
 public RemoteConsoleCommandLine(ScriptScope scope, RemoteCommandDispatcher remoteCommandDispatcher, AutoResetEvent remoteOutputReceived)
 {
     _remoteConsoleCommandDispatcher = new RemoteConsoleCommandDispatcher(remoteCommandDispatcher, remoteOutputReceived);
     Debug.Assert(scope != null);
     ScriptScope = scope;
 }
 internal RemoteConsoleCommandDispatcher(RemoteCommandDispatcher remoteCommandDispatcher, AutoResetEvent remoteOutputReceived)
 {
     _remoteCommandDispatcher = remoteCommandDispatcher;
     _remoteOutputReceived    = remoteOutputReceived;
 }
 public RemoteConsoleCommandLine(ScriptScope scope, RemoteCommandDispatcher remoteCommandDispatcher, AutoResetEvent remoteOutputReceived)
 {
     _remoteConsoleCommandDispatcher = new RemoteConsoleCommandDispatcher(remoteCommandDispatcher, remoteOutputReceived);
     Debug.Assert(scope != null);
     ScriptScope = scope;
 }