Beispiel #1
0
        public ConfigurationMockHelper(
            [NotNull, ItemNotNull] IEnumerable <string> additionalProbingPathsRelativeToTestDllsFolder,
            [NotNull, ItemNotNull] IEnumerable <string> pluginNames,
            [NotNull, ItemNotNull] IEnumerable <AssemblyInfo> assemblyElementInfos)
        {
            HashSet <string> allProbingPaths = new HashSet <string>();

            foreach (var relativeProbingPath in additionalProbingPathsRelativeToTestDllsFolder)
            {
                var absoluteProbingPath = $"{Path.Combine(TestFilesFolder, relativeProbingPath)}";
                if (!allProbingPaths.Contains(absoluteProbingPath))
                {
                    allProbingPaths.Add(absoluteProbingPath);
                }
            }

            _configurationMock = CreateElementMock <IConfiguration>("iocConfiguration");

            _assemblyLocator = new AssemblyLocator(() => _configurationMock.Object, Helpers.TestsEntryAssemblyFolder);
            _typeHelper      = new TypeHelper(_assemblyLocator, new TypeParser(),
                                              new PluginAssemblyTypeUsageValidator());

            ConfigureAdditionalProbingPaths(allProbingPaths);
            ConfigurePlugins(pluginNames, allProbingPaths);
            ConfigureAssemblies(assemblyElementInfos);

            _assemblyResolver = new AssemblyResolver(allProbingPaths.ToArray());
        }
Beispiel #2
0
        public TypeFinder(IAssemblyLocator assemblyLocator, IEventTypeFinder eventTypeFinder)
        {
            this.assemblyLocator = assemblyLocator;
            types = new Dictionary <string, Type>();

            var eventTypes = eventTypeFinder
                             .ListEventsTypes();

            eventTypeLookup = eventTypes
                              .ToDictionary(t => t.GetFullNameWihoutGenerics(), t => t);

            var lookupType = typeof(IEventConstraintHandler <>);
            var predicate  = new Func <Type, bool>(t => t.IsGenericType && t.GetGenericTypeDefinition() == lookupType);

            var lookup = assemblyLocator
                         .GetAssemblies()
                         .SelectMany(GetTypesSafely)
                         .Where(t => t.GetInterfaces().Any(predicate))
                         .Select(t => new { Handler = t, Type = t.GetInterfaces().First(predicate).GetGenericArguments()[0] })
                         .GroupBy(t => t.Type)
                         .ToDictionary(g => g.Key, g => g.Select(t => t.Handler));

            constraintHandlerTypes = eventTypes
                                     .SelectMany(ListInheritanceChange)
                                     .Distinct()
                                     .ToDictionary(type => type, type => lookup
                                                   .Where(kvp => kvp.Key.IsAssignableFrom(type))
                                                   .SelectMany(kvp => kvp.Value)
                                                   .ToList() as IEnumerable <Type>);
        }
Beispiel #3
0
        /// <summary>
        /// Gets an assembly reflector for a file.
        /// </summary>
        /// <returns>
        /// The reflector for the file.
        /// </returns>
        /// <param name='locator'>
        /// An assembly locator
        /// </param>
        /// <param name='path'>
        /// A file path
        /// </param>
        public virtual IAssemblyReflector GetReflectorForFile(IAssemblyLocator locator, string path)
        {
            if (reflector != null)
            {
                return(reflector);
            }

            // If there is a local copy of the cecil reflector, use it instead of the one in the gac
            Type   t;
            string asmFile = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "Mono.Addins.CecilReflector.dll");

            if (File.Exists(asmFile))
            {
                Assembly asm = Assembly.LoadFrom(asmFile);
                t = asm.GetType("Mono.Addins.CecilReflector.Reflector");
            }
            else
            {
                string refName = GetType().Assembly.FullName;
                int    i       = refName.IndexOf(',');
                refName = "Mono.Addins.CecilReflector.Reflector, Mono.Addins.CecilReflector" + refName.Substring(i);
                t       = Type.GetType(refName, false);
            }
            if (t != null)
            {
                reflector = (IAssemblyReflector)Activator.CreateInstance(t);
            }
            else
            {
                reflector = new DefaultAssemblyReflector();
            }

            reflector.Initialize(locator);
            return(reflector);
        }
        public TypeFinder()
        {
            assemblyLocator = GlobalHost.DependencyResolver.Resolve <IAssemblyLocator>();
            types           = new Dictionary <string, Type>();

            InitEventTypes();
            InitConstraintHandlerTypes();
        }
 public override IAssemblyReflector GetReflectorForFile(IAssemblyLocator locator, string path)
 {
     if (reflector == null)
     {
         reflector = new DomAssemblyReflector(solution);
     }
     return(reflector);
 }
