static AddrMap FromJson(MyJson.JsonNode_Array json) { AddrMap info = new AddrMap(); foreach (var item in json) { MethodInfo minfo = new MethodInfo(); minfo.name = item.GetDictItem("name").AsString(); minfo.startAddr = int.Parse(item.GetDictItem("addr").AsString(), System.Globalization.NumberStyles.HexNumber); var map = item.GetDictItem("map").AsList(); foreach (var mapitem in map) { var src = int.Parse(mapitem.ToString().Substring(5)); var addr = int.Parse(mapitem.ToString().Substring(0, 4), System.Globalization.NumberStyles.HexNumber); if (src < 0 || src >= 0xffff) { continue; } minfo.Add(src, addr); } minfo.Sort(); info.methods.Add(minfo); info.methods.Sort((a, b) => { return(a.startAddr - b.startAddr); }); } // [{"name":"Main","addr":"0000","map":["0011-11","0012-12","0023-14","004C-16707566","0054-15","0055-16","0074-17","007F-19","00B0-25","00C2-26","00D4-27","00E1-29","0101-32","0139-33","0155-34","0160-35"] //}] return(info); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public void ProcessRequest(HttpContext context) { // The request was not a request to invoke a server-side method. // Now, we will render the Javascript that will be used on the // client to run as a proxy or wrapper for the methods marked // with the AjaxMethodAttribute. if (context.Trace.IsEnabled) { context.Trace.Write(Constant.AjaxID, "Render class proxy Javascript"); } // Check wether the javascript is already rendered and cached in the // current context. string etag = context.Request.Headers["If-None-Match"]; string modSince = context.Request.Headers["If-Modified-Since"]; string path = type.FullName + "," + type.Assembly.FullName.Split(',')[0]; if (Utility.Settings.UseAssemblyQualifiedName) { path = type.AssemblyQualifiedName; } if (Utility.Settings != null && Utility.Settings.UrlNamespaceMappings.ContainsValue(path)) { foreach (string key in Utility.Settings.UrlNamespaceMappings.Keys) { if (Utility.Settings.UrlNamespaceMappings[key].ToString() == path) { path = key; break; } } } if (context.Cache[path] != null) { CacheInfo ci = (CacheInfo)context.Cache[path]; if (etag != null) { if (etag == ci.ETag) // TODO: null check { context.Response.StatusCode = 304; context.Response.SuppressContent = true; return; } } if (modSince != null) { if (modSince.IndexOf(";") > 0) { // If-Modified-Since: Tue, 06 Jun 2006 10:13:38 GMT; length=2935 modSince = modSince.Split(';')[0]; } try { DateTime modSinced = Convert.ToDateTime(modSince.ToString()).ToUniversalTime(); if (DateTime.Compare(modSinced, ci.LastModified.ToUniversalTime()) >= 0) { context.Response.StatusCode = 304; context.Response.SuppressContent = true; return; } } catch (FormatException) { if (context.Trace.IsEnabled) { context.Trace.Write(Constant.AjaxID, "The header value for If-Modified-Since = " + modSince + " could not be converted to a System.DateTime."); } } } } etag = type.AssemblyQualifiedName; etag = MD5Helper.GetHash(System.Text.Encoding.Default.GetBytes(etag)); DateTime now = DateTime.Now; DateTime lastMod = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); // .ToUniversalTime(); context.Response.AddHeader("Content-Type", "application/x-javascript"); context.Response.ContentEncoding = System.Text.Encoding.UTF8; context.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); context.Response.Cache.SetETag(etag); context.Response.Cache.SetLastModified(lastMod); // Ok, we do not have the javascript rendered, yet. // Build the javascript source and save it to the current // Application context. string url = context.Request.ApplicationPath + (context.Request.ApplicationPath.EndsWith("/") ? "" : "/") + Utility.HandlerPath + "/" + AjaxPro.Utility.GetSessionUri() + path + Utility.HandlerExtension; // find all methods that are able to be used with AjaxPro MethodInfo[] mi = type.GetMethods(); MethodInfo method; #if (NET20) List <MethodInfo> methods = new List <MethodInfo>(); #else MethodInfo[] methods = new MethodInfo[mi.Length]; // maximum length int mc = 0; #endif for (int y = 0; y < mi.Length; y++) { method = mi[y]; if (!method.IsPublic) { continue; } AjaxMethodAttribute[] ma = (AjaxMethodAttribute[])method.GetCustomAttributes(typeof(AjaxMethodAttribute), true); if (ma.Length == 0) { continue; } PrincipalPermissionAttribute[] ppa = (PrincipalPermissionAttribute[])method.GetCustomAttributes(typeof(PrincipalPermissionAttribute), true); if (ppa.Length > 0) { bool permissionDenied = true; for (int p = 0; p < ppa.Length && permissionDenied; p++) { #if (_____NET20) if (Roles.Enabled) { try { if (!String.IsNullOrEmpty(ppa[p].Role) && !Roles.IsUserInRole(ppa[p].Role)) { continue; } } catch (Exception) { // Should we disable this AjaxMethod of there is an exception? continue; } } else #endif if (ppa[p].Role != null && ppa[p].Role.Length > 0 && context.User != null && context.User.Identity.IsAuthenticated && !context.User.IsInRole(ppa[p].Role)) { continue; } permissionDenied = false; } if (permissionDenied) { continue; } } #if (NET20) methods.Add(method); #else methods[mc++] = method; #endif } // render client-side proxy file System.Text.StringBuilder sb = new System.Text.StringBuilder(); TypeJavaScriptProvider jsp = null; if (Utility.Settings.TypeJavaScriptProvider != null) { try { Type jspt = Type.GetType(Utility.Settings.TypeJavaScriptProvider); if (jspt != null && typeof(TypeJavaScriptProvider).IsAssignableFrom(jspt)) { jsp = (TypeJavaScriptProvider)Activator.CreateInstance(jspt, new object[3] { type, url, sb }); } } catch (Exception) { } } if (jsp == null) { jsp = new TypeJavaScriptProvider(type, url, sb); } jsp.RenderNamespace(); jsp.RenderClassBegin(); #if (NET20) jsp.RenderMethods(methods.ToArray()); #else jsp.RenderMethods(methods); #endif jsp.RenderClassEnd(); context.Response.Write(sb.ToString()); context.Response.Write("\r\n"); // save the javascript in current Application context to // speed up the next requests. // TODO: was können wir hier machen?? // System.Web.Caching.CacheDependency fileDepend = new System.Web.Caching.CacheDependency(type.Assembly.Location); context.Cache.Add(path, new CacheInfo(etag, lastMod), null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); if (context.Trace.IsEnabled) { context.Trace.Write(Constant.AjaxID, "End ProcessRequest"); } }