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

            Referencer.SetReferences(this, components);
            await Opener.OpenAsync(correlationId, components);
        }
        /// <summary>
        /// true if the component has been opened and false otherwise.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        public async Task OpenAsync(string correlationId)
        {
            if (!_opened)
            {
                _opened = true;
                var components = base.GetAll();
                Referencer.SetReferences(this.ParentReferences, components);
            }

            await Task.Delay(0);
        }
        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;
            }
        }