Beispiel #6
0
 public BCLTestAssemblyDefinition(string name, IAssemblyLocator locator)
 {
     Name            = name ?? throw new ArgumentNullException(nameof(name));
     AssemblyLocator = locator ?? throw new ArgumentNullException(nameof(locator));
     // the following pattern is used when generating xunit test
     // assemblies
     IsXUnit = name.Contains("_xunit-test");
 }
 public TypeHelper([NotNull] IAssemblyLocator assemblyLocator,
                   [NotNull] ITypeParser typeParser,
                   [NotNull] IPluginAssemblyTypeUsageValidator pluginAssemblyTypeUsageValidator)
 {
     _assemblyLocator = assemblyLocator;
     _typeParser      = typeParser;
     _pluginAssemblyTypeUsageValidator = pluginAssemblyTypeUsageValidator;
 }
Beispiel #8
0
        public static IEnumerable <Assembly> AssembliesWithReferenceToAssemblyOf(this IAssemblyLocator assemblyLocator, Type type)
        {
            string assemblyName = type.Assembly.GetName().Name;

            return(assemblyLocator.GetAssemblies()
                   .Where(a => a.GetReferencedAssemblies()
                          .Any(r => r.Name == assemblyName)));
        }
Beispiel #9
0
 public AssemblyDefinitionFactory(TestingFramework testingFramework, IAssemblyLocator assemblyLocator)
 {
     _testingFramework = testingFramework;
     if (_testingFramework == TestingFramework.Unknown)
     {
         throw new ArgumentOutOfRangeException(nameof(_testingFramework));
     }
     AssemblyLocator = assemblyLocator ?? throw new ArgumentNullException(nameof(assemblyLocator));
 }
Beispiel #10
0
        //force it to use the cecil reflector. rhe SR one breaks easily under MSBuild
        public override IAssemblyReflector GetReflectorForFile(IAssemblyLocator locator, string path)
        {
            string   asmFile   = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "Mono.Addins.CecilReflector.dll");
            Assembly asm       = Assembly.LoadFrom(asmFile);
            Type     t         = asm.GetType("Mono.Addins.CecilReflector.Reflector");
            var      reflector = (IAssemblyReflector)Activator.CreateInstance(t);

            reflector.Initialize(locator);
            return(reflector);
        }
        public TypeFinder(IAssemblyLocator assemblyLocator, IEventTypeFinder eventTypeFinder)
        {
            this.assemblyLocator = assemblyLocator;
            types = new Dictionary <string, Type>();

            eventTypes = eventTypeFinder
                         .ListEventsTypes()
                         .ToDictionary(t => t.GetFullNameWihoutGenerics(), t => t);
            InitConstraintHandlerTypes();
        }
Beispiel #12
0
        public TestAssemblyDefinition(string assemblyFullPath, IAssemblyLocator assemblyLocator, bool isXunit)
        {
            if (string.IsNullOrEmpty(assemblyFullPath))
            {
                throw new ArgumentException(nameof(assemblyFullPath));
            }

            Name            = Path.GetFileName(assemblyFullPath);
            AssemblyLocator = assemblyLocator ?? throw new ArgumentNullException(nameof(assemblyLocator));
            IsXUnit         = isXunit;
        }
 public ProjectDefinition(string name, IAssemblyLocator locator, ITestAssemblyDefinitionFactory factory, List <ITestAssemblyDefinition> assemblies, string extraArgs)
 {
     Name                      = name ?? throw new ArgumentNullException(nameof(locator));
     AssemblyLocator           = locator ?? throw new ArgumentNullException(nameof(locator));
     TestAssemblies            = assemblies ?? throw new ArgumentNullException(nameof(assemblies));
     AssemblyDefinitionFactory = factory ?? throw new ArgumentNullException(nameof(factory));
     foreach (var a in TestAssemblies)
     {
         a.AssemblyLocator = AssemblyLocator;
     }
     ExtraArgs = extraArgs;
 }
