コード例 #1
0
ファイル: MvcModuleSetup.cs プロジェクト: pentest30/Mystique
        public void EnableModule(string moduleName)
        {
            if (!PluginsLoadContexts.Any(moduleName))
            {
                CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);

                string filePath            = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll";
                string referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}";
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    System.Reflection.Assembly assembly = context.LoadFromStream(fs);
                    _referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                    MystiqueAssemblyPart controllerAssemblyPart = new MystiqueAssemblyPart(assembly);

                    AdditionalReferencePathHolder.AdditionalReferencePaths.Add(filePath);
                    _partManager.ApplicationParts.Add(controllerAssemblyPart);
                    PluginsLoadContexts.Add(moduleName, context);
                }
            }
            else
            {
                CollectibleAssemblyLoadContext context = PluginsLoadContexts.Get(moduleName);
                MystiqueAssemblyPart           controllerAssemblyPart = new MystiqueAssemblyPart(context.Assemblies.First());
                _partManager.ApplicationParts.Add(controllerAssemblyPart);
            }

            ResetControllActions();
        }
コード例 #2
0
ファイル: MvcModuleSetup.cs プロジェクト: ym1100/CoolCat
        public void EnableModule(string moduleName)
        {
            ServiceProvider provider        = CoolCatStartup.Services.BuildServiceProvider();
            var             contextProvider = new CollectibleAssemblyLoadContextProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                var dataStore     = scope.ServiceProvider.GetService <IDataStore>();
                var documentation = scope.ServiceProvider.GetService <IQueryDocumentation>();

                var context = contextProvider.Get(moduleName, _partManager, scope, dataStore, documentation);
                PluginsLoadContexts.Add(moduleName, context);
                context.Enable();
            }

            ResetControllActions();

            //if (!PluginsLoadContexts.Any(moduleName))
            //{
            //    ServiceProvider provider = CoolCatStartup.Services.BuildServiceProvider();
            //    var contextProvider = new CollectibleAssemblyLoadContextProvider();

            //    using (IServiceScope scope = provider.CreateScope())
            //    {
            //        var dataStore = scope.ServiceProvider.GetService<IDataStore>();
            //        var documentation = scope.ServiceProvider.GetService<IQueryDocumentation>();

            //        var context = contextProvider.Get(moduleName, _partManager, scope, dataStore, documentation);
            //        PluginsLoadContexts.Add(moduleName, context);
            //    }

            //    ResetControllActions();
            //}
        }
