本文整理汇总了C#中System.AppDomain.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.GetData方法的具体用法?C# AppDomain.GetData怎么用?C# AppDomain.GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.GetData方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitFromDomain
/// <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)
};
}
示例2: WriteUnhandledExceptionToEventLog
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();
}
}
}
示例3: OnAppDomainUnload
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);
}
示例4: AppDomainOwner
public static IContract AppDomainOwner(AppDomain domain)
{
if (domain == null)
throw new ArgumentNullException("domain");
System.Diagnostics.Contracts.Contract.EndContractBlock();
return (IContract)domain.GetData(s_appDomainOwner);
}
示例5: ContractOwnsAppDomain
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;
}
示例6: WriteUnhandledExceptionToEventLog
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();
}
}
}
}
示例7: Main
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;
}
示例8: GetAppDomainAssociated
public static ScriptEnvironmentSetup GetAppDomainAssociated(AppDomain domain) {
Contract.RequiresNotNull(domain, "domain");
return domain.GetData(AppDomainDataKey) as ScriptEnvironmentSetup;
}
示例9: IsWebApp
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);
}
示例10: RunInAppDomain
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());
}
示例11: GetCreator
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;
}