Пример #1
0
    static async Task RunDFrameControllerAsync(WebApplicationBuilder appBuilder, DFrameControllerOptions options, Action <WebHostBuilderContext, DFrameControllerOptions> configureOptions)
    {
        appBuilder.WebHost.ConfigureServices((WebHostBuilderContext ctx, IServiceCollection services) =>
        {
            services.AddGrpc();
            services.AddMagicOnion(x =>
            {
                // Should use same options between DFrame.Controller(this) and DFrame.Worker
                x.SerializerOptions = MessagePackSerializerOptions.Standard;
            });
            services.AddSingleton <IMagicOnionLogger, MagicOnionLogToLogger>();

            services.AddRazorPages()
            .ConfigureApplicationPartManager(manager =>
            {
                // import libraries razor pages
                var assembly     = typeof(DFrameControllerWebApplicationBuilderExtensions).Assembly;
                var assemblyPart = new CompiledRazorAssemblyPart(assembly);
                manager.ApplicationParts.Add(assemblyPart);
            });

            services.AddServerSideBlazor();

            // DFrame Options
            services.TryAddSingleton <DFrameControllerExecutionEngine>();
            services.TryAddSingleton <DFrameControllerLogBuffer>();
            services.AddSingleton <ILoggerProvider, DFrameControllerLoggerProvider>();
            services.AddScoped <LocalStorageAccessor>();
            configureOptions(ctx, options);
            services.AddSingleton(options);

            // If user sets custom provdier, use it.
            services.TryAddSingleton <IExecutionResultHistoryProvider, InMemoryExecutionResultHistoryProvider>();

            services.AddMessagePipe();
        });

        var app = appBuilder.Build();

        app.UseStaticFiles();
        app.UseRouting();

        app.MapBlazorHub();
        app.MapFallbackToPage("/_Host");

        app.MapMagicOnionService();

        DisplayConfiguration(app);

        if (!options.DisableRestApi)
        {
            RestApi.RegisterRestApi(app);
        }

        await app.RunAsync();
    }
Пример #2
0
        private static AssemblyPart GetOriginalAssemblyPartOrNull(
            CompiledRazorAssemblyPart compiledRazorAssemblyPart,
            ApplicationPartManager partManager)
        {
            var originalAssemblyName = compiledRazorAssemblyPart.Name.RemovePostFix(".Views");

            return(partManager.ApplicationParts
                   .OfType <AssemblyPart>()
                   .FirstOrDefault(p => p.Name == originalAssemblyName));
        }
 public void RegisteredPlugInServices(IServiceCollection services)
 {
     if (_standalone)
     {
         var assembly             = typeof(PluginBaseController).Assembly;
         var myAssembly           = AssemblyLoadContext.Default.LoadFromAssemblyPath(AssemblyDirectory + "\\" + assembly.GetName().Name + ".Views.dll");
         var viewsApplicationPart = new CompiledRazorAssemblyPart(myAssembly);
         services.AddMvc().ConfigureApplicationPartManager(manager => manager.ApplicationParts.Add(viewsApplicationPart));
     }
     services.AddSingleton <HelpTopicsProvider>();
     services.AddSingleton <IHelpResourceProvider>(new HelpResourceProvider());
 }
Пример #4
0
        /// <summary>
        /// 动态加载一个插件
        /// </summary>
        /// <returns></returns>
        public IActionResult Enable()
        {
            var assembly         = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Plugins\\DemoPlugin1.dll");
            var viewAssembly     = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Plugins\\DemoPlugin1.Views.dll");
            var viewAssemblyPart = new CompiledRazorAssemblyPart(viewAssembly);

            var controllerAssemblyPart = new AssemblyPart(assembly);

            _partManager.ApplicationParts.Add(controllerAssemblyPart);
            _partManager.ApplicationParts.Add(viewAssemblyPart);

            MyActionDescriptorChangeProvider.Instance.HasChanged = true;
            MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();

            return(Content("Enabled"));
        }
Пример #5
0
        public ApplicationCompiledPageFileProvider(IApplicationContext applicationContext)
        {
            _applicationContext = applicationContext;

            if (_pages != null)
            {
                return;
            }

            lock (_synLock)
            {
                if (_pages == null)
                {
                    var application = _applicationContext.Application;

                    var pages = new List <string>();

                    // Resolve the application precompiled assembly path.
                    var precompiledAssemblyPath = Path.Combine(Path.GetDirectoryName(application.Assembly.Location),
                                                               application.Assembly.GetName().Name + ".Views.dll");

                    if (File.Exists(precompiledAssemblyPath))
                    {
                        try
                        {
                            // Resolve the application compiled item provider.
                            var assembly = Assembly.LoadFile(precompiledAssemblyPath);
                            var provider = new CompiledRazorAssemblyPart(assembly) as IRazorCompiledItemProvider;

                            // Get application page ids which are paths from the root with a leading slash.
                            // And remove the leading slash to get normalized paths e.g "Pages/Foo.cshtml".
                            pages = provider.CompiledItems.Where(i => i.Identifier.StartsWith("/Pages/") &&
                                                                 i.Kind == RazorPageDocumentClassifierPass.RazorPageDocumentKind)
                                    .Select(i => i.Identifier.TrimStart('/')).ToList();
                        }

                        catch (FileLoadException)
                        {
                            // Don't throw if assembly cannot be loaded. This can happen if the file is not a managed assembly.
                        }
                    }

                    _pages = pages;
                }
            }
        }
