// Load substitutions private void LoadBuildSubstitution(XmlNode p) { // Get the standard attributes for substitution string rule = GetXmlAttr(p, "RuleNumber"); string startYear = GetXmlAttr(p, "StartYear"); string delimiter = GetXmlAttr(p, "Delimiter"); // Avoid user errors if (int.TryParse(rule, out int ruleNumber) && ushort.TryParse(startYear, out ushort year) && delimiter.Length == 1) { // Sub Substitution rule in Index class IJPSubstitutionRule sr = (IJPSubstitutionRule)ijp.GetSubstitutionRule(ruleNumber); // Set the start year in the substitution rule sr.StartYear = year; // Load the individual rules foreach (XmlNode c in p.ChildNodes) { if (c is XmlWhitespace) { continue; } switch (c.Name) { case "Rule": if (Enum.TryParse(GetXmlAttr(c, "Type"), true, out MsgToXml.Ba type)) { SetSubValues(sr, type, c, delimiter); } else { Log?.Invoke(this, $"Unknown substitution rule type =>{GetXmlAttr(c, "Type")}<="); } break; } } ijp.SetSubstitutionRule(sr); } }
private void RetrieveSubstitutions(XmlTextWriter writer, IJPMessage m, IJP ijp) { int maxSZ = -1; int[] sr = new int[100]; // They are assumed to be 0 for (int i = 0; i < m.CalendarConditions.Count; i++) { IJPCalendarCondition cc = m.CalendarConditions[i]; int n = cc.SubstitutionRuleNumber; maxSZ = Math.Max(maxSZ, n); if (cc.YearSubstitutionRule) { sr[n] |= (int)Ba.Year; } if (cc.MonthSubstitutionRule) { sr[n] |= (int)Ba.Month; } if (cc.DaySubstitutionRule) { sr[n] |= (int)Ba.Day; } if (cc.HourSubstitutionRule) { sr[n] |= (int)Ba.Hour; } if (cc.MinuteSubstitutionRule) { sr[n] |= (int)Ba.Minute; } if (cc.WeekNumberSubstitutionRule) { sr[n] |= (int)Ba.WeekNumber; } if (cc.WeekSubstitutionRule) { sr[n] |= (int)Ba.DayOfWeek; } } for (int i = 1; i <= maxSZ; i++) { if (sr[i] > 0) { IJPSubstitutionRule srs = (IJPSubstitutionRule)ijp.GetSubstitutionRule(i); writer.WriteStartElement("Substitution"); { writer.WriteAttributeString("Delimiter", "/"); writer.WriteAttributeString("StartYear", srs.StartYear.ToString()); writer.WriteAttributeString("RuleNumber", i.ToString()); writer.WriteAttributeString("RuleName", srs.Name); if ((sr[i] & (int)Ba.Year) > 0) { RetrieveSubstitution(writer, srs, Ba.Year, 0, 23); } if ((sr[i] & (int)Ba.Month) > 0) { RetrieveSubstitution(writer, srs, Ba.Month, 1, 12); } if ((sr[i] & (int)Ba.Day) > 0) { RetrieveSubstitution(writer, srs, Ba.Day, 1, 31); } if ((sr[i] & (int)Ba.Hour) > 0) { RetrieveSubstitution(writer, srs, Ba.Hour, 0, 23); } if ((sr[i] & (int)Ba.Minute) > 0) { RetrieveSubstitution(writer, srs, Ba.Minute, 0, 59); } if ((sr[i] & (int)Ba.WeekNumber) > 0) { RetrieveSubstitution(writer, srs, Ba.WeekNumber, 1, 53); } if ((sr[i] & (int)Ba.DayOfWeek) > 0) { RetrieveSubstitution(writer, srs, Ba.DayOfWeek, 1, 7); } } writer.WriteEndElement(); // Substitution } } }