Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void DisableModule(string moduleName)
        {
            var controller = _partManager.ApplicationParts.FirstOrDefault(p => p.Name == moduleName);

            if (controller != null)
            {
                _partManager.ApplicationParts.Remove(controller);
                var ui = _partManager.ApplicationParts.FirstOrDefault(p => p.Name == $"{moduleName}.Views");
                if (ui != null)
                {
                    _partManager.ApplicationParts.Remove(ui);
                }
                var items = new List <ServiceDescriptor>();
                foreach (var item in _serviceContext.Services)
                {
                    if (item.ServiceType.Assembly.GetName().Name == moduleName)
                    {
                        items.Add(item);
                    }
                }
                foreach (var service in items)
                {
                    _serviceContext.Services.Remove(service);
                }
                var context = PluginsLoadContexts.Get(moduleName);
                context.Disable();

                PluginsLoadContexts.Remove(moduleName);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                ResetControllActions();
            }
        }
Ejemplo n.º 3
0
        public void DisableModule(string moduleName)
        {
            var last = _partManager.ApplicationParts.First(p => p.Name == moduleName);

            _partManager.ApplicationParts.Remove(last);

            var context = PluginsLoadContexts.Get(moduleName);

            context.Disable();

            ResetControllActions();
        }
Ejemplo n.º 4
0
        public void DisableModule(string moduleName)
        {
            var controller = _partManager.ApplicationParts.First(p => p.Name == moduleName);

            _partManager.ApplicationParts.Remove(controller);

            var ui = _partManager.ApplicationParts.First(p => p.Name == $"{moduleName}.Views");

            _partManager.ApplicationParts.Remove(ui);

            var context = PluginsLoadContexts.Get(moduleName);

            context.Disable();

            ResetControllActions();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 6
0
        public IActionResult GetModuleScript(string moduleName, string fileName)
        {
            var fileContent = PluginsLoadContexts.Get(moduleName).LoadResource(fileName);

            return(new FileContentResult(fileContent, "text/javascript"));
        }