Beispiel #14
0
 public ScriptCreatorService(ILogger <ScriptCreatorService> logger,
                             IRuntimeCompilerService compiler,
                             ApplicationPartManager apm,
                             IServiceCollection services,
                             IAssemblyLocator assemblyLocator)
 {
     _logger   = logger;
     _compiler = compiler;
     _services = services;
     _apm      = apm;
     _locator  = assemblyLocator as ScribiAssemblyLocator;
 }
Beispiel #15
0
        public DefaultTransport(IAssemblyLocator assemblyLocator)
        {
            this.primaryResetEvent = new ManualResetEvent(false);
            this.delayResetEvent   = new ManualResetEvent(false);

            this.primaryQueueName  = assemblyLocator.GetEntryAssembly().GetName().Name;
            this.delayQueueName    = string.Format("{0}_Delay", this.primaryQueueName);
            this.errorQueueName    = string.Format("{0}_Error", this.primaryQueueName);
            this.primaryQueue      = new InMemoryQueue();
            this.delayQueue        = new InMemoryQueue();
            this.errorQueue        = new InMemoryQueue();
            this.publishedMessages = new List <Object>();
        }
        public DefaultTransport(IAssemblyLocator assemblyLocator)
        {
            this.primaryResetEvent = new ManualResetEvent(false);
            this.delayResetEvent = new ManualResetEvent(false);

            this.primaryQueueName = assemblyLocator.GetEntryAssembly().GetName().Name;
            this.delayQueueName = string.Format("{0}_Delay", this.primaryQueueName);
            this.errorQueueName = string.Format("{0}_Error", this.primaryQueueName);
            this.primaryQueue = new InMemoryQueue();
            this.delayQueue = new InMemoryQueue();
            this.errorQueue = new InMemoryQueue();
            this.publishedMessages = new List<Object>();
        }
 public void Register(Type serviceType, Func <object> activator)
 {
     if (serviceType == typeof(IAssemblyLocator))
     {
         innerResolver.Register(serviceType, () =>
         {
             IAssemblyLocator inner = (IAssemblyLocator)activator();
             return(new SemanticLoggingSinkAssemblyLocator(inner));
         });
     }
     else
     {
         innerResolver.Register(serviceType, activator);
     }
 }
