/*********************************************************************/ /* */ /* 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.Collections.Specialized; using AgentService.Platform.Modules; // using AgentService.Interface; namespace AgentService.Platform.Configuration { /// /// Class Configuration. Defines the startup parameters of the platform. /// [Serializable] public class Configuration { /// /// true if the platform is started for the first time. /// private bool bIsFirstStart; /// /// Gets the "first start" flag. /// public bool IsFirstStart { get { return this.bIsFirstStart; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.bIsFirstStart = value; } } /// /// failed modules flag. /// private bool bSkipFailedModules; /// /// Gets, sets the behavoiur that the platform will use for failed modules. /// If false platform will not start if at least one additional module cannot /// be loaded. /// public bool SkipFailedModules { get { return this.bSkipFailedModules; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.bSkipFailedModules = value; } } /// /// error flag. /// private bool bHasErrors; /// /// Indicates whether the configuration is consistent. /// public bool HasErrors { get { return this.bHasErrors; } } /// /// error message /// private string errorMessage; /// /// Gets the error message /// public string ErrorMessage { get { return this.errorMessage; } set { if (this.bUpdating == false) throw new InvalidOperationException("Properties can be modified only in the reading phase"); this.errorMessage = value; } } /// /// Base dir path for the AgentService platform /// protected string baseDirPath; /// /// Gets, sets the base dir path for the AgentService /// platform /// public string BaseDirPath { get { return this.baseDirPath; } set { if (this.bUpdating == false) throw new InvalidOperationException("Properties can be modified only in the updating phase"); this.baseDirPath = value; } } /// /// Repository file name /// protected string repositoryFile; /// /// Gets, sets the base dir path for the AgentService /// platform /// public string RepositoryFile { get { return this.repositoryFile; } set { if (this.bUpdating == false) throw new InvalidOperationException("Properties can be modified only in the updating phase"); this.repositoryFile = value; } } /// /// Description of the platform. /// private IPlatformDescription platformDescription; /// /// Gets the platform description. /// public IPlatformDescription PlatformDescription { get { return this.platformDescription; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.platformDescription = value; } } /// /// path where the core modules configuration files are stored /// private string coreModulesConfPath; /// /// Gets, sets the conf path for the core modules. /// public string CoreModulesConfPath { get { return this.coreModulesConfPath; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.coreModulesConfPath = value;; } } /// /// path where the core modules are stored /// private string coreModulesBinPath; /// /// Gets, sets the bin path for the core modules. /// public string CoreModulesBinPath { get { return this.coreModulesBinPath; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.coreModulesBinPath = value;; } } /// /// Info about the storage module. /// private ModuleInfo storageModule; /// /// Gets, sets the storage module loading information. /// public ModuleInfo StorageModule { get { return this.storageModule; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.storageModule = value; } } /// /// Info about the messaging module. /// private ModuleInfo messagingModule; /// /// Gets, sets the messaging module loading information. /// public ModuleInfo MessagingModule { get { return this.messagingModule; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.messagingModule = value; } } /// /// Info about the persistence module. /// private ModuleInfo persistenceModule; /// /// Gets, sets the persistence module loading information. /// public ModuleInfo PersistenceModule { get { return this.persistenceModule; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.persistenceModule = value; } } /// /// Info about the logging module. /// private ModuleInfo loggingModule; /// /// Gets, sets the logging module loading information. /// public ModuleInfo LoggingModule { get { return this.loggingModule; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.loggingModule = value; } } /// /// path where the additional modules configuration files are stored /// private string additionalModulesConfPath; /// /// Gets, sets the conf path for the additional modules. /// public string AdditionalModulesConfPath { get { return this.additionalModulesConfPath; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.additionalModulesConfPath = value; } } /// /// path where the additional modules are stored /// private string additionalModulesBinPath; /// /// Gets, sets the bin path for the additional modules. /// public string AdditionalModulesBinPath { get { return this.additionalModulesBinPath; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.additionalModulesBinPath = value; } } /// /// Additional modules information. /// private ModuleInfo[] additionalModules; /// /// Gets, sets the loading information about the additional modules. /// public ModuleInfo[] AdditionalModules { get { return this.additionalModules; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.additionalModules = value; } } /// /// Additional properties /// private StringDictionary properties; /// /// Gets, sets the additional properties. /// public StringDictionary Properties { get { return this.properties; } set { if (this.bUpdating == false) { throw new InvalidOperationException("Properties can be modified only in the reading phase"); } this.properties = value; } } /// /// true while the configuration object is built. /// bUpdating is set to true by calling BeginUpdate, /// while is set to false by calling EndUpdate /// private bool bUpdating; /// /// Gets true is the configuration object is updating /// public bool IsUpdating { get { return this.bUpdating; } } /// /// Begins the update process, and sets the Updating property to true. /// public void BeginUpdate() { this.bUpdating = true; } /// /// Terminates the update process and sets the Updating property to false. /// public void EndUpdate() { this.bUpdating = false; } /// /// Sets the HasErrors property to true during updating. Calling this method /// outside the updating process will throw an InvalidOperation exception. /// public void SetError() { if (this.bUpdating) this.bHasErrors = true; else throw new InvalidOperationException("Cannot notify errors while configuration is not in the updating phase."); } /// /// Clears the HasErrors flag. /// public void ResetError() { this.bHasErrors = false; } /// /// Adds a new module to the configuration. /// Note: the new module will be recognized at the next platform startup /// /// module information of the module that is going to be installed public void AddModule(ModuleInfo modInfo) { modInfo.State = ModuleInfoState.New; ModuleInfo[] backing = new ModuleInfo[this.additionalModules.Length + 1]; int ndx = 0; for(; ndx /// Removes a module from the configuration. /// /// module to Remove public void RemoveModule(ModuleInfo modInfo) { foreach(ModuleInfo mi in this.additionalModules) { if (mi == modInfo) { mi.State = ModuleInfoState.Removed; } } } } }