Example #1
0
        public void CreateEventsTest()
        {
            _log = new BdoLog();

            for (int i = 0; i < _testData.itemNumber; i++)
            {
                _log.AddError("Error" + i);
                _log.AddException("Exception" + i);
                _log.AddMessage("Message" + i);
                _log.AddWarning("Warning" + i);
                _log.AddSubLog(new BdoLog());
            }

            Test(_log);
        }
Example #2
0
        // ------------------------------------------
        // LOAD MANAGEMENT
        // ------------------------------------------

        #region Load Management

        /// <summary>
        /// Initializes information.
        /// </summary>
        /// <param name="log">The log to populate.</param>
        /// <returns>Returns the log of the task.</returns>
        protected override void Initialize(IBdoLog log)
        {
            log ??= new BdoLog();

            // we bind the trigger actions

            var options = Options as TBdoHostOptions <S>;

            Action_OnExecutionSucess  = options?.Action_OnExecutionSucess;
            Action_OnExecutionFailure = options?.Action_OnExecutionFailure;
            Action_OnStartSuccess     = options?.Action_OnStartSuccess;
            Action_OnStartFailure     = options?.Action_OnStartFailure;

            // we clone the current options host settings as the primary ones

            var primaryHostSettings = Options.HostSettings?.Clone <BdoHostSettings>();

            // we determine the root folder path

            var rootFolderPathDefinition = Options?.RootFolderPathDefinitions?.FirstOrDefault(p => p.Predicate(Options) == true);

            if (rootFolderPathDefinition != null)
            {
                Options?.SetRootFolder(rootFolderPathDefinition?.RootFolderPath);
            }

            // we update options (specially paths)

            Options.Update();

            // we initialize the logger

            Log.SetLogger(Options.StartUpLogger);

            // we launch the standard initialization of service

            base.Initialize(log);

            IBdoLog subLog;

            // we load the core extensions

            subLog = log.AddSubLog(title: "Loading core extensions...", eventKind: EventKinds.Message);
            _scope.LoadExtensions(ExtensionReferenceFactory.CreateRuntime()).AddEventsTo(subLog);
            if (!subLog.HasErrorsOrExceptions())
            {
                subLog.AddMessage("Core extensions loaded");
            }

            // if no errors was found

            if (!log.HasErrorsOrExceptions())
            {
                try
                {
                    // we load the host configuration

                    string hostConfigFilePath = GetKnownPath(BdoHostPathKind.HostConfigFile);
                    Options.SetHostSettings(primaryHostSettings ?? new BdoHostSettings());

                    if (!File.Exists(hostConfigFilePath))
                    {
                        var message = "Host configuration file ('" + BdoDefaultHostPaths.__DefaultHostConfigFileName + "') not found";
                        if (Options.IsHostConfigFileRequired == true)
                        {
                            subLog.AddError(message);
                        }
                        else if (Options.IsHostConfigFileRequired == false)
                        {
                            subLog.AddWarning(message);
                        }
                    }
                    else
                    {
                        subLog = log.AddSubLog(title: "Loading host configuration...", eventKind: EventKinds.Message);
                        Options.HostSettings.UpdateFromFile(
                            hostConfigFilePath,
                            new SpecificationLevels[] { SpecificationLevels.Definition, SpecificationLevels.Configuration },
                            Options?.AppSettingsSpecificationSet,
                            _scope, null).AddEventsTo(log);
                        if (!subLog.HasErrorsOrExceptions())
                        {
                            subLog.AddMessage("Host configuration loaded");
                        }
                    }

                    Options.Update().AddEventsTo(subLog);

                    if (string.IsNullOrEmpty(Options?.HostSettings.ApplicationInstanceName))
                    {
                        Options.HostSettings.ApplicationInstanceName = BdoAppConfiguration.__ApplicationInstanceName;
                    }

                    // we load extensions

                    subLog = log.AddSubLog(title: "Loading extensions...", eventKind: EventKinds.Message);

                    if (Options?.ExtensionReferences.Count == 0)
                    {
                        subLog.AddMessage("No extensions found");
                    }
                    else
                    {
                        Options.ExtensionLoadOptions?.WithLibraryFolderPath(GetKnownPath(BdoHostPathKind.LibraryFolder));
                        foreach (var reference in Options?.ExtensionReferences)
                        {
                            subLog.AddEvents(_scope.LoadExtensions(p => p.Update(Options?.ExtensionLoadOptions), reference), l => l.HasErrorsOrExceptionsOrWarnings());
                        }

                        if (!subLog.HasErrorsOrExceptions())
                        {
                            subLog.AddMessage("Extensions loaded");
                        }
                    }

                    if (!log.HasErrorsOrExceptions())
                    {
                        // we load the application configuration

                        Options.SetAppSettings(new S());

                        string appConfigFilePath = GetKnownPath(BdoHostPathKind.ConfigurationFolder) + BdoDefaultHostPaths.__DefaultAppConfigFileName;

                        subLog = log.AddSubLog(title: "Loading application configuration...", eventKind: EventKinds.Message);
                        if (!File.Exists(appConfigFilePath))
                        {
                            var message = "Application configuration file ('" + BdoDefaultHostPaths.__DefaultAppConfigFileName + "') not found";
                            if (Options.HostSettings.IsAppConfigFileRequired == true)
                            {
                                subLog.AddError(message);
                            }
                            else if (Options.HostSettings.IsAppConfigFileRequired == false)
                            {
                                subLog.AddWarning(message);
                            }
                        }
                        else
                        {
                            Options.Settings.UpdateFromFile(
                                appConfigFilePath,
                                new SpecificationLevels[] { SpecificationLevels.Definition, SpecificationLevels.Configuration },
                                Options?.AppSettingsSpecificationSet,
                                _scope, null).AddEventsTo(subLog);
                        }
                        if (!subLog.HasErrorsOrExceptions())
                        {
                            subLog.AddMessage("Application configuration loaded");
                        }
                        else
                        {
                            subLog.AddMessage(title: "No configuration loaded");
                        }

                        // we set the logger

                        Log.SetLogger(Options.LoggerInit?.Invoke(this));

                        // we load the data store

                        _scope.DataStore = Options?.DataStore;
                        subLog           = log.AddSubLog(title: "Loading data store...", eventKind: EventKinds.Message);
                        if (_scope.DataStore == null)
                        {
                            subLog.AddMessage(title: "No data store registered");
                        }
                        else
                        {
                            _scope.DataStore.LoadLazy(this, subLog);

                            if (!subLog.HasErrorsOrExceptions())
                            {
                                subLog.AddMessage("Data store loaded (" + _scope.DataStore.Depots.Count + " depots added)");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.AddException(ex);
                }
                finally
                {
                }
            }

            _isLoaded = !log.HasErrorsOrExceptions();
        }