Exemple #1
0
        /// <summary>Set this message's content.</summary>
        /// <param name="value">New value.</param>
        /// <returns>This MessageBuilder, for chaining purposes.</returns>
        public IMessageBuilder SetMessage(string value)
        {
            if (value == null)
            {
                throw new ElementException(ErrorCode.MessageDataMustNotBeNull);
            }
            value = NormalizeLineEndings(value);

            var length = value.Length;

            if (length < 8)
            {
                throw new ElementException(ErrorCode.MessageDataIsTooShort);
            }

            if (!value.StartsWith("MSH"))
            {
                throw new ElementException(ErrorCode.MessageDataMustStartWithMsh);
            }

            ComponentDelimiter = length >= 5
                ? value[4]
                : '^';

            EscapeCharacter = length >= 6
                ? value[5]
                : '\\';

            FieldDelimiter = length >= 3
                ? value[3]
                : '|';

            RepetitionDelimiter = length >= 7
                ? value[6]
                : '~';

            SubcomponentDelimiter = length >= 8
                ? value[7]
                : '&';

            _segments.Clear();
            var index = 1;

            foreach (var segment in value.Split(ReadOnlyEncodingConfiguration.SegmentDelimiter))
            {
                SetSegment(index++, segment);
            }

            return(this);
        }
Exemple #2
0
        /// <summary>Replace all component values within this field repetition.</summary>
        /// <param name="components">Values to replace with.</param>
        /// <returns>This RepetitionBuilder, for chaining purposes.</returns>
        public IRepetitionBuilder SetComponents(params string[] components)
        {
            _components.Clear();
            if (components == null)
            {
                return(this);
            }

            var index = 1;

            foreach (var component in components)
            {
                SetComponent(index++, component);
            }
            return(this);
        }
        /// <summary>Set this component's content.</summary>
        /// <param name="value">New value.</param>
        /// <returns>This ComponentBuilder, for chaining purposes.</returns>
        public IComponentBuilder SetComponent(string value)
        {
            _subcomponents.Clear();
            var index = 1;

            if (value == null)
            {
                return(this);
            }

            foreach (var subcomponent in value.Split(Encoding.SubcomponentDelimiter))
            {
                SetSubcomponent(index++, subcomponent);
            }

            return(this);
        }
        /// <summary>Set this field's content.</summary>
        /// <param name="value">New value.</param>
        /// <returns>This FieldBuilder, for chaining purposes.</returns>
        public virtual IFieldBuilder SetField(string value)
        {
            _repetitions.Clear();
            var index = 1;

            if (value == null)
            {
                return(this);
            }

            foreach (var repetition in value.Split(Encoding.RepetitionDelimiter))
            {
                SetFieldRepetition(index++, repetition);
            }

            return(this);
        }
 /// <summary>Replace all field values within this segment.</summary>
 /// <param name="fields">Values to replace with.</param>
 /// <returns>This SegmentBuilder, for chaining purposes.</returns>
 public ISegmentBuilder SetFields(params string[] fields)
 {
     _fields.Clear();
     return(SetFields(0, fields));
 }