/// <summary> /// implement for real calling to mvc /// </summary> /// <param name="query"> </param> /// <returns> </returns> protected override MvcResult InternalCall(MvcQuery query) { var ctx = new MvcContext(); var sw = new StringWriter(); ctx.Output = sw; query.Setup("http://localhost/", ctx); var handler = Container.Get <IMvcHandler>(); var result = new MvcResult(); try { handler.ProcessRequest(ctx); result.ActionResult = ctx.ActionResult; result.Content = sw.ToString(); result.ETag = ctx.Etag; result.LastModified = ctx.LastModified; result.Status = ctx.StatusCode; result.Error = ctx.Error; } catch (Exception e) { result.Error = e; } return(result); }
/// <summary> /// Make asynchronous call to Qorpent MVC /// </summary> /// <param name="query"> </param> /// <param name="callback"> </param> public void Call(MvcQuery query, Action<MvcResult> callback) { ThreadPool.QueueUserWorkItem(s => { var ac = (Asynccall) s; var result = Call(ac.Query); ac.Callback(result); }, new Asynccall {Query = query, Callback = callback}); }
/// <summary> /// Make asynchronous call to Qorpent MVC /// </summary> /// <param name="query"> </param> /// <param name="callback"> </param> public void Call(MvcQuery query, Action <MvcResult> callback) { ThreadPool.QueueUserWorkItem(s => { var ac = (Asynccall)s; var result = Call(ac.Query); ac.Callback(result); }, new Asynccall { Query = query, Callback = callback }); }
/// <summary> /// implement for real calling to mvc /// </summary> /// <param name="query"> </param> /// <returns> </returns> protected override MvcResult InternalCall(MvcQuery query) { var req = CreateWebRequest(query); if (null != Credentials) { req.Credentials = Credentials; } else { req.UseDefaultCredentials = true; } var result = new MvcResult(); try { var resp = (HttpWebResponse)req.GetResponse(); result.LastModified = resp.LastModified; var header = resp.Headers["ETag"]; if (header != null) { result.ETag = header; } result.Status = (int)resp.StatusCode; try { using (var r = resp.GetResponseStream()) { Debug.Assert(r != null, "r != null"); result.Content = new StreamReader(r).ReadToEnd(); } } catch (Exception ex) { result.Error = ex; } } catch (WebException ex) { var errorResponse = (HttpWebResponse)ex.Response; result.Status = (int)errorResponse.StatusCode; try { using (var resst = errorResponse.GetResponseStream()) { Debug.Assert(resst != null, "resst != null"); var sr = new StreamReader(resst); result.ErrorString = sr.ReadToEnd(); } } catch (Exception ex2) { result.Error = ex2; } } catch (Exception ex) { result.Error = ex; } return(result); }
/// <summary> /// Generates HTTP web request ro query /// </summary> /// <param name="query"> </param> /// <returns> </returns> protected WebRequest CreateWebRequest(MvcQuery query) { var resulturl = Url + "/" + query.Action.Replace(".", "/") + "." + query.RenderName.ToLower() + ".qweb"; if (null != query.Parameters) { var sb = new StringBuilder(); sb.Append("?"); if (query.Parameters is IDictionary <string, object> ) { foreach (var o in ((IDictionary <string, object>)query.Parameters)) { sb.Append("&"); sb.Append(Uri.EscapeUriString(o.Key)); sb.Append("="); sb.Append(Uri.EscapeUriString(o.Value.ToStr())); } } else if (query.Parameters is IDictionary <string, string> ) { foreach (var o in ((IDictionary <string, string>)query.Parameters)) { sb.Append("&"); sb.Append(Uri.EscapeUriString(o.Key)); sb.Append("="); sb.Append(Uri.EscapeUriString(o.Value)); } } else { var props = query.Parameters.GetType().GetProperties(); foreach (var p in props) { sb.Append("&"); sb.Append(Uri.EscapeUriString(p.Name)); sb.Append("="); sb.Append(Uri.EscapeUriString(p.GetValue(query.Parameters, null).ToStr())); } } resulturl += sb.ToString(); } var result = WebRequest.Create(resulturl); foreach (var header in query.Headers) { result.Headers.Add(header.Key, header.Value); } return(result); }
/// <summary> /// implement for real calling to mvc /// </summary> /// <param name="query"> </param> /// <returns> </returns> protected override MvcResult InternalCall(MvcQuery query) { var ctx = new MvcContext(); var sw = new StringWriter(); ctx.Output = sw; query.Setup("http://localhost/", ctx); var handler = Container.Get<IMvcHandler>(); var result = new MvcResult(); try { handler.ProcessRequest(ctx); result.ActionResult = ctx.ActionResult; result.Content = sw.ToString(); result.ETag = ctx.Etag; result.LastModified = ctx.LastModified; result.Status = ctx.StatusCode; result.Error = ctx.Error; } catch (Exception e) { result.Error = e; } return result; }
/// <summary> /// implement for real calling to mvc /// </summary> /// <param name="query"> </param> /// <returns> </returns> protected abstract MvcResult InternalCall(MvcQuery query);
/// <summary> /// Make synchronous call to Qorpent MVC /// </summary> /// <param name="query"> </param> /// <returns> </returns> public MvcResult Call(MvcQuery query) { lock (this) { return InternalCall(query); } }
/// <summary> /// Make synchronous call to Qorpent MVC /// </summary> /// <param name="query"> </param> /// <returns> </returns> public MvcResult Call(MvcQuery query) { lock (this) { return(InternalCall(query)); } }