private static Boolean isMatched(RouteSetting setting, String[] arrPath) { if (arrPath.Length == 0) { return(false); } if (setting.IsNamespaceIncluded()) { return(true); } if (arrPath.Length > setting.GetPathItems().Count) { return(false); } for (int i = 0; i < setting.GetPathItems().Count; i++) { if (i > arrPath.Length - 1) { break; } PathItem item = setting.GetPathItems()[i]; if (!item.isNamed() && !item.getName().Equals(arrPath[i])) { return(false); } } return(true); }
private static void addRouteInfo(String[] arrItem, RouteSetting setting) { Dictionary <String, RouteOtherInfo> dic = new Dictionary <String, RouteOtherInfo>(); for (int i = 1; i < arrItem.Length; i++) { if (strUtil.IsNullOrEmpty(arrItem[i])) { continue; } RouteOtherInfo info = RouteOtherInfo.Parse(arrItem[i]); if (info != null) { dic.Add(info.getName(), info); } } setting.setRouteOtherInfo(dic); if (dic.ContainsKey("default")) { setting.setDefaultValue(RouteOtherInfo.getDefaultValue(dic["default"])); } }
public static List <RouteSetting> ParseConfig(String configContent) { List <RouteSetting> results = new List <RouteSetting>(); if (strUtil.IsNullOrEmpty(configContent)) { return(results); } String[] arrLines = configContent.Trim().Split('\n'); foreach (String line in arrLines) { if (strUtil.IsNullOrEmpty(line)) { continue; } if (line.Trim().StartsWith("//")) { continue; } RouteSetting route = getRoute(line); results.Add(route); } return(results); }
private static RouteSetting getRoute( String line ) { String[] arrItem = line.Trim().Split( new char[] { ';' } ); String url = strUtil.TrimStart( arrItem[0], "url=>" ).Trim(); RouteSetting setting = new RouteSetting(); setting.setPath( url ); setting.SplitPath(); if ((arrItem.Length > 1) ) { addRouteInfo( arrItem, setting ); } return setting; }
private static RouteSetting getRoute(String line) { String[] arrItem = line.Trim().Split(new char[] { ';' }); String url = strUtil.TrimStart(arrItem[0], "url=>").Trim(); RouteSetting setting = new RouteSetting(); setting.setPath(url); setting.SplitPath(); if ((arrItem.Length > 1)) { addRouteInfo(arrItem, setting); } return(setting); }
private static void addRouteInfo( String[] arrItem, RouteSetting setting ) { Dictionary<String, RouteOtherInfo> dic = new Dictionary<String, RouteOtherInfo>(); for (int i = 1; i < arrItem.Length; i++) { if (strUtil.IsNullOrEmpty( arrItem[i] )) continue; RouteOtherInfo info = RouteOtherInfo.Parse( arrItem[i] ); if (info != null) dic.Add( info.getName(), info ); } setting.setRouteOtherInfo( dic ); if (dic.ContainsKey( "default" )) { setting.setDefaultValue( RouteOtherInfo.getDefaultValue( dic["default"] ) ); } }
private static Route getResult(RouteSetting setting, RouteParseInfo routeInfo) { Route result = setting.getRouteWithDefaultValue(); List <PathItem> items = setting.GetNamedItem(); for (int i = 0; i < items.Count; i++) { String[] arrValue = routeInfo.getPathArray(); if (i > arrValue.Length - 1) { break; } PathItem item = items[i]; if (item.isNamed() == false) { continue; } String val = arrValue[i]; if (strUtil.IsNullOrEmpty(val)) { continue; } // 如果条件不符合,跳过此条route if (setting.getRequirements().match(item.getName(), val) == false) { return(null); } result.setItem(item.getName(), val); } return(result); }
private static Boolean isMatched( RouteSetting setting, String[] arrPath ) { if (arrPath.Length == 0) return false; if (setting.IsNamespaceIncluded()) return true; if (arrPath.Length > setting.GetPathItems().Count) return false; for (int i = 0; i < setting.GetPathItems().Count; i++) { if (i > arrPath.Length - 1) break; PathItem item = setting.GetPathItems()[i]; if (!item.isNamed() && !item.getName().Equals( arrPath[i] )) return false; } return true; }
private static Route getResult( RouteSetting setting, RouteParseInfo routeInfo ) { Route result = setting.getRouteWithDefaultValue(); List<PathItem> items = setting.GetNamedItem(); for (int i = 0; i < items.Count; i++) { String[] arrValue = routeInfo.getPathArray(); if (i > arrValue.Length - 1) break; PathItem item = items[i]; if (item.isNamed() == false) continue; String val = arrValue[i]; if (strUtil.IsNullOrEmpty( val )) continue; // 如果条件不符合,跳过此条route if (setting.getRequirements().match( item.getName(), val ) == false) return null; result.setItem( item.getName(), val ); } return result; }
private static void processOwnerNamespaceAppId( RouteParseInfo routeInfo, RouteSetting route ) { String[] arrPathRow = routeInfo.getRowPathArray(); int count = route.GetNamedItem().Count; if (count == 0) { routeInfo.setPathArray( arrPathRow ); return; } String[] arrTemp; // 首先前面剔除掉 owner if (routeInfo.getOwnerInfo() != null) { arrTemp = new String[arrPathRow.Length - 2]; for (int i = 2; i < arrPathRow.Length; i++) { arrTemp[i - 2] = arrPathRow[i]; } } else { arrTemp = arrPathRow; } if (arrTemp.Length <= count) { routeInfo.setPathArray( arrTemp ); return; } // 然后末尾剔除掉 controller/action/id String[] arrPath = new String[count]; int x = 0; for (int i = arrTemp.Length - count; i < arrTemp.Length; i++) { arrPath[x] = arrTemp[i]; x++; } // 得到 ns StringBuilder ns = new StringBuilder(); int end = arrTemp.Length - count; for (int i = 0; i < end; i++) { if (i > 0) ns.Append( "." ); if (i == 0 && isEndsWithInt( arrTemp[i] )) { routeInfo.setAppId( strUtil.GetEndNumber( arrTemp[i] ) ); ns.Append( strUtil.TrimEnd( arrTemp[i], routeInfo.getAppId().ToString() ) ); } else ns.Append( arrTemp[i] ); } routeInfo.setPathArray( arrPath ); routeInfo.setNamespace( ns ); }
private static void processOwnerNamespaceAppId(RouteParseInfo routeInfo, RouteSetting route) { String[] arrPathRow = routeInfo.getRowPathArray(); int count = route.GetNamedItem().Count; if (count == 0) { routeInfo.setPathArray(arrPathRow); return; } String[] arrTemp; // 首先前面剔除掉 owner if (routeInfo.getOwnerInfo() != null) { arrTemp = new String[arrPathRow.Length - 2]; for (int i = 2; i < arrPathRow.Length; i++) { arrTemp[i - 2] = arrPathRow[i]; } } else { arrTemp = arrPathRow; } if (arrTemp.Length <= count) { routeInfo.setPathArray(arrTemp); return; } // 然后末尾剔除掉 controller/action/id String[] arrPath = new String[count]; int x = 0; for (int i = arrTemp.Length - count; i < arrTemp.Length; i++) { arrPath[x] = arrTemp[i]; x++; } // 得到 ns StringBuilder ns = new StringBuilder(); int end = arrTemp.Length - count; for (int i = 0; i < end; i++) { if (i > 0) { ns.Append("."); } if (i == 0 && isEndsWithInt(arrTemp[i])) { routeInfo.setAppId(strUtil.GetEndNumber(arrTemp[i])); ns.Append(strUtil.TrimEnd(arrTemp[i], routeInfo.getAppId().ToString())); } else { ns.Append(arrTemp[i]); } } routeInfo.setPathArray(arrPath); routeInfo.setNamespace(ns); }