コード例 #1
0
        private static void GetAllAssemblies()
        {
            void addAssemblies()
            {
                for (int i = 0; i < AssembliesCore._referencedAssemblies.Length; i++)
                {
                    AddAssembly(AssembliesCore._referencedAssemblies[i], false);
                }
            }

            AddAssembly(EntryAssembly, false);

            if (AssembliesCore._referencedAssemblies == null)
            {
                var cauldronHelper = EntryAssembly.GetType("CauldronInterceptionHelper")?.GetMethod("GetReferencedAssemblies", BindingFlags.Public | BindingFlags.Static);

                if (cauldronHelper != null)
                {
                    if (cauldronHelper.Invoke(null, null) is Assembly[] refAssemblies && refAssemblies.Length > 0)
                    {
                        AssembliesCore._referencedAssemblies = refAssemblies;
                        addAssemblies();
                        return;
                    }
                }

                var assemblies    = new List <Assembly>();
                var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();

                for (int i = 0; i < allAssemblies.Length; i++)
                {
                    var assembly = allAssemblies[i];
                    if (AddAssembly(assembly, false) != null)
                    {
                        var referencedAssemblies = assembly.GetReferencedAssemblies();
                        for (int c = 0; c < referencedAssemblies.Length; c++)
                        {
                            LoadAssembly(referencedAssemblies[c]);
                        }
                    }
                }
                ;

                return;
            }

            addAssemblies();
        }
コード例 #2
0
        /// <summary>
        /// 取得类型
        /// </summary>
        /// <returns>类型</returns>
        private Type GetType(string typeName)
        {
            Type type = Type.GetType(typeName);

            if (type == null)
            {
                type = DefaultAssembly.GetType(typeName);
            }
            if (type == null)
            {
                type = CallingAssembly.GetType(typeName);
            }
            if (type == null)
            {
                type = ExecutingAssembly.GetType(typeName);
            }
            if (type == null)
            {
                type = EntryAssembly.GetType(typeName);
            }
            return(type);
        }
コード例 #3
0
ファイル: Deployment.cs プロジェクト: ynkbt/moon
        // 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);
        }