#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Net; using System.Threading; using HeuristicLab.Clients.Hive.SlaveCore; using Microsoft.WindowsAzure.Diagnostics; using Microsoft.WindowsAzure.ServiceRuntime; namespace HeuristicLab.Clients.Hive.Slave.AzureClient { public class WorkerRole : RoleEntryPoint { private Core core; private Thread coreThread; private const string HiveServerAddressSetting = "HiveServerAddress"; private const string HiveServerCertificateSetting = "HiveServerCertifcateEncodedValue"; public override void Run() { core = new Core(false); string hiveServerAddress = RoleEnvironment.GetConfigurationSettingValue(HiveServerAddressSetting); string hiveServerCertificate = RoleEnvironment.GetConfigurationSettingValue(HiveServerCertificateSetting); // values are empty, settings from app.config are used if (!string.IsNullOrEmpty(hiveServerAddress) && !string.IsNullOrEmpty(hiveServerCertificate)) { core.SetNewHiveServer(hiveServerAddress, hiveServerCertificate); } coreThread = new Thread(core.Start); coreThread.Start(); while (true) { Thread.Sleep(10000); } } public override bool OnStart() { ServicePointManager.DefaultConnectionLimit = 12; //core = new Core(); try { if (!String.IsNullOrEmpty(RoleEnvironment.GetConfigurationSettingValue(Constants.DiagnosticsConnectionString))) { DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration(); dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1); dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose; DiagnosticMonitor.Start(Constants.DiagnosticsConnectionString, dmc); } } catch (RoleEnvironmentException ex) { // diagnostics connection string not in configuration // -> diagnostics disabled // nothing more to do } RoleEnvironment.Changed += RoleEnvironmentChanged; return base.OnStart(); } public override void OnStop() { core.Shutdown(); base.OnStop(); } private void RoleEnvironmentChanged(object sender, RoleEnvironmentChangedEventArgs e) { } } }