private bool TrySetupServer(int tryIndex, AppDomain sandbox, RunFrame frame) { string baseAddress; string port = _portArranger.Reserve(); SecurityHelper.AddIpListen(); SecurityOptionElement securityElem = frame.GetFirstElement <SecurityOptionElement>(); if (securityElem != null) { SetupSecureEnvironment(securityElem.Certificate, port); baseAddress = string.Format(SecureBaseAddressTemplate, Environment.MachineName, port); frame.SetState(KeyIsSecuredServer, true); } else { baseAddress = string.Format(NormalBaseAddressTemplate, Environment.MachineName, port); frame.SetState(KeyIsSecuredServer, false); } // looking into the RunFrames and search for TraceElement. if it exists // set the tracer's type to the configuration otherwise skip this step TraceElement traceElem = frame.GetFirstElement <TraceElement>(); Type traceType = null; if (traceElem != null) { traceType = traceElem.TracerType; } KatanaSelfHostServerInitiator serverInitiator; // create initiator in the sandbox if (sandbox != null) { serverInitiator = sandbox.CreateInstanceAndUnwrap( typeof(KatanaSelfHostServerInitiator).Assembly.FullName, typeof(KatanaSelfHostServerInitiator).FullName) as KatanaSelfHostServerInitiator; } else { serverInitiator = new KatanaSelfHostServerInitiator(); } try { // set up the server serverInitiator.Setup( baseAddress, TypeDescriptor.GetDesignatedMethod <NuwaKatanaConfigurationAttribute>(), TypeDescriptor.ConfigureMethod, traceType, GetDefaultRouteTemplate()); } catch (Exception ex) { EventLog appLog = new System.Diagnostics.EventLog(); appLog.Source = "Nuwa Katana Self Host Test"; appLog.WriteEntry(string.Format("try index: {0}\nbase address: {1}\n message: {2}\n stack trace: {3}\n", tryIndex, baseAddress, ex.Message, ex.StackTrace), EventLogEntryType.Error); return(false); } frame.SetState(KeyReservedPort, port); frame.SetState(KeyBaseAddresss, baseAddress); frame.SetState(KeyServerInitiator, serverInitiator); return(true); }
protected override bool InitializeServer(RunFrame frame) { string baseAddress; string port; var sandbox = CreateFullTrustAppDomain(); frame.SetState(KeySandbox, sandbox); // load test assemly into sandbox if (sandbox != null && TypeDescriptor.TestAssembly != null) { sandbox.Load(TypeDescriptor.TestAssembly.GetName()); } // setup security strategy and base address port = _portArranger.Reserve(); SecurityHelper.AddIpListen(); SecurityOptionElement securityElem = frame.GetFirstElement <SecurityOptionElement>(); if (securityElem != null) { SetupSecureEnvironment(securityElem.Certificate, port); baseAddress = string.Format(SecureBaseAddressTemplate, Environment.MachineName, port); frame.SetState(KeyIsSecuredServer, true); } else { baseAddress = string.Format(NormalBaseAddressTemplate, Environment.MachineName, port); frame.SetState(KeyIsSecuredServer, false); } // looking into the RunFrames and search for TraceElement. if it exists // set the tracer's type to the configuration otherwise skip this step TraceElement traceElem = frame.GetFirstElement <TraceElement>(); Type traceType = null; if (traceElem != null) { traceType = traceElem.TracerType; } // create initiator in the sandbox KatanaSelfHostServerInitiator serverInitiator; if (sandbox != null) { serverInitiator = sandbox.CreateInstanceAndUnwrap( typeof(KatanaSelfHostServerInitiator).Assembly.FullName, typeof(KatanaSelfHostServerInitiator).FullName) as KatanaSelfHostServerInitiator; } else { serverInitiator = new KatanaSelfHostServerInitiator(); } // set up the server serverInitiator.Setup( baseAddress, TypeDescriptor.GetDesignatedMethod <NuwaKatanaConfigurationAttribute>(), TypeDescriptor.ConfigureMethod, traceType, GetDefaultRouteTemplate()); frame.SetState(KeyReservedPort, port); frame.SetState(KeyBaseAddresss, baseAddress); frame.SetState(KeyServerInitiator, serverInitiator); return(true); }