AppDomainAndRunner GetOrCreateAppDomainRunner(AssemblyPath assembly)
        {
            AppDomainAndRunner appDomainAndRunner;

            if (_appDomains.TryGetValue(assembly, out appDomainAndRunner))
            {
                return(appDomainAndRunner);
            }

            var setup = new AppDomainSetup
            {
                ApplicationBase   = Path.GetDirectoryName(assembly),
                ApplicationName   = string.Format("Machine Specifications Runner"),
                ConfigurationFile = GetConfigFile(assembly)
            };

            if (!string.IsNullOrEmpty(_options.ShadowCopyCachePath))
            {
                setup.ShadowCopyFiles       = "true";
                setup.ShadowCopyDirectories = setup.ApplicationBase;
                setup.CachePath             = _options.ShadowCopyCachePath;
            }

            var appDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));

            var runner = CreateRunnerInSeparateAppDomain(appDomain, assembly);

            _appDomains.Add(assembly, new AppDomainAndRunner
            {
                AppDomain = appDomain,
                Runner    = runner
            });

            return(GetOrCreateAppDomainRunner(assembly));
        }
        public void RunNamespace(AssemblyPath assembly, string targetNamespace)
        {
            signalRunStart.Invoke();

            StartRun(assembly);
            GetOrCreateAppDomainRunner(assembly).Runner.RunNamespace(assembly, targetNamespace);
        }
        public void RunMember(AssemblyPath assembly, MemberInfo member)
        {
            signalRunStart.Invoke();

            StartRun(assembly);
            GetOrCreateAppDomainRunner(assembly).Runner.RunMember(assembly, member);
        }
        public override void ExecuteRecursive(TaskExecutionNode node)
        {
            var task = (RunAssemblyTask)node.RemoteTask;

            var priorCurrentDirectory = Environment.CurrentDirectory;
            try
            {
                // Use the assembly in the folder that the user has specified, or, if not, use the assembly location
                var assemblyFolder = GetAssemblyFolder(TaskExecutor.Configuration, task);
                var assemblyPath = new AssemblyPath(Path.Combine(assemblyFolder, GetFileName(task.AssemblyLocation)));

                Environment.CurrentDirectory = assemblyFolder;

                var listener = new PerAssemblyRunListener(Server, task);
                var contextList = new List<string>();
                node.Flatten(x => x.Children).Each(children => RegisterRemoteTaskNotifications(listener, children, contextList));

                var runOptions = RunOptions.Custom.FilterBy(contextList);
                var appDomainRunner = new AppDomainRunner(listener, runOptions);

                if (TaskExecutor.Configuration.ShadowCopy)
                {
                    string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                    runOptions.ShadowCopyTo(cachePath);
                    this.Server.SetTempFolderPath(cachePath);
                }

                appDomainRunner.RunAssembly(assemblyPath);
            }
            finally
            {
                Environment.CurrentDirectory = priorCurrentDirectory;
            }
        }
        public void StartRun(AssemblyPath assembly)
        {
            if (RunnerWasCreated(assembly))
            {
                return;
            }

            GetOrCreateAppDomainRunner(assembly).Runner.StartRun(assembly);
        }
        public void StartRun(AssemblyPath assembly)
        {
            if (RunnerWasCreated(assembly))
            {
                return;
            }

            GetOrCreateAppDomainRunner(assembly).Runner.StartRun(assembly);
        }
        ISpecificationRunner CreateRunnerInSeparateAppDomain(AppDomain appDomain, AssemblyPath assembly)
        {
#if !NETSTANDARD
            var mspecAssemblyFilename = Path.Combine(Path.GetDirectoryName(assembly), "Machine.Specifications.dll");

            if (!File.Exists(mspecAssemblyFilename))
            {
                return(new NullSpecificationRunner());
            }

            var mspecAssemblyName = AssemblyName.GetAssemblyName(mspecAssemblyFilename);

            var constructorArgs = new object[3];
            constructorArgs[0] = _listener;
            constructorArgs[1] = _options.ToXml();
            constructorArgs[2] = false;

            try
            {
                var defaultRunner = (IMessageSink)appDomain.CreateInstanceAndUnwrap(mspecAssemblyName.FullName,
                                                                                    RunnerType,
                                                                                    false,
                                                                                    0,
                                                                                    null,
                                                                                    constructorArgs,
                                                                                    null,
                                                                                    null,
                                                                                    null);
                return(new RemoteRunnerDecorator(defaultRunner));
            }
            catch (Exception err)
            {
                Console.Error.WriteLine("Runner failure: " + err);
                throw;
            }
#else
            var runnerType = Type.GetType($"{RunnerType}, Machine.Specifications");

            if (runnerType == null)
            {
                throw new InvalidOperationException("Machine.Specifications library not found");
            }

            var ctor = runnerType
                       .GetConstructors(BindingFlags.Instance | BindingFlags.Public)
                       .First(x => x.GetParameters().Length == 3);

            Runner.RunOptions options = new Runner.RunOptions(_options.IncludeTags, _options.ExcludeTags, _options.Filters);

            var listener = new ReflectionRunListener(_listener);
            var runner   = (Runner.ISpecificationRunner)ctor.Invoke(new object[] { listener, options, false });

            return(new ReflectionSpecificationRunner(runner));
#endif
        }
        static string GetConfigFile(AssemblyPath assembly)
        {
            var configFile = assembly + ".config";

            if (File.Exists(configFile))
            {
                return(configFile);
            }

            return(null);
        }
        public void EndRun(AssemblyPath assembly)
        {
            if (!RunnerWasCreated(assembly))
            {
                return;
            }

            var appDomainRunner = GetOrCreateAppDomainRunner(assembly);
            RemoveEntryFor(assembly);
            try
            {
                appDomainRunner.Runner.EndRun(assembly);
            }
            finally
            {
                UnloadAppDomain(appDomainRunner.AppDomain);
            }
        }
        public void EndRun(AssemblyPath assembly)
        {
            if (!RunnerWasCreated(assembly))
            {
                return;
            }

            var appDomainRunner = GetOrCreateAppDomainRunner(assembly);

            RemoveEntryFor(assembly);
            try
            {
                appDomainRunner.Runner.EndRun(assembly);
            }
            finally
            {
                UnloadAppDomain(appDomainRunner.AppDomain);
            }
        }
        ISpecificationRunner CreateRunnerInSeparateAppDomain(AppDomain appDomain, AssemblyPath assembly)
        {
            var mspecAssemblyFilename = Path.Combine(Path.GetDirectoryName(assembly), "Machine.Specifications.dll");

            if (!File.Exists(mspecAssemblyFilename))
            {
                return(new RemoteRunnerDecorator(new NullMessageSink()));
            }

            var mspecAssemblyName = AssemblyName.GetAssemblyName(mspecAssemblyFilename);

            var constructorArgs = new object[3];

            constructorArgs[0] = _listener;
            constructorArgs[1] = _options.ToXml();
            constructorArgs[2] = false;

            try
            {
                var defaultRunner = (IMessageSink)appDomain.CreateInstanceAndUnwrap(mspecAssemblyName.FullName,
                                                                                    "Machine.Specifications.Runner.Impl.DefaultRunner",
                                                                                    false,
                                                                                    0,
                                                                                    null,
                                                                                    constructorArgs,
                                                                                    null,
                                                                                    null,
                                                                                    null);
                return(new RemoteRunnerDecorator(defaultRunner));
            }
            catch (Exception err)
            {
                Console.Error.WriteLine("Runner failure: " + err);
                throw;
            }
        }
