/*********************************************************************/ /* */ /* 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.Text; using System.Collections.Generic; using System.Xml.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO; namespace AgentService.Platform { /// /// Class XmlAssemblySetupData. XML wrapper /// class for the AssemblySetupData type. /// [XmlRoot(ElementName="assembly")] [Serializable] public class XmlAssemblySetupData { /// /// Wrapper field for the Path property. /// [XmlAttribute(AttributeName="path")] public string Path; /// /// Wrapper field for the Overwrite property. /// [XmlAttribute(AttributeName = "overwrite")] public bool Overwrite; /// /// Deserialization constructor. /// public XmlAssemblySetupData() {} } /// /// Class XmlAgentSetupData. XML wrapper /// class for the AgentSetupData type. /// [XmlRoot(ElementName="agent")] [Serializable] public class XmlAgentSetupData { /// /// Wrapper field for the Name property. /// [XmlAttribute(AttributeName="name")] public string Name; /// /// Wrapper field for the FullTypeName property. /// [XmlAttribute(AttributeName="full-type-name")] public string FullTypeName; /// /// Wrapper field for the ConfigFile property. /// [XmlAttribute(AttributeName="config-file")] public string ConfigFile; /// /// Wrapper field for the Persist property. /// [XmlAttribute(AttributeName="is-persistent")] public bool Persist = false; /// /// Wrapper field for the UseDomain property. /// [XmlAttribute(AttributeName="use-domain")] public bool UseDomain = false; /// /// Wrapper field for the DomainName property. /// [XmlAttribute(AttributeName="domain-name")] public string DomainName; /// /// Deserialization constructor. /// public XmlAgentSetupData() { } } /// /// Class XmlBatchSetupData. XML wrapper /// class for BatchSetupData type. /// [XmlRoot(ElementName="setup")] [Serializable] public class XmlBatchSetupData { /// /// Wrapper field for the WaitToStart property. /// [XmlAttribute(AttributeName="wait-to-start")] public bool WaitToStart; /// /// Wrapper field for the Assemblies property. /// [XmlArrayAttribute(ElementName = "assemblies")] [XmlArrayItemAttribute(ElementName = "assembly")] public XmlAssemblySetupData[] Assemblies; /// /// Wrapper field for the Agents property. /// [XmlArrayAttribute(ElementName = "agents")] [XmlArrayItemAttribute(ElementName = "agent")] public XmlAgentSetupData[] Agents; /// /// Deserialization constructor /// public XmlBatchSetupData() { } } /// /// Class XmlBatch. Specializes the BatchBase /// class by providing a facility for reading /// the batch setup data from an xml file. /// public class XmlBatch : BatchBase { /// /// Reads the batch setup data from an xml file. /// /// batch setup information or null if reading fails protected override BatchSetupData ReadSetup() { XmlSerializer serializer = new XmlSerializer(typeof(XmlBatchSetupData)); System.IO.TextReader reader = null; XmlBatchSetupData batch = null; try { reader = new System.IO.StreamReader(this.conf); batch = serializer.Deserialize(reader) as XmlBatchSetupData; // ok now we will move the data into // a BatchSetupData instance. BatchSetupData bsd = new BatchSetupData(); // batch behaviour bsd.WaitToStart = batch.WaitToStart; // assemblies for (int ndx = 0; ndx < batch.Assemblies.Length; ndx++) { XmlAssemblySetupData xasd = batch.Assemblies[ndx]; bsd.Assemblies.Add(new AssemblySetupData(xasd.Path,xasd.Overwrite)); } // agents for (int ndx = 0; ndx < batch.Agents.Length; ndx++) { XmlAgentSetupData xasd = batch.Agents[ndx]; AgentSetupData asd = new AgentSetupData(xasd.Name, xasd.FullTypeName, xasd.ConfigFile, xasd.Persist); asd.UseDomain = xasd.UseDomain; asd.DomainName = xasd.DomainName; bsd.Agents.Add(asd); } return bsd; } catch (Exception ioex) { this.controller.Console.Error.WriteLine("Error while reading {0}: {1}", this.conf, ioex.Message); } finally { if (reader != null) { reader.Close(); } } return null; } } }