コード例 #3
0
ファイル: CoolCatStartup.cs プロジェクト: nov14/CoolCat
        public static void CoolCatSetup(this IServiceCollection services, IConfiguration configuration)
        {
            _serviceCollection = services;

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IDbHelper, DbHelper>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <ISystemManager, SystemManager>();
            services.AddScoped <IUnitOfWork, Repository.MySql.UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(CoolCatActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();

            var documentation = new CoolCatModuleDocumentation();

            services.AddSingleton <IQueryDocumentation>(documentation);
            services.AddSingleton(CoolCatActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();
                var         dataStore  = new DefaultDataStore(scope.ServiceProvider.GetService <ILogger <DefaultDataStore> >());
                services.AddSingleton <IDataStore>(dataStore);
                var contextProvider = new CollectibleAssemblyLoadContextProvider();

                if (unitOfWork.CheckDatabase())
                {
                    List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                    IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                    foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                    {
                        var context = contextProvider.Get(plugin.Name, mvcBuilder, scope, dataStore, documentation);
                        PluginsLoadContexts.Add(plugin.Name, context);
                    }
                }
            }

            AssemblyLoadContextResoving();

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            services.Replace <IViewCompilerProvider, CoolCatViewCompilerProvider>();
        }
コード例 #4
0
ファイル: MvcModuleSetup.cs プロジェクト: Eric-xgc/Mystique
        public void EnableModule(string moduleName)
        {
            if (!PluginsLoadContexts.Any(moduleName))
            {
                ServiceProvider provider        = MystiqueStartup.Services.BuildServiceProvider();
                var             contextProvider = new CollectibleAssemblyLoadContextProvider();

                using (IServiceScope scope = provider.CreateScope())
                {
                    var dataStore = scope.ServiceProvider.GetService <IDataStore>();

                    var context = contextProvider.Get(moduleName, _partManager, scope, dataStore);
                    PluginsLoadContexts.Add(moduleName, context);
                }

                ResetControllActions();
            }
        }
コード例 #5
0
        public void EnableModule(string moduleName)
        {
            if (!PluginsLoadContexts.Any(moduleName))
            {
                CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);

                var filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.dll");
                var viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.Views.dll");
                var referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName);
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    var assembly = context.LoadFromStream(fs);
                    _referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                    context.SetEntryPoint(assembly);

                    var controllerAssemblyPart = new MystiqueAssemblyPart(assembly);

                    AdditionalReferencePathHolder.AdditionalReferencePaths.Add(filePath);
                    _partManager.ApplicationParts.Add(controllerAssemblyPart);
                    PluginsLoadContexts.Add(moduleName, context);
                    context.Enable();
                }

                using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
                {
                    var viewAssembly = context.LoadFromStream(fsView);
                    _referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, viewAssembly);

                    var moduleView = new MystiqueRazorAssemblyPart(viewAssembly, moduleName);
                    _partManager.ApplicationParts.Add(moduleView);
                }
            }
            else
            {
                var context = PluginsLoadContexts.Get(moduleName);
                var controllerAssemblyPart = new MystiqueAssemblyPart(context.Assemblies.First());
                _partManager.ApplicationParts.Add(controllerAssemblyPart);
                context.Enable();
            }

            ResetControllActions();
        }
コード例 #6
0
        public void EnableModule(string moduleName)
        {
            try
            {
                var controller = _partManager.ApplicationParts.FirstOrDefault(p => p.Name == moduleName);
                if (controller == null)
                {
                    ServiceProvider provider        = _serviceContext.Services.BuildServiceProvider();
                    var             contextProvider = new CollectibleAssemblyLoadContextProvider();
                    using (IServiceScope scope = provider.CreateScope())
                    {
                        var context = contextProvider.Get(moduleName, _serviceContext.Services, _partManager, scope);
                        PluginsLoadContexts.Add(moduleName, context);
                        context.Enable();
                    }
                    ResetControllActions();
                }
            } catch (Exception e) {
                Console.WriteLine(e);
            }


            //if (!PluginsLoadContexts.Any(moduleName))
            //{
            //    ServiceProvider provider = CoolCatStartup.Services.BuildServiceProvider();
            //    var contextProvider = new CollectibleAssemblyLoadContextProvider();

            //    using (IServiceScope scope = provider.CreateScope())
            //    {
            //        var dataStore = scope.ServiceProvider.GetService<IDataStore>();
            //        var documentation = scope.ServiceProvider.GetService<IQueryDocumentation>();

            //        var context = contextProvider.Get(moduleName, _partManager, scope, dataStore, documentation);
            //        PluginsLoadContexts.Add(moduleName, context);
            //    }

            //    ResetControllActions();
            //}
        }
