public void Start() { ProcessCommandLine(); string adapterName = "None"; if (CommandLineInterface != null) { // valid interface specified on command line iIpAddress = CommandLineInterface.IPAddress; adapterName = "command line interface: " + CommandLineInterface.Name; } else { string hostName = Dns.GetHostName(); // If running on eng server - set the interface to send multicast on if (hostName == "ascit" || hostName == "eng") { iIpAddress = IPAddress.Parse("10.2.7.70"); adapterName = "server interface: " + hostName; } else { IList <NetworkInfoModel> ifaces = NetworkInfo.GetAllNetworkInterfaces(); foreach (NetworkInfoModel iface in ifaces) { // select first interface that is detected iIpAddress = iface.IPAddress; adapterName = "first interface discovered: " + iface.Name; break; } } } Console.WriteLine("Application started using " + adapterName + " (" + iIpAddress.ToString() + ")"); }
public Network(Helper aHelper) { iHelper = aHelper; iBoxList = new List <Box>(); iNetworkChangeWatcher = new NetworkChangeWatcher(); // create the list of network interfaces iInterfaces = new List <NetworkInterface>(); foreach (NetworkInfoModel i in NetworkInfo.GetAllNetworkInterfaces()) { if (i.OperationalStatus == EOperationalStatus.eUp || i.OperationalStatus == EOperationalStatus.eUnknown) { // don't add 3G network card on iPads/iPhones if (i.Name != "pdp_ip0") { iInterfaces.Add(new NetworkInterface(i)); } } } // create separate network stacks for each available interface iNetworkStacks = new List <NetworkStack>(); foreach (NetworkInterface iface in iInterfaces) { if (iface.Status == NetworkInterface.EStatus.eAvailable) { NetworkStack stack = new NetworkStack(aHelper, iface.Info.IPAddress); stack.Boxes.EventRoomAdded += RoomAddedHandler; stack.Boxes.EventRoomRemoved += RoomRemovedHandler; try { // start the stack UserLog.WriteLine(String.Format("{0}: Linn.Wizard.Network starting stack({1})", DateTime.Now, iface.Info.IPAddress.ToString())); stack.Start(); UserLog.WriteLine(String.Format("{0}: Linn.Wizard.Network starting stack({1}) ok", DateTime.Now, iface.Info.IPAddress.ToString())); // success - add it to the list iNetworkStacks.Add(stack); } catch (Exception e) { // failed to start - unhook handlers and ignore UserLog.WriteLine(String.Format("{0}: Linn.Wizard.Network starting stack({1}) failed", DateTime.Now, iface.Info.IPAddress.ToString())); UserLog.WriteLine("Error Message: " + e.Message); UserLog.WriteLine("Error Message: " + e.ToString()); stack.Boxes.EventRoomAdded -= RoomAddedHandler; stack.Boxes.EventRoomRemoved -= RoomRemovedHandler; } } } }