Author: igorz
Date: 2007-06-19 06:53:07 -0400 (Tue, 19 Jun 2007)
New Revision: 80123

Modified:
   trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs
   
trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs
   trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs
   trunk/mcs/class/System.Web/System.Web.Handlers/AssemblyResourceLoader.cs
Log:
implemented ScriptResource and NotifyScriptLoaded features

Modified: 
trunk/mcs/class/System.Web/System.Web.Handlers/AssemblyResourceLoader.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Handlers/AssemblyResourceLoader.cs    
2007-06-19 10:37:25 UTC (rev 80122)
+++ trunk/mcs/class/System.Web/System.Web.Handlers/AssemblyResourceLoader.cs    
2007-06-19 10:53:07 UTC (rev 80123)
@@ -31,6 +31,8 @@
 using System.Web.UI;
 using System.Reflection;
 using System.IO;
+using System.Resources;
+using System.Collections;
 
 namespace System.Web.Handlers {
 #if SYSTEM_WEB_EXTENSIONS
@@ -53,14 +55,18 @@
 #endif
                internal static string GetResourceUrl (Type type, string 
resourceName)
                {
-                       return GetResourceUrl (type.Assembly, resourceName);
+                       return GetResourceUrl (type.Assembly, resourceName, 
false);
                }
 
-               internal static string GetResourceUrl (Assembly assembly, 
string resourceName)
+               internal static string GetResourceUrl (Assembly assembly, 
string resourceName, bool notifyScriptLoaded)
                {
                        string aname = assembly == typeof 
(AssemblyResourceLoader).Assembly ? "s" : HttpUtility.UrlEncode 
(assembly.GetName ().FullName);
                        string apath = assembly.Location;
                        string atime = String.Empty;
+                       string extra = String.Empty;
+#if SYSTEM_WEB_EXTENSIONS
+                       extra = String.Format ("{0}n={1}", QueryParamSeparator, 
notifyScriptLoaded ? "t" : "f");
+#endif
 
 #if TARGET_JVM
                        atime = String.Format ("{0}t={1}", QueryParamSeparator, 
type.GetHashCode ());
@@ -68,15 +74,13 @@
                        if (apath != String.Empty)
                                atime = String.Format ("{0}t={1}", 
QueryParamSeparator, File.GetLastWriteTimeUtc (apath).Ticks);
 #endif
-                       string href = String.Format ("{0}?a={2}{1}r={3}{4}", 
HandlerFileName,
+                       string href = String.Format ("{0}?a={2}{1}r={3}{4}{5}", 
HandlerFileName,
                                                     QueryParamSeparator, aname,
-                                                    HttpUtility.UrlEncode 
(resourceName), atime);
-                       
-                       if (HttpContext.Current != null && 
HttpContext.Current.Request != null) {
-                               string appPath = 
HttpContext.Current.Request.ApplicationPath;
-                               if (!appPath.EndsWith ("/"))
-                                       appPath += "/";
+                                                        HttpUtility.UrlEncode 
(resourceName), atime, extra);
 
+                       HttpContext ctx = HttpContext.Current;
+                       if (ctx != null && ctx.Request != null) {
+                               string appPath = 
VirtualPathUtility.AppendTrailingSlash (ctx.Request.ApplicationPath);
                                href = appPath + href;
                        }
                        
@@ -94,10 +98,12 @@
                        string resourceName = context.Request.QueryString ["r"];
                        string asmName = context.Request.QueryString ["a"];
                        Assembly assembly;
+
+                       if (asmName == null || asmName == "s")
+                               assembly = typeof 
(AssemblyResourceLoader).Assembly;
+                       else
+                               assembly = Assembly.Load (asmName);
                        
-                       if (asmName == null || asmName == "s") assembly = 
GetType().Assembly;
-                       else assembly = Assembly.Load (asmName);
-                       
                        bool found = false;
                        foreach (WebResourceAttribute wra in 
assembly.GetCustomAttributes (typeof (WebResourceAttribute), false)) {
                                if (wra.WebResource == resourceName) {
@@ -130,6 +136,29 @@
                                c = s.Read (buf, 0, 1024);
                                output.Write (buf, 0, c);
                        } while (c > 0);
+#if SYSTEM_WEB_EXTENSIONS
+                       TextWriter writer = context.Response.Output;
+                       foreach (ScriptResourceAttribute sra in 
assembly.GetCustomAttributes (typeof (ScriptResourceAttribute), false)) {
+                               if (sra.ScriptName == resourceName) {
+                                       writer.WriteLine ();
+                                       writer.WriteLine ("{0}={{", 
sra.TypeName);
+                                       ResourceManager res=new 
ResourceManager(sra.ScriptResourceName, assembly);
+                                       foreach (DictionaryEntry entry in 
res.GetResourceSet (Threading.Thread.CurrentThread.CurrentUICulture, true, 
true)) {
+                                               string value = entry.Value as 
string;
+                                               if (value != null)
+                                                       writer.WriteLine 
("{0}:{1},", GetScriptStringLiteral ((string) entry.Key), 
GetScriptStringLiteral (value));
+                                       }
+                                       writer.WriteLine ("};");
+                                       break;
+                               }
+                       }
+
+                       bool notifyScriptLoaded = context.Request.QueryString 
["n"] == "t";
+                       if (notifyScriptLoaded) {
+                               writer.WriteLine ();
+                               writer.WriteLine 
("if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();");
+                       }
+#endif
                }
                
 #if !SYSTEM_WEB_EXTENSIONS

Modified: 
trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs
===================================================================
--- trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs   
2007-06-19 10:37:25 UTC (rev 80122)
+++ trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptModule.cs   
2007-06-19 10:53:07 UTC (rev 80123)
@@ -43,9 +43,25 @@
                }
 
                void AuthenticateRequest (object sender, EventArgs e) {
+                       // The AuthenticateRequest event is raised after the 
identity of the current user has been 
+                       // established. The handler for this event sets the 
SkipAuthorization property of the HttpContext 
+                       // for the current request. This property is checked in 
the authorization module to see 
+                       // if it has to omit authorization checking for the 
requested url. Usually an HttpModule 
+                       // use this property to allow anonymous access to some 
resources (for example, 
+                       // the Login Page if we’re using forms authentication). 
In our scenario, 
+                       // the ScriptModule sets the SkipAuthorization to true 
if the requested url is 
+                       // scriptresource.axd or if the authorization module is 
enabled and the request is a rest 
+                       // request to the authorization web service.
                }
 
                void PostAcquireRequestState (object sender, EventArgs e) {
+                       // The PostAcquireRequestState event is raised after 
the session data has been obtained. 
+                       // If the request is for a class that implements 
System.Web.UI.Page and it is a rest 
+                       // method call, the WebServiceData class (that was 
explained in a previous post) is used 
+                       // to call the requested method from the Page. After 
the method has been called, 
+                       // the CompleteRequest method is called, bypassing all 
pipeline events and executing 
+                       // the EndRequest method. This allows MS AJAX to be 
able to call a method on a page 
+                       // instead of having to create a web service to call a 
method.
                }
 
                void PreSendRequestHeaders (object sender, EventArgs e) {

Modified: 
trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs
===================================================================
--- 
trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs
  2007-06-19 10:37:25 UTC (rev 80122)
+++ 
trunk/mcs/class/System.Web.Extensions/System.Web.Handlers/ScriptResourceHandler.cs
  2007-06-19 10:53:07 UTC (rev 80123)
@@ -50,5 +50,13 @@
                }
 
                #endregion
+
+               // TODO: optimize
+               static string GetScriptStringLiteral (string value) {
+                       string s = value;
+                       s = s.Replace ("\\", "\\\\");
+                       s = s.Replace ("\"", "\\\"");
+                       return "\"" + s + "\"";
+               }
        }
 }

Modified: trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs
===================================================================
--- trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs        
2007-06-19 10:37:25 UTC (rev 80122)
+++ trunk/mcs/class/System.Web.Extensions/System.Web.UI/ScriptManager.cs        
2007-06-19 10:53:07 UTC (rev 80123)
@@ -39,6 +39,7 @@
 using System.Web.Configuration;
 using System.Web.UI.HtmlControls;
 using System.IO;
+using System.Globalization;
 
 namespace System.Web.UI
 {
@@ -454,7 +455,7 @@
                                        assembly = typeof 
(ScriptManager).Assembly;
                                else
                                        assembly = Assembly.Load 
(script.Assembly);
-                               url = ScriptResourceHandler.GetResourceUrl 
(assembly, script.Name);
+                               url = ScriptResourceHandler.GetResourceUrl 
(assembly, script.Name, script.NotifyScriptLoaded);
                        }
                        else {
                                throw new InvalidOperationException ("Name and 
Path cannot both be empty.");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to