Esempio n. 1
0
        /// <summary>
        /// Serializes the specified <see cref="object"/> and writes the EDI structure
        /// to a <c>Stream</c> using the specified <see cref="TextWriter"/>.
        /// </summary>
        /// <param name="textWriter">The <see cref="TextWriter"/> used to write the EDI structure.</param>
        /// <param name="grammar">The <see cref="IEdiGrammar"/> to use for reading from the text reader</param>
        /// <param name="value">The <see cref="object"/> to serialize.</param>
        /// <param name="objectType">
        /// The type of the value being serialized.
        /// Specifing the type is optional.
        /// </param>
        public void Serialize(TextWriter textWriter, IEdiGrammar grammar, object value, Type objectType)
        {
            var ediTextWriter = new EdiTextWriter(textWriter, grammar);

            Serialize(ediTextWriter, value, objectType);
            ediTextWriter.Close();
        }
Esempio n. 2
0
 public EdiPathComparer(IEdiGrammar grammar)
 {
     if (null == grammar)
     {
         throw new ArgumentNullException(nameof(grammar));
     }
     segmentOrder = new List <string> {
         grammar.InterchangeHeaderTag,
         grammar.FunctionalGroupHeaderTag,
         grammar.MessageHeaderTag,
         null, // custom segments go here.
         grammar.MessageTrailerTag,
         grammar.FunctionalGroupTrailerTag,
         grammar.InterchangeTrailerTag
     };
     if (!string.IsNullOrWhiteSpace(grammar.ServiceStringAdviceTag))
     {
         segmentOrder.Insert(0, grammar.ServiceStringAdviceTag);
         customSegmentIndex = 4;
     }
     else
     {
         customSegmentIndex = 3;
     }
 }
Esempio n. 3
0
 internal void AdvanceContrlCount(IEdiGrammar grammar)
 {
     if (SegmentName == grammar.FunctionalGroupTrailerTag)
     {
         SegmentCount += 2; // take into account one more (the header)
     }
     else if (SegmentName == grammar.InterchangeTrailerTag)
     {
         SegmentCount += SegmentCountCache;
     }
     else if (SegmentName == grammar.FunctionalGroupHeaderTag)
     {
         GroupCount++;
         MessageCount       = 0;
         SegmentCountCache += SegmentCount;
         SegmentCount       = 1;
     }
     else if (SegmentName == grammar.MessageHeaderTag)
     {
         MessageCount++;
         SegmentCountCache += SegmentCount;
         SegmentCount       = 1;
     }
     else
     {
         SegmentCount++;
     }
 }
