Skip to content

Repository files navigation

EDI.Net

EDI Parser/Deserializer.

This is a ground up implementation and does not make use of XML Serialization in any step of the process. This reduces the overhead of converting into multiple formats allong the way of getting the desired Clr object.

Tested with Tradacoms, EDIFact and ANSI ASC X12 (X12) formats.

Using attributes you can express all EDI rules like Mandatory/Conditional Segments, Elements & Components as well as describe component values size length and precision with the picture syntax (e.g 9(3), 9(10)V9(2) and X(3)).

Quick links

Installation

To install Edi.Net, run the following command in the Package Manager Console. Or download it here

PM>Install-Package"indice.Edi"

Attributes.

The general rules of thumb are :

AttributeDescription
EdiValueAny value inside a segment. (ie the component value 500 in bold)
UCI+001342651817+9907137000005:500+9912022000002:500+7
EdiElementElements are considered to be groups of values otherwise known as groups of components. One can use this attribute to deserialize into a complex class that resides inside a segment. For example this can usually be used to deserialize more than one value between + into a ComplexType (ie the whole element into a new class 9912022000002:500 in bold)
UCI+001342651817+9907137000005:500+9912022000002:500+7
EdiPathTo specify the path
EdiSegmentMarks a propery/class to be deserialized for a given segment. Used in conjunction with EdiPath
EdiSegmentGroupMarks a propery/class as a logical container of segments. This allows a user to decorate a class whith information regarding the starting and ending segments that define a virtual group other than the standard ones (Functional Group etc). Can be applied on Lists the same way that [Message] or [Segment] attributes work
EdiMessageMarks a propery/class to be deserialized for any message found.
EdiGroupMarks a propery/class to be deserialized for any group found.
EdiConditionIn case multiple MessageTypes or Segment types with the same name. Used to discriminate the classes based on a component value

Example usage:

There are available configurations (EdiGrammar) for EDIFact, Tradacoms and X12. Working examples for all supported EDI formats can be found in the source code under tests.

Note that all examples may be partialy implemented transmissions for demonstration purposes although they are a good starting point. If someone has complete poco classes for any transmition please feel free to contribute a complete test.

The following example makes use of the Tradacoms grammar.

vargrammar=EdiGrammar.NewTradacoms();varinterchange=default(Interchange);using(varstream=newStreamReader(@"c:\temp\sample.edi")){interchange=newEdiSerializer().Deserialize<Interchange>(stream,grammar);}

Annotated POCOS example using part of Tradacoms UtilityBill format:

publicclassInterchange{[EdiValue("X(14)",Path="STX/1/0")]publicstringSenderCode{get;set;}[EdiValue("X(35)",Path="STX/1/1")]publicstringSenderName{get;set;}[EdiValue("9(6)",Path="STX/3/0",Format="yyMMdd",Description="TRDT - Date")][EdiValue("9(6)",Path="STX/3/1",Format="HHmmss",Description="TRDT - Time")]publicDateTimeTransmissionStamp{get;set;}publicInterchangeHeaderHeader{get;set;}publicInterchangeTrailerTrailer{get;set;}publicList<UtilityBill>Invoices{get;set;}}[EdiMessage,EdiCondition("UTLHDR",Path="MHD/1")]publicclassInterchangeHeader{[EdiValue("9(4)"),EdiPath("TYP")]publicstringTransactionCode{get;set;}[EdiValue("9(1)",Path="MHD/1/1")]publicintVersion{get;set;}}[EdiMessage,EdiCondition("UTLTLR",Path="MHD/1")]publicclassInterchangeTrailer{[EdiValue("9(1)",Path="MHD/1/1")]publicintVersion{get;set;}}[EdiMessage,EdiCondition("UTLBIL",Path="MHD/1")]publicclassUtilityBill{[EdiValue("9(1)",Path="MHD/1/1")]publicintVersion{get;set;}[EdiValue("X(17)",Path="BCD/2/0",Description="INVN - Date")]publicstringInvoiceNumber{get;set;}publicMetetAdminNumberMeter{get;set;}publicContractDataSupplyContract{get;set;}[EdiValue("X(3)",Path="BCD/5/0",Description="BTCD - Date")]publicBillTypeCodeBillTypeCode{get;set;}[EdiValue("9(6)",Path="BCD/1/0",Format="yyMMdd",Description="TXDT - Date")]publicDateTimeIssueDate{get;set;}[EdiValue("9(6)",Path="BCD/7/0",Format="yyMMdd",Description="SUMO - Date")]publicDateTimeStartDate{get;set;}[EdiValue("9(6)",Path="BCD/7/1",Format="yyMMdd",Description="SUMO - Date")]publicDateTimeEndDate{get;set;}publicUtilityBillTrailerTotals{get;set;}publicUtilityBillValueAddedTaxVat{get;set;}publicList<UtilityBillCharge>Charges{get;set;}publicoverridestringToString(){returnstring.Format("{0} TD:{1:d} F:{2:d} T:{3:d} Type:{4}",InvoiceNumber,IssueDate,StartDate,EndDate,BillTypeCode);}}[EdiSegment,EdiPath("CCD")]publicclassUtilityBillCharge{[EdiValue("9(10)",Path="CCD/0")]publicintSequenceNumber{get;set;}[EdiValue("X(3)",Path="CCD/1")]publicChargeIndicator?ChargeIndicator{get;set;}[EdiValue("9(13)",Path="CCD/1/1")]publicint?ArticleNumber{get;set;}[EdiValue("X(3)",Path="CCD/1/2")]publicstringSupplierCode{get;set;}[EdiValue("9(10)V9(3)",Path="CCD/10/0",Description="CONS")]publicdecimal?UnitsConsumedBilling{get;set;}}

Contributions

The following is a set of guidelines for contributing to EDI.Net.

Did you find a bug?
  • Ensure the bug was not already reported by searching on GitHub under Issues.
  • If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
Did you write a patch that fixes a bug?

Open a new GitHub pull request with the patch. Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

Build the sourcecode

As of v1.0.7 the solution was adapted to support the dotnet core project system. In order to build and test the source code you will need either one of the following.

for more information check .Net Core official page.

The Picture clause

The Picture Clause is taken from COBOL laguage and the way it handles expressing numeric and alphanumric data types. It is used throug out tradacoms.

SymbolDescriptionExample PictureComponentc# result
9Numeric9(3)013int v = 13;
AAlphabeticnot used--
XAlphanumericX(20)This is alphanumericstring v = "This is alphanumeric";
VImplicit Decimal9(5)V(2)01342decimal v = 13.42M;
SSignnot used--
PAssumed Decimalnot used--

Roadmap (TODO)

  1. Implement serializer Serialize to write Clr classes to edi format (Using attributes). (planned for v1.1)
  2. Start github wiki page and begin documentation.
  3. Create a seperate package (or packages per EDI Format) to host well known interchange transmitions (ie Tradacoms Utitlity Bill). Then anyone can fork and contribute his own set of POCO classes.

Disclaimer. The project was inspired and influenced by the work done in the excellent library JSON.Net by James Newton King. Some utility parts for reflection string parsing etc. are used as is

About

EDI Parser and Deserializer with ambition to become full stack Serializer/deserializer.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages