public RoutedItemCoroutine(RouteInstance match, IControllerWrapperInstance controllerInstance, IHttpContext context, IConversionService conversionService, object model)
		{
			InstanceName = "RouteItem(" + string.Join(",", match.Parameters.Keys) + ")";
			_match = match;
			_context = context;
			_controller = controllerInstance;
			_conversionService = conversionService;
		}
Esempio n. 2
0
		//private Exception FindHttpException(Exception exception)
		//{
		//    if (exception is HttpException)
		//    {
		//        return exception;
		//    }
		//    if (exception.InnerException != null)
		//    {
		//        if (exception.InnerException is HttpException)
		//        {
		//            return exception.InnerException;
		//        }
		//        var tmpEx = FindHttpException(exception.InnerException);
		//        if (tmpEx == null) return null;
		//    }
		//    return null;
		//}

		internal IControllerWrapperInstance CreateController(RouteInstance instance)
		{
			if (!_controllers.ContainsKey(instance.Controller.Name)) return null;
			var cld = _controllers[instance.Controller.Name];
			var controller = (IController)ServiceLocator.Locator.Resolve(instance.Controller);
			if (controller == null) return null;
			return cld.CreateWrapper(controller);
		}
Esempio n. 3
0
		private RouteInstance IsValid(string[] route, RouteDefinition routeDefinition, string lower)
		{
			if (routeDefinition.IsStatic)
			{
				if (lower.StartsWith(routeDefinition.RouteString))
				{
					return new RouteInstance(true, false);
				}
			}

			if (route.Length > routeDefinition.Url.Count)
			{
				var last = routeDefinition.Url[routeDefinition.Url.Count - 1];
				if (!last.IsParameter && !last.LowerRoute.StartsWith("*", StringComparison.OrdinalIgnoreCase))
				{
					return null;
				}
			}

			var routeInstance = new RouteInstance();
			var index = -1;
			while (index < (route.Length - 1))
			{
				index++;
				
				var routeValue = route[index];
				if (index >= routeDefinition.Url.Count)
				{
					return null;
				}
				var block = routeDefinition.Url[index];
				if (block.IsParameter)
				{
					if (block.LowerRoute.StartsWith("*", StringComparison.OrdinalIgnoreCase))
					{
						var paramName = block.LowerRoute.Substring(1);
						var paramValue = "/" + string.Join("/", route, index, route.Length - index).Trim('/');
						routeInstance.Parameters.Add(paramName, paramValue);
						index = route.Length;
					}
					else
					{
						routeInstance.Parameters.Add(block.Name, routeValue);
					}
				}
				else
				{
					if (string.Compare(routeValue, block.Name, StringComparison.OrdinalIgnoreCase) != 0) return null;
				}
			}
			while (index < (routeDefinition.Url.Count - 1))
			{
				index++;
				var block = routeDefinition.Url[index];
				if (block.IsParameter)
				{
					if (routeDefinition.Parameters.ContainsKey(block.Name))
					{
						var parameter = routeDefinition.Parameters[block.Name];
						if (parameter.Optional)
						{
							if (parameter.Value != null && parameter.Value.GetType() != typeof(RoutingParameter))
							{
								routeInstance.Parameters.Add(block.Name, parameter.Value);
							}
						}
						else if (parameter.Value != null)
						{
							routeInstance.Parameters.Add(block.Name, parameter.Value);
						}
						else
						{
							return null;
						}
					}
					else
					{
						return null;
					}
				}
				else
				{
					return null;
				}

			}
			foreach (var param in routeDefinition.Parameters)
			{
				if (!routeInstance.Parameters.ContainsKey(param.Key))
				{
					var paramReal = param.Value;
					if (paramReal.Value != null && paramReal.Value.GetType() != typeof(RoutingParameter))
					{
						routeInstance.Parameters.Add(param.Key, paramReal.Value);
					}
				}
			}
			return routeInstance;
		}