Esempio n. 4
0
 public EdiTextReader(TextReader reader, IEdiGrammar grammar)
     : base(grammar) {
     if (null == reader)
         throw new ArgumentNullException(nameof(reader));
     _reader = reader;
     _lineNumber = 1;
     _chars = new char[1025];
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdiReader"/> class.
 /// </summary>
 protected EdiReader(IEdiGrammar grammar)
 {
     if (null == grammar)
     {
         throw new ArgumentNullException(nameof(grammar));
     }
     _currentState = State.Start;
     _grammar      = grammar;
     _stack        = new List <EdiPosition>(4);
     _maxDepth     = 5; // SEGMENT/ELEMENT/COMPONENT/VALUE
 }
Esempio n. 6
0
 /// <summary>
 /// Constructs an <see cref="EdiTextReader"/> using the <seealso cref="IEdiGrammar"/> of choice and a <seealso cref="TextReader"/>
 /// </summary>
 /// <param name="reader">The <see cref="TextReader"/></param>
 /// <param name="grammar">The <see cref="IEdiGrammar"/></param>
 public EdiTextReader(TextReader reader, IEdiGrammar grammar)
     : base(grammar)
 {
     if (null == reader)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     _reader     = reader;
     _lineNumber = 1;
     _chars      = new char[1025];
 }
Esempio n. 7
0
        /// <summary>
        /// Creates an instance of the <c>EdiWriter</c> class.
        /// </summary>
        protected EdiWriter(IEdiGrammar grammar)
        {
            if (null == grammar)
            {
                throw new ArgumentNullException(nameof(grammar));
            }
            _grammar      = grammar;
            _currentState = State.Start;
            _formatting   = Formatting.LinePerSegment;

            CloseOutput = true;
        }
Esempio n. 8
0
        /// <summary>
        /// Creates an instance of the <c>EdiWriter</c> class using the specified <see cref="TextWriter"/>. 
        /// </summary>
        /// <param name="textWriter">The <c>TextWriter</c> to write to.</param>
        public EdiTextWriter(TextWriter textWriter, IEdiGrammar grammar)
            : base(grammar) {
            if (textWriter == null) {
                throw new ArgumentNullException(nameof(textWriter));
            }

            _writer = textWriter;
            _charEscapeFlags = new bool[128];
            if (Grammar.ReleaseCharacter.HasValue) { 
                _charEscapeFlags[Grammar.DataElementSeparator] =
                _charEscapeFlags[Grammar.ComponentDataElementSeparator] =
                _charEscapeFlags[Grammar.SegmentNameDelimiter] =
                _charEscapeFlags[Grammar.SegmentTerminator] =
                _charEscapeFlags[Grammar.ReleaseCharacter.Value] = true;
            }
        }
Esempio n. 9
0
        public EdiGrammar(IEdiGrammar grammar) {
            _ComponentDataElementSeparator = grammar.ComponentDataElementSeparator;
            _DataElementSeparator = grammar.DataElementSeparator;
            _DecimalMark = grammar.DecimalMark;
            _ReleaseCharacter = grammar.ReleaseCharacter;
            _Reserved = grammar.Reserved.Clone() as char[];
            _SegmentTerminator = grammar.SegmentTerminator;

            _ServiceStringAdviceTag = grammar.ServiceStringAdviceTag;
            _InterchangeHeaderTag = grammar.InterchangeHeaderTag;
            _FunctionalGroupHeaderTag = grammar.FunctionalGroupHeaderTag;
            _MessageHeaderTag = grammar.MessageHeaderTag;
            _MessageTrailerTag = grammar.MessageTrailerTag;
            _FunctionalGroupTrailerTag = grammar.FunctionalGroupTrailerTag;
            _InterchangeTrailerTag = grammar.InterchangeTrailerTag;
        }
Esempio n. 10
0
        /// <summary>
        /// Construct an <see cref="EdiGrammar"/> given an other <seealso cref="IEdiGrammar"/>
        /// </summary>
        /// <param name="grammar"></param>
        public EdiGrammar(IEdiGrammar grammar)
        {
            ComponentDataElementSeparator = grammar.ComponentDataElementSeparator;
            DataElementSeparator          = grammar.DataElementSeparator;
            DecimalMark       = grammar.DecimalMark;
            ReleaseCharacter  = grammar.ReleaseCharacter;
            Reserved          = grammar.Reserved.Clone() as char[];
            SegmentTerminator = grammar.SegmentTerminator;

            ServiceStringAdviceTag    = grammar.ServiceStringAdviceTag;
            InterchangeHeaderTag      = grammar.InterchangeHeaderTag;
            FunctionalGroupHeaderTag  = grammar.FunctionalGroupHeaderTag;
            MessageHeaderTag          = grammar.MessageHeaderTag;
            MessageTrailerTag         = grammar.MessageTrailerTag;
            FunctionalGroupTrailerTag = grammar.FunctionalGroupTrailerTag;
            InterchangeTrailerTag     = grammar.InterchangeTrailerTag;
        }
Esempio n. 11
0
        /// <summary>
        /// Creates an instance of the <c>EdiWriter</c> class using the specified <see cref="TextWriter"/>.
        /// </summary>
        /// <param name="textWriter">The <c>TextWriter</c> to write to.</param>
        /// <param name="grammar">The <see cref="IEdiGrammar"/> to use for structure and dilimiters</param>
        public EdiTextWriter(TextWriter textWriter, IEdiGrammar grammar)
            : base(grammar)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            _writer          = textWriter;
            _charEscapeFlags = new bool[128];
            if (Grammar.ReleaseCharacter.HasValue)
            {
                _charEscapeFlags[Grammar.DataElementSeparator] =
                    _charEscapeFlags[Grammar.ComponentDataElementSeparator]      =
                        _charEscapeFlags[Grammar.SegmentNameDelimiter]           =
                            _charEscapeFlags[Grammar.SegmentTerminator]          =
                                _charEscapeFlags[Grammar.ReleaseCharacter.Value] = true;
            }
        }
