private XElement MapSegment(EdiSegment segment, Segment mapping) { var xml = new XElement(mapping != null ? mapping.Id : segment.Id); for (int i = 0; i < segment.Elements.Count; i++) { EdiElement element = segment.Elements[i]; if (element == null) { continue; } Element elementMapping = null; string segmentId; if (mapping != null) { if (mapping.Elements.Count > i) { elementMapping = mapping.Elements[i]; } segmentId = mapping.Id; } else { segmentId = segment.Id; } string defaultElementId = segmentId + (i + 1).ToString("d2"); xml.Add(MapElement(element, elementMapping, defaultElementId)); } return(xml); }
/// <summary> /// Gets or sets the value of the element at the specified position. /// </summary> /// <param name="position">The position of the element, starting at 1.</param> /// <returns>A string containing the value of the element.</returns> public string this[int position] { get { int index = position - 1; if (Elements.Count <= index || Elements[index] == null) { return(null); } return(Elements[index].Value); } set { int index = position - 1; if (!string.IsNullOrEmpty(value)) { while (Elements.Count <= index) { Elements.Add(null); } Elements[index] = new EdiElement(value); } else if (Elements.Count > index) { Elements[index] = null; } } }
/// <summary> /// Places an EdiElement at the specified position. /// </summary> /// <param name="position">The position of the element, starting at 1.</param> /// <param name="element">An EdiElement to place in this segment.</param> public void Element(int position, EdiElement element) { int index = position - 1; if (element != null) { while (Elements.Count <= index) Elements.Add(null); Elements[index] = element; } else if (Elements.Count > index) Elements[index] = null; }
private EdiElement ParseElement(string rawElement, EdiOptions options) { var element = new EdiElement(); string[] repetitions = options.RepetitionSeparator.HasValue ? SplitEdi(rawElement, options.RepetitionSeparator.Value, options.ReleaseCharacter) : new[] { rawElement }; foreach (string rawRepetition in repetitions) { if (rawRepetition != string.Empty) { element.Repetitions.Add(ParseRepetition(rawRepetition, options)); } } return(element); }
/// <summary> /// Places an EdiElement at the specified position. /// </summary> /// <param name="position">The position of the element, starting at 1.</param> /// <param name="element">An EdiElement to place in this segment.</param> public void Element(int position, EdiElement element) { int index = position - 1; if (element != null) { while (Elements.Count <= index) { Elements.Add(null); } Elements[index] = element; } else if (Elements.Count > index) { Elements[index] = null; } }
public bool IsMatch(EdiElement element) { if (_restrict && element == null) { return(false); } foreach (EdiRepetition repetition in element.Repetitions) { if (_restrict && !Options.Contains(repetition.Value)) { return(false); } if (repetition.Components.Where((t, i) => Components.Count > i && Components[i] != null && !Components[i].IsMatch(t)).Any()) { return(false); } } return(true); }
/// <summary> /// Gets or sets the value of the element at the specified position. /// </summary> /// <param name="position">The position of the element, starting at 1.</param> /// <returns>A string containing the value of the element.</returns> public string this[int position] { get { int index = position - 1; if (Elements.Count <= index || Elements[index] == null) return null; return Elements[index].Value; } set { int index = position - 1; if (!string.IsNullOrEmpty(value)) { while (Elements.Count <= index) Elements.Add(null); Elements[index] = new EdiElement(value); } else if (Elements.Count > index) Elements[index] = null; } }
public bool IsMatch(EdiElement element) { if (_restrict && element == null) return false; foreach (EdiRepetition repetition in element.Repetitions) { if (_restrict && !Options.Contains(repetition.Value)) return false; if (repetition.Components.Where((t, i) => Components.Count > i && Components[i] != null && !Components[i].IsMatch(t)).Any()) { return false; } } return true; }
private IEnumerable<XElement> MapElement(EdiElement element, Element mapping, string defaultElementId) { var repetitions = new List<XElement>(); foreach (EdiRepetition repetition in element.Repetitions) { var xml = new XElement(mapping != null ? mapping.Id : defaultElementId); if (repetition.Components.Count == 1) { if (mapping != null) { if (mapping.Components.Count == 0) { string mappedValue; if (mapping.Type == null || !MapValue(repetition, mapping.Type, out mappedValue)) xml.Value = repetition.Value; else { xml.SetAttributeValue("type", mapping.Type); xml.Value = mappedValue; } if (mapping.Options.Contains(repetition.Value)) { string definition = mapping.Options[repetition.Value]; if (definition != null && definition.Trim() != string.Empty) xml.SetAttributeValue("definition", definition); } } else xml.Add(MapComponent(repetition.Components[0], mapping.Components[0], mapping.Id + "01")); } else xml.Value = repetition.Value; } else { for (int i = 0; i < repetition.Components.Count; i++) { EdiComponent component = repetition.Components[i]; if (component == null) continue; Component componentMapping = null; string elementId; if (mapping != null) { if (mapping.Components.Count > i) componentMapping = mapping.Components[i]; elementId = mapping.Id; } else elementId = defaultElementId; string defaultComponentId = elementId + (i + 1).ToString("d2"); xml.Add(MapComponent(component, componentMapping, defaultComponentId)); } } repetitions.Add(xml); } return repetitions; }
private EdiElement ParseElement(string rawElement, EdiOptions options) { var element = new EdiElement(); string[] repetitions = options.RepetitionSeparator.HasValue ? SplitEdi(rawElement, options.RepetitionSeparator.Value, options.ReleaseCharacter) : new[] {rawElement}; foreach (string rawRepetition in repetitions) { if (rawRepetition != string.Empty) element.Repetitions.Add(ParseRepetition(rawRepetition, options)); } return element; }
private IEnumerable <XElement> MapElement(EdiElement element, Element mapping, string defaultElementId) { var repetitions = new List <XElement>(); foreach (EdiRepetition repetition in element.Repetitions) { var xml = new XElement(mapping != null ? mapping.Id : defaultElementId); if (repetition.Components.Count == 1) { if (mapping != null) { if (mapping.Components.Count == 0) { string mappedValue; if (mapping.Type == null || !MapValue(repetition, mapping.Type, out mappedValue)) { xml.Value = repetition.Value; } else { xml.SetAttributeValue("type", mapping.Type); xml.Value = mappedValue; } if (mapping.Options.Contains(repetition.Value)) { string definition = mapping.Options[repetition.Value]; if (definition != null && definition.Trim() != string.Empty) { xml.SetAttributeValue("definition", definition); } } } else { xml.Add(MapComponent(repetition.Components[0], mapping.Components[0], mapping.Id + "01")); } } else { xml.Value = repetition.Value; } } else { for (int i = 0; i < repetition.Components.Count; i++) { EdiComponent component = repetition.Components[i]; if (component == null) { continue; } Component componentMapping = null; string elementId; if (mapping != null) { if (mapping.Components.Count > i) { componentMapping = mapping.Components[i]; } elementId = mapping.Id; } else { elementId = defaultElementId; } string defaultComponentId = elementId + (i + 1).ToString("d2"); xml.Add(MapComponent(component, componentMapping, defaultComponentId)); } } repetitions.Add(xml); } return(repetitions); }