public virtual string GetInternalView(ILiaraContext context) { var code = context.Response.Status.Code; var fileName = code.ToString(); switch (code) { case 400: case 404: case 500: break; default: if (code > 400 && code < 500) { fileName = "40x"; } else if (code > 500 && code < 600) { fileName = "50x"; } else { fileName = "Error"; } break; } return GetInternalViewResource(fileName); }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Request.Info.Path.StartsWith("/parallel")) { // Run all three handlers in parallel. var t1 = new ParallelHandler1().ProcessAsync(context); var t2 = new ParallelHandler2().ProcessAsync(context); var t3 = new ParallelHandler3().ProcessAsync(context); // Optionally, continue with other handlers in chain. // or add the next line to the end of the function to do that only when the parallel process is complete. // base.ProcessAsync(content); // When everything is complete, do these. // PS: It is async, doesn't block. await Task.WhenAll(new[] {t1, t2, t3}); // All parallel stuff done. Now, do something with results. // Note: It is by design that message handlers don't return values. Its just supposed to handle // the messages. Not report back. So, here, the parallel handlers are writing directly to the // stream. Or, the orderly result composition will take place here, which has been shown // on the next Handler. } else { await base.ProcessAsync(context); } }
public override Task ProcessAsync(ILiaraContext context) { context.Response.WriteAsync("Hello!\r\n"); context.Response.WriteAsync(context.Request.Info.Uri.ToString()); return base.ProcessAsync(context); }
public override Task<object> ReadAsync(Type readAsType, Stream inputStream, ILiaraContext context) { // TODO: Model binding when RequestModel is explicit. var text = new StreamReader(inputStream).ReadToEnd(); var collection = ParseForm(text, isCaseSensitive: true); return Task.FromResult((object) collection); }
public override Task ProcessAsync(ILiaraContext context) { var map = context.Engine.Configuration.Routes; var reqPath = context.Request.Info.Path; IDictionary<string, Route[]> routeList; if (map.TryGetValue(reqPath.TrimEnd('/'), out routeList)) { Route[] routes; if (routeList.TryGetValue(context.Request.Info.Method, out routes)) { context.Route = routes[0]; } else { context.Response.Status = LiaraHttpStatus.MethodNotAllowed; return TaskHelpers.Completed(); } } else { context.Response.Status = LiaraHttpStatus.NotFound; return TaskHelpers.Completed(); } return base.ProcessAsync(context); }
public override async Task ProcessAsync(ILiaraContext context) { try { switch (context.Route.ActionReturnType) { case LiaraActionReturnType.Void: ((Action<ILiaraContext>) context.Route.Action)(context); break; case LiaraActionReturnType.Generic: context.Response.Content = ((Func<ILiaraContext, object>) context.Route.Action)(context); break; case LiaraActionReturnType.Task: context.Response.Content = await ((Func<ILiaraContext, Task<object>>) context.Route.Action)(context); break; } } catch (Exception ex) { context.Response.Status = LiaraHttpStatus.InternalServerError; context.Response.Content = ex; } }
public override Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context) { // TODO: Optimize memory - Streamed conversion. var objType = inputObject.GetType(); var value = JsonConvert.SerializeObject(inputObject, objType, settings); var bytes = context.Response.Format.CharsetEncoding.GetBytes(value); return targetStream.WriteAsync(bytes, 0, bytes.Length); }
public override async Task ProcessAsync(ILiaraContext context) { await Task.Delay(3000); await context.Response.WriteAsync( String.Format("in parallel, and un-ordered. :( \r\nSlowest method time: {0} seconds.\r\n", 4)); await context.Response.WriteAsync("I'm better suited for things where order doesn't matter. \r\n"); }
public virtual void PrepareWrite(ILiaraContext context) { var mediaType = context.Response.Format.MediaType; context.Response.Headers.ContentType.Value = mediaType + (mediaType != null ? ";" : null) + "charset=" + context.Response.Format.CharsetEncoding.WebName; }
public override async Task ProcessAsync(ILiaraContext context) { var stopwatch = new Stopwatch(); WriteEnvironment(context, false); stopwatch.Start(); await base.ProcessAsync(context); stopwatch.Stop(); WriteEnvironment(context, true, stopwatch.Elapsed); }
public override async Task ProcessAsync(ILiaraContext context) { // Anything put into content will be serialized into the stream, using the Formatter, // which is in-turn automatically selected using the FormatSelector. var t = new TestType {Message = "Hello!", RequestPath = context.Request.Info.Uri.ToString()}; context.Response.Content = t; await base.ProcessAsync(context); }
public virtual void PrepareWrite(ILiaraContext context) { var mediaType = context.Response.Format.MediaType; context.Response.Headers.ContentType.Value = mediaType + (mediaType != null ? ";" : null) + "charset=" + context.Response.Format.CharsetEncoding.WebName; }
public virtual ILiaraViewTemplate ResolveInternalView(ILiaraContext context) { if (context.Response.Status.Code != LiaraHttpStatus.OK.Code) { var viewName = "_liara_" + context.Response.Status.Code; var templateString = ViewProvider.GetInternalView(context); return new LiaraViewTemplate(viewName, templateString, true); } return null; }
public virtual ILiaraViewTemplate ResolveInternalView(ILiaraContext context) { if (context.Response.Status.Code != LiaraHttpStatus.OK.Code) { var viewName = "_liara_" + context.Response.Status.Code; var templateString = ViewProvider.GetInternalView(context); return(new LiaraViewTemplate(viewName, templateString, true)); } return(null); }
public virtual void SetContentAsErrorMessage(ILiaraContext context) { if (context.Response.Content == null || context.Response.Content.GetType() != typeof(ErrorMessage)) context.Response.Content = new ErrorMessage { ErrorCode = context.Response.Status.Code, Description = context.Response.Status.Description, Message = context.Response.Content }; }
public override async Task ProcessAsync(ILiaraContext context) { await Task.Delay(3000); await context.Response.WriteAsync( String.Format("in parallel, and un-ordered. :( \r\nSlowest method time: {0} seconds.\r\n", 4)); await context.Response.WriteAsync("I'm better suited for things where order doesn't matter. \r\n"); }
public override async Task ProcessAsync(ILiaraContext context) { var stopwatch = new Stopwatch(); WriteEnvironment(context, false); stopwatch.Start(); await base.ProcessAsync(context); stopwatch.Stop(); WriteEnvironment(context, true, stopwatch.Elapsed); }
public override async Task ProcessAsync(ILiaraContext context) { // Anything put into content will be serialized into the stream, using the Formatter, // which is in-turn automatically selected using the FormatSelector. var t = new TestType { Message = "Hello!", RequestPath = context.Request.Info.Uri.ToString() }; context.Response.Content = t; await base.ProcessAsync(context); }
public override async Task ProcessAsync(ILiaraContext context) { try { await base.ProcessAsync(context); } catch (Exception exception) { context.Response.Status = LiaraHttpStatus.InternalServerError; // Log asynchronously, and don't wait for completion. var task = context.Log.WriteExceptionAsync(exception); } }
public LiaraRequestParameters(ILiaraContext context) { this.context = context; if (context.Route.RequestModel != null) { isRequestContentAvailable = isRequestContentAvailabilitySet = true; internalContentType = ContentDeterminationType.Property; } else { internalContentType = ContentDeterminationType.Unknown; } }
public override async Task ProcessAsync(ILiaraContext context) { try { await base.ProcessAsync(context); } catch (Exception exception) { context.Response.Status = LiaraHttpStatus.InternalServerError; // Log asynchronously, and don't wait for completion. var task = context.Log.WriteExceptionAsync(exception); } }
public virtual void SetContentAsErrorMessage(ILiaraContext context) { if (context.Response.Content == null || context.Response.Content.GetType() != typeof(ErrorMessage)) { context.Response.Content = new ErrorMessage { ErrorCode = context.Response.Status.Code, Description = context.Response.Status.Description, Message = context.Response.Content } } ; } }
public virtual bool HandleStatus(ILiaraContext context) { switch (context.Response.Status.Code) { case 200: { return true; } default: { SetContentAsErrorMessage(context); return true; } } }
public override Task <object> ReadAsync(Type readAsType, Stream inputStream, ILiaraContext context) { var output = JObject.Parse( new StreamReader(inputStream, context.Request.Format.CharsetEncoding, false, 4096, true).ReadToEnd()); if (readAsType == typeof(object)) { object res = output; return(Task.FromResult(res)); } return(Task.FromResult(output.ToObject(readAsType))); }
public virtual bool HandleStatus(ILiaraContext context) { switch (context.Response.Status.Code) { case 200: { return(true); } default: { SetContentAsErrorMessage(context); return(true); } } }
public override Task<object> ReadAsync(Type readAsType, Stream inputStream, ILiaraContext context) { var output = JObject.Parse( new StreamReader(inputStream, context.Request.Format.CharsetEncoding, false, 4096, true).ReadToEnd()); if (readAsType == typeof (object)) { object res = output; return Task.FromResult(res); } return Task.FromResult(output.ToObject(readAsType)); }
public override ILiaraViewTemplate ResolveInternalView(ILiaraContext context) { if (context.Response.Status.Code != LiaraHttpStatus.OK.Code) { var viewName = "_liara_" + context.Response.Status.Code; var result = new LiaraViewTemplate(viewName, null, true); if (service.HasTemplate(viewName)) { return(result); } var templateString = ViewProvider.GetInternalView(context); service.GetTemplate(templateString, new ErrorMessage(), viewName); return(result); } return(null); }
public override async Task ProcessAsync(ILiaraContext context) { await base.ProcessAsync(context); // Use the response synchronization before writing to the stream. // Note: Make sure response synchronize is called at the end, in a case where this message handler is removed // from the chain, or replaced. context.Response.Synchronize(); if (context.Response.Content != null && context.Response.Format.Formatter != null) { await context.Response.Format.ProcessAsync( context.Response.Content, context.Environment.ResponseBody); } }
public override async Task ProcessAsync(ILiaraContext context) { await base.ProcessAsync(context); // Use the response synchronization before writing to the stream. // Note: Make sure response synchronize is called at the end, in a case where this message handler is removed // from the chain, or replaced. context.Response.Synchronize(); if (context.Response.Content != null && context.Response.Format.Formatter != null) { await context.Response.Format.ProcessAsync( context.Response.Content, context.Environment.ResponseBody); } }
public void WriteEnvironment(ILiaraContext context, bool responseOutStage, TimeSpan?timeTaken = null) { var sb = new StringBuilder(); var separator = new string('-', 20); sb.AppendLine(separator); sb.AppendLine(); sb.AppendLine(responseOutStage ? "Response Out - Environment Items:" : "Request In - Environment Items:"); sb.AppendLine(); if (responseOutStage) { sb.AppendLine(); sb.AppendLine(string.Format("Time taken for request: {0}", timeTaken)); sb.AppendLine(); } foreach (var prop in context.Environment.GetType().GetProperties()) { sb.Append(prop.Name + " : "); var value = prop.GetValue(context.Environment); if (value != null && value.GetType() == typeof(LiaraStringHashTable)) { sb.AppendLine(); sb.AppendLine(); var hashTable = (LiaraStringHashTable)value; foreach (var items in hashTable) { sb.AppendLine(items.Key + " : " + hashTable.Get(items.Key)); } sb.AppendLine(); } else if (value != null) { sb.AppendLine(value.ToString()); } else { sb.AppendLine(); } } sb.AppendLine(); sb.AppendLine(separator); context.Trace.WriteToAsync("Request Tracing", sb.ToString()); }
public virtual ILiaraViewTemplate ResolveView(ILiaraContext context) { var templateString = ViewProvider.GetView(context); if (templateString == null) { context.Response.Status = LiaraHttpStatus.NoViewAssociated; return ResolveInternalView(context); } var viewName = context.Response.Format.View; if (viewName == null) { if (context.Route != null) { viewName = context.Route.Id.ToString(); } } return new LiaraViewTemplate(viewName, templateString); }
public void WriteEnvironment(ILiaraContext context, bool responseOutStage, TimeSpan? timeTaken = null) { var sb = new StringBuilder(); var separator = new string('-', 20); sb.AppendLine(separator); sb.AppendLine(); sb.AppendLine(responseOutStage ? "Response Out - Environment Items:" : "Request In - Environment Items:"); sb.AppendLine(); if (responseOutStage) { sb.AppendLine(); sb.AppendLine(string.Format("Time taken for request: {0}", timeTaken)); sb.AppendLine(); } foreach (var prop in context.Environment.GetType().GetProperties()) { sb.Append(prop.Name + " : "); var value = prop.GetValue(context.Environment); if (value != null && value.GetType() == typeof (LiaraStringHashTable)) { sb.AppendLine(); sb.AppendLine(); var hashTable = (LiaraStringHashTable) value; foreach (var items in hashTable) { sb.AppendLine(items.Key + " : " + hashTable.Get(items.Key)); } sb.AppendLine(); } else if (value != null) { sb.AppendLine(value.ToString()); } else { sb.AppendLine(); } } sb.AppendLine(); sb.AppendLine(separator); context.Trace.WriteToAsync("Request Tracing", sb.ToString()); }
public virtual ILiaraFormatter GetRequestFormatter(Type readAsType, ILiaraContext context) { ILiaraFormatter[] formatterArray; if (context.Engine.Configuration.Formatters.MediaMap.TryGetValue( context.Request.Format.MediaType.ToString().ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanRead(readAsType, context)) return liaraFormatter; } } return context.Engine.Configuration.Formatters.FirstOrDefault( formatter => formatter.CanRead(readAsType, context)); }
public override async Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context) { var template = ResolveInternalView(context) ?? ResolveView(context); if (template.IsInternalTemplate) { if (inputObject.GetType() != typeof (ErrorMessage)) { inputObject = new ErrorMessage { ErrorCode = context.Response.Status.Code, Description = context.Response.Status.Description, Message = inputObject }; } } var viewOutput = await RenderView(template, inputObject, context); var buf = context.Response.Format.CharsetEncoding.GetBytes(viewOutput); await targetStream.WriteAsync(buf, 0, buf.Length); }
public override Task ProcessAsync(ILiaraContext context) { var res = context.Engine.Configuration.AuthenticationHandler.Authenticate(context); if (res) { if (Claims != null) { foreach (var claim in Claims) { var exists = context.Security.Claims.ContainsKey(claim[0]); if (exists) { if (claim.Length > 1) { if (!context.Security.Claims[claim[0]].Contains(claim[1])) { res = false; break; } } else { continue; } } res = false; break; } } } if (res) { context.Security.IsAuthenticated = true; return base.ProcessAsync(context); } context.Response.Status = LiaraHttpStatus.Unauthorized; return TaskHelpers.Completed(); }
public override Task ProcessAsync(ILiaraContext context) { var res = context.Engine.Configuration.AuthenticationHandler.Authenticate(context); if (res) { if (Claims != null) { foreach (var claim in Claims) { var exists = context.Security.Claims.ContainsKey(claim[0]); if (exists) { if (claim.Length > 1) { if (!context.Security.Claims[claim[0]].Contains(claim[1])) { res = false; break; } } else { continue; } } res = false; break; } } } if (res) { context.Security.IsAuthenticated = true; return(base.ProcessAsync(context)); } context.Response.Status = LiaraHttpStatus.Unauthorized; return(TaskHelpers.Completed()); }
public virtual ILiaraViewTemplate ResolveView(ILiaraContext context) { var templateString = ViewProvider.GetView(context); if (templateString == null) { context.Response.Status = LiaraHttpStatus.NoViewAssociated; return(ResolveInternalView(context)); } var viewName = context.Response.Format.View; if (viewName == null) { if (context.Route != null) { viewName = context.Route.Id.ToString(); } } return(new LiaraViewTemplate(viewName, templateString)); }
public override Task ProcessAsync(ILiaraContext context) { lock (syncRoot) { while (requestsInProgress >= MaxConcurrentRequests) { context.Log.WriteAsync("Max. concurrency level reached."); context.Log.WriteAsync("Active Requests: " + requestsInProgress); Monitor.Wait(syncRoot); } Interlocked.Increment(ref requestsInProgress); } var res = base.ProcessAsync(context); lock (syncRoot) { Interlocked.Decrement(ref requestsInProgress); Monitor.Pulse(syncRoot); } return res; }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Request.Info.Path.StartsWith("/parallel/ordered")) { var t1 = Task.Run(() => ParallelLambdas.Process1()); var t2 = Task.Run(() => ParallelLambdas.Process2()); var t3 = Task.Run(() => ParallelLambdas.Process3()); var t4 = Task.Run(() => ParallelLambdas.Process4()); await Task.WhenAll(new[] {t1, t2, t3, t4}); new[] {t1.Result, t2.Result, t3.Result, t4.Result}.ToList() .ForEach(async text => await context.Response.WriteAsync(text)); } else { await base.ProcessAsync(context); } }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Request.Info.Path.StartsWith("/parallel/ordered")) { var t1 = Task.Run(() => ParallelLambdas.Process1()); var t2 = Task.Run(() => ParallelLambdas.Process2()); var t3 = Task.Run(() => ParallelLambdas.Process3()); var t4 = Task.Run(() => ParallelLambdas.Process4()); await Task.WhenAll(new[] { t1, t2, t3, t4 }); new[] { t1.Result, t2.Result, t3.Result, t4.Result }.ToList() .ForEach(async text => await context.Response.WriteAsync(text)); } else { await base.ProcessAsync(context); } }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Environment.RequestBody != null) { var stream = (Stream) context.Environment.RequestBody; if (context.Request.Format.Formatter != null) { context.Request.Content = await context.Request.Format.ProcessAsync( context.Route.RequestModel ?? typeof (object), stream); if (context.Response.Status.Code == LiaraHttpStatus.BadRequest.Code || context.Response.Status.Code == LiaraHttpStatus.NotAcceptable.Code) { return; } } } await base.ProcessAsync(context); }
public virtual ILiaraFormatter GetResponseFormatter(Type inputObjectType, ILiaraContext context) { ILiaraFormatter[] formatterArray; if (context.Route != null && context.Route.PathExtension != null) { if (context.Engine.Configuration.Formatters.UrlMap.TryGetValue( context.Route.PathExtension.ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanWrite(inputObjectType, context)) { context.Response.Format.MediaType = liaraFormatter.GetDefaultMediaType(); return(liaraFormatter); } } } } foreach (var acceptedMediaType in context.Response.Format.AcceptedMediaTypes) { if (context.Engine.Configuration.Formatters.MediaMap.TryGetValue( MediaType.FromDerivedMediaType(acceptedMediaType).ToString().ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanWrite(inputObjectType, context)) { context.Response.Format.MediaType = acceptedMediaType; return(liaraFormatter); } } } } return (context.Engine.Configuration.Formatters.FirstOrDefault( formatter => formatter.CanWrite(inputObjectType, context))); }
public virtual ILiaraFormatter GetResponseFormatter(Type inputObjectType, ILiaraContext context) { ILiaraFormatter[] formatterArray; if (context.Route != null && context.Route.PathExtension != null) { if (context.Engine.Configuration.Formatters.UrlMap.TryGetValue( context.Route.PathExtension.ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanWrite(inputObjectType, context)) { context.Response.Format.MediaType = liaraFormatter.GetDefaultMediaType(); return liaraFormatter; } } } } foreach (var acceptedMediaType in context.Response.Format.AcceptedMediaTypes) { if (context.Engine.Configuration.Formatters.MediaMap.TryGetValue( MediaType.FromDerivedMediaType(acceptedMediaType).ToString().ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanWrite(inputObjectType, context)) { context.Response.Format.MediaType = acceptedMediaType; return liaraFormatter; } } } } return context.Engine.Configuration.Formatters.FirstOrDefault( formatter => formatter.CanWrite(inputObjectType, context)); }
public override Task ProcessAsync(ILiaraContext context) { lock (syncRoot) { while (requestsInProgress >= MaxConcurrentRequests) { context.Log.WriteAsync("Max. concurrency level reached."); context.Log.WriteAsync("Active Requests: " + requestsInProgress); Monitor.Wait(syncRoot); } Interlocked.Increment(ref requestsInProgress); } var res = base.ProcessAsync(context); lock (syncRoot) { Interlocked.Decrement(ref requestsInProgress); Monitor.Pulse(syncRoot); } return(res); }
public virtual ILiaraFormatter GetRequestFormatter(Type readAsType, ILiaraContext context) { ILiaraFormatter[] formatterArray; if (context.Engine.Configuration.Formatters.MediaMap.TryGetValue( context.Request.Format.MediaType.ToString().ToLower(), out formatterArray)) { foreach (var liaraFormatter in formatterArray) { if (liaraFormatter.CanRead(readAsType, context)) { return(liaraFormatter); } } } return (context.Engine.Configuration.Formatters.FirstOrDefault( formatter => formatter.CanRead(readAsType, context))); }
public override async Task ProcessAsync(ILiaraContext context) { if (context.Environment.RequestBody != null) { var stream = (Stream)context.Environment.RequestBody; if (context.Request.Format.Formatter != null) { context.Request.Content = await context.Request.Format.ProcessAsync( context.Route.RequestModel ?? typeof(object), stream); if (context.Response.Status.Code == LiaraHttpStatus.BadRequest.Code || context.Response.Status.Code == LiaraHttpStatus.NotAcceptable.Code) { return; } } } await base.ProcessAsync(context); }
public override async Task ProcessAsync(ILiaraContext context) { var requestStream = (LiaraStream) context.Request.Content; if (requestStream != null && requestStream.IsBuffered) { await requestStream.BufferFillTask; } await base.ProcessAsync(context); var responseStream = context.Environment.ResponseBody; if (responseStream.IsBuffered) { responseStream.Seek(0, SeekOrigin.Begin); if (!responseStream.IsBufferFilled) { await responseStream.BufferFillTask; } await responseStream.CopyToAsync(context.Environment.ResponseBody); } }
public override Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context) { var type = inputObject.GetType(); if (!ReflectionHelpers.IsTypeAnonymous(type)) { var xmlWriter = new XmlSerializer(type); xmlWriter.Serialize(targetStream, inputObject); } else { var status = context.Response.Status = LiaraHttpStatus.NotAcceptable; var error = new ErrorMessage { Description = status.Description, ErrorCode = status.Code, Message = inputObject.ToString() }; var xmlWriter = new XmlSerializer(typeof (ErrorMessage)); xmlWriter.Serialize(targetStream, error); } return TaskHelpers.Completed(); }
public override async Task ProcessAsync(ILiaraContext context) { var requestStream = (LiaraStream)context.Request.Content; if (requestStream != null && requestStream.IsBuffered) { await requestStream.BufferFillTask; } await base.ProcessAsync(context); var responseStream = context.Environment.ResponseBody; if (responseStream.IsBuffered) { responseStream.Seek(0, SeekOrigin.Begin); if (!responseStream.IsBufferFilled) { await responseStream.BufferFillTask; } await responseStream.CopyToAsync(context.Environment.ResponseBody); } }
public override Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context) { var type = inputObject.GetType(); if (!ReflectionHelpers.IsTypeAnonymous(type)) { var xmlWriter = new XmlSerializer(type); xmlWriter.Serialize(targetStream, inputObject); } else { var status = context.Response.Status = LiaraHttpStatus.NotAcceptable; var error = new ErrorMessage { Description = status.Description, ErrorCode = status.Code, Message = inputObject.ToString() }; var xmlWriter = new XmlSerializer(typeof(ErrorMessage)); xmlWriter.Serialize(targetStream, error); } return(TaskHelpers.Completed()); }
public void PrepareWrite(ILiaraContext context) { }
public bool CanWrite(Type inputObjectType, ILiaraContext context) { return(true); }
public bool CanRead(Type readAsType, ILiaraContext context) { return(false); }
public string GetView(ILiaraContext context) { var viewName = context.Response.Format.View; var route = context.Route; foreach (var viewLocation in ViewLocations) { foreach (var viewFileExtension in ViewFileExtensions) { var paths = new List<string>(); if (viewName == null) { var routePath = route.Path.Trim('/'); // Look for ViewPath\UrlPath{ext} paths.Add(Path.Combine(viewLocation, routePath + viewFileExtension)); // Look for ViewPath\UrlPath\{DefaultFiles}{ext} foreach (var viewDefaultFile in ViewDefaultFiles) { paths.Add(Path.Combine(viewLocation, routePath, viewDefaultFile + viewFileExtension)); } // Look for ViewPath\ModuleName\MethodName{ext} paths.Add(Path.Combine(viewLocation, route.MethodInfo.DeclaringType.Name, route.MethodInfo.Name + viewFileExtension)); // Look for ViewPath\ModuleName\ReturnTypeName{ext} // If its a generic type seperate it by '-' if (route.ActionReturnType == LiaraActionReturnType.Task) { paths.Add(Path.Combine(viewLocation, route.MethodInfo.DeclaringType.Name, string.Join("-", route.MethodInfo.ReturnType.GetGenericArguments().Select(x => x.FullName)) + viewFileExtension)); } else { paths.Add(Path.Combine(viewLocation, route.MethodInfo.DeclaringType.Name, route.MethodInfo.ReturnType.Name + viewFileExtension)); } } else { paths.Add(Path.Combine(viewLocation, viewName + viewFileExtension)); } foreach (var path in paths) { context.Trace.WriteToAsync("Views Searched", "{0} : {1}", context.Request.Info.Path, path); if (File.Exists(path)) return File.ReadAllText(path); } } } context.Trace.WriteToAsync("Unresolved Views", String.Format("View not found for {0} in method: {1}", context.Request.Info.Path, route != null ? route.MethodInfo.DeclaringType.FullName + "->" + route.MethodInfo.Name : "{Unresolved}")); return null; }
public override Task ProcessAsync(ILiaraContext context) { return(context.Route.Handlers.Execute(context)); }
public LiaraRequestHeaderCollection(ILiaraContext context) : base(context.Environment.RequestHeaders) { }
public void Synchronize(ILiaraContext context) { context.Response.Cookies.FlushToHeaders(); }
public Task <object> ReadAsync(Type readAsType, Stream inputStream, ILiaraContext context) { return(null); }
public Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context) { var bytes = context.Response.Format.CharsetEncoding.GetBytes(inputObject.ToString()); return(targetStream.WriteAsync(bytes, 0, bytes.Length)); }
public void Synchronize(ILiaraContext context) { }