private static void ParseAttribute(Context context, Attribute attribute) { bool addBreak = false; while (context.Lines.Count > 0) { string line = context.Lines[0]; context.Lines.RemoveAt(0); // Returning to previous level. if (line.StartsWith("# ") || line.StartsWith("## ") || line.StartsWith("### ") || line.StartsWith("#### ")) { context.Lines.Insert(0, line); return; } if (line.StartsWith("|") && !line.StartsWith("|Id") && !line.StartsWith("|-")) { string row = line.Trim().Substring(1, line.Length - 1); string[] columns = row.Split("|"); int value = int.Parse(columns[0].Trim().Substring(2), System.Globalization.NumberStyles.HexNumber); String label = columns[1].Trim(); attribute.ValueMap[value] = label; continue; } if (line.StartsWith("|Id") || line.StartsWith("|-")) { continue; } if ((attribute.AttributeDescription.Count == 0 && line.Trim().Length == 0)) { continue; } if (line.Trim().Length == 0 && attribute.AttributeDescription.Count > 0) { addBreak = true; continue; } if (addBreak && attribute.AttributeDescription.Count > 0) { attribute.AttributeDescription.Add(""); addBreak = false; } attribute.AttributeDescription.Add(line.Trim()); } }
private static void ParseAttributes(Context context) { Attribute attribute = null; while (context.Lines.Count > 0) { string line = context.Lines[0]; context.Lines.RemoveAt(0); // Returning to previous level. if (line.StartsWith("# ") || line.StartsWith("## ") || line.StartsWith("### ")) { context.Lines.Insert(0, line); return; } if (line.StartsWith("|") && !line.StartsWith("|Id") && !line.StartsWith("|-")) { ParseAttributeTable(context, line); } if (line.StartsWith("#### ")) { attribute = null; foreach (Attribute attr in context.Cluster.Attributes.Values) { if (attr.AttributeLabel.Equals(GetHeaderTitle(line).Substring(0, GetHeaderTitle(line).IndexOf(" ")))) { attribute = attr; break; } } if (attribute == null) { Console.WriteLine("***** Attribute not found: " + line); continue; } ParseAttribute(context, attribute); continue; } } }
private static void ParseAttributeTable(Context context, string line) { string row = line.Trim().Substring(1, line.Length - 1); string[] columns = row.Split("|"); Attribute attribute = new Attribute(); attribute.ValueMap = new SortedDictionary <int, string>(); attribute.AttributeId = int.Parse(columns[0].Trim().Substring(2), System.Globalization.NumberStyles.HexNumber); attribute.AttributeLabel = columns[1].Trim(); attribute.AttributeDescription = new List <string>(); attribute.AttributeAccess = columns[3].Trim(); attribute.AttributeImplementation = columns[4].Trim(); attribute.AttributeReporting = columns[5].Trim(); attribute.NameUpperCamelCase = CodeGeneratorUtil.LabelToEnumerationValue(attribute.AttributeLabel); attribute.NameUpperCamelCase = CodeGeneratorUtil.LabelToUpperCamelCase(attribute.AttributeLabel); attribute.NameLowerCamelCase = CodeGeneratorUtil.UpperCamelCaseToLowerCamelCase(attribute.NameUpperCamelCase); attribute.DataType = CodeGeneratorUtil.LabelToEnumerationValue(columns[2].Trim()); attribute.EnumName = "ATTR_" + attribute.AttributeLabel.ToUpper(); DataType dataType = new DataType(); dataType.DataTypeName = columns[2].Trim(); dataType.DataTypeType = attribute.DataType; Console.WriteLine(" Type:::" + attribute.AttributeLabel + ":: " + dataType.DataTypeType); dataType.DataTypeClass = ZclDataType.Mapping[attribute.DataType].DataClass; if (dataType.DataTypeClass == null) { throw new ArgumentException("Type not mapped: " + attribute.DataType); } attribute.DataTypeClass = dataType.DataTypeClass; context.DataTypes[attribute.DataType] = dataType; context.Cluster.Attributes.Add(attribute.AttributeId, attribute); }