/// <summary> /// Device factory /// </summary> /// <param name="multicastMessage">Device multicast discovery message</param> /// <returns></returns> public static Device Create(string multicastMessage) { Device discoveredDevice = null; // support limited special characters for computer name string exp1 = "((?:[a-zA-Z0-9]|[_.\\-])+)"; string exp2 = ".*?"; // Non-greedy match on filler string exp3 = "((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\\d])"; // IPv4 IP Address 1 string exp4 = ".*?"; // Non-greedy match on filler string exp5 = "((?:[0-9A-F][0-9A-F]:){5}(?:[0-9A-F][0-9A-F]))(?![:0-9A-F])"; // Mac Address 1 Regex matchExp = new Regex(exp1 + exp2 + exp3 + exp4 + exp5, RegexOptions.IgnoreCase | RegexOptions.Singleline); Match fields = matchExp.Match(multicastMessage); if (fields.Success) { discoveredDevice = new Device(); discoveredDevice.name = fields.Groups[1].ToString(); discoveredDevice.networkAddress = fields.Groups[2].ToString(); discoveredDevice.macAddress = fields.Groups[3].ToString(); discoveredDevice.lastPing = DateTime.Now; } return discoveredDevice; }
public EnumerationEventArgs(Device device) { this.device = device; }