/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation, */ /* version 2.1 of the License. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with this library; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ using System; namespace AgentService.Agent { //A custom attribute class to descript //all the KnowledgeType that could be present in a //Knowlegde instance. [AttributeUsage(AttributeTargets.Method)] public class KnowledgeItemAttribute:Attribute { #region Members /// /// the name of the KnowledgeItemAttribute /// protected string name; /// /// Gets the name of the KnowledgeItem /// public string Name { get { return this.name; } } /// /// the type of the KnowledgeItem /// protected Type type; /// /// Gets the type of the KnowledgeItem /// public Type Type { get { return this.type; } } /// /// true if is attribute of a get method, /// false if is attribute of a set method /// protected bool getset; /// /// Gets if is a Set or a Get Method /// public bool GetSet { get { return this.getset; } } #endregion #region Constructor /// /// Constructor for KnowlegdeItemAttribute must be used in declaration /// of Knowledges Types /// /// the name of the KnowledgeItem /// the type of the KnowlegdeItem /// true if a get method, false if a set public KnowledgeItemAttribute(String name, Type type, bool getset) { this.name = name; this.type = type; this.getset = getset; } #endregion #region Overrides /// /// Compare two instances for equality test. /// /// instance to compare to /// true if the two KnowledgeItemAttribute have the same name, the same type and the same accessors public override bool Equals(object obj) { KnowledgeItemAttribute kia = obj as KnowledgeItemAttribute; if (kia == null) return false; return ((kia.Type == this.type) && (kia.Name.CompareTo(this.name) == 0) && (kia.GetSet == this.getset)); } /// /// Returns the hash code for this instance. /// ///A 32-bit signed integer hash code. public override int GetHashCode() { return (this.name.GetHashCode() * this.type.ToString().GetHashCode() * this.getset.GetHashCode()); } #endregion } //A custom attribute class to descript //all the Knowledge that are present //in a particular Behaviour [AttributeUsage(AttributeTargets.Class)] public class KnowledgeAttribute : Attribute { #region Members /// /// the types of the Knowledges /// protected Type[] types; /// /// Gets the types of Knowlegdes in this Behaviour /// public Type[] Types { get { return this.types; } } #endregion #region Constructor /// /// Constructor of KnowledgeAttribute must be used in declaration /// of Behaviour Types /// /// the types of knowledges in behaviour public KnowledgeAttribute(params Type[] types) { this.types = types; } #endregion #region Overrides /// /// Compare two instances for equality test. /// /// instance to compare to /// true if the two KnowledgeAttribute have same types public override bool Equals(object obj) { KnowledgeAttribute ka = obj as KnowledgeAttribute; if (ka == null) { return false; } return (ka.types.Equals(this.types)); } /// /// Returns the hash code for this instance. /// ///A 32-bit signed integer hash code. public override int GetHashCode() { int hashcode = 1; foreach (Type type in this.types) { hashcode *= type.ToString().GetHashCode(); } return hashcode; } #endregion } //A custom attribute class to descript //all the Knowledges registered by the AgentTemplate [AttributeUsage(AttributeTargets.Class)] public class AgentKnowledgesAttribute : Attribute { #region Members /// /// the types of the Knowledges /// protected Type[] types; /// /// Gets the types of The Knowledges in this AgentTemplate /// public Type[] Types { get { return this.types; } } #endregion #region Constructor /// /// Constructor of the AgentKnowlegdeAttribute must be used /// in declaration of AgentTemplate Types /// /// Types of knowlegdes in this agent template public AgentKnowledgesAttribute(params Type[] types) { this.types = types; } #endregion #region Overrides /// /// Compare two instances for equality test. /// /// instance to compare to /// true if the two AgentKnowledgesAttribute have same types public override bool Equals(object obj) { AgentKnowledgesAttribute aka = obj as AgentKnowledgesAttribute; if (aka == null) return false; return (aka.types.Equals(this.types)); } /// /// Returns the hash code for this instance. /// ///A 32-bit signed integer hash code. public override int GetHashCode() { int hashcode = 1; foreach (Type type in this.types) { hashcode *= type.ToString().GetHashCode(); } return hashcode; } #endregion } //A custom attribute class to descript //all the Behaviours registered by the AgentTemplate [AttributeUsage(AttributeTargets.Class)] public class AgentBehavioursAttribute : Attribute { #region Members /// /// the types of Behaviours registered by the AgentTemplate /// protected Type[] types; /// /// Gets the types of Behaviours registered by the AgentTemplate /// public Type[] Types { get { return this.types; } } #endregion #region Constructor /// /// Constructor of the AgentBehaviourAttribute must be used /// in declaration of AgentTemplate types /// /// The Behaviours used by this AgentTemplate public AgentBehavioursAttribute(params Type[] types) { this.types = types; } #endregion #region Overrides /// /// Compare two instances for equality test. /// /// instance to compare to /// true if the two AgentBehavioursAttribute have same types public override bool Equals(object obj) { AgentBehavioursAttribute aba = obj as AgentBehavioursAttribute; if (aba == null) return false; return (aba.types.Equals(this.types)); } /// /// Returns the hash code for this instance. /// ///A 32-bit signed integer hash code. public override int GetHashCode() { int hashcode = 1; foreach (Type type in this.types) { hashcode *= type.ToString().GetHashCode(); } return hashcode; } #endregion } /// /// This class handles agent attribute exceptions. /// public class AgentAttributeException : Exception { /// /// Constructs an agent attribute exception with a given message string. /// /// The message string. public AgentAttributeException(string message) : base(message) { // TODO: Fix with Debug.WriteLine("AGENT ATTRIBUTE: {0}", message); // System.Console.WriteLine("AGENT ATTRIBUTE: {0}", message); } /// /// Constructs an agent attribute exception with a given message string and exception. /// /// The message string. /// The exception. public AgentAttributeException(string message, Exception innerException) : base(message, innerException) { // TODO: Fix with Debug.WriteLine("ERROR: AgentAttributeException: {0}.{1}", message, innerException.ToString()); // System.Console.WriteLine("ERROR: AgentAttributeException: {0}.{1}", message, innerException.ToString()); } } }