/// <summary> /// Parses a string into a connection object. /// </summary> /// <param name="text">The specified connection string.</param> /// <returns>Returns the connection object.</returns> public static InsteonConnection Parse(string text) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException(); } Regex connectionPattern = new Regex(@"\s*(?<type>[^: ]+)\s*:\s*(?<value>[^, ]+)\s*(,\s*(?<name>[^,]+)\s*)?(,\s*(?<address>[^, ]+))?"); Match m = connectionPattern.Match(text); if (!m.Success) { throw new FormatException(); } string type = m.Groups["type"].ToString().Trim(); string value = m.Groups["value"].ToString().Trim(); string name = m.Groups["name"].ToString().Trim(); string address = m.Groups["address"].ToString().Trim(); if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(value)) { throw new FormatException(); } type = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(type); InsteonConnectionType rtype = (InsteonConnectionType)System.Enum.Parse(typeof(InsteonConnectionType), type); InsteonAddress raddress = !string.IsNullOrEmpty(address) ? InsteonAddress.Parse(address) : new InsteonAddress(); return(new InsteonConnection(rtype, value, name, raddress)); }
internal SmartLincInfo(string url, string address) { this.Uri = new Uri(url); this.InsteonAddress = InsteonAddress.Parse(address); }