/// <summary> /// Converts the string representation of a t_struct_name to its /// struct equivalent. A return value indicates whether the /// operation succeeded. /// </summary> /// <param name="input">A string to convert.</param> /// <param name="value"> /// When this method returns, contains the struct equivalent of the value contained /// in input, if the conversion succeeded, or default(t_struct_name) if the conversion /// failed. The conversion fails if the input parameter is null or String.Empty, or is /// not of the correct format. This parameter is passed uninitialized. /// </param> /// <returns>True if input was converted successfully; otherwise, false.</returns> public unsafe static bool TryParse(string input, out t_struct_name value) { try { value = Newtonsoft.Json.JsonConvert.DeserializeObject <t_struct_name>(input); return(true); } catch { value = default(t_struct_name); return(false); } }
internal static string ToString(t_struct_name response_struct) { throw new NotImplementedException(); }
protected override void DispatchHttpRequest(HttpListenerContext context, string endpoint_name, string url) { var method = context.Request.HttpMethod; uint handler_id = 0; if (!s_HttpHandlerLookupTable.TryGetValue(endpoint_name, out handler_id)) { CommonHttpHandlers.PageNotFound(context); RootHttpHandler(context); return; } var querystring_idx = url.IndexOf('?'); switch (handler_id) { /*FOREACH*/ /*USE_LIST("t_protocol")*/ /*IF("$t_protocol->is_http_protocol()")*/ case /*MUTE*/ 0 /*MUTE_END*/ /*GET_ITERATOR_VALUE*/: { IF("$t_protocol->pt_request == PT_STRUCT_REQUEST"); MAP_VAR("t_struct_name", "META_OUTPUT(tsl->find_struct_or_cell($t_protocol->request_message_struct)->name)"); string json_string; t_struct_name request_struct; if (method == "GET") { if (querystring_idx == -1) { json_string = url; } else { json_string = url.Substring(0, querystring_idx); } } else if (method == "POST") { using (var sr = new System.IO.StreamReader(context.Request.InputStream)) json_string = sr.ReadToEnd(); } else { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } if (!t_struct_name.TryParse(json_string, out request_struct)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } END(); IF("$t_protocol->pt_response == PT_STRUCT_RESPONSE"); MAP_VAR("t_struct_name", "META_OUTPUT(tsl->find_struct_or_cell($t_protocol->response_message_struct)->name)"); t_struct_name response_struct /*MUTE*/ = null /*MUTE_END*/; END(); t_protocol_nameHandler(/*META_OUTPUT("get_http_handler_calling_parameters($t_protocol)")*/); IF("$t_protocol->pt_response == PT_STRUCT_RESPONSE"); context.Response.ContentType = "application/json"; string jsonp_callback = context.Request.QueryString["jsonp_callback"] ?? context.Request.QueryString["callback"]; string iframe_callback = context.Request.QueryString["iframe_callback"]; using (var sw = new System.IO.StreamWriter(context.Response.OutputStream)) { if (jsonp_callback != null) { sw.Write("{0}(", jsonp_callback); sw.Write(Serializer.ToString(response_struct)); sw.Write(");", jsonp_callback); } else if (iframe_callback != null) { context.Response.ContentType = "text/html"; sw.Write("<script language=\"javascript\" type=\"text/javascript\">window.top.window.{0}(", iframe_callback); sw.Write(Serializer.ToString(response_struct)); sw.Write(");</script>"); } else { sw.Write(Serializer.ToString(response_struct)); } } END(); } break; /*END*/ /*END*/ } }