/// <summary> /// Inits from domain. /// </summary> /// <param name="domain">The domain.</param> /// <returns></returns> public static BootstrapperParameters InitFromDomain(AppDomain domain) { return new BootstrapperParameters() { BootstrapperFile = (string)domain.GetData(bootstrapperDataKey), ConfigurationFile = (string)domain.GetData(bootstrapperConfigurationDataKey) }; }
internal static void WriteUnhandledExceptionToEventLog(AppDomain appDomain, Exception exception) { if (appDomain == null || exception == null) { return; } ProcessImpersonationContext imperContext = null; try { imperContext = new ProcessImpersonationContext(); String appId = appDomain.GetData(".appId") as String; if (appId == null) { appId = appDomain.FriendlyName; } string pid = SafeNativeMethods.GetCurrentProcessId().ToString(CultureInfo.InstalledUICulture); string description = SR.Resources.GetString(SR.Unhandled_Exception, CultureInfo.InstalledUICulture); Misc.ReportUnhandledException(exception, new string[5] {description, APPLICATION_ID, appId, PROCESS_ID, pid}); } catch { // ignore exceptions so that WriteErrorToEventLog never throws } finally { if (imperContext != null) { imperContext.Undo(); } } }
private void ContinueDomain(System.AppDomain appDomain) { try { // Get the service manager instance and finalize ContainerManager manager = (ContainerManager)appDomain.GetData("ContainerManager"); manager.Continue(); } catch (System.Exception ex) { string errorString = GenerateErrorString(ex); } }
public static void Main() { AppDomain appDomain = AppDomain.CurrentDomain; appDomain.AssemblyResolve += AppDomain_AssemblyResolve; appDomain.ProcessExit += AppDomain_ProcessExit; appDomain.ResourceResolve += AppDomain_ResourceResolve; appDomain.TypeResolve += AppDomain_TypeResolve; appDomain.UnhandledException += AppDomain_UnhandledException; string baseDirectory = appDomain.BaseDirectory; string friendlyName = appDomain.FriendlyName; Assembly[] assemblies = appDomain.GetAssemblies(); object data = appDomain.GetData(string.Empty); bool isFullyTrusted = appDomain.IsFullyTrusted; bool isHomogenous = appDomain.IsHomogenous; }
private static void OnAppDomainUnload(AppDomain appDomain) { ILogger logger = appDomain.GetData(Constants.LoggerKey) as ILogger; if (logger == null) { return; } logger.Fatal( "AppDomain with Id: '{0}' and BaseDirectory: '{1}' has been unloaded. Any in memory data stores have been lost. {2}", appDomain.Id, appDomain.BaseDirectory, HttpRuntimeShutdownMessageResolver.ResolveShutdownMessage()); // NLog writes its logs asynchronously, which means that if we don't wait, chances are the log will not be written // before the appdomain is actually shut down, so we sleep for 100ms and hopefully that is enough for NLog to do its thing Thread.Sleep(100); }
private void UnloadDomain(System.AppDomain appDomain) { try { // Get the service manager instance and finalize ContainerManager manager = (ContainerManager)appDomain.GetData("ContainerManager"); manager.Finalize(); if (appDomain != null) { System.AppDomain.Unload(appDomain); } } catch (System.Exception ex) { string errorString = GenerateErrorString(ex); } }
public static IContract AppDomainOwner(AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return (IContract)domain.GetData(s_appDomainOwner); }
public static bool ContractOwnsAppDomain(IContract contract, AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); if (contract == null) throw new ArgumentNullException("contract"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return domain.GetData(s_appDomainOwner) == contract; }
internal static void WriteUnhandledExceptionToEventLog(AppDomain appDomain, Exception exception) { if ((appDomain != null) && (exception != null)) { ProcessImpersonationContext context = null; try { context = new ProcessImpersonationContext(); string data = appDomain.GetData(".appId") as string; if (data == null) { data = appDomain.FriendlyName; } string str2 = System.Web.SafeNativeMethods.GetCurrentProcessId().ToString(CultureInfo.InstalledUICulture); string str3 = System.Web.SR.Resources.GetString("Unhandled_Exception", CultureInfo.InstalledUICulture); ReportUnhandledException(exception, new string[] { str3, "\r\n\r\nApplication ID: ", data, "\r\n\r\nProcess ID: ", str2 }); } catch { } finally { if (context != null) { context.Undo(); } } } }
public static int Main(string[] args) { AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _serverAppDomain = AppDomain.CreateDomain("Server", null, setup); _serverAppDomain.Load(typeof(ZyanConnection).Assembly.GetName()); CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() => { var server = EventServer.Instance; if (server != null) { Console.WriteLine("Event server started."); } }); _serverAppDomain.DoCallBack(serverWork); // Test IPC Binary int ipcBinaryTestResult = IpcBinaryTest.RunTest(); Console.WriteLine("Passed: {0}", ipcBinaryTestResult == 0); // Test TCP Binary int tcpBinaryTestResult = TcpBinaryTest.RunTest(); Console.WriteLine("Passed: {0}", tcpBinaryTestResult == 0); // Test TCP Custom int tcpCustomTestResult = TcpCustomTest.RunTest(); Console.WriteLine("Passed: {0}", tcpCustomTestResult == 0); // Test TCP Duplex int tcpDuplexTestResult = TcpDuplexTest.RunTest(); Console.WriteLine("Passed: {0}", tcpDuplexTestResult == 0); // Test HTTP Custom int httpCustomTestResult = HttpCustomTest.RunTest(); Console.WriteLine("Passed: {0}", httpCustomTestResult == 0); // Test NULL Channel const string nullChannelResultSlot = "NullChannelResult"; _serverAppDomain.DoCallBack(new CrossAppDomainDelegate(() => { int result = NullChannelTest.RunTest(); AppDomain.CurrentDomain.SetData(nullChannelResultSlot, result); })); var nullChannelTestResult = Convert.ToInt32(_serverAppDomain.GetData(nullChannelResultSlot)); Console.WriteLine("Passed: {0}", nullChannelTestResult == 0); // Stop the event server EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator; locator.GetEventServer().Dispose(); Console.WriteLine("Event server stopped."); if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS) { // Mono/Windows bug: // AppDomain.Unload freezes in Mono under Windows if tests for // System.Runtime.Remoting.Channels.Tcp.TcpChannel were executed. AppDomain.Unload(_serverAppDomain); Console.WriteLine("Server AppDomain unloaded."); } if (ipcBinaryTestResult + tcpBinaryTestResult + tcpCustomTestResult + tcpDuplexTestResult + httpCustomTestResult + nullChannelTestResult == 0) { Console.WriteLine("All tests passed."); return 0; } return 1; }
public static ScriptEnvironmentSetup GetAppDomainAssociated(AppDomain domain) { Contract.RequiresNotNull(domain, "domain"); return domain.GetData(AppDomainDataKey) as ScriptEnvironmentSetup; }
private static bool IsWebApp(AppDomain appDomain) { var configFile = (string) appDomain.GetData("APP_CONFIG_FILE"); if (string.IsNullOrEmpty(configFile)) return false; return ( Path.GetFileNameWithoutExtension(configFile) ?? string.Empty ).Equals( "WEB", StringComparison.OrdinalIgnoreCase); }
public virtual void Run() { this.TryObtainLock(); try { this.Preconditions(Pre.SiteSet | Pre.RootNamespaceSet | Pre.RootMonikerSet | Pre.EngineNotRunning | Pre.EngineNotClosed); System.AppDomain currentDomain = System.AppDomain.CurrentDomain; if (this.haveCompiledState) { if (this.rootNamespace != this.compiledRootNamespace) { throw new JSVsaException(JSVsaError.RootNamespaceInvalid); } this.loadedAssembly = this.LoadCompiledState(); currentDomain.SetData(this.engineMoniker, this.loadedAssembly); } else { if (this.failedCompilation) { throw new JSVsaException(JSVsaError.EngineNotCompiled); } this.startupClass = null; this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly; if (this.loadedAssembly == null) { string name = this.engineMoniker + "/" + currentDomain.GetHashCode().ToString(CultureInfo.InvariantCulture); Mutex mutex = new Mutex(false, name); if (mutex.WaitOne()) { try { this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly; if (this.loadedAssembly == null) { byte[] buffer; byte[] buffer2; this.engineSite.GetCompiledState(out buffer, out buffer2); if (buffer == null) { throw new JSVsaException(JSVsaError.GetCompiledStateFailed); } this.loadedAssembly = System.Reflection.Assembly.Load(buffer, buffer2, this.executionEvidence); currentDomain.SetData(this.engineMoniker, this.loadedAssembly); } } finally { mutex.ReleaseMutex(); mutex.Close(); } } } } try { if (this.startupClass == null) { this.startupClass = this.loadedAssembly.GetType(this.rootNamespace + "._Startup", true); } } catch (Exception exception) { throw new JSVsaException(JSVsaError.BadAssembly, exception.ToString(), exception); } try { this.startupInstance = (BaseVsaStartup)Activator.CreateInstance(this.startupClass); this.isEngineRunning = true; this.startupInstance.SetSite(this.engineSite); this.startupInstance.Startup(); } catch (Exception exception2) { throw new JSVsaException(JSVsaError.UnknownError, exception2.ToString(), exception2); } } finally { this.ReleaseLock(); } }
public static object RunInAppDomain(Delegate delg, AppDomain targetDomain, params object[] args) { var runner = new domainDomainRunner(delg, args, delg.GetHashCode()); targetDomain.DoCallBack(runner.Invoke); return targetDomain.GetData("appDomainResult" + delg.GetHashCode()); }
internal static IPluginCreator GetCreator(AppDomain domain, ILoggerFactory logfactory) { if (domain == null) throw new ArgumentNullException("domain"); if (logfactory == null) throw new ArgumentNullException("logfactory"); IPluginCreator creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator; if (creator == null) { domain.SetData(LOGGERFACTORYKEY, new ProxyLoggerFactory(logfactory)); domain.DoCallBack(() => { Logger.Singleton.LoggerFactory = AppDomain.CurrentDomain.GetData(LOGGERFACTORYKEY) as ILoggerFactory; AppDomain.CurrentDomain.SetData(PLUGINCREATORKEY, new PluginCreator()); }); domain.SetData(LOGGERFACTORYKEY, null); creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator; } return creator; }