Esempio n. 1
0
        public static HostStub Create(HostArgs hostArgs)
        {
            var appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = hostArgs.ApplicationBase
            };

            ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(hostArgs.RoleConfigurationFile);
            appDomainSetup.ConfigurationFile = hostArgs.RoleConfigurationFile;

            StubManagement.CopyStubAssemblyToRoleDirectory(hostArgs.ApplicationBase);

            var appDomain = AppDomain.CreateDomain(
                "LightBlue",
                null,
                appDomainSetup);

            Trace.Listeners.Add(new ConsoleTraceListener());

            var stub = (HostStub)appDomain.CreateInstanceAndUnwrap(
                typeof(HostStub).Assembly.FullName,
                typeof(HostStub).FullName);

            stub.ConfigureTracing(new ConsoleTraceShipper());

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionBehaviour.UnhandledExceptionHandler(hostArgs.Title);

            return(stub);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var hostArgs = HostArgs.ParseArgs(args);

            if (hostArgs == null)
            {
                return;
            }

            var handle = Process.GetCurrentProcess().MainWindowHandle;

            SetWindowText(handle, hostArgs.Title);

            var appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = hostArgs.ApplicationBase
            };

            ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(hostArgs.RoleConfigurationFile);
            appDomainSetup.ConfigurationFile = hostArgs.RoleConfigurationFile;

            StubManagement.CopyStubAssemblyToRoleDirectory(hostArgs.ApplicationBase);

            var appDomain = AppDomain.CreateDomain(
                "LightBlue",
                null,
                appDomainSetup);

            Trace.Listeners.Add(new ConsoleTraceListener());

            var stub = (HostStub)appDomain.CreateInstanceAndUnwrap(
                typeof(HostStub).Assembly.FullName,
                typeof(HostStub).FullName);

            stub.ConfigureTracing(new ConsoleTraceShipper());

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionBehaviour.UnhandledExceptionHandler(hostArgs.Title);

            stub.Run(workerRoleAssembly: hostArgs.Assembly,
                     configurationPath: hostArgs.ConfigurationPath,
                     serviceDefinitionPath: hostArgs.ServiceDefinitionPath,
                     roleName: hostArgs.RoleName,
                     useHostedStorage: hostArgs.UseHostedStorage);

            if (!hostArgs.AllowSilentFail)
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "The host {0} has exited unexpectedly",
                              hostArgs.Title));
            }
        }