Esempio n. 1
0
            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);
            }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
        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();
 }
Esempio n. 6
0
        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");
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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}");
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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;
            }
        }
Esempio n. 11
0
    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);
        }
    }
Esempio n. 12
0
            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 TestFriendlyName()
 {
     MyAppDomain domain = new MyAppDomain();
     Assert.AreEqual("MyFriendlyName", domain.GetFriendlyName());
     Assert.AreEqual("MyFriendlyName", domain.FriendlyName);
 }
Esempio n. 14
0
    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);
        }
    }
Esempio n. 15
0
        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);
        }