Пример #1
0
        /// <summary>
        /// 获取MVC操作的相关功能信息
        /// </summary>
        public static IFunction GetExecuteFunction(this ControllerContext context, IServiceProvider provider)
        {
            const string key   = Constants.CurrentMvcFunctionKey;
            IDictionary  items = context.HttpContext.Items;

            if (items.Contains(key))
            {
                return((IFunction)items[key]);
            }
            string           area            = context.GetAreaName();
            string           controller      = context.GetControllerName();
            string           action          = context.GetActionName();
            IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>();

            if (functionHandler == null)
            {
                return(null);
            }
            IFunction function = functionHandler.GetFunction(area, controller, action);

            if (function != null)
            {
                items.Add(key, function);
            }
            return(function);
        }
        public MvcOperationContext(ControllerContext context, string subject)
        {
            ControllerType = context.Controller?.GetType().ToString();
            Controller     = context.GetControllerName();
            Action         = context.GetActionName();
            Subject        = subject;
            var request = context.HttpContext.Request;

            IsChildAction = context.IsChildAction;
            Method        = request.HttpMethod;
            RawUrl        = request.RawUrl;
        }
Пример #3
0
        public object GetData(ControllerContext context, QueryParameters parameters)
        {
            var repositoryName = context.GetControllerName() + "repository";
            var repository     =
                Locator.GetAllInstances(typeof(IDynamicRepository)).FirstOrDefault(
                    o => o.GetType().Name.ToLowerInvariant() == repositoryName);

            if (repository == null)
            {
                throw new Exception(string.Format("Could not locate a repository named '{0}'", repositoryName));
            }
            return(repository.GetType().GetMethod("All").Invoke(repository, null));
        }
Пример #4
0
        /// <summary>
        /// 获取MVC操作的相关功能信息
        /// </summary>
        public static IFunction GetExecuteFunction(this ControllerContext context)
        {
            const string key   = Constants.CurrentFunctionKey;
            IDictionary  items = context.HttpContext.Items;

            if (items.Contains(key))
            {
                return((IFunction)items[key]);
            }
            string    area       = context.GetAreaName();
            string    controller = context.GetControllerName();
            string    action     = context.GetActionName();
            IFunction function   = OSharpContext.Current.FunctionHandler.GetFunction(area, controller, action);

            if (function != null)
            {
                items.Add(key, function);
            }
            return(function);
        }
        protected virtual ViewEngineResult FindThemeView(ControllerContext controllerContext, string viewName, string masterName, bool useCache, WorkType workType)
        {
            return AspectF.Define.MustBeNonNull(controllerContext).MustBeNonNullOrEmpty(viewName).Return<ViewEngineResult>(() =>
            {
                var theme = MvcHelper.GetCurrentTheme(workType);
                var controllerName = controllerContext.GetControllerName();

                string[] viewSearchedLocations;
                string[] masterSearchedLocations;
                string viewPath = this.GetPath(controllerContext, this.ViewLocationFormats, this.AreaViewLocationFormats, "ViewLocationFormats", viewName, controllerName, theme, "View", useCache, workType, out viewSearchedLocations);
                string masterPath = this.GetPath(controllerContext, this.MasterLocationFormats, this.AreaMasterLocationFormats, "MasterLocationFormats", masterName, controllerName, theme, "Master", useCache, workType, out masterSearchedLocations);

                if (!string.IsNullOrEmpty(viewPath) && (!string.IsNullOrEmpty(masterPath) || string.IsNullOrEmpty(masterName)))
                {
                    return new ViewEngineResult(this.CreateView(controllerContext, viewPath, masterPath), this);
                }

                if (null == viewSearchedLocations)
                    viewSearchedLocations = new string[0];
                if (null == masterSearchedLocations)
                    masterSearchedLocations = new string[0];
                return new ViewEngineResult(viewSearchedLocations.Union(masterSearchedLocations));
            });
        }
        protected virtual ViewEngineResult FindThemePartialView(ControllerContext controllerContext, string partialViewName, bool useCache, WorkType workType)
        {
            return AspectF.Define.MustBeNonNull(controllerContext).MustBeNonNullOrEmpty(partialViewName).Return<ViewEngineResult>(() =>
            {
                var theme = MvcHelper.GetCurrentTheme(workType);
                string controllerName = controllerContext.GetControllerName();

                string[] partialViewSearchedLocations;
                string partialViewPath = this.GetPath(controllerContext, this.PartialViewLocationFormats, this.AreaPartialViewLocationFormats, "PartialViewLocationFormats", partialViewName, controllerName, theme, "PartialView", useCache, workType, out partialViewSearchedLocations);

                if (!string.IsNullOrEmpty(partialViewPath))
                    return new ViewEngineResult(this.CreatePartialView(controllerContext, partialViewPath), this);
                else
                    return new ViewEngineResult(partialViewSearchedLocations);
            });
        }