Exemplo n.º 1
0
        /// <summary>
        /// Create an instance of the Module Engine
        /// </summary>
        /// <param name="container">IOC container</param>
        /// <returns>An instance of a module engine</returns>
        public static async Task <ModuleEngine> CreateInstance(Container container, SettingsService settingsService)
        {
            // Create instance
            var @this = new ModuleEngine(container, settingsService);

            @this._coreSettings = await settingsService.LoadSetting <CoreSettings>(@this, "Settings");

            // Find and instantiate modules
            List <Type> moduleTypes = new List <Type>();

            var moduleLoader = new ModuleLoader(container);

            moduleTypes.AddRange(moduleLoader.GetSuppliedModules());
            moduleTypes.AddRange(moduleLoader.GetInstalledModules());

            @this._modules = moduleLoader.CreateInstances(moduleTypes);

            // Seperate and order modules
            @this.SchemaInferenceModules = @this._modules.Where(m => m is InferenceModuleBase).Cast <InferenceModuleBase>().ToList();
            @this.RefinementModules      = OrderDependencies <RefinementModuleBase>(@this._modules.Where(m => m is RefinementModuleBase).Cast <IDependent>().ToList());
            @this.CombinationModule      = @this._modules.Where(m => m is ICombinationModule).Cast <ICombinationModule>().ToList();
            @this.MultidimModules        = @this._modules.Where(m => m is IMultidimModuleFact).Cast <IMultidimModuleFact>().ToList();
            @this.DimensionalModules     = OrderDependencies <DimensionalModuleBase>(@this._modules.Where(m => m is DimensionalModuleBase).Cast <IDependent>().ToList());

            @this.StarRefinementModules = @this._modules.Where(m => m is IStarRefinement).Cast <IStarRefinement>().ToList();
            @this.GenerationModules     = @this._modules.Where(m => m is IGeneration).Cast <IGeneration>().ToList();

            // Load configurations
            @this.ConfigurationManager = new ConfigurationManager(container, @this._modules);
            @this.Configurations       = await @this.ConfigurationManager.LoadConfigurations();

            if (@this.Configurations.Count == 0)
            {
                @this = @this.CreateDefaultConfiguration();
            }

            @this.CurrentConfiguration = @this.Configurations.First();

            // Load connections
            if (@this.Connections.Count == 0)
            {
                @this = @this.CreateDefaultConnections();
            }

            return(@this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get desired settings path. Create directory if not existent
        /// </summary>
        /// <typeparam name="T">Type of setting</typeparam>
        /// <param name="this">Object requesting setting</param>
        /// <param name="filename">Optional filename of setting</param>
        /// <returns>Path to file</returns>
        private string GetPath <T>(object @this, string filename) where T : new()
        {
            string path;

            // If module, then place together with DLL
            if (@this is IModule)
            {
                path = ModuleEngine.ModulePath((IModule)@this);
            }
            else
            {
                path = CoreSettingsPath;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            return(Path.Combine(path, (string.IsNullOrWhiteSpace(filename) ? typeof(T).Name : filename) + ".json"));
        }