Esempio n. 1
0
 public Handle(HostHandle hostHandle, IBus bus, IBusObserver busObserver, ILogContext logContext)
 {
     _bus         = bus;
     _busObserver = busObserver;
     _logContext  = logContext;
     _hostHandle  = hostHandle;
 }
Esempio n. 2
0
        // using reflection to use an internal .Net method to find the MainWindowHandle
        public CmdExeApi findHostProcessHandle()
        {
            HostHandle = HostCmdExeProcess.MainWindowHandle;
            if (HostHandle == null || HostHandle.ToInt32() == 0)
            {
                "in CmdExeAPI, HostCmdExeProcess.MainWindowHandle was null, so trying to find it using reflection".info();

                var processInfo = HostCmdExeProcess.field("processInfo");
                if (processInfo == null)
                {
                    "Process info was null".error();
                }
                else
                {
                    var processManagerType = "System".type("ProcessManager");
                    if (processManagerType == null)
                    {
                        "processManagerType was null".error();
                    }
                    else
                    {
                        HostHandle = (IntPtr)processManagerType.invokeStatic("GetMainWindowHandle", processInfo);
                    }
                }
            }
            if (HostHandle == null || HostHandle.ToInt32() == 0)
            {
                "in CmdExeAPI, HostCmdExeProcess.MainWindowHandle, failed to get the MainWindowHandle".error();
            }
            else
            {
                "handle:{0}".format(HostHandle.ToInt32()).info();
            }
            return(this);
        }
Esempio n. 3
0
            public Handle(HostHandle hostHandle, IBus bus, IBusObserver busObserver, ILogContext logContext)
            {
                _bus         = bus;
                _busObserver = busObserver;
                _logContext  = logContext;
                _hostHandle  = hostHandle;

                Ready = ReadyOrNot(hostHandle.Ready);
            }
Esempio n. 4
0
            public Handle(IHost host, HostHandle hostHandle, MassTransitBus bus, IBusObserver busObserver, ILogContext logContext)
            {
                _host        = host;
                _bus         = bus;
                _busObserver = busObserver;
                _logContext  = logContext;
                _hostHandle  = hostHandle;

                Ready = ReadyOrNot(hostHandle.Ready);
            }
Esempio n. 5
0
        public async Task <HostHandle> Start()
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_settings}");
            }

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints();

            _handle = new Handle(handles, this, ConnectionCache);

            return(_handle);
        }
Esempio n. 6
0
        public async Task <HostHandle> Start()
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_hostConfiguration.Description}");
            }

            HostReceiveEndpointHandle[] handles = _receiveEndpoints.StartEndpoints();

            _handle = new StartHostHandle(this, handles);

            return(_handle);
        }
Esempio n. 7
0
        public virtual Task <HostHandle> Start()
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_hostConfiguration.HostAddress}");
            }

            HostReceiveEndpointHandle[] handles = _receiveEndpoints.StartEndpoints();

            _handle = new StartHostHandle(this, handles, GetAgentHandles());

            return(Task.FromResult(_handle));
        }
Esempio n. 8
0
        public async Task Stop(CancellationToken cancellationToken)
        {
            LogContext.Current = _hostConfiguration.LogContext;

            await _riderCollection.Stop(cancellationToken).ConfigureAwait(false);

            await ReceiveEndpoints.Stop(cancellationToken).ConfigureAwait(false);

            foreach (var agent in GetAgentHandles())
            {
                await agent.Stop("Host stopped", cancellationToken).ConfigureAwait(false);
            }

            _handle = null;
        }
Esempio n. 9
0
        public async Task Stop(CancellationToken cancellationToken)
        {
            LogContext.Current = _hostConfiguration.LogContext;

            LogContext.Debug?.Log("Stopping bus: {HostAddress}", Address);

            await Riders.Stop(cancellationToken).ConfigureAwait(false);

            await ReceiveEndpoints.Stop(cancellationToken).ConfigureAwait(false);

            foreach (var agent in GetAgentHandles())
            {
                await agent.Stop("Bus stopped", cancellationToken).ConfigureAwait(false);
            }

            _handle = null;
        }
Esempio n. 10
0
        public virtual Task <HostHandle> Start(CancellationToken cancellationToken)
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_hostConfiguration.HostAddress}");
            }

            LogContext.Debug?.Log("Starting host: {HostAddress}", _hostConfiguration.HostAddress);

            DefaultLogContext = LogContext.Current;
            SendLogContext    = LogContext.Current.CreateLogContext(LogCategoryName.Transport.Send);
            ReceiveLogContext = LogContext.Current.CreateLogContext(LogCategoryName.Transport.Receive);

            HostReceiveEndpointHandle[] handles = _receiveEndpoints.StartEndpoints(cancellationToken);

            _handle = new StartHostHandle(this, handles, GetAgentHandles());

            return(Task.FromResult(_handle));
        }
