Example #1
0
 public IRoutingManager Add(string routeName, string routeUrl, string url, bool checkPhysicalUrlAccess, List <RoutingDictonaryInfo> defaults, List <RoutingDictonaryInfo> constraints, List <RoutingDictonaryInfo> dataTokens)
 {
     if (RoutingInfoList.Any(p => p.routeName == routeName))
     {
         if (Log != null)
         {
             Log.LogFormat(LoggerLevels.Warn, "Route已存在。 routeName:{0} routeUrl:{1} url:{2} by:{3}", routeName, routeUrl, url, StackHelper.GetCallingType().FullName);
         }
         return(this);
     }
     if (Log != null)
     {
         Log.LogFormat(LoggerLevels.Info, "AddRoute routeName:{0} routeUrl:{1} url:{2} by:{3}", routeName, routeUrl, url, StackHelper.GetCallingType().FullName);
     }
     #region 填充路由键值
     RouteValueDictionary defaultsRouteValueDictionary = null;
     if (defaults != null)
     {
         defaultsRouteValueDictionary = new RouteValueDictionary();
         defaults.Each(p => { defaultsRouteValueDictionary.Add(p.Key, p.Value); });
     }
     RouteValueDictionary constraintsRouteValueDictionary = null;
     if (constraints != null)
     {
         constraintsRouteValueDictionary = new RouteValueDictionary();
         constraints.Each(p => { constraintsRouteValueDictionary.Add(p.Key, p.Value); });
     }
     RouteValueDictionary dataTokensRouteValueDictionary = null;
     if (dataTokens != null)
     {
         dataTokensRouteValueDictionary = new RouteValueDictionary();
         dataTokens.Each(p => { dataTokensRouteValueDictionary.Add(p.Key, p.Value); });
     }
     #endregion
     RouteTable.Routes.MapPageRoute(routeName, routeUrl, url, checkPhysicalUrlAccess, defaultsRouteValueDictionary, constraintsRouteValueDictionary, dataTokensRouteValueDictionary);
     return(this);
 }
Example #2
0
        public IRoutingManager Add <T>(string routeName, string url) where T : IWebHandler
        {
            var fullName = typeof(T).FullName;
            var handler  = GlobalApplicationObject.Current.ApplicationContext.WebHandlerList.FirstOrDefault(p => p.FullName == fullName);

            if (handler == null)
            {
                Log.LogFormat(LoggerLevels.Error, "Handler不存在。 routeName:{0} url:{1} WebHandler:{2} by:{3}", routeName, url, fullName, StackHelper.GetCallingType().FullName);
            }
            else if (handler != null && !RouteWebHandlerInfoList.Any(p => p.routeName == routeName))
            {
                var routeWebHandlerInfo = new RouteWebHandlerInfo()
                {
                    routeName      = routeName,
                    routeUrl       = url,
                    WebHandlerInfo = handler
                };
                RouteWebHandlerInfoList.Add(routeWebHandlerInfo);
                Log.LogFormat(LoggerLevels.Info, "AddRoute routeName:{0} url:{1} WebHandler:{2} by:{3}", routeName, url, fullName, StackHelper.GetCallingType().FullName);
            }
            else
            {
                Log.LogFormat(LoggerLevels.Warn, "Route已存在。 routeName:{0} url:{1} WebHandler:{2} by:{3}", routeName, url, fullName, StackHelper.GetCallingType().FullName);
            }
            return(this);
        }