Esempio n. 12
0
 internal void Advance(IEdiGrammar grammar)
 {
     Position++;
     if (Type == EdiContainerType.Segment)
     {
         if (SegmentName == grammar.FunctionalGroupHeaderTag)
         {
             FunctionalGroupCount++;
             MessageCount = 0;
             SegmentCount = 0;
         }
         else if (SegmentName == grammar.MessageHeaderTag)
         {
             MessageCount++;
             SegmentCount = 0;
         }
         SegmentCount++;
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Deserializes the EDI structure contained by the specified <see cref="TextReader"/>
 /// into an instance of the specified type.
 /// </summary>
 /// <param name="reader">The <see cref="TextReader"/> containing the object.</param>
 /// <param name="grammar">The <see cref="IEdiGrammar"/> to use for reading from the text reader</param>
 /// <typeparam name="T">The type of the object to deserialize.</typeparam>
 /// <returns>The instance of <typeparamref name="T"/> being deserialized.</returns>
 public T Deserialize <T>(TextReader reader, IEdiGrammar grammar)
 {
     return((T)Deserialize(reader, grammar, typeof(T)));
 }
Esempio n. 14
0
 /// <summary>
 /// Serializes the specified <see cref="Object"/> and writes the EDI structure
 /// to a <c>Stream</c> using the specified <see cref="TextWriter"/>.
 /// </summary>
 /// <param name="textWriter">The <see cref="TextWriter"/> used to write the EDI structure.</param>
 /// <param name="grammar">The <see cref="IEdiGrammar"/> to use for reading from the text reader</param>
 /// <param name="value">The <see cref="Object"/> to serialize.</param>
 /// <param name="objectType">
 /// The type of the value being serialized.
 /// Specifing the type is optional.
 /// </param>
 public void Serialize(TextWriter textWriter, IEdiGrammar grammar, object value, Type objectType)
 {
     Serialize(new EdiTextWriter(textWriter, grammar), value, objectType);
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdiReader"/> class.
 /// </summary>
 protected EdiReader(IEdiGrammar grammar) {
     if (null == grammar)
         throw new ArgumentNullException(nameof(grammar));
     _currentState = State.Start;
     _grammar = grammar;
     _stack = new List<EdiPosition>(4);
     _maxDepth = 5; // SEGMENT/ELEMENT/COMPONENT/VALUE
 }
Esempio n. 16
0
        /// <summary>
        /// Creates an instance of the <c>EdiWriter</c> class. 
        /// </summary>
        protected EdiWriter(IEdiGrammar grammar) {
            if (null == grammar)
                throw new ArgumentNullException(nameof(grammar));
            _grammar = grammar;
            _currentState = State.Start;
            _formatting = Formatting.LinePerSegment;

            CloseOutput = true;
        }
Esempio n. 17
0
 public IEnumerable<EdiPropertyDescriptor> GetOrderedProperties(IEdiGrammar grammar) =>
     GetOrderedProperties(new EdiPathComparer(grammar));
Esempio n. 18
0
 /// <summary>
 /// Deserializes the EDI structure contained by the specified <see cref="StringReader"/>
 /// into an instance of the specified type.
 /// </summary>
 /// <param name="reader">The <see cref="TextReader"/> containing the object.</param>
 /// <param name="grammar">The <see cref="IEdiGrammar"/> to use for reading from the text reader</param>
 /// <param name="objectType">The <see cref="Type"/> of object being deserialized.</param>
 /// <returns>The instance of <paramref name="objectType"/> being deserialized.</returns>
 public object Deserialize(TextReader reader, IEdiGrammar grammar, Type objectType)
 {
     return(Deserialize(new EdiTextReader(reader, grammar), objectType));
 }
Esempio n. 19
0
 public IEnumerable <EdiPropertyDescriptor> GetOrderedProperties(IEdiGrammar grammar) =>
 GetOrderedProperties(new EdiPathComparer(grammar));
Esempio n. 20
0
        public static IEnumerable <DataEntity> ReadEDI <T>(string raw, Query query, Reflector r, IEdiGrammar grammar)
        {
            var n = default(T);

            using (TextReader sr = new StringReader(raw)) { n = new EdiSerializer().Deserialize <T>(sr, grammar); }
            return(r.ToDataEntities(new[] { n }, query.RootEntity));
        }