Author: zoltan
Date: 2007-10-04 16:24:15 -0400 (Thu, 04 Oct 2007)
New Revision: 86907

Modified:
   trunk/olive/class/agclr/Mono/ChangeLog
   trunk/olive/class/agclr/Mono/ManagedXamlLoader.cs
Log:
2007-10-04  Zoltan Varga  <[EMAIL PROTECTED]>

        * ManagedXamlLoader.cs (LoadDepsSynch): New property to control the 
synchronous
        downloading of dependencies.
        (LoadDependency): New helper method.
        (LoadAssembly): Call LoadDependency if needed.


Modified: trunk/olive/class/agclr/Mono/ChangeLog
===================================================================
--- trunk/olive/class/agclr/Mono/ChangeLog      2007-10-04 20:23:09 UTC (rev 
86906)
+++ trunk/olive/class/agclr/Mono/ChangeLog      2007-10-04 20:24:15 UTC (rev 
86907)
@@ -1,3 +1,10 @@
+2007-10-04  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * ManagedXamlLoader.cs (LoadDepsSynch): New property to control the 
synchronous
+       downloading of dependencies.
+       (LoadDependency): New helper method.
+       (LoadAssembly): Call LoadDependency if needed.
+
 2007-10-02  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * ManagedXamlLoader.cs (LoadObject): Log exceptions thrown from 
CreateInstance.

Modified: trunk/olive/class/agclr/Mono/ManagedXamlLoader.cs
===================================================================
--- trunk/olive/class/agclr/Mono/ManagedXamlLoader.cs   2007-10-04 20:23:09 UTC 
(rev 86906)
+++ trunk/olive/class/agclr/Mono/ManagedXamlLoader.cs   2007-10-04 20:24:15 UTC 
(rev 86907)
@@ -46,6 +46,7 @@
 //             string contents;
                static Dictionary<string, string> mappings = new Dictionary 
<string, string> ();
                XamlLoaderCallbacks callbacks;
+               bool load_deps_synch = false;
 
 #if WITH_DLR
                DLRHost dlr_host;
@@ -62,6 +63,17 @@
                                return native_loader;
                        }
                }
+
+               //
+               // Set whenever the loader will load dependencies synchronously 
using the browser
+               // This is used in cases where the user of the loader can't 
operate in async mode
+               // such as Control:InitializeFromXaml ()
+               //
+               public bool LoadDepsSynch {
+                       set {
+                               load_deps_synch = value;
+                       }
+               }
                
                public ManagedXamlLoader ()
                {
@@ -170,17 +182,28 @@
                        }
 
                        if (clientlib == null) {
-                               string mapped = GetMapping (asm_path);
-
-                               if (mapped != null) {
-                                       clientlib = Helper.LoadFile (mapped);
+                               if (load_deps_synch) {
+                                       byte[] arr = LoadDependency (asm_path);
+                                       if (arr != null)
+                                               clientlib = Assembly.Load (arr);
                                        if (clientlib == null) {
                                                Console.WriteLine 
("ManagedXamlLoader::LoadAssembly (asm_path={0} asm_name={1}): could not load 
client library: {2}", asm_path, asm_name, asm_path);
                                                return 
AssemblyLoadResult.LoadFailure;
                                        }
+                                       // FIXME: Load dependencies
                                } else {
-                                       RequestFile (asm_path);
-                                       return 
AssemblyLoadResult.MissingAssembly;
+                                       string mapped = GetMapping (asm_path);
+
+                                       if (mapped != null) {
+                                               clientlib = Helper.LoadFile 
(mapped);
+                                               if (clientlib == null) {
+                                                       Console.WriteLine 
("ManagedXamlLoader::LoadAssembly (asm_path={0} asm_name={1}): could not load 
client library: {2}", asm_path, asm_name, asm_path);
+                                                       return 
AssemblyLoadResult.LoadFailure;
+                                               }
+                                       } else {
+                                               RequestFile (asm_path);
+                                               return 
AssemblyLoadResult.MissingAssembly;
+                                       }
                                }
                        }
 
@@ -524,5 +547,27 @@
                        }
                }
 #endif
+
+               //
+               // Load a dependency file synchronously using the plugin
+               //
+               private byte[] LoadDependency (string path) {
+                       IntPtr plugin_handle = 
System.Windows.Interop.PluginHost.Handle;
+                       if (plugin_handle == IntPtr.Zero)
+                               return null;
+
+                       // FIXME: Cache result
+                       int size = 0;
+                       IntPtr n = NativeMethods.plugin_instance_load_url 
(plugin_handle, path, ref size);
+                       byte[] arr = new byte [size];
+                       unsafe {
+                               using (Stream u = new 
SimpleUnmanagedMemoryStream ((byte *) n, (int) size)){
+                                       u.Read (arr, 0, size);
+                               }
+                       }
+                       Helper.FreeHGlobal (n);
+
+                       return arr;;
+               }
        }
 }

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

Reply via email to