Using custom maps - olmelabs/EdiEngine GitHub Wiki

Sometimes to implement particular trading partner requirements you need to create custom map. Such maps are usually smaller as they contain only loops, segment and data elements used by your trading partner. In this case you can craft your own map. You can either define everything yourself or inherit from standard map, say using all data-elements and redefining only map loops and segments. Or you can define own segments as well.

In this example we have custom map and some custom segments. For simplicity segments are inherited from standard. SO the steps are.

  1. Create new Console Application
  2. Install Package from Nuget: Install-Package xEdi.EdiEngine
  3. Add Segments folder to project
  4. Add file "Segments.cs" custom segments (here we inherit from repository for simplicity)
namespace ConsoleApplication3.Segments
{
    public class ISA : EdiEngine.Standards.X12_004010.Segments.ISA
    {
    }

    public class IEA : EdiEngine.Standards.X12_004010.Segments.IEA
    {
    }

    public class GS : EdiEngine.Standards.X12_004010.Segments.GS
    {
    }

    public class GE : EdiEngine.Standards.X12_004010.Segments.GE
    {
    }

    public class ST : EdiEngine.Standards.X12_004010.Segments.ST
    {
    }

    public class SE : EdiEngine.Standards.X12_004010.Segments.SE
    {
    }

    public class W05 : EdiEngine.Standards.X12_004010.Segments.W05
    {
    }
}
  1. Add Maps folder to projects
  2. Add custom map - file "M_940.cs"
using ConsoleApplication3.Segments;
using EdiEngine.Common.Definitions;
using EdiEngine.Common.Enums;

namespace ConsoleApplication3.Maps
{
    public class M_940 : MapLoop
    {
        public M_940() : base(null)
        {
            Content.AddRange(new MapBaseEntity[] {
                new W05() { ReqDes = RequirementDesignator.Mandatory, MaxOccurs = 1 },
            });
        }
    }
}
  1. Add the following code to "Program.cs"
using System;
using EdiEngine;
using EdiEngine.Runtime;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string edi = @"ISA*00*          *00*          *ZZ*VENDOR         *ZZ*WAREHOUSE      *090902*0900*U*00401*000009221*0*P*>
GS*OW*VENDOR*WAREHOUSE*20090902*1700*9221*X*004010
ST*940*20066
W05*N*35131*POMAIL
SE*3*20066
GE*1*9221
IEA*1*000009221";

            //Your custom map assembly name in ctor
            EdiDataReader r = new EdiDataReader("ConsoleApplication3");
            EdiBatch b = r.FromString(edi);

            EdiTrans t = b.Interchanges[0].Groups[0].Transactions[0];

            Console.WriteLine(new JsonDataWriter().WriteToString(b));
            Console.Read();
        }
    }
}

This will output Json to console