public static bool Init()
        {
            //We will search our assemblies for Quests by reflection so
            //it is not neccessary anymore to register new quests with the
            //server, it is done automatically!
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                // Walk through each type in the assembly
                foreach (Type type in assembly.GetTypes())
                {
                    // Pick up a class
                    if (type.IsClass != true)
                    {
                        continue;
                    }

                    if (typeof(IBehaviourAction).IsAssignableFrom(type))
                    {
                        ActionAttribute attr = GetActionAttribute(type);
                        if (attr != null)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Registering BehaviourAction: " + type.FullName);
                            }
                            RegisterBehaviourAction(attr.ActionType, type);
                        }
                    }

                    if (typeof(IBehaviourTrigger).IsAssignableFrom(type))
                    {
                        TriggerAttribute attr = getTriggerAttribute(type);
                        if (attr != null)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Registering BehaviourTrigger: " + type.FullName);
                            }
                            RegisterBehaviourTrigger(attr.TriggerType, type);
                        }
                    }

                    if (typeof(IBehaviourRequirement).IsAssignableFrom(type))
                    {
                        RequirementAttribute attr = getRequirementAttribute(type);
                        if (attr != null)
                        {
                            if (log.IsInfoEnabled)
                            {
                                log.Info("Registering BehaviourRequirement: " + type.FullName);
                            }
                            RegisterBehaviourRequirement(attr.RequirementType, type);
                        }
                    }
                }
            }
            return(true);
        }
        private void LogRequirement(object value)
        {
            RequirementAttribute requirementAttribute = (RequirementAttribute)GetAttributeFrom(value, typeof(RequirementAttribute).Name);

            if (requirementAttribute != null && host != null)
            {
                host.CaptureRequirement(requirementAttribute.ProtocolDocName, requirementAttribute.RequirementID,
                                        requirementAttribute.Description);
            }
        }
        private void CheckOperation(IMethodCallMessage mcall)
        {
            Object[] methodAttributes =
                ((MemberInfo)(mcall.MethodBase)).GetCustomAttributes(typeof(RequirementAttribute), true);

            foreach (Object methodAttibute in methodAttributes)
            {
                if (((System.Type)(((Attribute)methodAttibute).TypeId)) == typeof(RequirementAttribute))
                {
                    RequirementAttribute opAttribute = (RequirementAttribute)methodAttibute;
                    site.CaptureRequirement(opAttribute.ProtocolDocName, opAttribute.RequirementID, opAttribute.Description);
                }
            }
        }
        /// <summary>
        /// Creates a new QuestRequirement and does some basich compativilite checks for the parameters
        /// </summary>
        /// <param name="defaultNPC"></param>
        /// <param name="type"></param>
        /// <param name="n"></param>
        /// <param name="v"></param>
        /// <param name="comp"></param>
        public AbstractRequirement(GameNPC defaultNPC, eRequirementType type, Object n, Object v, eComparator comp) : this(defaultNPC, type, comp)
        {
            RequirementAttribute attr = BehaviourMgr.getRequirementAttribute(this.GetType());
            // handle parameter N
            object defaultValueN = GetDefaultValue(attr.DefaultValueN);

            this.N = (TypeN)BehaviourUtils.ConvertObject(n, defaultValueN, typeof(TypeN));
            CheckParameter(this.N, attr.IsNullableN, typeof(TypeN));

            // handle parameter V
            object defaultValueV = GetDefaultValue(attr.DefaultValueV);

            this.v = (TypeV)BehaviourUtils.ConvertObject(v, defaultValueV, typeof(TypeV));
            CheckParameter(this.V, attr.IsNullableV, typeof(TypeV));
        }
Пример #5
0
        private IThomasElement Instantiate(Type elementType)
        {
            // Ist bereits eine Instanz vorhanden?
            if (_drivers.ContainsInstance(elementType))
            {
                return(_drivers.GetInstance(elementType));
            }
            if (_sensors.ContainsInstance(elementType))
            {
                return(_sensors.GetInstance(elementType));
            }
            if (_actors.ContainsInstance(elementType))
            {
                return(_actors.GetInstance(elementType));
            }
            if (_controllers.ContainsInstance(elementType))
            {
                return(_controllers.GetInstance(elementType));
            }

            // Parameter, die der neuen Instanz übergeben werden
            List <object> instanceParameters = new List <object>();

            // Erforderliche Abhängigkeiten. Sollte eine nicht verfügbar sein, ist dieses Element auch nicht verfügbar.
            RequirementAttribute requirementAttribute = (RequirementAttribute)elementType.GetCustomAttributes(typeof(RequirementAttribute), true).FirstOrDefault();

            if (requirementAttribute != null)
            {
                foreach (Type subElementType in requirementAttribute.RequiredElements)
                {
                    IThomasElement requiredInstance = Instantiate(subElementType);

                    if (requiredInstance == null)
                    {
                        Logger.Warning($"Abhängigkeit {subElementType.Name} von {elementType.Name} konnte nicht erfüllt werden.");
                        return(null);
                    }

                    instanceParameters.Add(requiredInstance);
                }
            }

            // Optionale Abhängigkeiten. Falls verfügbar, werden diese Komponenten dem aktuellen Element mit übergeben.
            OptionalAttribute optionalAttribute = (OptionalAttribute)elementType.GetCustomAttributes(typeof(OptionalAttribute), true).FirstOrDefault();

            if (optionalAttribute != null)
            {
                foreach (Type subElementType in optionalAttribute.OptionalElements)
                {
                    IThomasElement requiredInstance = Instantiate(subElementType);

                    if (requiredInstance == null)
                    {
                        Logger.Warning($"Optionale Abhängigkeit {subElementType.Name} von {elementType.Name} konnte nicht erfüllt werden.");
                    }

                    instanceParameters.Add(requiredInstance);
                }
            }

            // Falls ein Konfigurationselement angefordert wird, gib dieses, falls vorhanden zurück. Sollte es angefordert werden, aber nicht vorhanden sein, gib Null zurück.
            ConfigAttribute configAttribute = (ConfigAttribute)elementType.GetCustomAttributes(typeof(ConfigAttribute), true).FirstOrDefault();

            if (configAttribute != null)
            {
                instanceParameters.Add(_applicationConfig.ModuleConfigs.ContainsKey(configAttribute.Id) ? _applicationConfig.ModuleConfigs[configAttribute.Id] : null);
            }

            // Instanz erstellen
            IThomasElement instance = (IThomasElement)(instanceParameters.Count > 0 ? Activator.CreateInstance(elementType, instanceParameters.ToArray()) : Activator.CreateInstance(elementType));

            // Sonderbehandlung von Treibern, da diese aufgrund von fehlender Hardware nicht initialisiert werden könnten.
            if (typeof(IDriver).IsAssignableFrom(elementType))
            {
                if (_failedDrivers.Contains(elementType))
                {
                    return(null);
                }

                if (!((IDriver)instance).Initialize())
                {
                    Logger.Warning($"Treiber {((IDriver)instance).Name} konnte nicht initalisiert werden.");
                    _failedDrivers.Add(elementType);

                    return(null);
                }
            }

            // Instanz zu einem der Pools hinzufügen
            if (!_drivers.AddIfMatches(instance) && !_sensors.AddIfMatches(instance) && !_actors.AddIfMatches(instance) && !_controllers.AddIfMatches(instance))
            {
                throw new ArgumentException("Ungültiger Element-Typ", nameof(elementType));
            }

            return(instance);
        }