/*********************************************************************/
/*                                                                   */
/*                     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;
using System.Xml;
using System.Xml.Serialization;

namespace AgentService.Install.XmlDataModel
{
	/// <summary>
	/// Class XmlSystemInfo. Wrapper class
	/// used to write and read the XML tag
	/// &lt;system&gt;&lt;/system&gt;.
	/// </summary>
	[Serializable]
	[XmlRoot(ElementName="platform")]
	public class XmlSystemInfo : ICloneable
	{
		/// <summary>
		/// information about the creation
		/// and the management of agents.
		/// </summary>
		[XmlIgnore()]
		protected XmlFactoryInfo factory;
		/// <summary>
		/// Gets, sets the information about
		/// the creation and the management
		/// of agents.
		/// </summary>
		[XmlElement(ElementName="factory")]
		public XmlFactoryInfo Factory 
		{
			get 
			{
				return this.factory;
			}
			set
			{
				this.factory = value;
			}
		}
        //MOD : 18/05/2006 : added info on policy
        /// <summary>
        /// information about the creation
        /// of the agents in Application Domains
        /// </summary>
        protected XmlPolicyInfo policy;
        /// <summary>
        /// Gets, sets the information about
        /// the creation of the agents
        /// in Application Domains
        /// </summary>
        [XmlElement(ElementName = "policy")]
        public XmlPolicyInfo Policy
        {
            get
            {
                return this.policy;
            }
            set
            {
                this.policy = value;
            }
        }
		/// <summary>
		/// information about the platform
		/// remote access.
		/// </summary>
		protected XmlRemoteInfo remote;
		/// <summary>
		/// Gets, sets the information about
		/// the configuration of the platform
		/// remote access.
		/// </summary>
		[XmlElement(ElementName="remote")]
		public XmlRemoteInfo Remote 
		{
			get 
			{
				return this.remote;
			}
			set 
			{
				this.remote = value;
			}
		}
		/// <summary>
		/// Dummy default constructor used by
		/// the XML deserializer to create empty
		/// instances and the sets their properties
		/// reading them from the XML stream.
		/// </summary>
		public XmlSystemInfo()
		{
			this.remote = new XmlRemoteInfo();
            this.policy = new XmlPolicyInfo();
			this.factory = new XmlFactoryInfo();
		}
		/// <summary>
		/// Constructs an instance of the XmlSystemInfo type
		/// with the given parameters.
		/// </summary>
		/// <param name="factory">agent factory installation information</param>
        /// <param name="policy">domain policy installation information</param>
		/// <param name="remote">remote access installation information</param>
		public XmlSystemInfo(XmlFactoryInfo factory, XmlPolicyInfo policy, XmlRemoteInfo remote)
		{
			this.remote = remote;
            this.policy = policy;
			this.factory = factory;
		}
		#region ICloneable Members
		/// <summary>
		/// Clones this instance of XmlSystemInfo.
		/// </summary>
		/// <returns>identical copy of the object</returns>
		public object Clone()
		{
			return new XmlSystemInfo(this.factory.Clone() as XmlFactoryInfo,
                                     this.policy.Clone() as XmlPolicyInfo,
									 this.remote.Clone() as XmlRemoteInfo);
		}

		#endregion
	}

	/// <summary>
	/// Class XmlRemoteInfo. Wrapper class used
	/// to serialize and deserialize the &lt;remote&gt;
	/// tag. The tag is used to specify the platform
	/// remote access behaviour.
	/// </summary>
	[Serializable]
	[XmlRoot(ElementName="remote")]
	public class XmlRemoteInfo : ICloneable
	{
		/// <summary>
		/// if true activates the 
		/// platfom remte access service.
		/// </summary>
		protected bool bEnable;
		/// <summary>
		/// Gets, set the platform remote
		/// access service flag.
		/// </summary>
		[XmlAttribute(AttributeName="enable")]
		public bool Enable 
		{
			get 
			{
				return this.bEnable;
			}
			set 
			{
				this.bEnable = value;
			}
		}
		/// <summary>
		/// remote TCP port number used by
		/// the platform to listen for
		/// incoming connections.
		/// </summary>
		protected int port;
		/// <summary>
		/// Gets, sets the remote TCP port
		/// the platform uses to listen for 
		/// incoming connections.
		/// </summary>
		[XmlAttribute(AttributeName="port")]
		public int Port 
		{
			get 
			{
				return this.port;
			}
			set
			{
				this.port = value;
			}
		}
		/// <summary>
		/// if true secure the channel.
		/// </summary>
		protected bool bSecure;
		/// <summary>
		/// Gets, sets the secure mode
		/// flag. If true the platform
		/// willbe configured to listen
		/// only for secured connections.
		/// </summary>
		[XmlAttribute(AttributeName="secure")]
		public bool Secure 
		{
			get 
			{
				return this.bSecure;
			}
			set 
			{
				this.bSecure = value;
			}
		}
		/// <summary>
		/// Dummy default constructor used by
		/// the XML deserializer to create empty
		/// instances and the sets their properties
		/// reading them from the XML stream.
		/// </summary>
		public XmlRemoteInfo()
		{
			this.bEnable = false;
			this.bSecure = false;
			this.port = 0;
		}
		/// <summary>
		/// Construts an instance of the XmlRemoteInfo type
		/// with the given paramaters.
		/// </summary>
		/// <param name="bEnable">remote access activation flag</param>
		/// <param name="port">port number on which will be installed the service</param>
		/// <param name="bSecure">if true makes the communication secure</param>
		public XmlRemoteInfo(bool bEnable, int port, bool bSecure)
		{
			this.bEnable = bEnable;
			this.port = port;
			this.bSecure = bSecure;
		}
		#region ICloneable Members
		/// <summary>
		/// Clones this instance of the XmlRemoteInfo.
		/// </summary>
		/// <returns>identical copy of the object</returns>
		public object Clone()
		{
			return new XmlRemoteInfo(this.bEnable, this.port, this.bSecure);
		}

		#endregion
	}

    /// <summary>
    /// Class XmlPolicyInfo. Wrapper class to
    /// write and read the XML tag &ltpolicy /&gt;.
    /// The tag has two properties which are:
    /// <list type="bullet">
    /// <item>FullTypeName: DomainPolicy full type name to use.</item>
    /// <item>AssemblyFile: path to the assembly file which containes the specified DomainPolicy.</item>
    /// </list>
    /// </summary>
    [Serializable]
    [XmlRoot(ElementName = "policy")]
    public class XmlPolicyInfo : ICloneable
    {
        /// <summary>
        /// full type name of the DomainPolicy
        /// derived class selected for the
        /// installation.
        /// </summary>
        protected string fullTypeName;
        /// <summary>
        /// Gets, sets the full type name
        /// of the DomainPolicy derived 
        /// class that will be installed
        /// in the platfom.
        /// </summary>
        [XmlAttribute(AttributeName = "full-type-name")]
        public string FullTypeName
        {
            get
            {
                return this.fullTypeName;
            }
            set
            {
                this.fullTypeName = value;
            }
        }
        /// <summary>
        /// full path to the assembly that
        /// Contains the definition of the
        /// selected DomainPolicy.
        /// </summary>
        protected string assemblyFile;
        /// <summary>
        /// Gets, sets the full path to the 
        /// assembly that Contains the definition 
        /// of the selected DomainPolicy.
        /// </summary>
        [XmlAttribute(AttributeName = "assembly-file")]
        public string AssemblyFile
        {
            get
            {
                return this.assemblyFile;
            }
            set
            {
                this.assemblyFile = value;
            }
        }
        /// <summary>
        /// Dummy default constructor used by
        /// the XML deserializer to create empty
        /// instances and the sets their properties
        /// reading them from the XML stream.
        /// </summary>		
        public XmlPolicyInfo()
        {
            this.assemblyFile = string.Empty;
            this.fullTypeName = string.Empty;
        }
        /// <summary>
        /// Constructs an instance of the XmlPolicyInfo
        /// type with the given parameters.
        /// </summary>
        /// <param name="fullTypeName">full type name of the domain policy</param>		
        /// <param name="assemblyFile">file name of the assembly containing the definition of the type</param>
        public XmlPolicyInfo(string fullTypeName, string assemblyFile)
        {
            this.fullTypeName = fullTypeName;
            this.assemblyFile = assemblyFile;
        }
        #region ICloneable Members
        /// <summary>
        /// Clones this instance of the XmlPolicyInfo type.
        /// </summary>
        /// <returns>an identical copy of the object</returns>
        public object Clone()
        {
            return new XmlPolicyInfo(this.fullTypeName.Clone() as string,
                                      this.assemblyFile.Clone() as string);
        }

        #endregion
    }


	/// <summary>
	/// Class XmlFactoryInfo. Wrapper class to
	/// write and read the XML tag &ltfactory /&gt;.
	/// The tag has three properties which are:
	/// <list type="bullet">
	/// <item>Persistence: boolean value that activates the persistence subsystem.</item>
	/// <item>FullTypeName: AgentFactory full type name to use.</item>
	/// <item>AssemblyFile: path to the assembly file which containes the specified AgentFactory.</item>
	/// </list>
	/// </summary>
	[Serializable]
	[XmlRoot(ElementName="factory")]
	public class XmlFactoryInfo : ICloneable
	{
		/// <summary>
		/// persistence flag.
		/// </summary>
		protected bool bPersistence;
		/// <summary>
		/// Gets, sets the persistence flag.
		/// </summary>
		[XmlAttribute(AttributeName="persistence")]
		public bool Persistence 
		{
			get 
			{
				return this.bPersistence;
			}
			set 
			{
				this.bPersistence = value;
			}
		}
		/// <summary>
		/// full type name of the AgentFactory
		/// derived class selected for the
		/// installation.
		/// </summary>
		protected string fullTypeName;
		/// <summary>
		/// Gets, sets the full type name
		/// of the AgentFactory derived 
		/// class that will be installed
		/// in the platfom.
		/// </summary>
		[XmlAttribute(AttributeName="full-type-name")]
		public string FullTypeName
		{
			get 
			{
				return this.fullTypeName;
			}
			set 
			{
				this.fullTypeName = value;
			}
		}
		/// <summary>
		/// full path to the assembly that
		/// Contains the definition of the
		/// selected agent factory.
		/// </summary>
		protected string assemblyFile;
		/// <summary>
		/// Gets, sets the full path to the 
		/// assembly that Contains the definition 
		/// of the selected agent factory.
		/// </summary>
		[XmlAttribute(AttributeName="assembly-file")]
		public string AssemblyFile
		{
			get 
			{
				return this.assemblyFile;
			}
			set 
			{
				this.assemblyFile = value;
			}
		}
		/// <summary>
		/// Dummy default constructor used by
		/// the XML deserializer to create empty
		/// instances and the sets their properties
		/// reading them from the XML stream.
		/// </summary>		
		public XmlFactoryInfo()
		{
			this.fullTypeName = string.Empty;
			this.bPersistence = false;
			this.assemblyFile = string.Empty;
		}	
		/// <summary>
		/// Constructs an instance of the XmlFactoryInfo
		/// type with the given parameters.
		/// </summary>
		/// <param name="fullTypeName">full type name of the agent factory</param>		
		/// <param name="assemblyFile">file name of the assembly containing the definition of the type</param>
		/// <param name="bPersistence">persistence subsystema activation flag</param>
		public XmlFactoryInfo(string fullTypeName, string assemblyFile, bool bPersistence)
		{
			this.fullTypeName = fullTypeName;
			this.assemblyFile = assemblyFile;
			this.bPersistence = bPersistence;
		}	
		#region ICloneable Members
		/// <summary>
		/// Clones this instance of the XmlFactoryInfo type.
		/// </summary>
		/// <returns>an identical copy of the object</returns>
		public object Clone()
		{
			return new XmlFactoryInfo(this.fullTypeName.Clone() as string, 
									  this.assemblyFile.Clone() as string, 
									  this.bPersistence);
		}

		#endregion
	}

}
