public void GenerateCode(Type[] types) { var actorTypes = types.Where(t => Utility.IsActorInterface(t)).ToArray(); var observerTypes = types.Where(t => Utility.IsObserverInterface(t)).ToArray(); var actorCodeGen = new InterfacedActorCodeGenerator() { Options = Options }; foreach (var type in actorTypes) actorCodeGen.GenerateCode(type, CodeWriter); var observerCodeGen = new InterfacedObserverCodeGenerator() { Options = Options }; foreach (var type in observerTypes) observerCodeGen.GenerateCode(type, CodeWriter); }
static Type GetServiceSpecification(Type[] types) { return types .Where(x => x.HasInterface<IServiceSpecification>()) .DefaultIfEmpty(typeof(DefaultServiceSpecification)) .FirstOrDefault(); }
public void CheckTables(Type[] types, int unitNumber) { foreach (var type in types.Where(type => !TableExist(type.Name + unitNumber.ToString()))) { CreateTable(type); } }
public static ComponentInfo[] GetComponentInfos(Type[] types) { return types .Where(type => !type.IsInterface) .Where(type => type.GetInterfaces().Any(i => i.FullName == "Entitas.IComponent")) .Select(type => CreateComponentInfo(type)) .ToArray(); }
public static Type[] TargetTypesToRun(Type[] availableTypes) { var targetTypesToRun = availableTypes .Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(Spec))) .Select(t => t) .ToArray(); return targetTypesToRun; }
public static Type[] GetSystems(Type[] types) { return types .Where(type => !type.IsInterface && type != typeof(ReactiveSystem) && type != typeof(Systems) && type.GetInterfaces().Contains(typeof(ISystem))) .ToArray(); }
/// <summary> /// Provides the ability to pass in and configure femah with a predefined collection of FeatureSwitchTypes, i.e. those /// types implementing IFeatureSwitch. Predominantly used for unit testing purposes, allowing us to configure femah with /// a known subset of FeatureSwitchTypes. /// </summary> /// <param name="types" type="Type[]">An array containing the FeatureSwitchTypes to configure</param> /// <returns type="FemahFluentConfiguration" /> public FemahFluentConfiguration WithSelectedFeatureSwitchTypes(Type[] types) { foreach (var t in types.Where(t => t.GetInterfaces().Contains(typeof(IFeatureSwitch)))) { _config.StandardSwitchTypes.Add(t); } return this; }
//TODO remove duplicate query public static Type[] TargetTypesToRun(IEnumerable<DefinitionSource> typesSources, Type[] availableTypes) { var targetTypesToRun = availableTypes .Where(t => !t.IsAbstract && t.IsSubclassOf(typeof (Spec))) .Where(t => typesSources.Select(x => x.ClassName).Distinct().Contains(t.FullName, StringComparer.OrdinalIgnoreCase)) .Select(t => t) .ToArray(); return targetTypesToRun; }
public IEnumerable<SqlQuery> PrepareQueries(Type[] types, bool onlyEnabledQueries = true) { // Search for types with at least one attribute that have a QueryAttribute return types.Where(t => !_ignoreTypes.Contains(t)) .SelectMany(t => t.GetCustomAttributes<QueryAttribute>() .Where(a => !onlyEnabledQueries || a.Enabled) .Select(a => new SqlQuery(t, a, _dapper))) .ToArray(); }
public object Create(Type[] typesToProxy, object[] constructorArguments) { var callRouter = _callRouterFactory.Create(_context); var primaryProxyType = GetPrimaryProxyType(typesToProxy); var additionalTypes = typesToProxy.Where(x => x != primaryProxyType).ToArray(); var proxy = _proxyFactory.GenerateProxy(callRouter, primaryProxyType, additionalTypes, constructorArguments); _callRouterResolver.Register(proxy, callRouter); return proxy; }
public BaseApp FindBaseApp(Type[] assemblyTypes) { foreach (var t in assemblyTypes.Where(t => t.BaseType == typeof(BaseApp))) { return (BaseApp) Activator.CreateInstance(t); } throw new TypeLoadException("No class found subclassing BaseApp"); }
public static void ConfigureMapper(Type[] types) { var mapTypes = types.Where(t=>IsDefined(t,typeof(AutoMapAttribute)) ||IsDefined(t,typeof(AutoMapFromAttribute)) ||IsDefined(t,typeof(AutoMapToAttribute))); foreach (var type in mapTypes) { MapType(type); } }
public CodeGenFile[] Generate(Type[] components) { return components .Where(shouldGenerate) .Aggregate(new List<CodeGenFile>(), (files, type) => { files.Add(new CodeGenFile { fileName = type + CLASS_SUFFIX, fileContent = generateComponentExtension(type).ToUnixLineEndings() }); return files; }).ToArray(); }
public CodeGenFile[] Generate(Type[] components) { return components .Where(shouldGenerate) .Aggregate(new List<CodeGenFile>(), (files, type) => { files.Add(new CodeGenFile { fileName = type + classSuffix, fileContent = generateComponentExtension(type) }); return files; }).ToArray(); }
public CodeGenFile[] Generate(Type[] systems) { return systems .Where(type => type.GetConstructor(new Type[0]) != null) .Aggregate(new List<CodeGenFile>(), (files, type) => { files.Add(new CodeGenFile { fileName = type + CLASS_SUFFIX, fileContent = string.Format(CLASS_TEMPLATE, type.Name, type).ToUnixLineEndings() }); return files; }) .ToArray(); }
public static ResourceQuery ParseUrnQuery(this Uri urn, Type [] models) { var urlModelLookup = models .Where(type => type.ContainsCustomAttribute<ResourceTypeAttribute>()) .Select(type => { var resourceTypeAttr = type.GetCustomAttribute<ResourceTypeAttribute>(); return new KeyValuePair<string, Type>(resourceTypeAttr.Urn, type); }) .ToDictionary(); return new ResourceQuery(); }
public CodeGenFile[] Generate(Type[] systems) { return systems .Where(type => type.GetConstructor(new Type[0]) != null) .Aggregate(new List<CodeGenFile>(), (files, type) => { files.Add(new CodeGenFile { fileName = type + classSuffix, fileContent = string.Format(classTemplate, type.Name, type) }); return files; }) .ToArray(); }
/// <summary> /// /// </summary> /// <param name="game"></param> /// <param name="types"></param> void Initialize ( Game game, Type[] types ) { Context = null; Game = game; commands = types .Where( t1 => t1.IsSubclassOf(typeof(Command)) ) .Where( t2 => t2.HasAttribute<CommandAttribute>() ) .ToDictionary( t3 => t3.GetCustomAttribute<CommandAttribute>().Name ); CommandList = commands.Select( cmd => cmd.Key ).OrderBy( name => name ).ToArray(); Log.Message("Invoker: {0} commands found", commands.Count); }
IEnumerable<ObservableTemplate> GenerateTemplates(Type[] types) { return types.Where(t => t.IsInterface && t.GetInterfaces().Any(i => i == typeof(Ch.Elca.Iiop.Idl.IIdlEntity))) .Distinct() .GroupBy(t => t.Namespace) .Select(g => new ObservableTemplate { Namespace = g.Key, ClassTemplates = g.Select(t => new ClassTemplate(t)) .Where(t => t.MethodTemplates.Any()) .ToArray() }) .Where(a => a.ClassTemplates.Any()) .OrderBy(a => a.Namespace); }
/// <summary> /// Prepare the specified types. /// </summary> public static void Prepare(Type[] types) { if (!types.Any()) return; if (types.Any(NothingToDo.With)) throw new InvalidOperationException( "Unable to make proxies for types: " + string.Join(", ", types.Where(NothingToDo.With))); var unpreparedTypes = types .Where(t => !proxies.ContainsKey(t)) .ToArray(); var compiledAssembly = MakeAssembly(cu => { cu.ReferencedAssemblies.Add(ShieldedDll); foreach (var loc in unpreparedTypes.SelectMany(GetReferences).Distinct()) cu.ReferencedAssemblies.Add(loc); foreach (var t in unpreparedTypes) PrepareType(t, cu); }); foreach (var t in unpreparedTypes) proxies.TryAdd(t, compiledAssembly.GetType( t.Namespace + "." + GetNameForDerivedClass(t))); }
/// <summary> /// Ensures a type contract with multiple typed arguments. /// </summary> public static bool Ensure(object[] objects, Type[] typeContract, int optionalCount = 0) { if (optionalCount > typeContract.Length) throw new ArgumentOutOfRangeException(nameof(optionalCount)); if (objects.Length + optionalCount < typeContract.Length) return false; return !typeContract.Where((t, i) => { if (t == null) return false; if (objects.Length <= i) return i < typeContract.Length - optionalCount; return objects[i] != null && objects[i].GetType() != t; }).Any(); }
private static IEnumerable<Type> SearchAssemblyForType(Type type, bool includeTypeItself, Assembly assembly) { var types = new Type[0]; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { Trace.TraceInformation(ex.Message); } foreach (Type matchingType in types.Where( t => (type.IsGenericAssignableFrom(t) || type.IsAssignableFrom(t)) && (includeTypeItself || (t != type)) && (includeTypeItself || !t.IsAbstract))) { yield return matchingType; } }
public static ComponentInfo[] GetComponentInfos(Type[] types) { var infosFromComponents = types .Where(type => !type.IsInterface) .Where(type => !type.IsAbstract) .Where(type => type.GetInterfaces().Any(i => i.FullName == "Entitas.IComponent")) .Select(type => CreateComponentInfo(type)); var infosForNonComponents = types .Where(type => !type.IsGenericType) .Where(type => !type.GetInterfaces().Any(i => i.FullName == "Entitas.IComponent")) .Where(type => GetPools(type).Length > 0) .SelectMany(type => CreateComponentInfosForClass(type)); var generatedComponentsLookup = infosForNonComponents.ToLookup(info => info.fullTypeName); return infosFromComponents .Where(info => !generatedComponentsLookup.Contains(info.fullTypeName)) .Concat(infosForNonComponents) .ToArray(); }
public IEnumerable<MethodInfo> FindAvailableMethods(Type[] types) { if (!string.IsNullOrEmpty(TypeName)) { types = types.Where(type => type.Name == TypeName).ToArray(); if (!types.Any()) { var message = string.Format("No type named '{0}' could be found.", TypeName); throw new InvalidOperationException(message); } } const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; return types.SelectMany(type => type.GetMethods(bindingFlags) .OrderByDescending(method => method.GetParameters().Length)); }
static Dictionary<string, Type[]> getLookups(Type[] components) { var currentIndex = 0; var orderedComponents = components .Where(shouldGenerate) .Aggregate(new Dictionary<Type, string[]>(), (acc, type) => { acc.Add(type, type.IndicesLookupTags()); return acc; }) .OrderByDescending(kv => kv.Value.Length); return orderedComponents .Aggregate(new Dictionary<string, Type[]>(), (lookups, kv) => { var type = kv.Key; var lookupTags = kv.Value; var incrementIndex = false; foreach (var lookupTag in lookupTags) { if (!lookups.ContainsKey(lookupTag)) { lookups.Add(lookupTag, new Type[components.Length]); } var types = lookups[lookupTag]; if (lookupTags.Length == 1) { for (int i = 0; i < types.Length; i++) { if (types[i] == null) { types[i] = type; break; } } } else { types[currentIndex] = type; incrementIndex = true; } } if (incrementIndex) { currentIndex++; } return lookups; }); }
/// <summary> /// Method that implements parameter binding hookup to the global configuration object's /// ParameterBindingRules collection delegate. /// /// This routine filters based on POST/PUT method status and simple parameter /// types. /// </summary> /// <example> /// GlobalConfiguration.Configuration. /// .ParameterBindingRules /// .Insert(0,SimplePostVariableParameterBinding.HookupParameterBinding); /// </example> /// <param name="descriptor"></param> /// <returns></returns> public static HttpParameterBinding HookupParameterBinding(HttpParameterDescriptor descriptor) { var supportedMethods = descriptor.ActionDescriptor.SupportedHttpMethods; // Only apply this binder on POST and PUT operations if (supportedMethods.Contains(HttpMethod.Post) || supportedMethods.Contains(HttpMethod.Put)) { var supportedTypes = new Type[] { typeof(string), typeof(int), typeof(decimal), typeof(double), typeof(bool), typeof(DateTime), typeof(byte[]) }; if (supportedTypes.Where(typ => typ == descriptor.ParameterType).Count() > 0) return new SimplePostVariableParameterBinding(descriptor); } return null; }
public static IEnumerable<ServiceBinding> FindTopLevelServices(Type genericInterfaceTypeDefinition, Type interfaceType, Type[] typesToSearch) { if (genericInterfaceTypeDefinition == null) { throw Error.ArgumentNull("genericInterfaceTypeDefinition"); } if (interfaceType == null) { throw Error.ArgumentNull("interfaceType"); } if (typesToSearch == null) { throw Error.ArgumentNull("typesToSearch"); } return typesToSearch .Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == genericInterfaceTypeDefinition) && Enumerable.Any<Type>(t.GetTopLevelInterfaces(), interfaceType.IsAssignableFrom)) .SelectMany(t => t.GetTopLevelInterfaces().Where(interfaceType.IsAssignableFrom), (t, i) => new { InterfaceType = i, ImplementerType = t }) .Select(b => new ServiceBinding(b.InterfaceType, b.ImplementerType)) .ToArray(); }
/// <summary> /// Ensures a type contract with multiple typed argument, with multiple types per argument. /// </summary> public static bool Ensure(object[] objects, Type[][] typeContract, int optionalCount = 0) { if (optionalCount > typeContract.Length) throw new ArgumentOutOfRangeException(nameof(optionalCount)); if (objects.Length + optionalCount < typeContract.Length) return false; return !typeContract.Where((types, i) => { if (types == null || types.Length == 0) return false; if (objects.Length <= i) return i < typeContract.Length - optionalCount; if (objects[i] != null) { var type = objects[i].GetType(); return types.Any(t => type == t); } return false; }).Any(); }
public static Type[] GetComponents(Type[] types) { return types .Where(type => type.GetInterfaces().Contains(typeof(IComponent))) .ToArray(); }
public async Task SetupAsync(Type[] allMessageTypes, Type[] recievingMessageTypes) { _logger.Debug("Starting the setup of AzureServicebusTransport..."); _namespaceManager = NamespaceManager.CreateFromConnectionString(_configuration.GetConnectionString()); _messagingFactory = MessagingFactory.CreateFromConnectionString(_configuration.GetConnectionString()); _messageTypes = allMessageTypes; var sendCommandTypes = _messageTypes .Where(t => typeof (IBusCommand) .IsAssignableFrom(t)); var sendEventTypes = _messageTypes .Where(t => typeof(IBusEvent) .IsAssignableFrom(t)); var recieveCommandTypes = recievingMessageTypes .Where(t => typeof(IBusCommand) .IsAssignableFrom(t)); var recieveEventTypes = recievingMessageTypes .Where(t => typeof(IBusEvent) .IsAssignableFrom(t)); if (_configuration.GetEnableTopicAndQueueCreation()) { foreach (var type in sendCommandTypes) { var path = PathFactory.QueuePathFor(type); if (!_namespaceManager.QueueExists(path)) await _namespaceManager.CreateQueueAsync(path); var client = _messagingFactory.CreateQueueClient(path); client.PrefetchCount = 10; //todo;: in config? var eventDrivenMessagingOptions = new OnMessageOptions { AutoComplete = true, //todo: in config? MaxConcurrentCalls = 10 //todo: in config? }; eventDrivenMessagingOptions.ExceptionReceived += OnExceptionReceived; client.OnMessageAsync(OnMessageRecieved, eventDrivenMessagingOptions); if (!_queues.TryAdd(type, client)) { _logger.Error("Could not add the queue with type: {0}", type.FullName); } } foreach (var type in sendEventTypes) { var path = PathFactory.TopicPathFor(type); if (!_namespaceManager.TopicExists(path)) _namespaceManager.CreateTopic(path); var client = _messagingFactory.CreateTopicClient(path); if (!_topics.TryAdd(type, client)) { _logger.Error("Could not add the topic with type: {0}", type.FullName); } } } _logger.Debug("Setup of AzureServicebusTransport completed!"); throw new NotImplementedException(); }