private static bool SendInvokeResult(HttpContext context, HttpRequest request, string typeName, string methodName, JsonResponseFormats format) { if (format == JsonResponseFormats.invalid) { throw new InvalidOperationException("The specified response format requested was invalid."); } string[] parameters = null; if (request.QueryString["params"] != null) { parameters = HttpUtility.UrlDecode(request.QueryString["params"]).Split(new string[] { ParameterDelimiter }, StringSplitOptions.RemoveEmptyEntries); List <string> newParameters = new List <string>(); foreach (string parameter in parameters) { // if for some strange reason someone enters this sequence of characters the javascript will reverse and replace the sequence // here we're un-reversing string reversed = StringExtensions.Reverse(ParameterDelimiter); newParameters.Add(parameter.Replace(reversed, ParameterDelimiter)); } parameters = newParameters.ToArray(); } HttpResponse response = context.Response; JsonResult result = GetJsonResultFromInvoke(typeName, methodName, parameters); switch (format) { case JsonResponseFormats.json: response.Clear(); response.Write(JsonSerializer.ToJson(result)); response.Flush(); response.SuppressContent = true; // necessary to suppress html that may have been added to the response. //HttpContext.Current.ApplicationInstance.CompleteRequest(); //response.End(); break; case JsonResponseFormats.box: BoxServer.SendDataBoxResponse(context, result); break; } return(true); }
public override void WireScriptsAndValidate() { this.controlToRender.TagName = "div"; this.controlToRender.Attributes.Add("class", "contextMenu"); this.controlToRender.Style.Add("display", "none"); this.controlToRender.Attributes.Add("jsonid", this.jsonId); this.controlToRender.Attributes.Add("id", this.DomId); this.controlToRender.Controls.Add(new LiteralControl("This control is not complete. It still needs client side wiring and the jQuery contextMenu plugin isn't quite approprate here.")); WriteDefaultTemplateToDisk(typeof(ContextMenuItem)); foreach (Node file in this.BackingDoodad.Files) { ContextMenuItem item = ContextMenuItem.FromNode(file); this.controlToRender.Controls.Add(new LiteralControl(BoxServer.GetTemplatedString(item, this.TemplateName))); } }
public static void WriteDefaultTemplateToDisk(Type typeToTemplate) { string filePath = HttpContext.Current.Server.MapPath(BoxServer.GetVirtualDataBoxPathWithoutFileCheck(typeToTemplate, "default")); string csPath = filePath + ".cs"; if (!File.Exists(filePath) || !File.Exists(csPath)) { lock (writeLock) { string dirPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string ascxRes = "naizari.javascript.datacontrols." + typeToTemplate.Name.ToLower() + ".ascx"; if (Resources.TextFiles.ContainsKey(ascxRes)) { if (!File.Exists(filePath)) { string ascx = Resources.TextFiles[ascxRes]; using (StreamWriter sw = new StreamWriter(filePath)) { sw.Write(ascx.Replace("$$TypeName$$", StringExtensions.PascalCase(typeToTemplate.Name))); } } if (!File.Exists(csPath)) { WriteCodeBehind(typeToTemplate, csPath); } } } } }
private static void SendDataBoxScriptResponse(HttpContext context) { BoxServer.SendDataBoxScriptResponse(context); }
private static void SendBoxResponse(HttpContext context, string boxPath) { BoxServer.SendBoxResponse(context, boxPath); }