Пример #12
0
 public static XElement ToXml(this AssemblyPath path)
 {
     return(new XElement("assembly", Path.GetFullPath(path)));
 }
 public void RunNamespace(AssemblyPath assembly, string targetNamespace)
 {
 }
 bool RunnerWasCreated(AssemblyPath assembly)
 {
     return(_appDomains.ContainsKey(assembly));
 }
 public void RunAssembly(AssemblyPath assembly)
 {
     RunAssemblies(new[] { assembly });
 }
Пример #16
0
        public void RunMember(AssemblyPath assembly, MemberInfo member)
        {
            var root = new XElement("runner", new XElement("runmember", assembly.ToXml()));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root, member));
        }
        ISpecificationRunner CreateRunnerInSeparateAppDomain(AppDomain appDomain, AssemblyPath assembly)
        {
            var mspecAssemblyFilename = Path.Combine(Path.GetDirectoryName(assembly), "Machine.Specifications.dll");
            if (!File.Exists(mspecAssemblyFilename))
            {
                return new RemoteRunnerDecorator(new NullMessageSink());
            }

            var mspecAssemblyName = AssemblyName.GetAssemblyName(mspecAssemblyFilename);

            var constructorArgs = new object[3];
            constructorArgs[0] = _listener;
            constructorArgs[1] = _options.ToXml();
            constructorArgs[2] = false;

            try
            {
                var defaultRunner = (IMessageSink)appDomain.CreateInstanceAndUnwrap(mspecAssemblyName.FullName,
                    "Machine.Specifications.Runner.Impl.DefaultRunner",
                    false,
                    0,
                    null,
                    constructorArgs,
                    null,
                    null,
                    null);
                return new RemoteRunnerDecorator(defaultRunner);
            }
            catch (Exception err)
            {
                Console.Error.WriteLine("Runner failure: " + err);
                throw;
            }
        }
 public void RunMember(AssemblyPath assembly, MemberInfo member)
 {
     _signalRunStart.Invoke();
     StartRun(assembly);
     GetOrCreateAppDomainRunner(assembly).Runner.RunMember(assembly, member);
 }
 public void EndRun(AssemblyPath assembly)
 {
 }
 public void RunAssembly(AssemblyPath assembly)
 {
     RunAssemblies(new[] { assembly });
 }
 public void RunNamespace(AssemblyPath assembly, string targetNamespace)
 {
     _signalRunStart.Invoke();
     StartRun(assembly);
     GetOrCreateAppDomainRunner(assembly).Runner.RunNamespace(assembly, targetNamespace);
 }
        static string GetConfigFile(AssemblyPath assembly)
        {
            var configFile = assembly + ".config";

            if (File.Exists(configFile))
            {
                return configFile;
            }

            return null;
        }
 bool RunnerWasCreated(AssemblyPath assembly)
 {
     return _appDomains.ContainsKey(assembly);
 }
        AppDomainAndRunner GetOrCreateAppDomainRunner(AssemblyPath assembly)
        {
            AppDomainAndRunner appDomainAndRunner;
            if (_appDomains.TryGetValue(assembly, out appDomainAndRunner))
            {
                return appDomainAndRunner;
            }

            var setup = new AppDomainSetup
            {
                ApplicationBase = Path.GetDirectoryName(assembly),
                ApplicationName = string.Format("Machine Specifications Runner"),
                ConfigurationFile = GetConfigFile(assembly)
            };

            if (!string.IsNullOrEmpty(_options.ShadowCopyCachePath))
            {
                setup.ShadowCopyFiles = "true";
                setup.ShadowCopyDirectories = setup.ApplicationBase;
                setup.CachePath = _options.ShadowCopyCachePath;
            }

            var appDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));

            var runner = CreateRunnerInSeparateAppDomain(appDomain, assembly);

            _appDomains.Add(assembly, new AppDomainAndRunner
            {
                AppDomain = appDomain,
                Runner = runner
            });

            return GetOrCreateAppDomainRunner(assembly);
        }
 public void RunMember(AssemblyPath assembly, MemberInfo member)
 {
 }
        public void RunNamespace(AssemblyPath assembly, string targetNamespace)
        {
            var root = new XElement("runner", new XElement("runnamespace", assembly.ToXml(), new XElement("namespace", targetNamespace)));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root));
        }
 public void StartRun(AssemblyPath assembly)
 {
 }
