//-------------------------------------------------------------------------------------------------// 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 ExperimentEngine(int unitId, AppData appData) : base(unitId, appData) { this.configuration = (Configuration)appData.labConfiguration; }
//-------------------------------------------------------------------------------------------------// 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); }