Beispiel #1
0
 public AsyncAccess(RemoteProxy proxy)
 {
     _proxy = proxy;
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new RemoteScriptFactory.  A remote process will be created for
        /// execution of code.  The code will execute on a thread with the specified
        /// apartment state.
        /// </summary>
        public RemoteScriptFactory(ApartmentState aptState)
        {
            Process process = null;
            try {
                RegisterChannel();

                process = new Process();
                process.StartInfo = GetProcessStartInfo(aptState);

                _remoteRuntimeProcess = process;

                if (!process.Start() || process.HasExited) {
                    throw new InvalidOperationException(String.Format("Failed to start remote REPL process: {0}", process.ExitCode));
                }

                // read in the channel names we will connect to.  There are two of them, one is
                // bound to a certain thread, the 2nd is async and enables aborting work items.
                string uri = process.StandardOutput.ReadLine();
                if (!uri.StartsWith("URI: ")) {
                    throw new InvalidOperationException("Didn't get URI, got " + uri);
                }

                string abortUri = process.StandardOutput.ReadLine();
                if (!abortUri.StartsWith("ABORTURI: ")) {
                    throw new InvalidOperationException("Didn't get ABORTURI, got " + abortUri);
                }

                // finally get our objects
                _proxy = (RemoteProxy)RemotingServices.Connect(typeof(RemoteProxy), uri.Substring(5));
                _proxy.SetParentProcess(Process.GetCurrentProcess().Id);

                _asyncAccess = (AsyncAccess)RemotingServices.Connect(typeof(AsyncAccess), abortUri.Substring(10));
            } finally {
                if (_proxy == null) {
                    if (process != null) {
                        TerminateProcess(process.Handle, 1);
                        process.Close();
                    }
                    GC.SuppressFinalize(this);
                }
            }
        }