/// <summary> /// Takes an xml string, and returns a DataValue object. /// Returns null if the xml doesn't represent a DataValue. /// </summary> /// <param name="xml"></param> /// <returns></returns> public static DataValue XMLDeserialize(string xml) { Match m = typeregex.Match(xml); if (m.Success) { Group g = m.Groups[1]; string dataType = g.ToString(); switch (dataType) { case "StringType": StringValue sv = new StringValue(); sv.FromXML(xml); return sv; case "DoubleType": DoubleValue dv = new DoubleValue(); dv.FromXML(xml); return dv; case "IntegerType": IntegerValue iv = new IntegerValue(); iv.FromXML(xml); return iv; case "BooleanType": BooleanValue bv = new BooleanValue(); bv.FromXML(xml); return bv; case "LocationType": LocationValue lv = new LocationValue(); lv.FromXML(xml); return lv; case "VelocityType": VelocityValue vv = new VelocityValue(); vv.FromXML(xml); return vv; case "AttributeCollectionType": AttributeCollectionValue av = new AttributeCollectionValue(); av.FromXML(xml); return av; case "CustomAttributesType": CustomAttributesValue cav = new CustomAttributesValue(); cav.FromXML(xml); return cav; case "StringListType": StringListValue slv = new StringListValue(); slv.FromXML(xml); return slv; case "PolygonType": PolygonValue polyv = new PolygonValue(); polyv.FromXML(xml); return polyv; case "StateTableType": StateTableValue stv = new StateTableValue(); stv.FromXML(xml); return stv; case "CapabilityType": CapabilityValue cv = new CapabilityValue(); cv.FromXML(xml); return cv; case "VulnerabilityType": VulnerabilityValue vv2 = new VulnerabilityValue(); vv2.FromXML(xml); return vv2; case "ConeType": ConeValue cv2 = new ConeValue(); cv2.FromXML(xml); return cv2; case "SensorType": SensorValue sv2 = new SensorValue(); sv2.FromXML(xml); return sv2; case "SensorArrayType": SensorArrayValue sav = new SensorArrayValue(); sav.FromXML(xml); return sav; case "EmitterType": EmitterValue ev = new EmitterValue(); ev.FromXML(xml); return ev; case "RangeRingDisplayType": RangeRingDisplayValue rrdv = new RangeRingDisplayValue(); rrdv.FromXML(xml); return rrdv; case "AttackCollectionType": AttackCollectionValue attCV = new AttackCollectionValue(); attCV.FromXML(xml); return attCV; case "WrapperType": WrapperValue wrapper = new WrapperValue(); wrapper.FromXML(xml); return wrapper; case "ClassificationDisplayRulesType": ClassificationDisplayRulesValue cdrv = new ClassificationDisplayRulesValue(); cdrv.FromXML(xml); return cdrv; default: return null; } } else { return null; } }
new public void FromXML(string xml) { Match m = regex.Match(xml); List<ConeValue> attributesCones; if (m.Success) { ranges = new Dictionary<string, List<ConeValue>>(); sensorName = m.Groups[1].Value; maxRange = Convert.ToDouble(m.Groups[2].Value); string attributeLists = m.Groups[3].Value; foreach (Match m3 in attsregex.Matches(attributeLists)) { attributesCones = new List<ConeValue>(); string attname = m3.Groups[1].Value; bool isEngram = Boolean.Parse(m3.Groups[2].Value); attIsEngram[attname] = isEngram; foreach (Match m4 in attregex.Matches(m3.Groups[3].Value)) { ConeValue cv = new ConeValue(); cv.FromXML(m4.Value); attributesCones.Add(cv); } ranges.Add(attname, attributesCones); } } else { throw new Exception(String.Format("Invalid XML string in {0}: {1}", dataType, xml)); } }