// will be called when all assemblies are loaded (can be async for downloading) // which means we need to report errors to the plugin, since it won't get it from calling managed code internal bool CreateApplication() { SetCurrentApplication(null); if (EntryAssembly == null) { EmitError(2103, "Could not find the entry point assembly"); return(false); } Type entry_type = EntryAssembly.GetType(EntryPointType); if (entry_type == null) { EmitError(2103, String.Format("Could not find the startup type {0} on the {1}", EntryPointType, EntryPointAssembly)); return(false); } if (!entry_type.IsSubclassOf(typeof(Application)) && entry_type != typeof(Application)) { #if SANITY Type t = entry_type; int spacing = 0; Console.WriteLine("Application type: {0}", typeof(Application).AssemblyQualifiedName); while (t != null) { if (spacing > 0) { for (int i = 0; i < spacing; i++) { Console.Write(" "); } Console.Write("+ "); } Console.WriteLine("{0} from {1}", t.AssemblyQualifiedName, t.Assembly.Location); spacing += 2; t = t.BaseType; } #endif EmitError(2103, "Startup type does not derive from System.Windows.Application"); return(false); } foreach (Assembly a in Assemblies) { Application.LoadXmlnsDefinitionMappings(a); } Application instance = null; try { instance = (Application)Activator.CreateInstance(entry_type); // set HasElevatedPermissions based on IsRunningOutOfBrowser and ElevatedPermissions.Required if (IsElevatedPermissionsRequired) { instance.HasElevatedPermissions = instance.IsRunningOutOfBrowser; } } catch { EmitError(2103, String.Format("Error while creating the instance of type {0}", entry_type)); return(false); } if (instance.IsRunningOutOfBrowser) { IntPtr window_handle = instance.MainWindow.native; WindowSettings ws = OutOfBrowserSettings.WindowSettings; if (ws != null) { Window w = instance.MainWindow; w.Width = ws.Width; w.Height = ws.Height; switch (ws.WindowStartupLocation) { case WindowStartupLocation.Manual: w.Left = ws.Left; w.Top = ws.Top; break; case WindowStartupLocation.CenterScreen: IntPtr windowing_system = NativeMethods.runtime_get_windowing_system(); IntPtr moon_window = NativeMethods.window_get_moon_window(window_handle); w.Left = ((NativeMethods.moon_windowing_system_get_screen_width(windowing_system, moon_window) - w.Width) / 2); w.Top = ((NativeMethods.moon_windowing_system_get_screen_height(windowing_system, moon_window) - w.Height) / 2); break; default: // let the OS decide where to show the window break; } Uri source = UriHelper.FromNativeUri(NativeMethods.surface_get_source_location(Surface.Native)); string host = source.Host; if (String.IsNullOrEmpty(source.Host)) { host = "localhost"; } NativeMethods.window_set_title(window_handle, ws.Title + " - " + host); NativeMethods.window_set_style(window_handle, ws.WindowStyle); } else { NativeMethods.window_set_title(window_handle, OutOfBrowserSettings.ShortName); } } StartupEventArgs args = new StartupEventArgs(); instance.OnStartup(args); return(true); }