// Set the substitution values for a class private bool VerifySubValues(ccSR attribute, XmlNode c, string delimiter) { bool success = true; // Avoid user errors if (int.TryParse(GetXmlAttr(c, "Base"), out int b)) { Prop prop = EIP.AttrDict[ClassCode.Substitution_rules, (byte)attribute].Set; string[] s = GetXmlValue(c).Split(delimiter[0]); for (int i = 0; i < s.Length; i++) { int n = b + i; // Avoid user errors if (n >= prop.Min && n <= prop.Max) { string sent = s[i]; string back = GetAttribute(attribute, n); if (ReportAll || sent != back) { string msg = $"{c.Name}\t{GetAttrData(attribute).Class}\t{attribute}\t{n}" + $"\t{"N/A"}\t{GetIndexSetting(ccIDX.Item)}\t{sent}\t{back}"; Traffic?.Tasks.Add(new TrafficPkt(Traffic.TaskType.AddVerify, msg.Replace('_', ' '))); } } } } return(success); }
// Add a new rule to either msg or global private void AddOneRule(Src n) { ccSR attr = (ccSR)cbAttribute.SelectedIndex; // Make sure the user filled it in if (ruleSpecified(attr)) { // Get the new rule SubstitutionRule sr = GetSubstitutionRule(attr); if (Subs[(int)n] == null) { // Create a whole new substitution with one rule Subs[(int)n] = GetNewSubstitution(); Subs[(int)n].SubRule = new SubstitutionRule[] { sr }; } else { // Delete the rule if it exists List <SubstitutionRule> r = new List <SubstitutionRule>(); foreach (SubstitutionRule t in Subs[(int)n].SubRule) { if (t.Type != attr.ToString()) { r.Add(t); } } // Add the new rule to the list and turn it back to an array r.Add(sr); Subs[(int)n].SubRule = r.ToArray(); } } }
// Check to see if a rule is being used private bool ruleSpecified(ccSR rule) { for (int i = 0; i < subTexts[(int)rule].Length; i++) { if (!string.IsNullOrEmpty(subTexts[(int)rule][i].Text)) { return(true); } } return(false); }
// get the substitutions for one type private SubstitutionRule GetSubstitutionRule(ccSR t) { TextBox[] tbs = subTexts[(int)t]; string[] s = new string[tbs.Length]; for (int i = 0; i < tbs.Length; i++) { s[i] = tbs[i].Text; } return(new SubstitutionRule() { Base = startWith[(int)t], Type = t.ToString(), Text = String.Join(txtDelimiter.Text, s) }); }
private void SetSubValues(ccSR attribute, SubstitutionRule r, string delimiter) { Prop prop = EIP.AttrDict[ClassCode.Substitution_rules, (byte)attribute].Set; string[] s = r.Text.Split(delimiter[0]); for (int i = 0; i < s.Length; i++) { int n = r.Base + i; // Avoid user errors if (n >= prop.Min && n <= prop.Max) { byte[] data = FormatOutput(prop, n, 1, s[i]); SetAttribute(ClassCode.Substitution_rules, (byte)attribute, data); } } }
private void SetSubValues(ccSR attribute, SubstitutionRule r, string delimiter) { Prop prop = Data.AttrDict[ClassCode.Substitution_rules, (int)attribute].Data; string[] s = r.Text.Split(delimiter[0]); string t = new string(' ', prop.Len); for (int i = 0; i < s.Length; i++) { int n = r.Base + i; // Avoid user errors if (n >= prop.Min && n <= prop.Max) { string t2 = new string(' ', prop.Len) + s[i]; p.SetAttribute(attribute, n - prop.Min, t2.Substring(t2.Length - prop.Len)); } } }
// Set the values associated with a rule private void SetSubValues(ccSR attribute, SubstitutionRule r, string delimiter) { AttrData attr = p.GetAttrData(attribute); Prop prop = attr.Data; string[] s = r.Text.Split(delimiter[0]); int n = Math.Min(attr.Count, s.Length); Section <ccSR> sub = new Section <ccSR>(p, attribute, 0, prop.Len * n, false); { // Avoid many I/Os for (int i = 0; i < n; i++) { if (!string.IsNullOrEmpty(s[i])) { sub.SetAttribute(attribute, i, s[i]); } } sub.WriteSection(); } }
private void RetrieveSubstitution(List <SubstitutionRule> sr, ccSR rule) { AttrData attr = GetAttrData(rule); int n = (int)(attr.Get.Max - attr.Get.Min + 1); string[] subCode = new string[n]; for (int i = 0; i < n; i++) { subCode[i] = GetAttribute(rule, i + (int)attr.Get.Min); } for (int i = 0; i < n; i += 10) { sr.Add(new SubstitutionRule() { Type = rule.ToString().Replace("_", ""), Base = (int)(i + attr.Get.Min), Text = string.Join("/", subCode, i, Math.Min(10, n - i)), }); } }