Beispiel #1
0
        public ITest LoadPlug(AppDomain appDomain, string assemblyFile, string classname)
        {
            ITest             test       = null;
            PlugLoadEventArgs loadEvent1 = new PlugLoadEventArgs();

            loadEvent1.PlugName      = classname;
            loadEvent1.AppDomainName = appDomain.FriendlyName;
            loadEvent1.AssemblyName  = assemblyFile;

            if (LoadingPlug != null)
            {
                LoadingPlug(this, loadEvent1);
            }

            try
            {
                //Assembly assembly = Assembly.LoadFrom(appDomain.BaseDirectory + assemblyName + ".dll");
                //test = (ITest)assembly.CreateInstance(classname);
                test = (ITest)appDomain.CreateInstanceFromAndUnwrap(assemblyFile, classname);

                if (test != null)
                {
                    if (test is MarshalByRefObject && appDomain != AppDomain.CurrentDomain)
                    {
                        sponsorer.Register((MarshalByRefObject)test);
                    }

                    //TODO: setOutput here...
                    loadEvent1.TestName = test.Name;

                    if (PlugLoaded != null)
                    {
                        PlugLoaded(this, loadEvent1);
                    }

                    test.InitTest();
                }
            }
            catch (Exception ex)
            {
                //addException(ex);
                loadEvent1.ExceptionInfo = BaseUtils.GetExceptionInfo(ex);

                if (PlugLoadException != null)
                {
                    PlugLoadException(this, loadEvent1);
                }
            }

            return(test);
        }
Beispiel #2
0
        public ITest[] LoadAllPlugs(IPlugLoadInfo info)
        {
            //resetMessages();
            ArrayList tests = new ArrayList();

            string assemblyName  = null;
            string appDomainName = null;

            try
            {
                string[] assemblies = info.GetAssemblyFiles();
                for (int i = 0; i < assemblies.Length; i++)
                {
                    assemblyName  = assemblies[i];
                    appDomainName = info.GetAppDomainName(assemblies[i]);

                    AppDomain appDomain = LoadAppDomain(appDomainName);
                    string[]  testcases = info.GetTestsFromAssembly(assemblyName);

                    LoadAllPlugs(assemblyName, appDomain, testcases, tests);
                }
            }
            catch (Exception e)
            {
                PlugLoadEventArgs loadEvent = new PlugLoadEventArgs();
                loadEvent.AppDomainName = appDomainName;
                loadEvent.AssemblyName  = assemblyName;
                loadEvent.ExceptionInfo = BaseUtils.GetExceptionInfo(e);

                if (PlugLoadException != null)
                {
                    PlugLoadException(this, loadEvent);
                }
            }

            //message += "\n\nDone !\n\n";
            ITest[] ret = new ITest[tests.Count];
            for (int i = 0; i < tests.Count; i++)
            {
                ret[i] = (ITest)tests[i];
            }
            //return (ITest[])tests.ToArray(typeof(ITest));
            return(ret);
        }
Beispiel #3
0
        public AppDomain LoadAppDomain(string appDomainName)
        {
            PlugLoadEventArgs loadEvent1 = new PlugLoadEventArgs();

            loadEvent1.AppDomainName = appDomainName;

            if (LoadingAppDomain != null)
            {
                LoadingAppDomain(this, loadEvent1);
            }

            AppDomain appDomain;

            if (appDomainName == null || string.Empty.Equals(appDomainName) ||
                "default".Equals(appDomainName))
            {
                appDomain = AppDomain.CurrentDomain;
            }
            else if (appDomainTable.Contains(appDomainName))
            {
                appDomain = (AppDomain)appDomainTable[appDomainName];
            }
            else
            {
                //AppDomainSetup appSetup = new AppDomainSetup();
                AppDomainSetup appSetup = AppDomain.CurrentDomain.SetupInformation;
                appSetup.ApplicationName    = appDomainName;
                appSetup.ShadowCopyFiles    = "true";
                appSetup.LoaderOptimization = LoaderOptimization.MultiDomain;

                appDomain = AppDomain.CreateDomain(appDomainName, AppDomain.CurrentDomain.Evidence, appSetup);

                if (appDomain != null && !appDomainTable.Contains(appDomain.FriendlyName))
                {
                    appDomainTable.Add(appDomain.FriendlyName, appDomain);
                    if (AppDomainLoaded != null)
                    {
                        AppDomainLoaded(this, loadEvent1);
                    }
                }
            }

            return(appDomain);
        }
Beispiel #4
0
        private bool Unload(ref AppDomain appDomain)
        {
            bool success = false;

            PlugLoadEventArgs plea = new PlugLoadEventArgs();
            string            name = appDomain.FriendlyName;

            plea.AppDomainName = name;//TODO: check this !

            if (UnloadingAppDomain != null)
            {
                UnloadingAppDomain(this, plea);
            }

            try
            {
                if (appDomain != null)
                {
                    AppDomain.Unload(appDomain);
                    appDomain = null;
                    appDomainTable.Remove(name);

                    if (AppDomainUnloaded != null)
                    {
                        AppDomainUnloaded(this, plea);
                    }
                }
            }
            catch (Exception e)
            {
                plea.ExceptionInfo = BaseUtils.GetExceptionInfo(e);

                if (AppDomainUnloaded != null)
                {
                    AppDomainUnloaded(this, plea);
                }

                success = false;
            }

            return(success);
        }
Beispiel #5
0
        public ITest LoadPlug(string appDomainName, string assemblyFile, string classname)
        {
            try
            {
                AppDomain appDomain = LoadAppDomain(appDomainName);
                return(LoadPlug(appDomain, assemblyFile, classname));
            }
            catch (Exception e)
            {
                PlugLoadEventArgs loadEvent = new PlugLoadEventArgs();
                loadEvent.AppDomainName = appDomainName;
                loadEvent.AssemblyName  = assemblyFile;
                loadEvent.ExceptionInfo = BaseUtils.GetExceptionInfo(e);

                if (PlugLoadException != null)
                {
                    PlugLoadException(this, loadEvent);
                }
            }
            return(null);
        }