Пример #1
0
 public PluginController(IPluginManager pluginManager, IReferenceContainer referenceContainer, IDbConnectionFactory dbConnectionFactory, IQueryDocumentation queryDocumentation, IDataStore dataStore) : base(ModuleDefiniation.MODULE_NAME, dataStore)
 {
     _pluginManager       = pluginManager;
     _referenceContainer  = referenceContainer;
     _dbConnectionFactory = dbConnectionFactory;
     _queryDocumentation  = queryDocumentation;
 }
Пример #2
0
 public PluginsController(IPluginManager pluginManager, IReferenceContainer referenceContainer, IDbConnectionFactory dbConnectionFactory, IQueryDocumentation queryDocumentation)
 {
     _pluginManager       = pluginManager;
     _referenceContainer  = referenceContainer;
     _dbConnectionFactory = dbConnectionFactory;
     _queryDocumentation  = queryDocumentation;
 }
Пример #3
0
 public PluginsController(IPluginManager pluginManager, IReferenceContainer referenceContainer, IDbHelper dbHelper, IQueryDocumentation queryDocumentation)
 {
     _pluginManager      = pluginManager;
     _referenceContainer = referenceContainer;
     _dbHelper           = dbHelper;
     _queryDocumentation = queryDocumentation;
 }
        public CollectibleAssemblyLoadContext Get(string moduleName, ApplicationPartManager apm, IServiceScope scope, IDataStore dataStore, IQueryDocumentation documentation)
        {
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

            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);

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

                context.SetEntryPoint(assembly);

                loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                apm.ApplicationParts.Add(controllerAssemblyPart);

                BuildNotificationProvider(assembly, scope);
                RegisterModuleQueries(dataStore, moduleName, assembly, scope, documentation);
            }

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

                CoolCatRazorAssemblyPart moduleView = new CoolCatRazorAssemblyPart(viewAssembly, moduleName);
                apm.ApplicationParts.Add(moduleView);
            }

            context.Enable();

            return(context);
        }
        private static void RegisterModuleQueries(IDataStore dataStore, string moduleName, Assembly assembly, IServiceScope scope, IQueryDocumentation documentation)
        {
            IEnumerable <Type> queries = assembly.GetExportedTypes().Where(p => p.GetInterfaces().Any(x => x == typeof(IDataStoreQuery)));

            if (queries.Any())
            {
                var dbHelper = scope.ServiceProvider.GetService <IDbHelper>();

                foreach (Type p in queries)
                {
                    var constructor = p.GetConstructors().FirstOrDefault(p => p.GetParameters().Length == 1);

                    if (constructor != null)
                    {
                        IDataStoreQuery obj = (IDataStoreQuery)constructor.Invoke(new object[] { dbHelper });
                        documentation.BuildDocumentation(moduleName, obj);
                        dataStore.RegisterQuery(moduleName, obj.QueryName, obj.Query);
                    }
                    else
                    {
                        IDataStoreQuery obj = (IDataStoreQuery)assembly.CreateInstance(p.FullName);
                        documentation.BuildDocumentation(moduleName, obj);
                        dataStore.RegisterQuery(moduleName, obj.QueryName, obj.Query);
                    }
                }
            }
        }
        public CollectibleAssemblyLoadContext Get(string moduleName, IMvcBuilder mvcBuilder, IServiceScope scope, IDataStore dataStore, IQueryDocumentation documentation)
        {
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

            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);

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

                context.SetEntryPoint(assembly);

                loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);


                var resources = assembly.GetManifestResourceNames();

                if (resources.Any())
                {
                    foreach (var item in resources)
                    {
                        var stream = new MemoryStream();
                        var source = assembly.GetManifestResourceStream(item);
                        source.CopyTo(stream);

                        context.RegisterResource(item, stream.ToArray());
                    }
                }

                BuildNotificationProvider(assembly, scope);
                RegisterModuleQueries(dataStore, moduleName, assembly, scope, documentation);
            }

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

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

            context.Enable();

            return(context);
        }
 public CollectibleAssemblyLoadContext Get(string moduleName, IMvcBuilder mvcBuilder, IServiceScope scope, IDataStore dataStore, IQueryDocumentation documentation)
 {
     return(Get(moduleName, mvcBuilder.PartManager, scope, dataStore, documentation));
 }