Example #1
0
		public ContextManager(ContextAdapter adapter)
		{
			ctx = adapter;
			handlers.Add(new InstanceHandler());
			handlers.Add(new StaticFileHandler() {BaseFolder = "/../../../../../../QCloud/qode/src/assets", Name = "assets"});
			handlers.Add(new StaticFileHandler() {BaseFolder = "res"});
		}
Example #2
0
		public HandleResult Handle(ContextAdapter context)
		{
			var rlt = new HandleResult();
			try
			{
				Handle(context, rlt);
			}
			catch (Exception ex)
			{
				rlt.Error(ex);
			}
			return rlt;
		}
Example #3
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");
			}
		}
Example #4
0
		protected abstract void Handle(ContextAdapter context, HandleResult result);
Example #5
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);
					}
				}
			}
		}
Example #6
0
		public LhBizUnit(ContextAdapter context) : base(context) { }
Example #7
0
		public TestBizUnit(ContextAdapter context) : base(context) { }
Example #8
0
		public BizUnit(ContextAdapter context)
		{
			cx = context;
		}
Example #9
0
		public override void Execute(ContextAdapter context)
		{
			context.Response.Header("Location", Location);
			context.Response.Status(302);
		}
Example #10
0
		public abstract void Execute(ContextAdapter context);