コード例 #7
0
ファイル: MystiqueStartup.cs プロジェクト: pentest30/Mystique
        public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddOptions();
            services.Configure <ConnectionStringSetting>(configuration.GetSection("ConnectionStringSetting"));

            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();
            services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                MvcRazorRuntimeCompilationOptions option = scope.ServiceProvider.GetService <MvcRazorRuntimeCompilationOptions>();

                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();
                List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                {
                    CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(plugin.Name);
                    string moduleName          = plugin.Name;
                    string filePath            = $"{AppDomain.CurrentDomain.BaseDirectory}Modules/{moduleName}/{moduleName}.dll";
                    string referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules/{moduleName}";

                    _presets.Add(filePath);
                    using (FileStream fs = new FileStream(filePath, FileMode.Open))
                    {
                        System.Reflection.Assembly assembly = context.LoadFromStream(fs);
                        context.SetEntryPoint(assembly);
                        loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                        MystiqueAssemblyPart controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
                        mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
                        PluginsLoadContexts.Add(plugin.Name, context);

                        var providers = assembly.GetExportedTypes().Where(p => p.GetInterfaces().Any(x => x.Name == "INotificationProvider"));

                        if (providers.Any())
                        {
                            var register = scope.ServiceProvider.GetService <INotificationRegister>();

                            foreach (var p in providers)
                            {
                                var obj    = (INotificationProvider)assembly.CreateInstance(p.FullName);
                                var result = obj.GetNotifications();

                                foreach (var item in result)
                                {
                                    foreach (var i in item.Value)
                                    {
                                        register.Subscribe(item.Key, i);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            mvcBuilder.AddRazorRuntimeCompilation(o =>
            {
                foreach (string item in _presets)
                {
                    o.AdditionalReferencePaths.Add(item);
                }

                AdditionalReferencePathHolder.AdditionalReferencePaths = o.AdditionalReferencePaths;
            });

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });
        }
コード例 #8
0
ファイル: MystiqueStartup.cs プロジェクト: neoayi/Mystique
        public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
        {
            _serviceCollection = services;

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <ISystemManager, SystemManager>();
            services.AddScoped <IUnitOfWork, Repository.MySql.UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();
            services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();

                if (unitOfWork.CheckDatabase())
                {
                    List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                    IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                    foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                    {
                        CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(plugin.Name);
                        string moduleName = plugin.Name;

                        string filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.dll");
                        string viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.Views.dll");
                        string referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName);

                        _presets.Add(filePath);
                        using (FileStream fs = new FileStream(filePath, FileMode.Open))
                        {
                            Assembly assembly = context.LoadFromStream(fs);
                            context.SetEntryPoint(assembly);

                            loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                            MystiqueAssemblyPart controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
                            mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
                            PluginsLoadContexts.Add(plugin.Name, context);

                            BuildNotificationProvider(assembly, scope);
                        }

                        using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
                        {
                            Assembly viewAssembly = context.LoadFromStream(fsView);
                            loader.LoadStreamsIntoContext(context, referenceFolderPath, viewAssembly);

                            MystiqueRazorAssemblyPart moduleView = new MystiqueRazorAssemblyPart(viewAssembly, moduleName);
                            mvcBuilder.PartManager.ApplicationParts.Add(moduleView);
                        }

                        context.Enable();
                    }
                }
            }

            AssemblyLoadContextResoving();

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            services.Replace <IViewCompilerProvider, MystiqueViewCompilerProvider>();
        }
コード例 #9
0
        public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddOptions();
            services.Configure <ConnectionStringSetting>(configuration.GetSection("ConnectionStringSetting"));

            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddSingleton <IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();
            services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);

            var mvcBuilder = services.AddMvc();

            var provider = services.BuildServiceProvider();

            using (var scope = provider.CreateScope())
            {
                var option = scope.ServiceProvider.GetService <MvcRazorRuntimeCompilationOptions>();

                var unitOfWork        = scope.ServiceProvider.GetService <IUnitOfWork>();
                var allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                var loader            = scope.ServiceProvider.GetService <IReferenceLoader>();

                foreach (var plugin in allEnabledPlugins)
                {
                    var context             = new CollectibleAssemblyLoadContext();
                    var moduleName          = plugin.Name;
                    var filePath            = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}\\{moduleName}.dll";
                    var referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules\\{moduleName}";

                    _presets.Add(filePath);
                    using (var fs = new FileStream(filePath, FileMode.Open))
                    {
                        var assembly = context.LoadFromStream(fs);
                        loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                        var controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
                        mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
                        PluginsLoadContexts.Add(plugin.Name, context);
                    }
                }
            }

            mvcBuilder.AddRazorRuntimeCompilation(o =>
            {
                foreach (var item in _presets)
                {
                    o.AdditionalReferencePaths.Add(item);
                }

                AdditionalReferencePathHolder.AdditionalReferencePaths = o.AdditionalReferencePaths;
            });

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });
        }