using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Clients.Hive.SlaveCore; using Microsoft.WindowsAzure.ServiceRuntime; namespace HeuristicLab.Clients.Hive.Slave.AzureClient { static class HiveHelper { private static HiveServiceLocator ConfigureHive() { var serviceLocator = new HiveServiceLocator(); serviceLocator.RemoteAddress = RoleEnvironment.GetConfigurationSettingValue("HiveServerAddress"); serviceLocator.IdentityCertificate = RoleEnvironment.GetConfigurationSettingValue("HiveServerCertifcateEncodedValue"); serviceLocator.Username = RoleEnvironment.GetConfigurationSettingValue("HiveServerUsername"); serviceLocator.Password = RoleEnvironment.GetConfigurationSettingValue("HiveServerPassword"); return serviceLocator; } public static void RegisterSlaveToGroup(string groupName) { var locator = ConfigureHive(); var me = locator.CallHiveService(service => { return service.GetSlave(ConfigManager.Instance.GetClientInfo().Id); }); var group = locator.CallHiveService(service => { return (from s in service.GetSlaveGroups() where s.Name == groupName select s).FirstOrDefault(); }); if (me.ParentResourceId == null || me.ParentResourceId != me.Id) { me.ParentResourceId = group.Id; locator.CallHiveService((s) => s.UpdateSlaveGroup((SlaveGroup)group)); locator.CallHiveService((s) => s.UpdateSlave(me)); } } } }