Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to deserialised segment "UNG" #138

Closed
FannyMaulny opened this issue Oct 7, 2019 · 2 comments
Closed

Impossible to deserialised segment "UNG" #138

FannyMaulny opened this issue Oct 7, 2019 · 2 comments
Assignees
Labels

Comments

@FannyMaulny
Copy link

FannyMaulny commented Oct 7, 2019

Hello,

In the file EdiSerializer.cs line 136, I needed to remove the "else" because I needed to go this loop line 136 to deserialised a segment "UNG" for a fonctional group.

if (reader.IsStartGroup) {
                       TryCreateContainer(reader, stack, EdiStructureType.Group);
                    } else if (reader.IsEndGroup) {
                        while (stack.Peek().StructureType > EdiStructureType.Group) {
                            stack.Pop();
                        }
                        value = stack.Peek().Instance;
                    }                    
                    if (reader.TokenType == EdiToken.SegmentName) {
                        while (true) {
                            if (TryCreateContainer(reader, stack, EdiStructureType.SegmentGroup)
                                || TryCreateContainer(reader, stack, EdiStructureType.Segment)
                                || implicitSegments.Contains(reader.Value)
                                || !AutoEndSegmentGroups) {
                                break;
                            }

                            stack.Pop();

                            if (stack.Count == 0) {
                                throw new EdiException(
                                    "Unable to deserialize segment {0}. No matching property found on stack.".FormatWith(
                                        reader.Culture,
                                        reader.Value));
                            }
                        }
                    } else if (reader.TokenType == EdiToken.ElementStart) {
                        TryCreateContainer(reader, stack, EdiStructureType.Element);
                    }

Here is the description of my classes :

