Пример #1
0
        /// <summary>Creates a new silo in a remote app domain and returns a handle to it.</summary>
        public static SiloHandle Create(string siloName, Silo.SiloType type, ClusterConfiguration config, NodeConfiguration nodeConfiguration, Dictionary <string, GeneratedAssembly> additionalAssemblies)
        {
            AppDomainSetup setup = GetAppDomainSetupInfo();

            var appDomain = AppDomain.CreateDomain(siloName, null, setup);

            // Load each of the additional assemblies.
            AppDomainSiloHost.CodeGeneratorOptimizer optimizer = null;
            foreach (var assembly in additionalAssemblies.Where(asm => asm.Value != null))
            {
                if (optimizer == null)
                {
                    optimizer =
                        (AppDomainSiloHost.CodeGeneratorOptimizer)
                        appDomain.CreateInstanceAndUnwrap(
                            typeof(AppDomainSiloHost.CodeGeneratorOptimizer).Assembly.FullName, typeof(AppDomainSiloHost.CodeGeneratorOptimizer).FullName, false,
                            BindingFlags.Default,
                            null,
                            null,
                            CultureInfo.CurrentCulture,
                            new object[] { });
                }

                optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
            }

            var args = new object[] { siloName, type, config };

            var siloHost = (AppDomainSiloHost)appDomain.CreateInstanceAndUnwrap(
                typeof(AppDomainSiloHost).Assembly.FullName, typeof(AppDomainSiloHost).FullName, false,
                BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
                new object[] { });

            appDomain.UnhandledException += ReportUnobservedException;
            appDomain.DoCallBack(RegisterPerfCountersTelemetryConsumer);

            siloHost.Start();

            var retValue = new AppDomainSiloHandle
            {
                Name                 = siloName,
                SiloHost             = siloHost,
                NodeConfiguration    = nodeConfiguration,
                SiloAddress          = siloHost.SiloAddress,
                Type                 = type,
                AppDomain            = appDomain,
                additionalAssemblies = additionalAssemblies,
#if !NETSTANDARD_TODO
                AppDomainTestHook = siloHost.AppDomainTestHook,
#endif
            };

            retValue.ImportGeneratedAssemblies();

            return(retValue);
        }
Пример #2
0
        /// <summary>Creates a new silo in a remote app domain and returns a handle to it.</summary>
        public static SiloHandle Create(string siloName, Silo.SiloType type, Type siloBuilderFactory, ClusterConfiguration config, NodeConfiguration nodeConfiguration, IDictionary <string, GeneratedAssembly> additionalAssemblies, string applicationBase = null)
        {
            AppDomainSetup setup = GetAppDomainSetupInfo(applicationBase);

            var appDomain = AppDomain.CreateDomain(siloName, null, setup);

            try
            {
                // Load each of the additional assemblies.
                AppDomainSiloHost.CodeGeneratorOptimizer optimizer = null;
                foreach (var assembly in additionalAssemblies.Where(asm => asm.Value != null))
                {
                    if (optimizer == null)
                    {
                        optimizer =
                            (AppDomainSiloHost.CodeGeneratorOptimizer)
                            appDomain.CreateInstanceAndUnwrap(
                                typeof(AppDomainSiloHost.CodeGeneratorOptimizer).Assembly.FullName, typeof(AppDomainSiloHost.CodeGeneratorOptimizer).FullName, false,
                                BindingFlags.Default,
                                null,
                                null,
                                CultureInfo.CurrentCulture,
                                new object[] { });
                    }

                    optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
                }

                var args = new object[] { siloName, siloBuilderFactory, config };

                var siloHost = (AppDomainSiloHost)appDomain.CreateInstanceAndUnwrap(
                    typeof(AppDomainSiloHost).Assembly.FullName, typeof(AppDomainSiloHost).FullName, false,
                    BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
                    new object[] { });

                appDomain.UnhandledException += ReportUnobservedException;

                siloHost.Start();

                var retValue = new AppDomainSiloHandle
                {
                    Name                 = siloName,
                    SiloHost             = siloHost,
                    NodeConfiguration    = nodeConfiguration,
                    SiloAddress          = siloHost.SiloAddress,
                    Type                 = type,
                    AppDomain            = appDomain,
                    additionalAssemblies = additionalAssemblies,
                    AppDomainTestHook    = siloHost.AppDomainTestHook,
                };

                retValue.ImportGeneratedAssemblies();

                return(retValue);
            }
            catch (Exception)
            {
                UnloadAppDomain(appDomain);
                throw;
            }
        }