//---------------------------------------------------------------------------------------//

        public LabExperimentResult(LabConfiguration labConfiguration)
        {
            try
            {
                //
                // Load XML experiment result string from the lab configuration
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlExperimentResult);
                XmlNode     xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentResult);
                this.xmlNodeExperimentResult = xmlRootNode.Clone();

                //
                // Check that all required XML nodes exist
                //
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_timestamp, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_title, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_version, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_experimentId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_unitId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupName, true);
            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }
        }
        //---------------------------------------------------------------------------------------//
        public LabExperimentResult(LabConfiguration labConfiguration)
        {
            try
            {
                //
                // Load XML experiment result string from the lab configuration
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlExperimentResult);
                XmlNode xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentResult);
                this.xmlNodeExperimentResult = xmlRootNode.Clone();

                //
                // Check that all required XML nodes exist
                //
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_timestamp, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_title, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_version, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_experimentId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_unitId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupId, true);
                XmlUtilities.GetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupName, true);
            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }
        }
        //---------------------------------------------------------------------------------------//
        public LabExperimentResult(int experimentId, string sbName, DateTime timestamp, string setupId,
            int unitId, LabConfiguration labConfiguration)
        {
            const string STRLOG_MethodName = "LabExperimentResult";

            string logMessage = STRLOG_experimentId + experimentId.ToString() +
                Logfile.STRLOG_Spacer + STRLOG_sbName + Logfile.STRLOG_Quote + sbName + Logfile.STRLOG_Quote +
                Logfile.STRLOG_Spacer + STRLOG_unitId + unitId.ToString();

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            try
            {
                //
                // Load XML experiment result string from the lab configuration
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlExperimentResult);
                XmlNode xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentResult);
                this.xmlNodeExperimentResult = xmlRootNode.Clone();

                //
                // Add the result information
                //
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_timestamp, timestamp.ToString(STR_DateTimeFormat), false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_title, labConfiguration.Title, false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_version, labConfiguration.Version, false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_experimentId, experimentId);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_unitId, unitId);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupId, setupId, false);
                int setupIndex = Array.IndexOf(labConfiguration.SetupIds, setupId);
                if (setupIndex >= 0)
                {
                    string setupName = labConfiguration.SetupNames[setupIndex];
                    XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupName, setupName, false);
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //---------------------------------------------------------------------------------------//

        public LabExperimentResult(int experimentId, string sbName, DateTime timestamp, string setupId,
                                   int unitId, LabConfiguration labConfiguration)
        {
            const string STRLOG_MethodName = "LabExperimentResult";

            string logMessage = STRLOG_experimentId + experimentId.ToString() +
                                Logfile.STRLOG_Spacer + STRLOG_sbName + Logfile.STRLOG_Quote + sbName + Logfile.STRLOG_Quote +
                                Logfile.STRLOG_Spacer + STRLOG_unitId + unitId.ToString();

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            try
            {
                //
                // Load XML experiment result string from the lab configuration
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlExperimentResult);
                XmlNode     xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentResult);
                this.xmlNodeExperimentResult = xmlRootNode.Clone();

                //
                // Add the result information
                //
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_timestamp, timestamp.ToString(STR_DateTimeFormat), false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_title, labConfiguration.Title, false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_version, labConfiguration.Version, false);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_experimentId, experimentId);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_unitId, unitId);
                XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupId, setupId, false);
                int setupIndex = Array.IndexOf(labConfiguration.SetupIds, setupId);
                if (setupIndex >= 0)
                {
                    string setupName = labConfiguration.SetupNames[setupIndex];
                    XmlUtilities.SetXmlValue(this.xmlNodeExperimentResult, Consts.STRXML_setupName, setupName, false);
                }
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //-------------------------------------------------------------------------------------------------//
        public ExperimentValidation(LabConfiguration labConfiguration)
        {
            const string STRLOG_MethodName = "ExperimentValidation";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            try
            {
                //
                // Check that the lab configuration exists
                //
                if (labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_LabConfiguration);
                }

                // Save the lab configuration
                this.labConfiguration = labConfiguration;

                //
                // Check that the validation XML node exists
                //
                if (labConfiguration.XmlValidation == null)
                {
                    throw new ArgumentNullException(STRERR_XmlValidation);
                }

                //
                // Load XML validation string from the lab configuration and save a copy of the XML node
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlValidation);
                XmlNode xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_validation);
                this.xmlNodeValidation = xmlRootNode.Clone();
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
Esempio n. 6
0
        //-------------------------------------------------------------------------------------------------//

        public ExperimentValidation(LabConfiguration labConfiguration)
        {
            const string STRLOG_MethodName = "ExperimentValidation";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            try
            {
                //
                // Check that the lab configuration exists
                //
                if (labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_LabConfiguration);
                }

                // Save the lab configuration
                this.labConfiguration = labConfiguration;

                //
                // Check that the validation XML node exists
                //
                if (labConfiguration.XmlValidation == null)
                {
                    throw new ArgumentNullException(STRERR_XmlValidation);
                }

                //
                // Load XML validation string from the lab configuration and save a copy of the XML node
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlValidation);
                XmlNode     xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_validation);
                this.xmlNodeValidation = xmlRootNode.Clone();
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //-------------------------------------------------------------------------------------------------//
        public ExperimentSpecification(LabConfiguration labConfiguration, EquipmentService equipmentServiceProxy)
        {
            const string STRLOG_MethodName = "ExperimentSpecification";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            //
            // Save these for use by the Parse() method
            //
            this.labConfiguration = labConfiguration;
            this.equipmentServiceProxy = equipmentServiceProxy;

            try
            {
                //
                // Load XML specification string from the lab configuration and save a copy of the XML node
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlSpecification);
                XmlNode xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentSpecification);
                this.xmlNodeSpecification = xmlRootNode.Clone();

                //
                // Check that all required XML specification nodes exist
                //
                XmlUtilities.GetXmlValue(this.xmlNodeSpecification, Consts.STRXML_setupId, true);

                //
                // Load XML configuration string from the lab configuration and save a copy of the XML node
                //
                xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlConfiguration);
                xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_configuration);
                this.xmlNodeConfiguration = xmlRootNode.Clone();
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //-------------------------------------------------------------------------------------------------//

        public ExperimentSpecification(LabConfiguration labConfiguration, EquipmentService equipmentServiceProxy)
        {
            const string STRLOG_MethodName = "ExperimentSpecification";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            //
            // Save these for use by the Parse() method
            //
            this.labConfiguration      = labConfiguration;
            this.equipmentServiceProxy = equipmentServiceProxy;

            try
            {
                //
                // Load XML specification string from the lab configuration and save a copy of the XML node
                //
                XmlDocument xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlSpecification);
                XmlNode     xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_experimentSpecification);
                this.xmlNodeSpecification = xmlRootNode.Clone();

                //
                // Check that all required XML specification nodes exist
                //
                XmlUtilities.GetXmlValue(this.xmlNodeSpecification, Consts.STRXML_setupId, true);

                //
                // Load XML configuration string from the lab configuration and save a copy of the XML node
                //
                xmlDocument = XmlUtilities.GetXmlDocument(labConfiguration.XmlConfiguration);
                xmlRootNode = XmlUtilities.GetXmlRootNode(xmlDocument, Consts.STRXML_configuration);
                this.xmlNodeConfiguration = xmlRootNode.Clone();
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //-------------------------------------------------------------------------------------------------//
        public LabExperimentEngine(int unitId, AppData appData)
        {
            const string STRLOG_MethodName = "LabExperimentEngine";

            string logMessage = STRLOG_unitId + unitId.ToString();

            Logfile.WriteCalled(null, STRLOG_MethodName, logMessage);

            //
            // Initialise local variables
            //
            this.disposed = true;
            this.unitId = unitId;
            this.labExperimentInfo = null;

            //
            // Initialise private properties
            //
            this.slRunning = false;

            try
            {
                //
                // Initialise local variables from application data
                //
                if (appData == null)
                {
                    throw new ArgumentNullException(STRERR_appData);
                }

                this.allowedServiceBrokers = appData.allowedServiceBrokers;
                if (this.allowedServiceBrokers == null)
                {
                    throw new ArgumentNullException(STRERR_allowedServiceBrokers);
                }

                this.experimentQueue = appData.experimentQueue;
                if (this.experimentQueue == null)
                {
                    throw new ArgumentNullException(STRERR_experimentQueue);
                }

                this.experimentResults = appData.experimentResults;
                if (this.experimentResults == null)
                {
                    throw new ArgumentNullException(STRERR_experimentResults);
                }

                this.experimentStatistics = appData.experimentStatistics;
                if (this.experimentStatistics == null)
                {
                    throw new ArgumentNullException(STRERR_experimentStatistics);
                }

                this.labConfiguration = appData.labConfiguration;
                if (this.labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_labConfiguration);
                }

                this.signalCompleted = appData.signalCompleted;
                if (this.signalCompleted == null)
                {
                    throw new ArgumentNullException(STRERR_signalCompleted);
                }

                //
                // Try to get a proxy to the equipment service, it may not exist
                //
                this.equipmentServiceProxy = null;
                this.equipmentServiceAPI = null;
                try
                {
                    this.equipmentServiceAPI = new EquipmentServiceAPI(this.unitId);
                    this.equipmentServiceProxy = this.equipmentServiceAPI.EquipmentServiceProxy;
                    if (this.equipmentServiceProxy != null)
                    {
                        this.equipmentServiceProxy.GetTimeUntilReady();
                    }
                }
                catch
                {
                    // No equipment service available
                }

                //
                // Save email addresses for experiment completion notification
                //
                this.emailAddressLabServer = appData.emailAddressLabServer;
                this.emailAddressesExperimentCompleted = appData.emailAddressesExperimentCompleted;
                this.emailAddressesExperimentFailed = appData.emailAddressesExperimentFailed;

                //
                // Create thread objects
                //
                this.statusLock = new Object();
                if (this.statusLock == null)
                {
                    throw new ArgumentNullException(STRERR_statusLock);
                }
                this.threadLabExperimentEngine = new Thread(new ThreadStart(LabExperimentEngineThread));
                if (this.threadLabExperimentEngine == null)
                {
                    throw new ArgumentNullException(STRERR_threadLabExperimentEngine);
                }

                //
                // Don't start the thread yet, the method Start() must be called to start the thread
                // after the derived class has completed its initialisation.
                //
                Logfile.Write(STRLOG_LabExperimentEngineIsReady + STRLOG_unitId + this.unitId.ToString());
            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
 //-------------------------------------------------------------------------------------------------//
 public LabExperimentManager(AllowedServiceBrokersDB allowedServiceBrokers, LabConfiguration labConfiguration)
     : this(allowedServiceBrokers, labConfiguration, 0)
 {
 }
        //-------------------------------------------------------------------------------------------------//
        public LabExperimentManager(AllowedServiceBrokersDB allowedServiceBrokers, LabConfiguration labConfiguration, int farmSize)
        {
            const string STRLOG_MethodName = "LabExperimentManager";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            try
            {
                // Thread objects have not been created yet
                this.disposed = true;

                //
                // Initialise local variables
                //
                this.appData = new AppData();
                if (this.appData == null)
                {
                    throw new ArgumentNullException(STRERR_appData);
                }

                if (allowedServiceBrokers == null)
                {
                    throw new ArgumentNullException(STRERR_allowedServiceBrokers);
                }
                this.appData.allowedServiceBrokers = allowedServiceBrokers;

                if (labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_labConfiguration);
                }
                this.appData.labConfiguration = labConfiguration;

                //
                // Get the farm size
                //
                try
                {
                    if (farmSize == 0)
                    {
                        // Get the farm size from the Application's configuration file
                        this.appData.farmSize = Utilities.GetIntAppSetting(Consts.STRCFG_FarmSize);
                    }
                    else
                    {
                        this.appData.farmSize = farmSize;
                    }
                }
                catch (ArgumentNullException)
                {
                    // Farm size is not specified, default to 1
                    this.appData.farmSize = 1;
                }
                catch (Exception)
                {
                    throw new ArgumentException(STRERR_FarmSizeInvalid);
                }
                if (this.appData.farmSize < 1)
                {
                    throw new ArgumentException(STRERR_FarmSizeMinimum);
                }
                if (this.appData.farmSize > MAX_FARM_SIZE)
                {
                    throw new ArgumentException(STRERR_FarmSizeMaximum + MAX_FARM_SIZE.ToString());
                }

                Logfile.Write(STRLOG_farmSize + appData.farmSize);

                //
                // Create class instances and objects that are not derived
                //
                this.experimentQueue = new ExperimentQueueDB();
                if (this.experimentQueue == null)
                {
                    throw new ArgumentNullException(STRERR_experimentQueue);
                }
                this.appData.experimentQueue = this.experimentQueue;

                this.experimentResults = new ExperimentResults();
                if (this.experimentResults == null)
                {
                    throw new ArgumentNullException(STRERR_experimentResults);
                }
                this.appData.experimentResults = this.experimentResults;

                this.experimentStatistics = new ExperimentStatistics();
                if (this.experimentStatistics == null)
                {
                    throw new ArgumentNullException(STRERR_experimentStatistics);
                }
                this.appData.experimentStatistics = this.experimentStatistics;

                this.signalCompleted = new Object();
                if (this.signalCompleted == null)
                {
                    throw new ArgumentNullException(STRERR_signalCompleted);
                }
                this.appData.signalCompleted = this.signalCompleted;

                //
                // Get email addresses for the LabServer, experiment completion/cancelled and failed
                //
                try
                {
                    this.appData.emailAddressLabServer = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressLabServer);
                    char[] splitterCharArray = new char[] { Consts.CHR_CsvSplitterChar };
                    string csvEmail = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressesExperimentCompleted);
                    this.appData.emailAddressesExperimentCompleted = csvEmail.Split(splitterCharArray);
                    csvEmail = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressesExperimentFailed);
                    this.appData.emailAddressesExperimentFailed = csvEmail.Split(splitterCharArray);
                }
                catch
                {
                }

                //
                // Initialise property variables
                //
                this.slRunning = false;
                this.slStatus = StatusCodes.Unknown;
                this.slOnline = false;
                this.slLabStatusMessage = string.Empty;

                //
                // Create thread objects
                //
                this.managerLock = new Object();
                if (this.managerLock == null)
                {
                    throw new ArgumentNullException(STRERR_managerLock);
                }
                this.statusLock = new Object();
                if (this.statusLock == null)
                {
                    throw new ArgumentNullException(STRERR_statusLock);
                }
                this.signalSubmitted = new Object();
                if (this.signalSubmitted == null)
                {
                    throw new ArgumentNullException(STRERR_signalSubmitted);
                }
                this.threadLabExperimentManager = new Thread(new ThreadStart(LabExperimentManagerThread));
                if (this.threadLabExperimentManager == null)
                {
                    throw new ArgumentNullException(STRERR_threadLabExperimentManager);
                }

                //
                // Don't start the thread yet, the method Start() must be called to start the thread
                // after the derived class has completed its initialisation.
                //

            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
        //-------------------------------------------------------------------------------------------------//

        public LabExperimentEngine(int unitId, AppData appData)
        {
            const string STRLOG_MethodName = "LabExperimentEngine";

            string logMessage = STRLOG_unitId + unitId.ToString();

            Logfile.WriteCalled(null, STRLOG_MethodName, logMessage);

            //
            // Initialise local variables
            //
            this.disposed          = true;
            this.unitId            = unitId;
            this.labExperimentInfo = null;

            //
            // Initialise private properties
            //
            this.slRunning = false;

            try
            {
                //
                // Initialise local variables from application data
                //
                if (appData == null)
                {
                    throw new ArgumentNullException(STRERR_appData);
                }

                this.allowedServiceBrokers = appData.allowedServiceBrokers;
                if (this.allowedServiceBrokers == null)
                {
                    throw new ArgumentNullException(STRERR_allowedServiceBrokers);
                }

                this.experimentQueue = appData.experimentQueue;
                if (this.experimentQueue == null)
                {
                    throw new ArgumentNullException(STRERR_experimentQueue);
                }

                this.experimentResults = appData.experimentResults;
                if (this.experimentResults == null)
                {
                    throw new ArgumentNullException(STRERR_experimentResults);
                }

                this.experimentStatistics = appData.experimentStatistics;
                if (this.experimentStatistics == null)
                {
                    throw new ArgumentNullException(STRERR_experimentStatistics);
                }

                this.labConfiguration = appData.labConfiguration;
                if (this.labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_labConfiguration);
                }

                this.signalCompleted = appData.signalCompleted;
                if (this.signalCompleted == null)
                {
                    throw new ArgumentNullException(STRERR_signalCompleted);
                }

                //
                // Try to get a proxy to the equipment service, it may not exist
                //
                this.equipmentServiceProxy = null;
                this.equipmentServiceAPI   = null;
                try
                {
                    this.equipmentServiceAPI   = new EquipmentServiceAPI(this.unitId);
                    this.equipmentServiceProxy = this.equipmentServiceAPI.EquipmentServiceProxy;
                    if (this.equipmentServiceProxy != null)
                    {
                        this.equipmentServiceProxy.GetTimeUntilReady();
                    }
                }
                catch
                {
                    // No equipment service available
                }

                //
                // Save email addresses for experiment completion notification
                //
                this.emailAddressLabServer             = appData.emailAddressLabServer;
                this.emailAddressesExperimentCompleted = appData.emailAddressesExperimentCompleted;
                this.emailAddressesExperimentFailed    = appData.emailAddressesExperimentFailed;

                //
                // Create thread objects
                //
                this.statusLock = new Object();
                if (this.statusLock == null)
                {
                    throw new ArgumentNullException(STRERR_statusLock);
                }
                this.threadLabExperimentEngine = new Thread(new ThreadStart(LabExperimentEngineThread));
                if (this.threadLabExperimentEngine == null)
                {
                    throw new ArgumentNullException(STRERR_threadLabExperimentEngine);
                }

                //
                // Don't start the thread yet, the method Start() must be called to start the thread
                // after the derived class has completed its initialisation.
                //
                Logfile.Write(STRLOG_LabExperimentEngineIsReady + STRLOG_unitId + this.unitId.ToString());
            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
Esempio n. 13
0
        //-------------------------------------------------------------------------------------------------//

        public LabExperimentManager(AllowedServiceBrokersDB allowedServiceBrokers, LabConfiguration labConfiguration, int farmSize)
        {
            const string STRLOG_MethodName = "LabExperimentManager";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            try
            {
                // Thread objects have not been created yet
                this.disposed = true;

                //
                // Initialise local variables
                //
                this.appData = new AppData();
                if (this.appData == null)
                {
                    throw new ArgumentNullException(STRERR_appData);
                }

                if (allowedServiceBrokers == null)
                {
                    throw new ArgumentNullException(STRERR_allowedServiceBrokers);
                }
                this.appData.allowedServiceBrokers = allowedServiceBrokers;

                if (labConfiguration == null)
                {
                    throw new ArgumentNullException(STRERR_labConfiguration);
                }
                this.appData.labConfiguration = labConfiguration;

                //
                // Get the farm size
                //
                try
                {
                    if (farmSize == 0)
                    {
                        // Get the farm size from the Application's configuration file
                        this.appData.farmSize = Utilities.GetIntAppSetting(Consts.STRCFG_FarmSize);
                    }
                    else
                    {
                        this.appData.farmSize = farmSize;
                    }
                }
                catch (ArgumentNullException)
                {
                    // Farm size is not specified, default to 1
                    this.appData.farmSize = 1;
                }
                catch (Exception)
                {
                    throw new ArgumentException(STRERR_FarmSizeInvalid);
                }
                if (this.appData.farmSize < 1)
                {
                    throw new ArgumentException(STRERR_FarmSizeMinimum);
                }
                if (this.appData.farmSize > MAX_FARM_SIZE)
                {
                    throw new ArgumentException(STRERR_FarmSizeMaximum + MAX_FARM_SIZE.ToString());
                }

                Logfile.Write(STRLOG_farmSize + appData.farmSize);

                //
                // Create class instances and objects that are not derived
                //
                this.experimentQueue = new ExperimentQueueDB();
                if (this.experimentQueue == null)
                {
                    throw new ArgumentNullException(STRERR_experimentQueue);
                }
                this.appData.experimentQueue = this.experimentQueue;

                this.experimentResults = new ExperimentResults();
                if (this.experimentResults == null)
                {
                    throw new ArgumentNullException(STRERR_experimentResults);
                }
                this.appData.experimentResults = this.experimentResults;

                this.experimentStatistics = new ExperimentStatistics();
                if (this.experimentStatistics == null)
                {
                    throw new ArgumentNullException(STRERR_experimentStatistics);
                }
                this.appData.experimentStatistics = this.experimentStatistics;

                this.signalCompleted = new Object();
                if (this.signalCompleted == null)
                {
                    throw new ArgumentNullException(STRERR_signalCompleted);
                }
                this.appData.signalCompleted = this.signalCompleted;

                //
                // Get email addresses for the LabServer, experiment completion/cancelled and failed
                //
                try
                {
                    this.appData.emailAddressLabServer = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressLabServer);
                    char[] splitterCharArray = new char[] { Consts.CHR_CsvSplitterChar };
                    string csvEmail          = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressesExperimentCompleted);
                    this.appData.emailAddressesExperimentCompleted = csvEmail.Split(splitterCharArray);
                    csvEmail = Utilities.GetAppSetting(Consts.STRCFG_EmailAddressesExperimentFailed);
                    this.appData.emailAddressesExperimentFailed = csvEmail.Split(splitterCharArray);
                }
                catch
                {
                }

                //
                // Initialise property variables
                //
                this.slRunning          = false;
                this.slStatus           = StatusCodes.Unknown;
                this.slOnline           = false;
                this.slLabStatusMessage = string.Empty;

                //
                // Create thread objects
                //
                this.managerLock = new Object();
                if (this.managerLock == null)
                {
                    throw new ArgumentNullException(STRERR_managerLock);
                }
                this.statusLock = new Object();
                if (this.statusLock == null)
                {
                    throw new ArgumentNullException(STRERR_statusLock);
                }
                this.signalSubmitted = new Object();
                if (this.signalSubmitted == null)
                {
                    throw new ArgumentNullException(STRERR_signalSubmitted);
                }
                this.threadLabExperimentManager = new Thread(new ThreadStart(LabExperimentManagerThread));
                if (this.threadLabExperimentManager == null)
                {
                    throw new ArgumentNullException(STRERR_threadLabExperimentManager);
                }

                //
                // Don't start the thread yet, the method Start() must be called to start the thread
                // after the derived class has completed its initialisation.
                //
            }
            catch (Exception ex)
            {
                // Log the message and throw the exception back to the caller
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
Esempio n. 14
0
        //-------------------------------------------------------------------------------------------------//

        public LabExperimentManager(AllowedServiceBrokersDB allowedServiceBrokers, LabConfiguration labConfiguration)
            : this(allowedServiceBrokers, labConfiguration, 0)
        {
        }