Пример #28
0
        public void RunAssembly(AssemblyPath assembly)
        {
            var root = new XElement("runner", new XElement("runassembly", assembly.ToXml()));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root));
        }
 public void RunAssembly(AssemblyPath assembly)
 {
 }
 void RemoveEntryFor(AssemblyPath assembly)
 {
     _appDomains.Remove(assembly);
 }
Пример #31
0
        public void RunNamespace(AssemblyPath assembly, string targetNamespace)
        {
            var root = new XElement("runner", new XElement("runnamespace", assembly.ToXml(), new XElement("namespace", targetNamespace)));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root));
        }
 void RemoveEntryFor(AssemblyPath assembly)
 {
     _appDomains.Remove(assembly);
 }
 protected bool Equals(AssemblyPath other)
 {
     return string.Equals(specAssemblyPath, other.specAssemblyPath);
 }
 public void RunNamespace(AssemblyPath assembly, string targetNamespace)
 {
     runner.RunNamespace(Assembly.LoadFrom(assembly), targetNamespace);
 }
 public void StartRun(AssemblyPath assembly)
 {
     runner.StartRun(Assembly.LoadFrom(assembly));
 }
        public void RunMember(AssemblyPath assembly, MemberInfo member)
        {
            var root = new XElement("runner", new XElement("runmember", assembly.ToXml()));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root, member));
        }
 public void RunMember(AssemblyPath assembly, MemberInfo member)
 {
     runner.RunMember(Assembly.LoadFrom(assembly), member);
 }
 public void EndRun(AssemblyPath assembly)
 {
     runner.EndRun(Assembly.LoadFrom(assembly));
 }
Пример #39
0
        public void EndRun(AssemblyPath assembly)
        {
            var root = new XElement("runner", new XElement("endrun", assembly.ToXml()));

            remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root));
        }
        public void RunAssembly(AssemblyPath assembly)
        {
            var root = new XElement("runner", new XElement("runassembly", assembly.ToXml()));

            _remoteRunner.SyncProcessMessage(new RemoteRunnerMessage(root));
        }
Пример #41
0
 protected bool Equals(AssemblyPath other)
 {
     return(string.Equals(specAssemblyPath, other.specAssemblyPath));
 }
 public void RunAssembly(AssemblyPath assembly)
 {
     runner.RunAssembly(Assembly.LoadFrom(assembly));
 }