Esempio n. 11
0
        public HostHandle Start(CancellationToken cancellationToken)
        {
            if (_handle != null)
            {
                LogContext.Warning?.Log("Start called, but the host was already started: {Address} ({Reason})", _hostConfiguration.HostAddress,
                                        "Already Started");

                return(_handle);
            }

            LogContext.SetCurrentIfNull(_hostConfiguration.LogContext);

            LogContext.Debug?.Log("Starting host: {HostAddress}", _hostConfiguration.HostAddress);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints(cancellationToken);

            HostRiderHandle[] riders = _riderCollection.StartRiders(cancellationToken);

            _handle = new StartHostHandle(this, handles, riders);

            return(_handle);
        }
Esempio n. 12
0
        public virtual Task <HostHandle> Start(CancellationToken cancellationToken)
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_hostConfiguration.HostAddress}");
            }

            if (LogContext.Current == null)
            {
                throw new ConfigurationException("No valid LogContext was configured.");
            }

            _hostConfiguration.LogContext = LogContext.Current;

            LogContext.Debug?.Log("Starting host: {HostAddress}", _hostConfiguration.HostAddress);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints(cancellationToken);

            _handle = new StartHostHandle(this, handles, GetAgentHandles());

            return(Task.FromResult(_handle));
        }
Esempio n. 13
0
        public async Task <BusHandle> StartAsync(CancellationToken cancellationToken)
        {
            if (_busHandle != null)
            {
                _log.Warn($"The bus was already started, additional Start attempts are ignored: {Address}");
                return(_busHandle);
            }

            await _busObservable.PreStart(this).ConfigureAwait(false);

            Handle busHandle = null;

            var endpoints = new List <ReceiveEndpointHandle>();
            var hosts     = new List <HostHandle>();
            var observers = new List <ConnectHandle>();
            var busReady  = new BusReady(_receiveEndpoints);

            try
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting bus hosts...");
                }

                foreach (IBusHostControl host in _hosts)
                {
                    HostHandle hostHandle = host.Start();

                    hosts.Add(hostHandle);
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting receive endpoints...");
                }

                foreach (IReceiveEndpoint endpoint in _receiveEndpoints)
                {
                    ConnectHandle observerHandle = endpoint.ConnectReceiveObserver(_receiveObservers);
                    observers.Add(observerHandle);

                    ReceiveEndpointHandle handle = endpoint.Start();

                    endpoints.Add(handle);
                }

                busHandle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

                await busHandle.Ready.WithCancellation(cancellationToken).ConfigureAwait(false);

                await _busObservable.PostStart(this, busReady.Ready).ConfigureAwait(false);

                _busHandle = busHandle;

                return(_busHandle);
            }
            catch (Exception ex)
            {
                try
                {
                    if (busHandle != null)
                    {
                        busHandle.Stop(TimeSpan.FromSeconds(60));
                    }
                    else
                    {
                        var handle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

                        handle.Stop(TimeSpan.FromSeconds(60));
                    }
                }
                catch (Exception stopException)
                {
                    _log.Error("Failed to stop partially created bus", stopException);
                }

                await _busObservable.StartFaulted(this, ex).ConfigureAwait(false);

                throw;
            }
        }
Esempio n. 14
0
        BusHandle IBusControl.Start()
        {
            if (_busHandle != null)
            {
                _log.Warn($"The bus was already started, additional Start attempts are ignored: {Address}");
                return(_busHandle);
            }

            TaskUtil.Await(() => _busObservable.PreStart(this));

            Exception exception = null;

            var endpoints = new List <ReceiveEndpointHandle>();
            var hosts     = new List <HostHandle>();
            var observers = new List <ConnectHandle>();
            var busReady  = new BusReady(_receiveEndpoints);

            try
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting bus hosts...");
                }

                foreach (IBusHostControl host in _hosts)
                {
                    try
                    {
                        HostHandle hostHandle = host.Start();

                        hosts.Add(hostHandle);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Starting receive endpoints...");
                }

                foreach (IReceiveEndpoint endpoint in _receiveEndpoints)
                {
                    try
                    {
                        ConnectHandle observerHandle = endpoint.ConnectReceiveObserver(_receiveObservers);
                        observers.Add(observerHandle);

                        ReceiveEndpointHandle handle = endpoint.Start();

                        endpoints.Add(handle);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                try
                {
                    var handle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

                    handle.Stop(TimeSpan.FromSeconds(60));
                }
                catch (Exception ex)
                {
                    _log.Error("Failed to stop partially created bus", ex);
                }

                TaskUtil.Await(() => _busObservable.StartFaulted(this, exception));

                throw new MassTransitException("The service bus could not be started.", exception);
            }

            _busHandle = new Handle(hosts, endpoints, observers, this, _busObservable, busReady);

            TaskUtil.Await(() => _busObservable.PostStart(this, busReady.Ready));

            return(_busHandle);
        }