// En-tête d'interchange
    [EdiSegment, EdiPath("UNB")]
    public class Segment_UNB
    {
        // S001 : IDENTIFIANT DE SYNTAXE
        [EdiValue("X(4)", Path = "UNB/0/0", Mandatory = true)]
        public string S001_0001_1_IdentifiantSyntaxe { get; set; }
        [EdiValue("9(1)", Path = "UNB/0/1", Mandatory = true)]
        public int S001_0002_1_NumeroVersionSyntaxe { get; set; }

        // S002 : EMETTEUR DE L'INTERCHANGE
        [EdiValue("X(35)", Path = "UNB/1/0", Mandatory = true)]
        public string S002_0004_1_IdentificationEmetteur { get; set; }
        [EdiValue("X(4)", Path = "UNB/1/1", Mandatory = true)]
        public string S002_0007_1_QualifiantIdentification { get; set; }
        [EdiValue("X(14)", Path = "UNB/1/2", Mandatory = false)]
        public string S002_0008_1_AdresseAcheminementRetour { get; set; }

        // S003 : RECEPTEUR DE L'INTERCHANGE
        [EdiValue("X(35)", Path = "UNB/2/0", Mandatory = true)]
        public string S003_0010_1_IdentificationDestinataire { get; set; }
        [EdiValue("X(4)", Path = "UNB/2/1", Mandatory = true)]
        public string S003_0007_1_QualifiantIdentification { get; set; }
        [EdiValue("X(14)", Path = "UNB/2/2", Mandatory = false)]
        public string S003_0014_1_AdresseAcheminement { get; set; }

        // S004 : DATE ET HEURE DE PREPARATION
        [EdiValue("9(6)", Path = "UNB/3/0", Format = "yyMMdd", Description = "Date de préparation")]
        public DateTime S004_0017_1_DatePreparation { get; set; }
        [EdiValue("9(4)", Path = "UNB/3/1", Format = "HHmm", Description = "Heure de préparation")]
        public DateTime S004_0019_1_HeurePreparation { get; set; }

        // 0020 : REFERENCE DE CONTROLE DE L’INTERCHANGE
        [EdiValue("X(14)", Path = "UNB/4/0", Mandatory = true)]
        public string _0020_1_ReferenceControleInterchange { get; set; }

        // S005 : REFERENCE DESTINATAIRE / MOT DE PASSE 
        // 0026 : REFERENCE APPLICATION
        // 0029 : CODE DE PRIORITE POUR LE TRAITEMENT
        // 0031 : DEMANDE D’ACCUSE DE RECEPTION

        // 0032 : IDENTIFICATION DE L’ACCORD D’INTERCHANGE
        [EdiValue("X(35)", Path = "UNB/9/0", Mandatory = true)]
        public string _0032_1_IdentificationAccordInterchange { get; set; }

        // 0035 : INDICATEUR DE TEST
        [EdiValue("9(1)", Path = "UNB/10/0", Mandatory = false)]
        public int _0035_1_IndicateurTest { get; set; }
    }

    // En-tête de groupe fonctionnel
    [EdiSegment, EdiPath("UNG")]
    public class Segment_UNG
    {
        // 0038 : INDENTIFICATION DU GROUPE FONCTIONNEL
        [EdiValue("X(6)", Path = "UNG/0/0", Mandatory = true)]
        public string _0038_1_IdentificationGouprFonctionnel { get; set; }

        // S006 : IDENTIF. DE L’EMETTEUR DE L’APPLICATION
        [EdiValue("X(35)", Path = "UNG/1/0", Mandatory = true)]
        public string S006_0040_1_IdentificationEmetteur { get; set; }

        // S007 : IDENTIF. DU DESTINATAIRE DE L’APPLICATION
        [EdiValue("X(35)", Path = "UNG/2/0", Mandatory = true)]
        public string S007_0044_1_IdentificationDestinataire { get; set; }
        
        // S004 : DATE ET HEURE DE PREPARATION
        [EdiValue("9(6)", Path = "UNG/3/0", Format = "yyMMdd", Description = "Date de préparation")]
        public DateTime S004_0017_1_DatePreparation { get; set; }
        [EdiValue("9(4)", Path = "UNG/3/1", Format = "HHmm", Description = "Heure de préparation")]
        public DateTime S004_0019_1_HeurePreparation { get; set; }

        // 0048 : N° DE REFERENCE DU GROUPE FONCTIONNEL
        [EdiValue("X(14)", Path = "UNG/4/0", Mandatory = true)]
        public string _0048_1_ReferenceGroupeFonctionnel { get; set; }

        // 0051 : AGENCE DE CONTROLE
        [EdiValue("X(2)", Path = "UNG/5/0", Mandatory = true)]
        public string _0051_1_AgenceControle { get; set; }

        // S008 : VERSION DU MESSAGE
        [EdiValue("X(3)", Path = "UNG/6/0", Mandatory = true)]
        public string S008_0052_1_NumeroVersionMessage { get; set; }
        [EdiValue("X(3)", Path = "UNG/6/1", Mandatory = true)]
        public string S008_0054_1_NumeroRevisionMessage { get; set; }
        [EdiValue("X(6)", Path = "UNG/6/2", Mandatory = true)]
        public string S008_0057_1_CodeAttibueParAssociation { get; set; }
    }

    // En-tête de message
    [EdiSegment, EdiPath("UNH")]
    public class Segment_UNH
    {
        // 0062 : NUMERO DE REFERENCE DU MESSAGE
        [EdiValue("X(14)", Path = "UNH/0/0", Mandatory = true)]
        public string _0062_1_NumeroReferenceMessage { get; set; }

        // S009 : IDENTIFIANT DU MESSAGE
        [EdiValue("X(6)", Path = "UNH/1/0", Mandatory = true)]
        public string S009_0065_1_IdentifiantTypeMessage { get; set; }
        [EdiValue("X(3)", Path = "UNH/1/1", Mandatory = true)]
        public string S009_0052_1_NumeroVersionTypeMessage { get; set; }
        [EdiValue("X(3)", Path = "UNH/1/2", Mandatory = true)]
        public string S009_0054_1_NumeroRevisionMessage { get; set; }
        [EdiValue("X(2)", Path = "UNH/1/3", Mandatory = true)]
        public string S009_0051_1_AgenceControle { get; set; }
        [EdiValue("X(6)", Path = "UNH/1/4", Mandatory = false)]
        public string S009_0057_1_CodeAttribueParAssociation { get; set; }

        // 0068 : REFERENCE COMMUNE D'ACCES
        [EdiValue("X(35)", Path = "UNH/2/0", Mandatory = false)]
        public string _0068_1_ReferenceCommuneAcces { get; set; }
    }
    // Debut du message
    [EdiSegment, EdiPath("BGM")]
    public class Segment_BGM
    {
        // C002 : NOM DU DOCUMENT OU MESSAGE
        [EdiValue("X(3)", Path = "BGM/0/0", Mandatory = true)]
        public string C002_1001_1_NomDocumentOuMessage { get; set; }
        [EdiValue("X(17)", Path = "BGM/0/1", Mandatory = true)]
        public string C002_1131_1_QltListeCodes { get; set; }
        [EdiValue("X(3)", Path = "BGM/0/2", Mandatory = true)]
        public string C002_3055_1_OrgResponbsableListeCodes { get; set; }
        [EdiValue("X(35)", Path = "BGM/0/3", Mandatory = false)]
        public string C002_1000_1_NomDocumentOuMessage2 { get; set; }

        // C106 : IDENTIFICATION DU DOCUMENT OU MESSAGE
        [EdiValue("X(35)", Path = "BGM/1/0", Mandatory = false)]
        public string C106_1004_1_NumeroDocumentOuMessage { get; set; }

    }
    // Fin de message
    [EdiSegment, EdiPath("UNT")]
    public class Segment_UNT
    {
        // 0074 : NOMBRE DE SEGMENTS DANS LE MESSAGE
        [EdiValue("9(6)", Path = "UNT/0/0", Mandatory = true)]
        public int _0074_1_NombreSegmentsDansMessage { get; set; }
        // 0062 : NUMÉRO DE RÉFÉRENCE DU MESSAGE
        [EdiValue("X(14)", Path = "UNT/1/0", Mandatory = true)]
        public string _0062_1_NumeroReferenceMessage { get; set; }
    }

    // Fin de groupe fonctionnel
    [EdiSegment, EdiPath("UNE")]
    public class Segment_UNE
    {
        // 0060 : NOMBRE DE MESSAGES
        [EdiValue("9(6)", Path = "UNE/0/0", Mandatory = true)]
        public int _0060_1_NombreMessage { get; set; }
        // 0048 : N° DE REFERENCE DU GROUPE FONCTIONNEL
        [EdiValue("X(14)", Path = "UNE/1/0", Mandatory = true)]
        public string _0048_1_NumeroReferenceGroupeFonctionnel { get; set; }
    }

    // Fin d'interchange
    [EdiSegment, EdiPath("UNZ")]
    public class Segment_UNZ
    {
        // 0036 : COMPTEUR DE CONTROLE DE L’INTERCHANGE
        [EdiValue("X(1)", Path = "UNZ/0/0", Mandatory = true)]
        public int _0036_1_CompteurControleInterchange { get; set; }
        // 0020 : REFERENCE DE CONTROLE DE L’INTERCHANGE
        [EdiValue("X(14)", Path = "UNZ/1/0", Mandatory = true)]
        public string _0020_1_ReferenceControleInterchange { get; set; }
    }
