Example #1
0
        public void Init()
        {
            services.AddSingleton(dbContext);
            services.AddSingleton(logger);
            services.AddSingleton(loggerFactory);

            services.AddSingleton <IUnitOfWork, UnitOfWork>();
            services.AddSingleton <IEngineRepository, EngineRepository>();
            services.AddSingleton <IMessageRepository, MessageRepository>();

            services.AddSingleton <IMessageService, MessageService>();
            services.AddSingleton <ISqlValidationService, SqlValidationService>();
            services.AddSingleton(loggerFactory.CreateLogger <StorageService>());
            services.AddSingleton <IStorageService, StorageService>();
            services.AddSingleton(Configuration);
            services.AddSingleton(loggerFactory.CreateLogger <EngineJob>());
            services.AddSingleton(loggerFactory.CreateLogger <EngineTask>());
            services.AddSingleton(loggerFactory.CreateLogger <EngineElement>());

            services.AddSingleton <IEngine, Engine>();
            services.AddTransient <IEngineJob, EngineJob>();
            services.AddTransient <IEngineTask, EngineTask>();
            services.AddTransient <EngineLink>();

            // Register all extensions elements and modules types
            var engineModuleTypes = AssembliesExtensions.GetTypesImplementingInterface <IEngineModule>(new string[] { Configuration.ExtensionsFolder }, false);

            foreach (var engineModule in engineModuleTypes)
            {
                engineModule.GetMethod("RegisterModule").Invoke(null, new object[] { services });
            }

            // build the service providere used in Engine
            serviceProvider = services.BuildServiceProvider();
        }
Example #2
0
 private IEnumerable <IModuleType> GetModuleTypes()
 {
     return(AssembliesExtensions.GetTypesImplementingInterface <IEngineModule>(new string[] { configuration.ExtensionsFolder }, true)
            .Select(ed => new ModuleTypeViewModel
     {
         Key = (string)ed.GetProperty("KeyConst")?.GetValue(ed),
         Name = (string)ed.GetProperty("Name")?.GetValue(ed),
         Description = (string)ed.GetProperty("Description")?.GetValue(ed)
     }));
 }
        private static IEngineData GetPopertyDataValue(IElementPropertyEntry inputProperty)
        {
            var engineDataType = AssembliesExtensions.GetTypesImplementingInterface <IEngineData>() //current loaded asemblies
                                 .FirstOrDefault(ed => (DataType)ed.GetProperty("DataTypeConst").GetValue(ed) == inputProperty.DataType);

            var engineDataValue = (IEngineData)Activator.CreateInstance(engineDataType);

            engineDataValue.ReadFromStringValue(inputProperty.Value);
            return(engineDataValue);
        }
Example #4
0
        public void SetDataValueIfEmpty(EngineDataDirection direction, string propertyKey, DataType dataType, string persistingValue)
        {
            var engineDataType = AssembliesExtensions.GetTypesImplementingInterface <IEngineData>()
                                 .FirstOrDefault(ed => (DataType)ed.GetProperty("DataTypeConst").GetValue(ed) == dataType);

            var engineDataValue = (IEngineData)Activator.CreateInstance(engineDataType);

            engineDataValue.ReadFromStringValue(persistingValue);

            SetDataValueIfEmpty(direction, propertyKey, engineDataValue);
        }
Example #5
0
        public IEngineModule GetEngineModule(string moduleTypeKey)
        {
            var engineModuleType = AssembliesExtensions.GetTypesImplementingInterface <IEngineModule>(new string[] { configuration.ExtensionsFolder }, true)
                                   .FirstOrDefault(ed => (string)ed.GetProperty("KeyConst")?.GetValue(ed) == moduleTypeKey);

            // Check if the element type exists
            if (engineModuleType == null)
            {
                throw new EngineException(logger, "Error. The module type not exists.");
            }

            // Load the engine element using engine service provider
            var engineModule = (IEngineModule)engine.ServiceProvider.GetService(engineModuleType);

            return(engineModule);
        }
Example #6
0
        public IElementType GetEngineElementType(string elementKey)
        {
            var result            = new ElementTypeViewModel();
            var engineElementType = AssembliesExtensions.GetTypesImplementingInterface <IEngineElement>(new string[] { Configuration.ExtensionsFolder }, true)
                                    .FirstOrDefault(ed => (string)ed.GetProperty("KeyConst")?.GetValue(ed) == elementKey);

            if (engineElementType == null)
            {
                // we cant find a valid element implementation
                throw new EngineException(logger, $"Cannot find a valid implementation for the element with key: '{elementKey}'.");
            }

            result.Key         = elementKey;
            result.Name        = (string)engineElementType.GetProperty("Name")?.GetValue(engineElementType);
            result.Description = (string)engineElementType.GetProperty("Description")?.GetValue(engineElementType);

            return(result);
        }
Example #7
0
        /// <summary>
        /// Registers the output properties.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="description">The description.</param>
        /// <param name="dataType">Type of the data.</param>
        /// <param name="mandatory"></param>
        /// <exception cref="EngineException">Invalid property fields provided.
        /// or
        /// Cannot add property for this element. The property with key {key} still exists.</exception>
        public void RegisterOutputProperties(string key, string description, DataType dataType, bool mandatory = false)
        {
            if (key.IsNullOrWhiteSpace())
            {
                throw new EngineException(logger, $"Invalid property fields provided.");
            }

            if (outputProperties.Any(p => p.Key == key))
            {
                throw new EngineException(logger, $"Cannot add property for this element. The property with key {key} still exists.");
            }

            outputProperties.Add(new ElementProperty(key, description, dataType, mandatory));
            // Init default value

            var engineDataType = AssembliesExtensions.GetTypesImplementingInterface <IEngineData>()
                                 .FirstOrDefault(ed => (DataType)ed.GetProperty("DataTypeConst").GetValue(ed) == dataType);

            SetDataValue(EngineDataDirection.Output, key, (IEngineData)Activator.CreateInstance(engineDataType));
        }
Example #8
0
        public IEngineElement GetEngineElement(string elementKey)
        {
            var engineElementType = AssembliesExtensions.GetTypesImplementingInterface <IEngineElement>(new string[] { Configuration.ExtensionsFolder }, true)
                                    .FirstOrDefault(ed => (string)ed.GetProperty("KeyConst")?.GetValue(ed) == elementKey);

            if (engineElementType == null)
            {
                // we cant find a valid element implementation
                throw new EngineException(logger, $"Cannot find a valid implementation for the element with key: '{elementKey}'.");
            }

            // create new instance of Engine Element
            var engineElement = (IEngineElement)serviceProvider.GetService(engineElementType);

            if (engineElement == null)
            {
                // we cant find a valid module implementation
                throw new EngineException(logger, $"Cannot find a registered instance for the element with key: '{elementKey}'.");
            }

            return(engineElement);
        }