This project has moved. For the latest updates, please go here.

Migration to 5.1

Mar 13, 2015 at 5:06 PM
Hi,
I was working with 4.1 version and I see you make a 5.1 version.
When I Migrate, I had some small problem I quickly corrected in my code (s_UNB become unb, validation is now on the messages and not on the interchange...), that's not the subject.

I would like to upgrade the version of ediFabric but I don't know if I can upgrade only the Framework project in order to keep my class generated from xsd in the definitions and validators project.
Can you tell me if it can cause some problem?


In addition, I see a little bug in the 5.1 version in the InterchangeContext class.
in the public InterchangeContext(string contents) constructor, if your file not begin with una or unb or isa segment (a bad edi file in fact), the method not throw an exception but the ediHelper.getEdiSegment Methods cannot be launched properly.
In order not to launch getEdiSegment methods if the file is not a good EdiFile,
I replace the if statement with else if and throw an exception in the else like this :
        if (contents.ToUpper().StartsWith(EdiSegments.Isa))
            {
                try
                {
                    // Parse X12 separators, they are always contained within the envelope
                    DataElementSeparator = contents[3].ToString(CultureInfo.InvariantCulture);
                    var isa = string.Concat(contents.Take(106));
                    var isaElements = isa.Split(DataElementSeparator[0]);
                    ComponentDataElementSeparator = string.Concat(isaElements[16].First());
                    // Repetition is either the defaukt ^ or else if explicitly specified when U is present
                    RepetitionSeparator = isaElements[11] != "U" ? isaElements[11] : "^";
                    // Handle carriage return\new line segment terminators
                    var st = isaElements[16].Skip(1).DefaultIfEmpty('G').First();
                    SegmentTerminator = st.ToString(CultureInfo.InvariantCulture);
                    if (SegmentTerminator == " " || string.IsNullOrEmpty(SegmentTerminator)
                        || SegmentTerminator == "G") SegmentTerminator = Environment.NewLine;
                    // No release terminator for X12
                    ReleaseIndicator = "";
                    Format = EdiFormats.X12;
                    TargetNamespace = Namespaces.X12;
                }
                catch (Exception ex)
                {
                    throw new ParserException("Can't find X12 interchange delimiters", ex);
                }
            }

            // Edifact
           //old if replace with else if
            else if (contents.ToUpper().StartsWith(EdiSegments.Unb))
            {
                //  Default Edifact separators
                ComponentDataElementSeparator = ":";
                DataElementSeparator = "+";
                ReleaseIndicator = "?";
                RepetitionSeparator = "*";
                SegmentTerminator = "'";
                Format = EdiFormats.Edifact;
                TargetNamespace = Namespaces.Edifact;
            }

            // Edifact with non default separators, set on the UNA segment
            //old if replace with else if
            else if (contents.ToUpper().StartsWith(EdiSegments.Una))
            {
                try
                {
                    //  Parse UNA separators
                    var una = contents.Replace(EdiSegments.Una, "").Take(6).ToList();

                    ComponentDataElementSeparator = una[0].ToString(CultureInfo.InvariantCulture);
                    DataElementSeparator = una[1].ToString(CultureInfo.InvariantCulture);
                    ReleaseIndicator = una[3].ToString(CultureInfo.InvariantCulture);
                    RepetitionSeparator = "*";
                    SegmentTerminator = una[5].ToString(CultureInfo.InvariantCulture);
                    Format = EdiFormats.Edifact;
                    TargetNamespace = Namespaces.Edifact;
                }
                catch (Exception ex)
                {
                    throw new ParserException("Can't find UNA interchange delimiters", ex);
                }
            }
            else { 
              //new exception here

                throw new ParserException("Can't identify EDI Format");
            }
Is my solution ok for you and can you tell me if I can upgrade only the framework project and not all the solution ?


thank you in advance and sorry for my poor english !
And thank you a lot for ediFabric which is a beautiful project !!!
Coordinator
Mar 16, 2015 at 5:37 PM
Hi bobertin,

Yes you can only upgrade the Framework project, the rest is the same and the way the classes are retrieved hasn't changed.
I'll look into your advise and will update the code. Thank you for the contribution and don't worry - your English is perfect.

Hope ediFabric helped you to save time.

Best regards,
Don Zoeggerle