本文整理汇总了C#中System.AppDomain.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.SetData方法的具体用法?C# AppDomain.SetData怎么用?C# AppDomain.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
static void Load()
{
if (AppDomain.CurrentDomain.FriendlyName != "OnlineVideosSiteUtilDlls")
{
if (_useSeperateDomain)
{
_domain = AppDomain.CreateDomain("OnlineVideosSiteUtilDlls", null, null, null, true);
// we need to subscribe to AssemblyResolve on the MP2 AppDomain because OnlineVideos.dll is loaded in the LoadFrom Context
// and when unwrapping transparent proxy from our AppDomain, resolving types will fail because it looks only in the default Load context
// we simply help .Net by returning the already loaded assembly from the LoadFrom context
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
_pluginLoader = (PluginLoader)_domain.CreateInstanceFromAndUnwrap(
Assembly.GetExecutingAssembly().Location,
typeof(PluginLoader).FullName);
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve;
_domain.SetData(typeof(PluginLoader).FullName, _pluginLoader);
}
else
{
_domain = AppDomain.CurrentDomain;
_pluginLoader = new PluginLoader();
}
}
else
{
_domain = AppDomain.CurrentDomain;
_pluginLoader = (PluginLoader)AppDomain.CurrentDomain.GetData(typeof(PluginLoader).FullName);
}
}
示例2: CreateRemoteHost
protected override HostedService CreateRemoteHost(AppDomain appDomain)
{
appDomain.SetData("ConnectionString",_connectionString);
appDomain.DoCallBack(SetConnectionStringInAppDomain);
var service = base.CreateRemoteHost(appDomain);
return service;
}
示例3: SetShadowPathForNativeDll
public static void SetShadowPathForNativeDll(AppDomain appDomain, string dllFileName, string dllPath)
{
if (dllFileName == null) throw new ArgumentNullException("dllFileName");
if (dllPath == null) throw new ArgumentNullException("dllPath");
var key = AppDomainCustomDllPathKey + dllFileName.ToLowerInvariant();
appDomain.SetData(key, dllPath);
}
示例4: simpleButton1_Click
private void simpleButton1_Click(object sender, EventArgs e)
{
OpenFileDialog configform = new OpenFileDialog();
configform.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
configform.Filter = "程序集文件(*.dll,*.exe)|*.dll;*.exe";
configform.FilterIndex = 1;
configform.RestoreDirectory = true;
if (configform.ShowDialog() == DialogResult.OK)
{
try
{
if (currentDomain != null)
AppDomain.Unload(currentDomain);
currentDomain = AppDomain.CreateDomain("temp");
string configfile = configform.FileName + ".config";
string filedic = Path.GetDirectoryName(configform.FileName);
var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
if(File.Exists(configfile))
currentDomain.SetData("APP_CONFIG_FILE", configfile);
var test = currentDomain.SetupInformation;
exDataAccess = (ExDataAccess)currentDomain.CreateInstanceAndUnwrap(typeof(ExDataAccess).Assembly.FullName, typeof(ExDataAccess).FullName);
currentDomain.SetData("APPBASE", filedic);
m.Invoke(null, new object[] { funsion.Invoke(currentDomain, null), "APPBASE", filedic });
this.textEdit1.Text = configform.FileName;
var results = exDataAccess.FindAttributes(configform.FileName);
if (results.Count > 0)
{
this.treeList1.ClearNodes();
foreach (var result in results)
{
this.treeList1.Nodes.Add(result[0], result[1], result[2]);
}
}
currentDomain.SetupInformation.ConfigurationFile =configform.FileName+".config";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
示例5: Run
//private static void domain_DomainUnload(object sender, EventArgs e)
//{
// Trace.WriteLine("domain_DomainUnload()");
//}
static void Run(object runSourceRestartParameters)
{
__domain = AppDomain.CreateDomain(__runsourceDomainName);
if (runSourceRestartParameters != null)
{
__domain.SetData(__domainRestartParametersName, runSourceRestartParameters);
runSourceRestartParameters = null;
}
__domain.ExecuteAssembly(Path.Combine(zapp.GetAppDirectory(), __runsourceExeName));
}
示例6: ConfigureNewDomain
public void ConfigureNewDomain(AppDomain domain)
{
if (!string.IsNullOrWhiteSpace(AssemblyFolder))
domain.SetData("Folder", AssemblyFolder);
if (domain == AppDomain.CurrentDomain)
ResolveCustomAssemblies();
else
domain.DoCallBack(new CrossAppDomainDelegate(ResolveCustomAssemblies));
}
示例7: AssemblyStarter
//ncrunch: no coverage start
public AssemblyStarter(string assemblyFilePath, bool copyToLocalFolderForExecution)
{
if (!File.Exists(assemblyFilePath))
throw new FileNotFoundException("Assembly not found, unable to start it", assemblyFilePath);
rememberedDirectory = Directory.GetCurrentDirectory();
var assemblyFullPath = GetFullPathFromRelativeOrAbsoluteFilePath(assemblyFilePath);
if (copyToLocalFolderForExecution)
CopyAssemblyFileAndAllDependencies(assemblyFullPath);
else if (!string.IsNullOrEmpty(assemblyFullPath))
Directory.SetCurrentDirectory(assemblyFullPath);
domain = AppDomain.CreateDomain(DomainName, null, CreateDomainSetup(assemblyFullPath));
domain.SetData("EntryAssembly", Path.GetFullPath(assemblyFilePath));
}
示例8: CreateAndStartServerInstance
protected override IManagedAppBase CreateAndStartServerInstance()
{
IManagedApp appServer;
try
{
m_HostDomain = CreateHostAppDomain();
m_HostDomain.SetData(typeof(IsolationMode).Name, IsolationMode.AppDomain);
var marshalServerType = typeof(MarshalManagedApp);
appServer = (IManagedApp)m_HostDomain.CreateInstanceAndUnwrap(marshalServerType.Assembly.FullName,
marshalServerType.FullName,
true,
BindingFlags.CreateInstance,
null,
new object[] { GetMetadata().AppType },
null,
new object[0]);
if (!appServer.Setup(Bootstrap, Config))
{
OnExceptionThrown(new Exception("Failed to setup MarshalManagedApp"));
return null;
}
if (!appServer.Start())
{
OnExceptionThrown(new Exception("Failed to start MarshalManagedApp"));
return null;
}
m_HostDomain.DomainUnload += new EventHandler(m_HostDomain_DomainUnload);
return appServer;
}
catch (Exception e)
{
if (m_HostDomain != null)
{
AppDomain.Unload(m_HostDomain);
m_HostDomain = null;
}
OnExceptionThrown(e);
return null;
}
}
示例9: Start
/// <summary>
/// Starts this server instance.
/// </summary>
/// <returns>
/// return true if start successfull, else false
/// </returns>
protected override IWorkItemBase Start()
{
IWorkItem appServer;
try
{
m_HostDomain = CreateHostAppDomain();
m_HostDomain.SetData(typeof(IsolationMode).Name, IsolationMode.AppDomain);
var marshalServerType = typeof(MarshalAppServer);
appServer = (IWorkItem)m_HostDomain.CreateInstanceAndUnwrap(marshalServerType.Assembly.FullName,
marshalServerType.FullName,
true,
BindingFlags.CreateInstance,
null,
new object[] { ServerTypeName },
null,
new object[0]);
if (!appServer.Setup(Bootstrap, ServerConfig, Factories))
{
OnExceptionThrown(new Exception("Failed to setup MarshalAppServer"));
return null;
}
if (!appServer.Start())
{
OnExceptionThrown(new Exception("Failed to start MarshalAppServer"));
return null;
}
m_HostDomain.DomainUnload += new EventHandler(m_HostDomain_DomainUnload);
return appServer;
}
catch (Exception e)
{
if (m_HostDomain != null)
{
AppDomain.Unload(m_HostDomain);
m_HostDomain = null;
}
OnExceptionThrown(e);
return null;
}
}
示例10: CreateInstance
public static RemoteLoader CreateInstance(AppDomain remoteDomain, string csUnitRoot) {
try {
remoteDomain.SetData("csUnitRoot", csUnitRoot);
var remoteLoader = (RemoteLoader) remoteDomain.CreateInstanceFromAndUnwrap(
Path.Combine(csUnitRoot, "csUnit.Core.dll"),
typeof(RemoteLoader).FullName);
return remoteLoader;
}
catch (Exception ex) {
Debug.WriteLine(string.Format("## Listing assemblies in domain '{0}'##", remoteDomain.FriendlyName));
foreach (var assembly in remoteDomain.GetAssemblies()) {
Debug.WriteLine(assembly.FullName);
}
Debug.WriteLine("## end of list ##");
Debug.WriteLine("Could not instantiate remote loader. " + ex);
return null;
}
}
示例11: ProjectExecutionContext
public ProjectExecutionContext(Project project, IServiceProvider serviceProvider)
{
Debug.Assert(project != null, "project is null.");
Debug.Assert(!VsUtils.IsMiscellaneousProject(project), "project is misc files project.");
_domain = AppDomain.CreateDomain(
"ProjectExecutionContextDomain",
null,
new AppDomainSetup
{
ApplicationBase = VsUtils.GetProjectTargetDir(project, serviceProvider),
ConfigurationFile = VsUtils.GetProjectConfigurationFile(project, serviceProvider),
ShadowCopyFiles = "true" // Prevents locking
});
var dataDirectory = VsUtils.GetProjectDataDirectory(project, serviceProvider);
if (dataDirectory != null)
{
_domain.SetData("DataDirectory", dataDirectory);
}
_executor = new ExecutorWrapper(_domain, VsUtils.GetProjectTargetFileName(project));
}
示例12: InitializeAppDomain
/// <summary>
/// Initializes the application domain with the debugger proxy.
/// </summary>
/// <param name="scriptDomain">The script domain.</param>
internal static void InitializeAppDomain(AppDomain scriptDomain)
{
scriptDomain.SetData(VSDebuggerProxy.AppDomainDataName, debuggerProxy);
}
示例13: AssociateWithAppDomain
public void AssociateWithAppDomain(AppDomain domain) {
Contract.RequiresNotNull(domain, "domain");
domain.SetData(AppDomainDataKey, this);
}
示例14: LoadAllRunnersIntoAppDomain
private void LoadAllRunnersIntoAppDomain()
{
domain = AppDomain.CreateDomain("Delta Engine Assembly Updater", null, CreateDomainSetup());
domain.SetData("resolver", resolver);
domain.SetData("domainInitializationCode", domainInitializationCode);
domain.DoCallBack(InitializeInDomain);
foreach (string assembly in AssemblyFilenames)
LoadRunners(assembly);
}
示例15: Init
public void Init(bool fullBind)
{
string name = Path.GetRandomFileName();
tempDir = Path.Combine(Path.GetTempPath(), name);
string robocodeShadow = Path.Combine(tempDir, Path.GetFileName(robocodeAssembly.Location));
string hostShadow = Path.Combine(tempDir, Path.GetFileName(hostAssembly.Location));
string controlShadow = Path.Combine(tempDir, Path.GetFileName(controlAssembly.Location));
string jniShadow = Path.Combine(tempDir, Path.GetFileName(jniAssembly.Location));
Directory.CreateDirectory(tempDir);
File.Copy(robocodeAssembly.Location, robocodeShadow);
File.Copy(controlAssembly.Location, controlShadow);
File.Copy(hostAssembly.Location, hostShadow);
File.Copy(jniAssembly.Location, jniShadow);
var trustAssemblies = new[]
{
Reflection.GetStrongName(robocodeAssembly),
Reflection.GetStrongName(controlAssembly),
Reflection.GetStrongName(hostAssembly),
Reflection.GetStrongName(jniAssembly),
};
var domainSetup = new AppDomainSetup();
Evidence securityInfo = AppDomain.CurrentDomain.Evidence;
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(
new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.Assertion));
permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, tempDir));
permissionSet.AddPermission(new UIPermission(PermissionState.None));
//permissionSet.AddPermission(HostProtection);
domainSetup.ApplicationBase = tempDir;
domainSetup.ApplicationName = name;
//domainSetup.SandboxInterop = true;
domainSetup.DisallowBindingRedirects = true;
domainSetup.DisallowCodeDownload = true;
domainSetup.DisallowPublisherPolicy = true;
domainSetup.AppDomainInitializer = AppDomainSeed.Load;
domain = AppDomain.CreateDomain(name, securityInfo, domainSetup, permissionSet, trustAssemblies);
domain.SetData("fullBind", fullBind);
domain.SetData("JavaHome", Bridge.Setup.JavaHome);
domain.DoCallBack(AppDomainSeed.Bind);
}