Beispiel #1
0
        private static Dictionary <string, SegmentSpecification> Get5010Spec()
        {
            lock (syncObject)
                if (_5010Specification == null)
                {
                    Stream       specStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EdiFactory.Specifications.Ansi-5010Specification.xml");
                    StreamReader reader     = new StreamReader(specStream);
                    SegmentSet   set        = SegmentSet.Deserialize(reader.ReadToEnd());
                    _5010Specification = new Dictionary <string, SegmentSpecification>();
                    foreach (var segment in set.Segments)
                    {
                        foreach (var element in segment.Elements)
                        {
                            if (element.Type == ElementDataTypeEnum.Identifier && !string.IsNullOrEmpty(element.QualifierSetRef))
                            {
                                var qualifierSet = set.QualifierSets.FirstOrDefault(qs => qs.Name == element.QualifierSetRef);
                                if (qualifierSet != null)
                                {
                                    element.AllowedIdentifiers.AddRange(qualifierSet.AllowedIdentifiers);
                                    element.QualifierSetId = qualifierSet.Id;
                                }
                            }
                        }

                        _5010Specification.Add(segment.SegmentId, segment);
                    }
                }
            return(_5010Specification);
        }
        public void SerializeSegmentSet()
        {
            SegmentSet set = new SegmentSet {
                Name = "4010"
            };
            SegmentSpecification isa = new SegmentSpecification {
                SegmentId = "ISA"
            };

            set.Segments.Add(isa);
            isa.Elements.Add(new ElementSpecification
            {
                Name      = "Author Info Qualifier",
                Required  = true,
                MinLength = 2,
                MaxLength = 2,
                Type      = ElementDataTypeEnum.Identifier
            });
            string xml = set.Serialize();

            Trace.Write(xml);
            SegmentSet           copy    = SegmentSet.Deserialize(xml);
            SegmentSpecification isaCopy = copy.Segments.FirstOrDefault(s => s.SegmentId == "ISA");

            Assert.IsNotNull(isaCopy);
            Assert.AreEqual("ISA", isaCopy.SegmentId);
            Assert.AreEqual("Author Info Qualifier", isaCopy.Elements[0].Name);
            Assert.AreEqual(2, isaCopy.Elements[0].MinLength);
        }