Register() public static method

public static Register ( IEnumerable files, AppDomain domain = null ) : IDisposable
files IEnumerable
domain System.AppDomain
return IDisposable
Example #1
0
        public void Init(string platformType, string initializeAssembly, string mainAssembly, IEnumerable <string> references)
        {
            this.mainAssembly = mainAssembly;
            this.references   = references.ToList();
            if (Platform.Instance == null)
            {
                var refs = new[] { Path.GetDirectoryName(typeof(AppDomainProxy).Assembly.Location), mainAssembly };
                resolver = AssemblyResolver.Register(refs.Union(this.references));

                var plat = Activator.CreateInstance(Type.GetType(platformType)) as Platform;
                Platform.Initialize(plat);
                if (!string.IsNullOrEmpty(initializeAssembly))
                {
                    plat.LoadAssembly(initializeAssembly);
                }
                plat.Add(typeof(IPlatformTheme), () => new DomainPlatformThemeHandler(this));
                var app = new Application();
                app.Attach();
                app.Terminating += App_Terminating;

                app.UnhandledException += App_UnhandledException;

                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
            }
        }
Example #2
0
        public override void Update(string code)
        {
            var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (AssemblyResolver.Register(baseDir))
                base.Update(code);
        }
Example #3
0
        public void Init(string platformType, string initializeAssembly, string mainAssembly, IEnumerable <string> references)
        {
            if (Platform.Instance == null)
            {
                resolver = AssemblyResolver.Register(references.Union(new[] { mainAssembly, Path.GetDirectoryName(typeof(AppDomainProxy).Assembly.Location) }));

                var plat = Activator.CreateInstance(Type.GetType(platformType)) as Platform;
                Platform.Initialize(plat);
                if (!string.IsNullOrEmpty(initializeAssembly))
                {
                    plat.LoadAssembly(initializeAssembly);
                }
                new Application().Attach();
            }

            designPanel = new DesignPanel();
            designPanel.MainAssembly = mainAssembly;
            designPanel.References   = references.ToList();
        }
Example #4
0
        bool SetupAppDomain(bool setBuilder)
        {
            if (!requiresNewDomain && domain != null)
            {
                EnsureWatcher();
                return(false);
            }

            requiresNewDomain = false;
#pragma warning disable 618
            // doesn't work without for some reason, and there's no non-obsolete alternative.
            if (!AppDomain.CurrentDomain.ShadowCopyFiles)
            {
                AppDomain.CurrentDomain.SetShadowCopyFiles();
            }
#pragma warning restore 618

            var baseDir            = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var initializeAssembly = Builders.BaseCompiledInterfaceBuilder.InitializeAssembly;

            var shadowCopyDirs = string.Join(";", GetShadowCopyDirs().Distinct());
            var setup          = new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                PrivateBinPath  = $"{baseDir};{shadowCopyDirs}",

                ShadowCopyFiles       = "true",
                ShadowCopyDirectories = shadowCopyDirs,
                CachePath             = Path.Combine(Path.GetDirectoryName(MainAssembly), "Eto.Designer"),

                LoaderOptimization = LoaderOptimization.MultiDomain,
                //LoaderOptimization = LoaderOptimization.NotSpecified
            };

            proxy  = null;
            domain = AppDomain.CreateDomain("eto.designer." + domainCount++, null, setup);
            try
            {
                using (AssemblyResolver.Register(baseDir))
                {
                    var proxyObject = domain.CreateInstanceFromAndUnwrap(typeof(AppDomainProxy).Assembly.Location, typeof(AppDomainProxy).FullName) as AppDomainProxy;
                    proxy = proxyObject as AppDomainProxy;
                    if (proxy == null)
                    {
                        throw new InvalidOperationException($"Could not create proxy for domain\nApplicationBase: {AppDomain.CurrentDomain.BaseDirectory}\nBaseDir: {baseDir}\nShadowCopyDirs: {shadowCopyDirs}");
                    }
                }
                proxy.Init(Platform.Instance.GetType().AssemblyQualifiedName, initializeAssembly, MainAssembly, references);

                proxy.HookupEvents(eventSink);

                if (setBuilder)
                {
                    proxy.SetBuilder(fileName);
                }
                if (!string.IsNullOrEmpty(code))
                {
                    proxy.Update(code);
                }
            }
            catch (Exception ex)
            {
                UnloadDomain(domain);
                domain = null;
                proxy  = null;
                throw new InvalidOperationException($"Could not set up proxy for domain: {ex.GetBaseException().Message}", ex);
            }

            EnsureWatcher();

            return(true);
        }