private void Set(ClassConfig classConfig, FactoryAttribute attribute) { if (attribute is ClassConfigAttribute cca) { cca.SetConfigValue(classConfig); } }
private static bool ShouldGenerateGetGrainMethods(Type type) { // we don't generate these methods if this is a client object factory. var factoryType = FactoryAttribute.CollectFactoryTypesSpecified(type); return(factoryType != FactoryAttribute.FactoryTypes.ClientObject); }
protected override void InitSimulation(int seed, LevelInfo level, PlayerInfo[] players, Slot[] slots) { Assembly levelAssembly = Assembly.Load(level.Type.AssemblyFile); Type levelType = levelAssembly.GetType(level.Type.TypeName); SimulationContext context = new SimulationContext( ExtensionLoader.DefaultTypeResolver, ExtensionLoader.ExtensionSettings); simulation = Activator.CreateInstance(levelType, context) as Level; // Player erzeugen LevelSlot[] levelSlots = new LevelSlot[AntMe.Level.MAX_SLOTS]; for (int i = 0; i < AntMe.Level.MAX_SLOTS; i++) { // Skipp, falls nicht vorhanden if (players[i] == null) { continue; } Assembly playerAssembly = Assembly.Load(players[i].Type.AssemblyFile); Type factoryType = playerAssembly.GetType(players[i].Type.TypeName); // Identify Name var playerAttributes = factoryType.GetCustomAttributes(typeof(FactoryAttribute), true); if (playerAttributes.Length != 1) { throw new Exception("Player does not have the right number of Player Attributes"); } FactoryAttribute playerAttribute = playerAttributes[0] as FactoryAttribute; // Find the right Mapping var mappingAttributes = playerAttribute.GetType(). GetCustomAttributes(typeof(FactoryAttributeMappingAttribute), false); if (mappingAttributes.Length != 1) { throw new Exception("Player Attribute has no valid Property Mapping Attribute"); } FactoryAttributeMappingAttribute mappingAttribute = mappingAttributes[0] as FactoryAttributeMappingAttribute; // Werte auslesen string name = playerAttribute.GetType().GetProperty(mappingAttribute.NameProperty). GetValue(playerAttribute, null) as string; levelSlots[i] = new LevelSlot() { FactoryType = factoryType, Name = name, Color = slots[i].ColorKey, Team = slots[i].Team }; } // Level initialisieren simulation.Init(seed, levelSlots); }
private static void ConfigureServices(IServiceCollection services, IConfiguration config) { var assemblies = new[] { Assembly.GetExecutingAssembly() }; BindingAttribute.ConfigureBindings(services, assemblies); OptionsAttribute.ConfigureOptions(services, config, assemblies); FactoryAttribute.ConfigureFactories(services, assemblies); services.ConfigureApiClient(); services.AddSingleton(config); services.AddSingleton <IFileSystem, FileSystem>(); services.AddDbContext <ManagementDbContext>(options => { options.UseSqlite("Data Source=disunity.db"); }, ServiceLifetime.Singleton); }
private static void BindServices(IServiceCollection services, IConfigurationRoot configuration) { Console.WriteLine("Binding services..."); OptionsAttribute.ConfigureOptions(services, configuration); BindingAttribute.ConfigureBindings(services); FactoryAttribute.ConfigureFactories(services); services // bind third-party services (can't add binding attributes to classes we don't control) .AddLogging(builder => builder.AddConsole()) .AddSingleton(configuration) .AddSingleton(new Serializer()) .AddSingleton <ISlugHelper, SlugHelper>() .AddSingleton <CommandService>(); }
private static bool ShouldGenerateObjectRefFactory(GrainInterfaceData ifaceData) { var ifaceType = ifaceData.Type; // generate CreateObjectReference in 2 cases: // 1) for interfaces derived from IGrainObserver // 2) when specifically specifies via FactoryTypes.ClientObject or FactoryTypes.Both if (IsObserver(ifaceType)) { return(true); } var factoryType = FactoryAttribute.CollectFactoryTypesSpecified(ifaceType); return(factoryType == FactoryAttribute.FactoryTypes.ClientObject || factoryType == FactoryAttribute.FactoryTypes.Both); }
public static void ConfigureAttributes(this IServiceCollection services) { BindingAttribute.ConfigureBindings(services); FactoryAttribute.ConfigureFactories(services); }
/// <summary> /// Liest alle notwendigen Informationen aus dem gegebenen Typ aus und /// liefert das gesammelte PlayerInfo. /// </summary> /// <param name="type">Type</param> /// <returns>Infos über den Player</returns> private static PlayerInfo AnalysePlayerType(Type type) { FactoryAttribute[] playerAttributes = (FactoryAttribute[])type.GetCustomAttributes(typeof(FactoryAttribute), true); // Kein oder zu viele Description Attributes if (playerAttributes.Length != 1) { throw new NotSupportedException( string.Format("The Class '{0}' ({1}) has no valid PlayerAttribute", type.FullName, type.Assembly.FullName)); } // Property Mapping FactoryAttribute playerAttribute = playerAttributes[0]; var mappings = playerAttribute.GetType().GetCustomAttributes(typeof(FactoryAttributeMappingAttribute), true); if (mappings.Length != 1) { throw new NotSupportedException("The Player Attribute has no valid Property Mapping"); } var mapping = mappings[0] as FactoryAttributeMappingAttribute; Type playerType = playerAttribute.GetType(); // Map Name PropertyInfo nameProperty = playerType.GetProperty(mapping.NameProperty); if (nameProperty == null) { throw new NotSupportedException("The Name Property from Player Attribute Mapping does not exist"); } string name = (string)nameProperty.GetValue(playerAttribute, null); if (string.IsNullOrEmpty(name)) { throw new NotSupportedException("The Name of a Player can't be Empty"); } // Map Author PropertyInfo authorProperty = playerType.GetProperty(mapping.AuthorProperty); if (authorProperty == null) { throw new NotSupportedException("The Author Property from Player Attribute Mapping does not exist"); } string author = (string)authorProperty.GetValue(playerAttribute, null); if (author == null) { author = string.Empty; } PlayerInfo playerInfo = new PlayerInfo() { Guid = type.GUID, Type = TypeInfo.FromType(type), Name = name, Author = author }; // Faction finden // TODO: Richtiger lookup playerInfo.FactionType = ""; // TODO: Stats anhängen // if (PlayerStatistics.ContainsKey(playerInfo. return(playerInfo); }