protected Type GetType(MyAppDomain ad, string basename, string[] templateParam) { if (templateParam.Length > 0 && basename.IndexOf('`') == -1) { basename += "`" + templateParam.Length; } Type[] subtypes = new Type[templateParam.Length]; for (int i = 0; i < subtypes.Length; i++) { string bn = GetBase(templateParam[i]); string[] args = GetTemplateArguments(templateParam[i]); subtypes[i] = GetType(ad, bn, args); } Type t = GetType(basename); if (t != null && subtypes.Length > 0) { try { Type t2 = t.MakeGenericType(subtypes); System.Console.Error.WriteLine("returning type2: " + t2.FullName); return(t2); } catch (Exception e) { reportError(e); } } if (t != null) { System.Console.Error.WriteLine("returning type: " + t.FullName); } return(t); }
public void InjectBaseDirAndCheckConfigPathsTest() { string fakeBaseDir = @"y:\root\"; var old = LogFactory.CurrentAppDomain; try { var currentAppDomain = new MyAppDomain(); currentAppDomain.BaseDirectory = fakeBaseDir; LogFactory.CurrentAppDomain = currentAppDomain; //test 1 AssertLayoutRendererOutput("${basedir}", fakeBaseDir); //test 2 var paths = LogManager.LogFactory.GetCandidateConfigFilePaths().ToList(); var count = paths.Count(p => p.StartsWith(fakeBaseDir)); Assert.True(count > 0, string.Format("At least one path should start with '{0}'", fakeBaseDir)); } finally { //restore LogFactory.CurrentAppDomain = old; } }
public void TestFriendlyName() { MyAppDomain domain = new MyAppDomain(); Assert.AreEqual("MyFriendlyName", domain.GetFriendlyName()); Assert.AreEqual("MyFriendlyName", domain.FriendlyName); }
public void TestHashCode() { MyAppDomain domain1 = new MyAppDomain(); int hash1 = domain1.GetHashCode(); MyAppDomain domain2 = new MyAppDomain(); int hash2 = domain2.GetHashCode(); Assert.IsTrue(hash1 != hash2, "check we have two different domains"); }
public void TestDisposable() { MyAppDomain domain = new MyAppDomain(); AppDomain appDomain = domain.AppDomain; Assert.AreEqual("MyFriendlyName", appDomain.FriendlyName, "check for expected friendly name"); IDisposable disposable = (IDisposable)domain; disposable.Dispose(); }
public static void DomainMainGo() { string DataName = "MyData"; string DataValue = "Some Data to be stored"; Console.WriteLine("Retrieving current domain"); MyAppDomain Obj = new MyAppDomain(); Obj.Domain = AppDomain.CurrentDomain; Console.WriteLine("Setting domain data"); Obj.SetDomainData(DataName, DataValue); Console.WriteLine("Getting domain data"); Console.WriteLine($"The Data found for key{DataName},is{Obj.GetDomainData(DataName)},running on thread id: {Obj.ThreadId}"); }
public Task StartTask(CancellationTokenSource cancellationTokenSource) { Task = Task.Factory.StartNew(() => { Task.Factory.StartNew(() => { while (!cancellationTokenSource.IsCancellationRequested) { Thread.Sleep(TimeSpan.FromMilliseconds(500)); } if (cancellationTokenSource.IsCancellationRequested) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); } }, cancellationTokenSource.Token); Task.Factory.StartNew(() => { var nodeAppDomainSetup = new AppDomainSetup { ApplicationBase = DirectoryNodeAssemblyLocationFullPath.FullName, ApplicationName = NodeAssemblyName, ShadowCopyFiles = "true", ConfigurationFile = NodeconfigurationFile.FullName }; MyAppDomain = AppDomain.CreateDomain(NodeconfigurationFile.Name, null, nodeAppDomainSetup); var assemblyToExecute = new FileInfo(Path.Combine(nodeAppDomainSetup.ApplicationBase, nodeAppDomainSetup.ApplicationName)); this.Log().DebugWithLineNumber("Node (appdomain) will start with friendly name : " + MyAppDomain.FriendlyName); MyAppDomain.ExecuteAssembly(assemblyToExecute.FullName); }, cancellationTokenSource.Token); }, cancellationTokenSource.Token); return(Task); }
public void BaseDir_FixTempDir_ChoosesProcessDir() { var tempPath = System.IO.Path.GetTempPath(); var old = LogFactory.CurrentAppDomain; try { var currentAppDomain = new MyAppDomain(); currentAppDomain.BaseDirectory = tempPath; LogFactory.CurrentAppDomain = currentAppDomain; //test 1 AssertLayoutRendererOutput("${basedir}", tempPath); //test 2 AssertLayoutRendererOutput("${basedir:fixtempdir=true}", Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)); } finally { //restore LogFactory.CurrentAppDomain = old; } }
public static void Main(string[] arg) { try { bool first = true; string[] argv = null; if (arg.Length > 0) { argv = arg[0].Split(new string[] {sep}, StringSplitOptions.None); } else { argv = new string[0]; } MyAppDomain ad = new MyAppDomain(argv); while (true) { try { if (!first) // Just to indicate that there's no more output from the command and we're ready for new input System.Console.WriteLine(sep); first = false; string command = System.Console.ReadLine(); System.Console.Error.WriteLine("got: " + command); if (command == null) break; string[] args = Regex.Split(command, sep); ArrayList modules = null; if (args[0] == "-findclass") { modules = new ArrayList(); string line = null; try { while ((line = System.Console.ReadLine()) != null) { if (line == sep) break; modules.Add(line); } } catch (Exception) {} } if (!ad.Execute(args, modules)) { break; } } catch (Exception e) { reportError(e); } } } catch (Exception e) { reportError(e); } }
protected Type GetType(MyAppDomain ad, string basename, string[] templateParam) { if (templateParam.Length > 0 && basename.IndexOf('`') == -1) { basename += "`" + templateParam.Length; } Type[] subtypes = new Type[templateParam.Length]; for (int i = 0; i < subtypes.Length; i++) { string bn = GetBase(templateParam[i]); string[] args = GetTemplateArguments(templateParam[i]); subtypes[i] = GetType(ad, bn, args); } Type t = GetType(basename); if (t != null && subtypes.Length > 0) { try { Type t2 = t.MakeGenericType(subtypes); System.Console.Error.WriteLine("returning type2: " + t2.FullName); return t2; } catch (Exception e) { reportError(e); } } if (t != null) System.Console.Error.WriteLine("returning type: " + t.FullName); return t; }
public static void Main(string[] arg) { try { bool first = true; string[] argv = null; if (arg.Length > 0) { argv = arg[0].Split(new string[] { sep }, StringSplitOptions.None); } else { argv = new string[0]; } MyAppDomain ad = new MyAppDomain(argv); while (true) { try { if (!first) { // Just to indicate that there's no more output from the command and we're ready for new input System.Console.WriteLine(sep); } first = false; string command = System.Console.ReadLine(); System.Console.Error.WriteLine("got: " + command); if (command == null) { break; } string[] args = Regex.Split(command, sep); ArrayList modules = null; if (args[0] == "-findclass") { modules = new ArrayList(); string line = null; try { while ((line = System.Console.ReadLine()) != null) { if (line == sep) { break; } modules.Add(line); } } catch (Exception) {} } if (!ad.Execute(args, modules)) { break; } } catch (Exception e) { reportError(e); } } } catch (Exception e) { reportError(e); } }
public Task StartTask(int numberOfManagers, int numberOfNodes, bool useLoadBalancerIfJustOneManager, CancellationTokenSource cancellationTokenSource) { Task = Task.Factory.StartNew(() => { Task.Factory.StartNew(() => { while (!cancellationTokenSource.IsCancellationRequested) { Thread.Sleep(TimeSpan.FromMilliseconds(500)); } if (cancellationTokenSource.IsCancellationRequested) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); } }, cancellationTokenSource.Token); Task.Factory.StartNew(() => { string[] commandArguments = new string[3]; commandArguments[0] = "Managers=" + numberOfManagers; commandArguments[1] = "Nodes=" + numberOfNodes; commandArguments[2] = "UseLoadBalancerIfJustOneManager=" + useLoadBalancerIfJustOneManager; var assemblyLocationFullPath = Path.Combine(Settings.Default.ManagerIntegrationConsoleHostLocation, Buildmode); var directoryManagerAssemblyLocationFullPath = new DirectoryInfo(assemblyLocationFullPath); var configFileName = new FileInfo(Path.Combine(directoryManagerAssemblyLocationFullPath.FullName, Settings.Default.ManagerIntegrationConsoleHostConfigurationFile)); var managerAppDomainSetup = new AppDomainSetup { ApplicationBase = directoryManagerAssemblyLocationFullPath.FullName, ApplicationName = Settings.Default.ManagerIntegrationConsoleHostAssemblyName, ShadowCopyFiles = "true", AppDomainInitializerArguments = commandArguments, ConfigurationFile = configFileName.FullName }; MyAppDomain = AppDomain.CreateDomain(managerAppDomainSetup.ApplicationName, AppDomain.CurrentDomain.Evidence, managerAppDomainSetup); var assemblyToExecute = new FileInfo(Path.Combine(managerAppDomainSetup.ApplicationBase, managerAppDomainSetup.ApplicationName)); MyAppDomain.ExecuteAssembly(assemblyToExecute.FullName, managerAppDomainSetup.AppDomainInitializerArguments); }, cancellationTokenSource.Token); }, cancellationTokenSource.Token); return(Task); }