Example #1
0
        public CoreAdminService(string moduleName, IServiceProvider serviceProvider)
        {
            _adminSiteProvider = serviceProvider.GetService <IAdminSiteProvider>();
            _logger            = serviceProvider.GetService <ILogger <CoreAdminService> >();
            _moduleRegistry    = serviceProvider.GetService <IModuleRegistry>();
            _serviceProvider   = serviceProvider;

            _serializer = new JsonSerializer();
            _serializer.NullValueHandling = NullValueHandling.Ignore;
            _serializer.Converters.Add(new Core.Common.Json.GuidConverter());


            var adminConfiguratorType = _moduleRegistry.GetModuleMetaInfoByModuleName(moduleName)?.AdminConfiguratorTypeInfo;

            if (adminConfiguratorType == null)
            {
                throw new ArgumentNullException(string.Format(Resources.AdminConfiguratorNotFound, moduleName));
            }
            _adminSite = _adminSiteProvider.GetAdminConfig(adminConfiguratorType.AsType());

            if (_adminSite.AdminType == AdminType.Entity)
            {
                _adminRepository = new AdminRepository(_adminSite, _serviceProvider);
            }
        }
Example #2
0
        public async Task <IHtmlContent> GetAdminPageResult(ActionContext actionContext)
        {
            var currentPage = _scopeService.PageContext.CurrentPage;

            if (currentPage.AdminPage == null)
            {
                return(null);
            }

            var moduleName     = currentPage.AdminPage.ModuleName;
            var modelName      = currentPage.AdminPage.ModelName;
            var moduleMetaInfo = _moduleRegistry.GetModuleMetaInfoByModuleName(moduleName);

            var assembly           = DefaultAssemblyPartDiscoveryProvider.DiscoverAssemblyParts(Globals.EntryPointAssembly).FirstOrDefault(a => a.FullName == moduleMetaInfo.ModuleAssemblyFullName);
            var controllerTypeInfo = assembly.GetDerivedTypeInfos(typeof(IAdminController)).FirstOrDefault();
            var controllerName     = controllerTypeInfo.Name.Replace("Controller", "");
            var actionName         = nameof(AdminController <IAdminConfigurator> .Admin);


            var routeContext = new RouteContext(actionContext.HttpContext);

            routeContext.RouteData = new RouteData();
            //routeContext.RouteData.Values.Add("area", moduleName);
            //routeContext.RouteData.Values.Add("controller", controllerName);
            //routeContext.RouteData.Values.Add("action", actionName);
            //routeContext.RouteData.Values.Add("entity", entityName);

            var routeParams = new RouteValueDictionary(new { model = modelName });
            var routeValues = new RouteValueDictionary(new { area = moduleName, controller = controllerName, action = actionName });

            foreach (var router in actionContext.RouteData.Routers)
            {
                routeContext.RouteData.PushState(router, null, null);
            }

            routeContext.RouteData.PushState(null, routeValues, null);
            routeContext.RouteData.PushState(null, routeParams, null);

            var adminActionContext = GetActionContext(routeContext);


            //var invoker = _moduleInvokerProvider.CreateInvoker(moduleActionContext);
            //var result = await invoker.InvokeAction() as ViewResult;



            var result = await _actionInvoker.InvokeAction(actionContext.HttpContext, controllerTypeInfo.Namespace, controllerName, actionName, adminActionContext) as ViewResult;

            var htmlResult = result.ExecuteResultToHTML(adminActionContext);

            return(htmlResult);
        }