Пример #6
0
        public static IEnumerable <CompiledRazorAssemblyPart> GetPluginRazors(string unitPackagesName = "UnitPackages", string searchPackagePattern = "*.Views.dll")
        {
            List <CompiledRazorAssemblyPart> compiledRazorAssemblyParts = new List <CompiledRazorAssemblyPart>();

            if (string.IsNullOrEmpty(unitPackagesName))
            {
                throw new ArgumentException("UnitPackagesName parameter cannot be empty");
            }

            if (string.IsNullOrEmpty(searchPackagePattern))
            {
                throw new ArgumentException("SearchPackagePattern parameter cannot be empty");
            }

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, unitPackagesName);

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

            DirectoryInfo root = new DirectoryInfo(path);

            DirectoryInfo[] dics = root.GetDirectories();

            foreach (var item in dics)
            {
                var files = item.GetFiles(searchPackagePattern).ToList();

                foreach (var file in files)
                {
                    using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                    {
                        var context = new PluginLoadContext(file.FullName);

                        var assembly = context.LoadFromStream(fs);

                        var viewAssemblyPart = new CompiledRazorAssemblyPart(assembly);

                        compiledRazorAssemblyParts.Add(viewAssemblyPart);
                    }
                }
            }

            return(compiledRazorAssemblyParts);
        }
Пример #7
0
        public void OnGet()
        {
            var assembly         = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test", "RazorClassLibrary1.dll"));
            var assemblyView     = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test", "RazorClassLibrary1.Views.dll"));
            var viewAssemblyPart = new CompiledRazorAssemblyPart(assemblyView);

            var controllerAssemblyPart = new AssemblyPart(assembly);

            _partManager.ApplicationParts.Add(controllerAssemblyPart);
            _partManager.ApplicationParts.Add(viewAssemblyPart);
            //TestRazorReferenceManager.Test(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test", "RazorClassLibrary1.Views.dll"), _partManager);
            var a = HttpContext.RequestServices.GetService(typeof(IViewCompilerProvider)) as MyViewCompilerProvider;

            a.Modify();
            MyActionDescriptorChangeProvider.Instance.HasChanged = true;
            MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
        }
Пример #8
0
        public IActionResult Index()
        {
            var assembly     = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DLL\\PluginController\\PluginController.dll");
            var viewAssembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DLL\\PluginController\\PluginController.Views.dll");

            var controllerAssemblyPart = new AssemblyPart(assembly);
            var viewAssemblyPart       = new CompiledRazorAssemblyPart(viewAssembly);

            _applicationPartManager.ApplicationParts.Add(controllerAssemblyPart);
            _applicationPartManager.ApplicationParts.Add(viewAssemblyPart);

            _pluginActionDescriptorProvider.Reload();
            var feature = new ViewsFeature();

            _applicationPartManager.PopulateFeature <ViewsFeature>(feature);
            return(Content("Enabled"));;
        }
Пример #9
0
        private static void AddDependencies(
            List <ApplicationPart> list,
            CompiledRazorAssemblyPart compiledRazorAssemblyPart,
            ApplicationPartManager partManager,
            IModuleContainer moduleContainer)
        {
            if (!compiledRazorAssemblyPart.Name.EndsWith(".Views"))
            {
                return;
            }

            var originalAssemblyPart = GetOriginalAssemblyPartOrNull(compiledRazorAssemblyPart, partManager);

            if (originalAssemblyPart == null)
            {
                return;
            }

            list.Add(originalAssemblyPart);
        }
Пример #10
0
        public IActionResult Enable()
        {
            var assembly         = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DemoPlugin1\\DemoPlugin1.dll");
            var assembly1        = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DemoPlugin1\\DemoPlugin1.Views.dll");
            var viewAssemblyPart = new CompiledRazorAssemblyPart(assembly1);


            var controllerAssemblyPart = new AssemblyPart(assembly);

            _partManager.ApplicationParts.Add(controllerAssemblyPart);

            ABC.ServiceCollection.Configure <RazorViewEngineOptions>(o =>
            {
                o.ViewLocationFormats.Add($"/DemoPlugin1/Views" + "/{1}/{0}" + RazorViewEngine.ViewExtension);
            });

            //_partManager.ApplicationParts.Add(viewAssemblyPart);

            MyActionDescriptorChangeProvider.Instance.HasChanged = true;
            MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();

            return(Content("Enabled"));
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddControllersWithViews();
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            var assembly         = Assembly.LoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "netcoreapp3.1", "DemoPlugin.dll"));
            var assemblyView     = Assembly.LoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "netcoreapp3.1", "DemoPlugin.Views.dll"));
            var viewAssemblyPart = new CompiledRazorAssemblyPart(assemblyView);

            var controllerAssemblyPart = new AssemblyPart(assembly);
            var mvcBuilders            = services.AddMvc();

            mvcBuilders.ConfigureApplicationPartManager(apm =>
            {
                apm.ApplicationParts.Add(controllerAssemblyPart);
                apm.ApplicationParts.Add(viewAssemblyPart);
            });
        }
 public WidgetRazorAssemblyPart(CompiledRazorAssemblyPart compiledRazorAssemblyPart)
 {
     _compiledRazorAssemblyPart = compiledRazorAssemblyPart;
 }