class EdiPaiement
    {
        public Segment_UNB UNB { get; set; }
        public List<GroupeFonctionnel> GroupesFonctionnels { get; set; }
        public Segment_UNZ UNZ { get; set; }

        public EdiPaiement()
        {
            UNB = new Segment_UNB();
            GroupesFonctionnels = new List<GroupeFonctionnel>();
            UNZ = new Segment_UNZ();
        }

        [EdiGroup]
        public class GroupeFonctionnel
        {
            public Segment_UNG UNG { get; set; }
            public List<Message> Messages { get; set; }
            public Segment_UNE UNE { get; set; }

            public GroupeFonctionnel()
            {
                UNG = new Segment_UNG();
                Messages = new List<Message>();
                UNE = new Segment_UNE();
            }
        }

        [EdiMessage]
        public class Message
        {
            public Segment_UNH UNH { get; set; }
            public Segment_BGM BGM { get; set; }
            public Segment_UNT UNT { get; set; }
            public Message()
            {
                UNH = new Segment_UNH();
                BGM = new Segment_BGM();
                UNT = new Segment_UNT();
            }
        }
    } 

If I don't remove "else" line 136 in EdiSerializer.cs, when I execute the following code, my segment UNG and UNE are not deserialized :

static void Main(string[] args)
        {
            EdiPaiement fichierEdiPaiementFluxCva_1329DEF = new EdiPaiement();
            IEdiGrammar grammaire = EdiGrammar.NewEdiFact();
            grammaire.SetAdvice('+', '+', ':', '\'', '?', ' ', ',');

            EdiSerializer serializer = new EdiSerializer { AutoEndSegmentGroups = true };
            fichierEdiPaiementFluxCva_1329DEF = serializer.Deserialize<EdiPaiement>(new StreamReader(@"E:\Perso\Recherches pour EDI WEB\test4.edi"), grammaire);
            Console.WriteLine("Fichier EDI lu !");
        }

Here is my file EDIFACT :

UNA:+,? '
UNB+UNOL:3+35044551600023:5:I+7501751:146+191007:1205+20191007120559+++++TDT-PED-IN-DP1501/CVA19+1'
UNG+INFENT+NON_SECURISE_NON_SIGNE+MULTI_DISTRIBUTION+191007:1205+1+UN+D:00B:PD1501'
UNH+00001+INFENT:D:00B:UN:PD1501'
BGM+CVA:71:211+INFENT1905SRL BIC IS RN19100211451'
UNT+000100+00001'
UNE+000001+1'
UNZ+1+20191007120559'
@cleftheris
Copy link
Contributor

Hi @FannyMaulny,

thanks for pointing this out! I don't know how I missed this since I have fixed it in the past for the message headers and trailers. Anyway a new version is on its way to nuget v1.9.3 wait for a couple of minutes in order for it to show up.

@cleftheris
Copy link
Contributor

It is up, so please give it a try https://www.nuget.org/packages/indice.Edi/1.9.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants