private void AddBerConverterToXML(DynamicBerConverter ber, ref XElement xmlRoot) { foreach (int pos in ber.ConversionRules.Keys) { XElement xmlber = new XElement(DECODE_ID); xmlber.Add(new XAttribute(NAME_ID, ber.Name)); xmlber.Add(new XAttribute(TAGS_ID, ber.IncludeTags)); string rule = ber.ConversionRules[pos]; rule = rule.Replace("{", String.Empty); rule = rule.Replace("}", String.Empty); xmlber.Add(new XAttribute(VALUE_ID, rule)); foreach (string field in ber.FieldNames[pos].Values) { xmlber.Add(new XElement(FIELD_ID, new XAttribute(NAME_ID, field))); } xmlRoot.Add(xmlber); } }
private void GetBerConverterFromXML(XElement xmlBer) { DynamicBerConverter dynber = new DynamicBerConverter(); if (xmlBer.Attributes(NAME_ID).FirstOrDefault() == null) { return; } dynber.Name = xmlBer.Attributes(NAME_ID).FirstOrDefault().Value; string tags = "false";; if (xmlBer.Attributes(TAGS_ID).FirstOrDefault() != null) { tags = xmlBer.Attributes(TAGS_ID).FirstOrDefault().Value; } bool incltags = false; Boolean.TryParse(tags, out incltags); dynber.IncludeTags = incltags; if (BerConverterList.ContainsKey(dynber.Name)) { dynber = BerConverterList[dynber.Name]; } dynber.SetConversionRule(xmlBer.Attributes(VALUE_ID).FirstOrDefault().Value); foreach (XElement xmlfield in xmlBer.Elements(FIELD_ID)) { if (xmlfield.Attributes(NAME_ID).FirstOrDefault() != null) { string name = xmlfield.Attributes(NAME_ID).FirstOrDefault().Value; dynber.AddFieldName(name); } } BerConverterList.AddSafe <string, DynamicBerConverter>(dynber.Name, dynber); }
public List <string> DynamicBerDecoding(DirectoryAttribute attrib, DynamicAttributeAssociator assoc, ref bool match) { List <string> ret = new List <string>(); DynamicBerConverter dynber = ForestBase.ADHelperDynamicDLL.BerConverterList.GetValueSafe <string, DynamicBerConverter>(assoc.BerConverterName); if (dynber != null) { List <string> fields = new List <string>(); try { foreach (byte[] value in attrib.GetValues(typeof(byte[]))) { fields = dynber.DecodePrintable(value); if (fields.Count != 0) { ret.AddRange(fields); } else { ret.AddFormatted("\t\t<not decoded>: {0}", ASCIIEncoding.Unicode.GetString(value)); } } match = true; } catch (Exception ex) { ex.ToDummy(); ret.AddFormatted("\t\t<not decoded>: {0}", attrib[0].GetType().ToString()); } } return(ret); }
public StatsData(byte[] statsControlValue) { DynamicBerConverter dynber = MainBase.DynamicDll.BerConverterList.Where(b => b.Key == "StatsData").FirstOrDefault().Value; Fields = dynber.Decode(statsControlValue); }