Ejemplo n.º 1
0
		protected override void Handle(ContextAdapter context, HandleResult rlt)
		{
			if (!string.IsNullOrWhiteSpace(Name) &&
			    !string.Equals(context.Request.Url.Instance, Name, StringComparison.OrdinalIgnoreCase))
			{
				return;
			}
			var route = context.Request.Url.Route;
			if (!string.IsNullOrWhiteSpace(Name))
			{
				route = route.Replace(Name, string.Empty);
			}
			//var path = route.PathMap(AppDomain.CurrentDomain.BaseDirectory + "res");
			var path = route.PathMap(BaseFolder.PathAbs());

			var ext = path.PathExt();
			var dtype = Dobj.Get<string>(settings.Instance.mime, "*");
			var etype = Dobj.Get<string>(settings.Instance.mime, ext);
			if (!string.IsNullOrWhiteSpace(etype))
			{
				context.Response.Type(etype);
			}
			else
			{
				context.Response.Type(dtype);
			}

			if (File.Exists(path))
			{
				var s = File.Open(path, FileMode.Open);
				context.Response.Write(s);
				rlt.Set(true);
			}
			else
			{
				context.Response.Type("text/html");
			}
		}
Ejemplo n.º 2
0
		protected override void Handle(ContextAdapter context, HandleResult rlt)
		{
			var iname = context.Request.Url.Instance;
			var aname = context.Request.Url.Action;

			var typename = Dobj.Get<string>(settings.Instance.mapping, iname);
			if (typename != null)
			{
				var o = ReflectionExtensions.CreateInstance(typename, null, context);
				if (o != null)
				{
					try
					{
						context.Response.Type("text/html");
						var result = (o is BizUnit)
							? ((BizUnit) o).Execute(aname, context.Request.Url.RouteArgs)
							: ReflectionExtensions.Invoke(o.GetType(), aname, o, context.Request.Url.RouteArgs);
						if (result == null)
						{
							// Do nothing (void);
						}
						else if (result is ActionStep)
						{
							var ar = (ActionStep) result;
							ar.Execute(context);
						}
						else if (result is Stream)
						{
							context.Response.Write((Stream) result);
						}
						else
						{
							context.Response.Write(result.ToString());
						}
						rlt.Set(true);
					}
					catch (Exception ex)
					{
						context.Response.Status(403);
						context.Response.Type("text/html");
						log.e(ex);
					}
				}
			}
		}