Example #1
0
        /// <summary>
        /// Updates information for runtime.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="scriptVariableSet">The set of script variables to consider.</param>
        /// <param name="log">The log to update.</param>
        public override void UpdateRuntimeInfo(IBdoScope scope = null, IScriptVariableSet scriptVariableSet = null, IBdoLog log = null)
        {
            foreach (DataElementSet elementSet in Objects)
            {
                AssemblyHelper.CreateInstance(ClassFullName, out object item).AddEventsTo(log);

                if (!log.HasErrorsOrExceptions() && (item is DataItem))
                {
                    elementSet.UpdateRuntimeInfo(scope, scriptVariableSet, log);
                    item.UpdateFromElementSet <DetailPropertyAttribute>(elementSet, scope, scriptVariableSet);
                }

                Add(item);
            }

            base.UpdateRuntimeInfo(scope, scriptVariableSet, log);
        }
        /// <summary>
        /// Creates the instance of the specified definition.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="configuration">The configuration to consider.</param>
        /// <param name="name">The name to consider.</param>
        /// <param name="log">The log to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <returns>Returns the created task.</returns>
        public static BdoTask CreateTask(
            this IBdoScope scope,
            IBdoTaskConfiguration configuration = null,
            string name = null,
            IBdoLog log = null,
            IScriptVariableSet scriptVariableSet = null)
        {
            BdoTask task = null;

            if (scope?.Check(true).HasErrorsOrExceptions() == false)
            {
                if (configuration != null)
                {
                    // we get the task class reference

                    IBdoTaskDefinition definition = scope.ExtensionStore.GetItemDefinitionWithUniqueId <IBdoTaskDefinition>(configuration?.DefinitionUniqueId);
                    if (definition == null)
                    {
                        log?.AddError("Could not retrieve the extension task '" + configuration.DefinitionUniqueId + "' definition");
                    }
                    else
                    {
                        // we intantiate the task

                        AssemblyHelper.CreateInstance(definition.RuntimeType, out object item).AddEventsTo(log);

                        if (!log.HasErrorsOrExceptions())
                        {
                            task      = item as BdoTask;
                            task.Name = name ?? configuration?.Name;
                            task.UpdateFromElementSet <TaskInputAttribute>(configuration, scope, scriptVariableSet);
                            task.UpdateFromElementSet <TaskOutputAttribute>(configuration, scope, scriptVariableSet);
                        }
                    }
                }
            }

            return(task);
        }
Example #3
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();
        }