private void GeneratePageContent(ViewContext context, Page page)
        {
            string controllerName = context.RouteData.GetRequiredString("controller");
            string actionName     = context.RouteData.GetRequiredString("action");
            string areaName       = context.RouteData.DataTokens["area"] as string;

            //将控制器传入的验证错误信息转发给页面
            foreach (var modelState in context.ViewData.ModelState)
            {
                if (modelState.Value.Errors.Count < 1)
                {
                    continue;
                }

                foreach (var error in modelState.Value.Errors)
                {
                    page.ModelState.AddModelError(modelState.Key, error.ErrorMessage);
                }
            }

            //首先生成工作台节点下的基本控件
            this.GeneratePageContent(page, _pluginContext.PluginTree.Find(_pluginContext.Settings.WorkbenchPath));

            string path     = PluginPath.Combine(string.IsNullOrWhiteSpace(areaName) ? "Workspace" : areaName, "Views", controllerName, actionName);
            var    viewNode = _pluginContext.PluginTree.Find(path);

            if (viewNode != null)
            {
                this.GeneratePageContent(page, viewNode);
            }
        }
Beispiel #2
0
        private PluginTreeNode GetControllerNode(RequestContext requestContext, string controllerName)
        {
            Route route = requestContext.RouteData.Route as Route;

            if (route == null)
            {
                return(null);
            }

            var controllerPath = string.Empty;
            var area           = VirtualPathHelper.GetArea(requestContext.RouteData);

            if (string.IsNullOrWhiteSpace(area))
            {
                controllerPath = PluginPath.Combine(ROOT_CONTROLLERS_PATH, controllerName);
            }
            else
            {
                controllerPath = PluginPath.Combine(ROOT_CONTROLLERS_PATH, area, controllerName);
            }

            requestContext.RouteData.DataTokens["area"]            = area;
            requestContext.RouteData.DataTokens["controller.path"] = controllerPath;

            return(_pluginContext.PluginTree.Find(controllerPath));
        }
		protected override void OnStart(string[] args)
		{
			this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web"), this.Web);
			this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web", "ViewEngines"), this.Web.ViewEngines);
			this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web", "Api"), this.Web.Api);

			var routeProvider = this.Web.RouteProvider;

			if(routeProvider != null)
			{
				foreach(var token in routeProvider.GetRoutes())
				{
					var route = token.ToRoute();

					if(route is RouteBase)
						RouteTable.Routes.Add((RouteBase)route);
					else if(route is IHttpRoute)
						GlobalConfiguration.Configuration.Routes.Add(token.Name, (IHttpRoute)route);
				}
			}

			//启用XML序列化器,否则会导致未显式指定内容格式的请求无法序列化
			GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
			//GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = false;

			//初始化JSON格式化器的参数
			if(GlobalConfiguration.Configuration.Formatters.JsonFormatter != null)
			{
				GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

				var contractResolver = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver as Newtonsoft.Json.Serialization.DefaultContractResolver;
				if(contractResolver != null)
					contractResolver.IgnoreSerializableAttribute = true;
			}

			//调用基类同名方法,以启动工作台下Startup下的所有工作者
			base.OnStart(args);
		}
        public PluginServiceProvider(Builtin builtin) : base(builtin.Name)
        {
            var path = builtin.Properties.GetRawValue("path");

            if (string.IsNullOrWhiteSpace(path))
            {
                if (string.Equals(builtin.FullPath, SERVICES_PATH, StringComparison.OrdinalIgnoreCase))
                {
                    _path = builtin.FullPath;
                }
                else
                {
                    _path = PluginPath.Combine(SERVICES_PATH, builtin.Name);
                }
            }
            else
            {
                _path = path == "." ? builtin.FullPath : path;
            }

            _context     = builtin.Context;
            this.Storage = new PluginServiceStorage(this);
        }