Beispiel #18
0
 public void Initialize(IAssemblyLocator locator)
 {
     this.locator            = locator;
     defaultAssemblyResolver = new DefaultAssemblyResolver();
     defaultAssemblyResolver.ResolveFailure += delegate(object sender, AssemblyNameReference reference) {
         var file = locator.GetAssemblyLocation(reference.FullName);
         if (file != null)
         {
             return(LoadAssembly(file, true));
         }
         else
         {
             return(null);
         }
     };
 }
        public ProjectDefinition(string name, IAssemblyLocator locator, ITestAssemblyDefinitionFactory factory, string [] assemblies, string extraArgs)
        {
            if (assemblies.Length == 0)
            {
                throw new ArgumentException("Most provide at least an assembly.");
            }

            Name                      = name ?? throw new ArgumentNullException(nameof(name));
            TestAssemblies            = new List <ITestAssemblyDefinition> (assemblies.Length);
            AssemblyLocator           = locator ?? throw new ArgumentNullException(nameof(locator));
            AssemblyDefinitionFactory = factory ?? throw new ArgumentNullException(nameof(factory));
            ExtraArgs                 = extraArgs;
            foreach (var assembly in assemblies)
            {
                TestAssemblies.Add(factory.Create(assembly, AssemblyLocator));
            }
        }
        internal static List<Type> GetTypesWithAttribute(IAssemblyLocator assemblyLocator,  Type attributeType)
        {
            string attributeAssemblyName = attributeType.Assembly.GetName().Name;

            List<Type> typesWithAttribute = new List<Type>();
            IEnumerable<Assembly> assemblies = assemblyLocator.GetAssemblies();
            
            foreach (Assembly assembly in assemblies)
            {
                AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
                if (referencedAssemblies.Count(a => a.Name == attributeAssemblyName) == 0)
                    continue;

                List<Type> typesWithAttributeInAssembly = GetTypesWithAttributeInAssembly(assembly, attributeType);
                typesWithAttribute.AddRange(typesWithAttributeInAssembly);
            }

            return typesWithAttribute;
        }
 public TimedJobService(IAssemblyLocator locator, IServiceProvider services)
 {
     this.services = services;
     this.locator = locator;
     this.logger = services.GetService<ILogger>();
     this.dynamicJobs = services.GetService<IDynamicTimedJobProvider>();
     var asm = locator.GetAssemblies();
     foreach (var x in asm)
     {
         // 查找基类为Job的类
         var types = x.DefinedTypes.Where(y => y.BaseType == typeof(Job)).ToList();
         foreach (var y in types)
         {
             JobTypeCollection.Add(y);
         }
     }
     StartHardTimers();
     if (dynamicJobs != null)
         StartDynamicTimers();
 }
        public GenericPollerProcess(IUnityContainer container)
        {
            _container      = container;
            _idGuid         = Guid.NewGuid();
            _totalStopwatch = new Stopwatch();

            _assemblyLocator  = this._container.Resolve <IAssemblyLocator>();
            _assemblyResolver = this._container.Resolve <IAssemblyResolver>();
            _logger           = (ContextLogger)this._container.Resolve <ILogger>();
            _tracer           = (ContextTracer)this._container.Resolve <ITracer>();

            var config = this._container.Resolve <GenericPollerConfiguration>();

            _pollerSleepMilliseconds = config.DefaultSleepMilliseconds;

            ConfigureAutoShutdown(config);

            this._logger.OtherData["GenericPollerVersion"] = Assembly.GetExecutingAssembly().FullName;
            this._tracer.OtherData["GenericPollerVersion"] = Assembly.GetExecutingAssembly().FullName;
        }
Beispiel #23
0
        internal static List <Type> GetTypesWithAttribute(IAssemblyLocator assemblyLocator, Type attributeType)
        {
            string attributeAssemblyName = attributeType.Assembly.GetName().Name;

            List <Type>            typesWithAttribute = new List <Type>();
            IEnumerable <Assembly> assemblies         = assemblyLocator.GetAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
                if (referencedAssemblies.Count(a => a.Name == attributeAssemblyName) == 0)
                {
                    continue;
                }

                List <Type> typesWithAttributeInAssembly = GetTypesWithAttributeInAssembly(assembly, attributeType);
                typesWithAttribute.AddRange(typesWithAttributeInAssembly);
            }

            return(typesWithAttribute);
        }
