Пример #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);
        }
Пример #2
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);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="controllerContext">Current Controller Context</param>
        /// <param name="locationFormats">View location format or master location format</param>
        /// <param name="areaLocationFormats">Area view location format or area master location format</param>
        /// <param name="locationFormatsPropertyName">location format name as return argument in information</param>
        /// <param name="viewName">Target View Name which is be finding</param>
        /// <param name="controllerName">Current Controller Name</param>
        /// <param name="theme">Target Theme Name which is be finding</param>
        /// <param name="cacheKeyPrefix">Prefix for parts of cache key name</param>
        /// <param name="useCache">If using cache</param>
        /// <param name="workType">Current Work Type (PC or mobile)</param>
        /// <param name="searchedLocations">Get the locations have been searched where don't have view pages</param>
        /// <returns>The path of target view</returns>
        protected virtual string GetPath(
            ControllerContext controllerContext, 
            string[] locationFormats, 
            string[] areaLocationFormats, 
            string locationFormatsPropertyName, 
            string viewName, 
            string controllerName, 
            string theme, 
            string cacheKeyPrefix, 
            bool useCache, 
            WorkType workType, 
            out string[] searchedLocations)
        {
            searchedLocations = null; // initialize searched locations

            // if view name is empty, return empty
            if (string.IsNullOrEmpty(viewName))
                return string.Empty;

            // get current area name
            string areaName = controllerContext.GetAreaName();

            // handle admin area
            if (!string.IsNullOrEmpty(areaName) && areaName.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
            {
                // don't support mobile for admin
                if (workType == WorkType.Mobile)
                {
                    searchedLocations = new string[0]; // empty because program doesn't search any location
                    return string.Empty;
                }

                var formats = areaLocationFormats.ToList();
                formats.InsertRange(0, LocationSettings.AdminLocationFormat); // make sure admin location is the default searching location
                areaLocationFormats = formats.ToArray();
            }

            var viewLocations = GetViewLocations(locationFormats, !string.IsNullOrEmpty(areaName) ? areaLocationFormats : null); // pass location format and area location format (if area is not in url, pass null)
            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty.", new object[] { locationFormatsPropertyName }));
            }

            string keyName = this.CreateCacheKey(
                cacheKeyPrefix,
                viewName,
                this.CheckIfRelativePath(viewName) ? string.Empty : controllerName,  // if the view name includes controller name, will not pass controller name
                areaName,
                theme);

            if (useCache)
            {
                // use API to cache view location
                var cachedLocation = this.ViewLocationCache.GetViewLocation(controllerContext.HttpContext, keyName);
                if (null != cachedLocation)
                    return cachedLocation; // if location has been cached, return;
            }

            // if useCache is false and view location hasn't been cached.
            // No matter whether the useCache is true or not, location always inserts into cache
            // the view name doesn't includes path
            if (!this.CheckIfRelativePath(viewName))
            {
                return this.GetPathFromGeneralName(controllerContext, viewLocations, viewName, controllerName, areaName, theme, keyName, ref searchedLocations);
            }
            else
            {
                return this.GetPathFromSpecificName(controllerContext, viewName, keyName, ref searchedLocations);
            }
        }