public static String ProcessRequest(String url, String search, String postData) { var controller = new BaseController(); if (url.StartsWith("admin/")) { url = url.Substring(6); controller.Admin = true; } try { using (var writer = new StringWriter()) { if (url.StartsWith("_page/")) { Render(controller, RequestUrlKind.Page, url.Substring(6), search, writer); } else if (url.StartsWith("_dialog/")) { Render(controller, RequestUrlKind.Dialog, url.Substring(8), search, writer); } else if (url.StartsWith("_popup/")) { Render(controller, RequestUrlKind.Popup, url.Substring(7), search, writer); } else if (url.StartsWith("_data/")) { var command = url.Substring(6); controller.Data(command, null /*tenantId, userId*/, postData, null /**/).Wait(); } else if (url.StartsWith("_image/")) { controller.Attachment("/" + url, null /*setParams*/).Wait(); // with _image prefix } else { // TODO: exception writer.Write($"<div>page '{url}' not found.</div>"); } return(writer.ToString()); } } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } // TODO:: /exception return($"<div>{ex.Message}</div>"); } }
Byte[] ProcessRequestImpl(String url, String search, Byte[] post, Boolean postMethod) { if (url.StartsWith("admin/")) { url = url.Substring(6); _controller.Admin = true; } _controller.Host.StartApplication(_controller.Admin); try { MimeType = MIME_HTML; using (var dr = new DesktopResponse()) { if (String.IsNullOrEmpty(url)) { RenderIndex(dr.Output); } else if (url.StartsWith("shell/")) { Shell(url.Substring(6).ToLowerInvariant(), dr.Output, out String shellMime); MimeType = shellMime; } else if (url.StartsWith("_page/")) { Render(RequestUrlKind.Page, url.Substring(6), search, dr.Output); } else if (url.StartsWith("_dialog/")) { Render(RequestUrlKind.Dialog, url.Substring(8), search, dr.Output); } else if (url.StartsWith("_popup/")) { Render(RequestUrlKind.Popup, url.Substring(7), search, dr.Output); } else if (url.StartsWith("_data/")) { var command = url.Substring(6); dr.ContentType = "application/json"; String jsonData = Encoding.UTF8.GetString(post); _controller.Data(command, SetSqlParams, jsonData, dr).Wait(); MimeType = dr.ContentType; if (dr.IsBinaryWrited) { return(dr.GetBytes()); } } else if (url.StartsWith("_image/")) { if (postMethod) { SaveImage("/" + url, dr.Output); } else { var bytes = LoadImage("/" + url, dr); MimeType = dr.ContentType; return(bytes); } } else if (url.StartsWith("_static_image/")) { var bytes = StaticImage(url.Substring(14).Replace('-', '.'), dr); MimeType = dr.ContentType; return(bytes); } else if (url.StartsWith("_export/")) { Export("/" + url, search, dr); MimeType = dr.ContentType; ContentDisposition = dr.Headers["Content-Disposition"]; return(dr.GetBytes()); } else { RenderIndex(dr.Output); } return(Encoding.UTF8.GetBytes(dr.Output.ToString())); } } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } // TODO:: /exception String msg = $"<div>{ex.Message}</div>"; return(Encoding.UTF8.GetBytes(msg)); } }
Byte[] ProcessRequestImpl(String url, Byte[] post, Boolean postMethod) { if (url.StartsWith("admin/")) { url = url.Substring(6); _controller.Host.SetAdmin(true); } _controller.Host.StartApplication(_controller.Admin); try { MimeType = MIME_HTML; using (var dr = new DesktopResponse()) { if (String.IsNullOrEmpty(url)) { RenderIndex(dr.Output); } else if (url.StartsWith("shell/")) { Shell(url.Substring(6).ToLowerInvariant(), dr.Output, out String shellMime); MimeType = shellMime; } else if (url.StartsWith("report/")) { Report(url.Substring(6).ToLowerInvariant(), dr); MimeType = dr.ContentType; ContentDisposition = dr.Headers["Content-Disposition"]; if (dr.IsBinaryWrited) { return(dr.GetBytes()); } } else if (url.StartsWith("_page/")) { Render(RequestUrlKind.Page, url.Substring(6), dr.Output); } else if (url.StartsWith("_dialog/")) { Render(RequestUrlKind.Dialog, url.Substring(8), dr.Output); } else if (url.StartsWith("_popup/")) { Render(RequestUrlKind.Popup, url.Substring(7), dr.Output); } else if (url.StartsWith("_data/")) { var command = url.Substring(6); dr.ContentType = "application/json"; String jsonData = Encoding.UTF8.GetString(post); _controller.Data(command, SetSqlQueryParams, jsonData, dr).Wait(); MimeType = dr.ContentType; if (dr.IsBinaryWrited) { return(dr.GetBytes()); } } else if (url.StartsWith("_image/")) { if (postMethod) { throw new NotImplementedException("SaveImage (post)"); } else { var bytes = LoadImage("/" + url, dr); MimeType = dr.ContentType; return(bytes); } } else if (url.StartsWith("_static_image/")) { var bytes = StaticImage(url.Substring(14).Replace('-', '.'), dr); MimeType = dr.ContentType; return(bytes); } else if (url.StartsWith("_export/")) { Export("/" + url, dr); MimeType = dr.ContentType; ContentDisposition = dr.Headers["Content-Disposition"]; return(dr.GetBytes()); } else if (url.StartsWith("_application/")) { if (!postMethod) { throw new InvalidOperationException(); } var command = url.Substring(13); String jsonData = Encoding.UTF8.GetString(post); _controller.ApplicationCommand(command, SetUserTenantToParams, jsonData, dr).Wait(); MimeType = MIME_JSON; if (dr.OutputStream.Length == 0) { dr.Output.WriteLine("{}"); } return(Encoding.UTF8.GetBytes(dr.Output.ToString())); } else if (url.StartsWith("fragment/")) { LoadFragment(url.Substring(9), dr); MimeType = dr.ContentType; return(dr.GetBytes()); } else { RenderIndex(dr.Output); } return(Encoding.UTF8.GetBytes(dr.Output.ToString())); } } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } // TODO:: /exception StatusCode = 255; return(Encoding.UTF8.GetBytes(_controller.Localize(ex.Message))); } }