- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Clients.Hive.Slave/3.3/Manager/ConfigManager.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using System.Linq; 26 26 using System.Management; 27 using System.Net.NetworkInformation; 27 28 using HeuristicLab.Clients.Hive.SlaveCore.Properties; 28 29 … … 34 35 public class ConfigManager { 35 36 private static ConfigManager instance = null; 37 private const string vmwareNameString = "VMware"; 38 private const string virtualboxNameString = "VirtualBox"; 39 private const int macLength = 6; 40 private const int macLongLength = 8; 41 36 42 public static ConfigManager Instance { 37 43 get { return instance; } … … 117 123 st.JobsFetched = SlaveStatusInfo.TasksFetched; 118 124 st.JobsFailed = SlaveStatusInfo.TasksFailed; 119 st.ExceptionsOccured = SlaveStatusInfo.ExceptionsOccured;120 125 121 126 st.Jobs = jobManager.GetExecutionTimes().Select(x => new TaskStatus { TaskId = x.Key, ExecutionTime = x.Value }).ToList(); … … 180 185 /// </summary> 181 186 private static Guid GetUniqueMachineIdFromMac() { 182 ManagementClass mgtClass = new ManagementClass("Win32_NetworkAdapterConfiguration"); 183 ManagementObjectCollection mgtCol = mgtClass.GetInstances(); 184 185 foreach (ManagementObject mgtObj in mgtCol) { 186 foreach (var prop in mgtObj.Properties) { 187 if (prop.Value != null && prop.Name == "MACAddress") { 188 try { 189 //simply take the first nic 190 string mac = prop.Value.ToString(); 191 byte[] b = new byte[8]; 192 string[] macParts = mac.Split(':'); 193 if (macParts.Length == 6) { 194 for (int i = 0; i < macParts.Length; i++) { 195 b[i + 2] = (byte)((ParseNybble(macParts[i][0]) << 4) | ParseNybble(macParts[i][1])); 196 } 197 198 // also get machine name and save it to the first 4 bytes 199 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, b); 200 return guid; 201 } else 202 throw new Exception("Error getting mac addresse"); 203 } 204 catch { 205 throw new Exception("Error getting mac addresse"); 206 } 207 } 208 } 209 } 210 throw new Exception("Error getting mac addresse"); 211 } 212 213 /// <summary> 214 /// return numeric value of a single hex-char 215 /// (see: http://stackoverflow.com/questions/854012/how-to-convert-hex-to-a-byte-array) 216 /// </summary> 217 static int ParseNybble(char c) { 218 if (c >= '0' && c <= '9') { 219 return c - '0'; 220 } 221 if (c >= 'A' && c <= 'F') { 222 return c - 'A' + 10; 223 } 224 if (c >= 'a' && c <= 'f') { 225 return c - 'a' + 10; 226 } 227 throw new ArgumentException("Invalid hex digit: " + c); 187 //try to get a real network interface, not a virtual one 188 NetworkInterface validNic = NetworkInterface.GetAllNetworkInterfaces() 189 .FirstOrDefault(x => 190 !x.Name.Contains(vmwareNameString) && 191 !x.Name.Contains(virtualboxNameString) && 192 (x.NetworkInterfaceType == NetworkInterfaceType.Ethernet || 193 x.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet)); 194 195 if (validNic == default(NetworkInterface)) { 196 validNic = NetworkInterface.GetAllNetworkInterfaces().First(); 197 } 198 199 byte[] addr = validNic.GetPhysicalAddress().GetAddressBytes(); 200 if (addr.Length < macLength || addr.Length > macLongLength) { 201 throw new ArgumentException(string.Format("Error generating slave UID: MAC address has to have a length between {0} and {1} bytes. Actual MAC address is: {2}", 202 macLength, macLongLength, addr)); 203 } 204 205 if (addr.Length < macLongLength) { 206 byte[] b = new byte[8]; 207 Array.Copy(addr, 0, b, 2, addr.Length); 208 addr = b; 209 } 210 211 // also get machine name and save it to the first 4 bytes 212 Guid guid = new Guid(Environment.MachineName.GetHashCode(), 0, 0, addr); 213 return guid; 228 214 } 229 215
Note: See TracChangeset
for help on using the changeset viewer.