Ejemplo n.º 1
0
        internal static IEnumerable <CustomInvoic> ConvertEdifactToObjectsWithCompiledXsltMap(Stream stream)
        {
            Framework.Envelopes.Edifact.Interchange interchange = null;

            try
            {
                // Parse the EDI
                // This will load the class from the default classes assembly (configured in app.config or EdiFabric.Definitions)
                interchange = Framework.Envelopes.Edifact.Interchange.LoadFrom(stream);
            }
            catch (ParserException ex)
            {
                // Do something if EDI can't be parsed
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.InnerException.Message);
                Debug.WriteLine(ex.ToString());
            }

            // Get all Invoic messages from all groups
            var invoicMessages = interchange.OfTag("INVOIC");

            foreach (var invoicMsg in invoicMessages)
            {
                // Validate each message
                // This will load the xsd from the default xsd assembly (configured in app.config or EdiFabric.Validators)
                var brokenRules = invoicMsg.Validate().ToList();

                if (brokenRules.Any())
                {
                    // Do something if the message is invalid
                    foreach (var br in brokenRules)
                    {
                        Debug.WriteLine(br);
                    }
                }

                // Convert each Invoic message to our custom entity using compiled Xslt map
                yield return(invoicMsg.Item.Map());
            }
        }
Ejemplo n.º 2
0
 private static List <Message> OfTag(this Framework.Envelopes.Edifact.Interchange interchange, string tag)
 {
     return(interchange.Groups.SelectMany(m => m.Messages).Where(msg => msg.Context.Tag == tag).ToList());
 }