Exemplo n.º 1
0
        public async Task OpenAsync(string correlationId)
        {
            var components = _references.GetAll();

            Referencer.SetReferences(this, components);
            await Opener.OpenAsync(correlationId, components);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the component.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        public async Task OpenAsync(string correlationId)
        {
            if (!_opened)
            {
                var components = base.GetAll();
                await Opener.OpenAsync(correlationId, components);

                _opened = true;
            }
        }
        private async Task RunAsync(string correlationId, CancellationToken token)
        {
            _correlationId = correlationId;

            CaptureErrors();

            //await StartAsync(correlationId, token);

            if (_config == null)
            {
                throw new InvalidStateException(correlationId, "NO_CONFIG", "Container was not configured");
            }

            try
            {
                _logger.Trace(correlationId, "Starting container.");

                // Create references with configured components
                InitReferences(_references);
                _references.PutFromConfig(_config);

                // Reference and open components
                var components = _references.GetAll();
                Referencer.SetReferences(_references, components);
                await Opener.OpenAsync(correlationId, _references.GetAll());

                // Get reference to logger
                _logger = new CompositeLogger(_references);

                // Get reference to container info
                var infoDescriptor = new Descriptor("*", "container-info", "*", "*", "*");
                _info = (ContextInfo)_references.GetOneRequired(infoDescriptor);

                _logger.Info(correlationId, "Container {0} started.", _info.Name);
            }
            catch (Exception ex)
            {
                _references = null;
                _logger.Error(correlationId, ex, "Failed to start container");

                throw;
            }
        }
        public async Task StartAsync(string correlationId, CancellationToken token)
        {
            if (Config == null)
            {
                throw new InvalidStateException(correlationId, "NO_CONFIG", "Container was not configured");
            }

            try
            {
                Logger.Trace(correlationId, "Starting container.");

                // Create references with configured components
                InitReferences(References);
                References.PutFromConfig(Config);

                // Reference and open components
                var components = References.GetAll();
                Referencer.SetReferences(References, components);
                await Opener.OpenAsync(correlationId, References.GetAll());

                // Get reference to logger
                Logger = new CompositeLogger(References);

                // Get reference to container info
                var infoDescriptor = new Descriptor("*", "container-info", "*", "*", "*");
                Info = (ContainerInfo)References.GetOneRequired(infoDescriptor);

                Logger.Info(correlationId, "Container {0} started.", Info.Name);
            }
            catch (Exception ex)
            {
                References = null;
                Logger.Error(correlationId, ex, "Failed to start container");

                throw;
            }
        }