Beispiel #24
0
        public string GenerateModuleClassCode(IDynamicAssemblyBuilder dynamicAssemblyBuilder,
                                              IAssemblyLocator assemblyLocator,
                                              string moduleClassNamespace, string moduleClassName,
                                              IEnumerable <BindingConfigurationForFile> moduleServiceConfigurationElements)
        {
            // Lets add this assembly, since we are referencing DiHelper in auto-generated code.
            dynamicAssemblyBuilder.AddReferencedAssembly(typeof(AutofacDiManager));
            dynamicAssemblyBuilder.AddReferencedAssembly(typeof(ContainerBuilder));
            dynamicAssemblyBuilder.AddReferencedAssembly(typeof(AutofacRegistration));

            var moduleClassContents = new StringBuilder();

            moduleClassContents.AppendLine($"using Autofac;");

            moduleClassContents.AppendLine($"namespace {moduleClassNamespace}");
            moduleClassContents.AppendLine("{");

            moduleClassContents.AppendLine($"public class {moduleClassName} : {typeof(Module).FullName}");
            moduleClassContents.AppendLine("{");

            DiManagerImplementationHelper.AddCodeForOnDiContainerReadyMethod(moduleClassContents);

            // Add Load() method
            moduleClassContents.AppendLine($"protected override void Load({typeof(ContainerBuilder).FullName} builder)");
            moduleClassContents.AppendLine("{");
            moduleClassContents.AppendLine("base.Load(builder);");

            foreach (var service in moduleServiceConfigurationElements)
            {
                AddServiceBindings(moduleClassContents, service, dynamicAssemblyBuilder);
            }

            moduleClassContents.AppendLine("}");
            // End Load() method

            moduleClassContents.AppendLine("}");
            moduleClassContents.AppendLine("}");
            return(moduleClassContents.ToString());
        }
        public TimedJobService(IAssemblyLocator locator, IServiceProvider services)
        {
            this.services    = services;
            this.locator     = locator;
            this.logger      = services.GetService <ILogger>();
            this.dynamicJobs = services.GetService <IDynamicTimedJobProvider>();
            var asm = locator.GetAssemblies();

            foreach (var x in asm)
            {
                // 查找基类为Job的类
                var types = x.DefinedTypes.Where(y => y.BaseType == typeof(Job)).ToList();
                foreach (var y in types)
                {
                    JobTypeCollection.Add(y);
                }
            }
            StartHardTimers();
            if (dynamicJobs != null)
            {
                StartDynamicTimers();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentConfigurationProvider"/> class.
 /// </summary>
 /// <param name="persistenceConfigurerProvider">The persistence configurer provider.</param>
 /// <param name="assemblyLocator">The assembly locator.</param>
 public FluentConfigurationProvider( IPersistenceConfigurerProvider persistenceConfigurerProvider, IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
     _persistenceConfigurer = persistenceConfigurerProvider.Configure ();
 }
Beispiel #27
0
 public void Initialize(IAssemblyLocator locator)
 {
     this.locator = locator;
 }
		public void Initialize (IAssemblyLocator locator)
		{
		}
 /// <summary>
 ///     Set of assembly names without extension to fail loading, or locate.
 /// </summary>
 /// <param name="assemblyLocator"></param>
 public AssemblyLocatorMock([NotNull] IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
 }
 public DefaultQueueNameResolver(IAssemblyLocator assemblyLocator)
 {
     queueName = new Lazy<string>(() => assemblyLocator.GetEntryAssembly().GetName().Name);
 }
 public ReflectedHubDescriptorProvider(IAssemblyLocator locator, ILoggerFactory loggerFactory)
 {
     _locator = locator;
     _hubs    = new Lazy <IDictionary <string, HubDescriptor> >(BuildHubsCache);
     _logger  = loggerFactory.CreateLogger <ReflectedHubDescriptorProvider>();
 }
 public NHibernateStorageElement(IAssemblyLocator assemblyLocator, ITypeDiscoverer typeDiscoverer)
 {
     _assemblyLocator = assemblyLocator;
     _typeDiscoverer = typeDiscoverer;
     EntityContextType = typeof(EntityContext<>);
 }
Beispiel #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LookupTypeService"/> class.
 /// </summary>
 /// <param name="assemblyLocator">The assembly locator.</param>
 public LookupTypeService(IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
 }
Beispiel #34
0
 public void Initialize(IAssemblyLocator locator)
 {
     this.locator = locator;
 }
 public ReflectedHubDescriptorProvider(IAssemblyLocator locator, ILoggerFactory loggerFactory)
 {
     _locator = locator;
     _hubs = new Lazy<IDictionary<string, HubDescriptor>>(BuildHubsCache);
     _logger = loggerFactory.CreateLogger<ReflectedHubDescriptorProvider>();
 }
 public SynchronizationHookContext(IAssemblyLocator assemblyLocator)
 {
     AssemblyLocator = assemblyLocator;
 }
Beispiel #37
0
		public TypeDiscoverer(IAssemblyLocator assemblyLocator)
		{
			_assemblyLocator = assemblyLocator;
			_types = new List<Type>();
			CollectTypes();
		}
Beispiel #38
0
		public override IAssemblyReflector GetReflectorForFile (IAssemblyLocator locator, string path)
		{
			if (reflector == null)
				reflector = new DomAssemblyReflector (solution);
			return reflector;
		}
 public TabLocator(IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
 }
Beispiel #40
0
 public IndexModel(IAssemblyLocator locator, IOptions <DbMigrationOptions> option, IDbTool dbTool)
 {
     _locator = locator;
     _options = option.Value;
     _dbTool  = dbTool;
 }
		/// <summary>
		/// Gets an assembly reflector for a file.
		/// </summary>
		/// <returns>
		/// The reflector for the file.
		/// </returns>
		/// <param name='locator'>
		/// An assembly locator
		/// </param>
		/// <param name='path'>
		/// A file path
		/// </param>
		public virtual IAssemblyReflector GetReflectorForFile (IAssemblyLocator locator, string path)
		{
			if (reflector != null)
				return reflector;
			
			// If there is a local copy of the cecil reflector, use it instead of the one in the gac
			Type t;
			string asmFile = Path.Combine (Path.GetDirectoryName (GetType().Assembly.Location), "Mono.Addins.CecilReflector.dll");
			if (File.Exists (asmFile)) {
				Assembly asm = Assembly.LoadFrom (asmFile);
				t = asm.GetType ("Mono.Addins.CecilReflector.Reflector");
			}
			else {
				string refName = GetType().Assembly.FullName;
				int i = refName.IndexOf (',');
				refName = "Mono.Addins.CecilReflector.Reflector, Mono.Addins.CecilReflector" + refName.Substring (i);
				t = Type.GetType (refName, false);
			}
			if (t != null)
				reflector = (IAssemblyReflector) Activator.CreateInstance (t);
			else
				reflector = new DefaultAssemblyReflector ();
			
			reflector.Initialize (locator);
			return reflector;
		}
 public IISQueueNameResolver(IAssemblyLocator assemblyLocator)
     : base(assemblyLocator)
 {
 }
 public EmbeddedRavenDbStorageElement(IAssemblyLocator assemblyLocator)
 {
     EntityContextType = typeof(EntityContext<>);
     _assemblyLocator = assemblyLocator;
 }
 public GlobalPropertySettingsLocator(IAssemblyLocator assemblyLocator)
 {
     this.assemblyLocator = assemblyLocator;
 }
Beispiel #45
0
 public static IEnumerable <Assembly> AssembliesWithReferenceToAssemblyOf <T>(this IAssemblyLocator assemblyLocator)
 {
     return(assemblyLocator.AssembliesWithReferenceToAssemblyOf(typeof(T)));
 }
 public SemanticLoggingSinkAssemblyLocator(IAssemblyLocator innerLocator)
 {
     this.innerLocator = innerLocator;
 }
 public TabLocator(IAssemblyLocator assemblyLocator)
 {
     this.assemblyLocator = assemblyLocator;
 }
 public PageTypeDefinitionLocator(IAssemblyLocator assemblyLocator)
 {
     this.assemblyLocator = assemblyLocator;
 }
 public ConfigurationFileElementFactory([NotNull] IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
     _typeHelper      = IoCServiceFactoryAmbientContext.Context.CreateTypeHelper(_assemblyLocator);
     _classMemberValueInitializerHelper = IoCServiceFactoryAmbientContext.Context.CreateClassMemberValueInitializerHelper(_typeHelper);
 }
Beispiel #50
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LookupTypeService"/> class.
 /// </summary>
 /// <param name="assemblyLocator">The assembly locator.</param>
 public LookupTypeService(IAssemblyLocator assemblyLocator)
 {
     _assemblyLocator = assemblyLocator;
 }
 IEnumerable<Type> FindMigrations(IAssemblyLocator assemblyLocator)
 {
     return assemblyLocator.AssembliesWithReferenceToAssemblyOf<Migration>().TypesAssignableTo<Migration>().Concrete();
 }
 public SemanticLoggingSinkAssemblyLocator(IAssemblyLocator innerLocator)
 {
     this.innerLocator = innerLocator;
 }