/// <summary>
        /// Registers the host service with a channel.
        /// </summary>
        /// <param name="hostService">The remote host service.</param>
        /// <param name="channel">The channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostService"/> or 
        /// <paramref name="channel"/> is null.</exception>
        public static void RegisterWithChannel(RemoteHostService hostService, IServerChannel channel)
        {
            if (hostService == null)
                throw new ArgumentNullException("hostService");
            if (channel == null)
                throw new ArgumentNullException("channel");

            channel.RegisterService(ServiceName, hostService);
        }
        /// <summary>
        /// Registers the host service with a channel.
        /// </summary>
        /// <param name="hostService">The remote host service.</param>
        /// <param name="channel">The channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostService"/> or
        /// <paramref name="channel"/> is null.</exception>
        public static void RegisterWithChannel(RemoteHostService hostService, IServerChannel channel)
        {
            if (hostService == null)
            {
                throw new ArgumentNullException("hostService");
            }
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            channel.RegisterService(ServiceName, hostService);
        }
Exemplo n.º 3
0
        public HostTerminationReason Run(TimeSpan? watchdogTimeout)
        {
            using (RemoteHostService hostService = new RemoteHostService(watchdogTimeout))
            {
                if (ownerProcess != null)
                {
                    ownerProcess.Exited += delegate { hostService.Dispose(); };
                    ownerProcess.EnableRaisingEvents = true;
                }

                if (ownerProcess == null || !ownerProcess.HasExited)
                {
                    HostServiceChannelInterop.RegisterWithChannel(hostService, serverChannel);
                    hostService.WaitUntilShutdown();
                }

                if (hostService.WatchdogTimerExpired)
                    return HostTerminationReason.WatchdogTimeout;

                if (ownerProcess != null && ownerProcess.HasExited)
                    return HostTerminationReason.Disowned;
            }

            return HostTerminationReason.Disposed;
        }