private static EdiSegmentCollection extract(EdiSegmentCollection segments, SegmentLabel labelType, SegmentLabel closeType, int ndx)
        {
            IList<Segment> lst;
            var segs = segments.SegmentList.ToList();

            lst = getPreviousSegmentsToStrip(segments, closeType, ndx, labelType);

            lst.ToList().ForEach(segment => segs.Remove(segment));

            if (segs.Count == 0)
                throw new Exception(string.Format("{0} label was missing!", labelType));

            var close_seg = segs.First();

            if(ndx > 0)
                segs.Remove(close_seg);

            lst = segs.TakeWhile(s => s.Label.Value != closeType.Value).ToList();

            lst.ToList().ForEach(segment => segs.Remove(segment));

            if (segs.Count == 0)
                throw new Exception(string.Format("{0} label was missing!", labelType));

            close_seg = segs.First();

            if (close_seg.Label != closeType)
                throw new Exception("This should never happen!");

            lst.Add(close_seg);
            return new EdiSegmentCollection(lst,segments.ElementDelimiter);
        }
 public void can_split_file_contents()
 {
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "ST*850*0001~", Label = SegmentLabel.DocumentLabel});
     _lst.Add(new Segment { Contents = "BEG*00*SA*4110076497**20071031~CUR*BY*USD~", Label = "BEG".GetSegmentLabel() });
     _lst.Add(new Segment { Contents = "PER*BD*Brenda Fritz*TE*512-425-6314~", Label = "PER".GetSegmentLabel() });
     _lst.Add(new Segment {Contents = "SE*16*0001~", Label = SegmentLabel.DocumentClose});
     _lst.Add(new Segment {Contents = "ST*850*0001~", Label = SegmentLabel.DocumentLabel});
     _lst.Add(new Segment { Contents = "BEG*00*SA*4110076497**20071031~CUR*BY*USD~", Label = "BEG".GetSegmentLabel() });
     _lst.Add(new Segment { Contents = "PER*BD*Brenda Fritz*TE*512-425-6314~", Label = "PER".GetSegmentLabel() });
     _lst.Add(new Segment {Contents = "SE*16*0001~", Label = SegmentLabel.DocumentClose});
     _lst.Add(new Segment {Contents = "ST*850*0001~", Label = SegmentLabel.DocumentLabel});
     _lst.Add(new Segment { Contents = "BEG*00*SA*4110076497**20071031~CUR*BY*USD~", Label = "BEG".GetSegmentLabel() });
     _lst.Add(new Segment { Contents = "PER*BD*Brenda Fritz*TE*512-425-6314~", Label = "PER".GetSegmentLabel() });
     _lst.Add(new Segment {Contents = "SE*16*0001~", Label = SegmentLabel.DocumentClose});
     _lst.Add(new Segment {Contents = "ST*850*0001~", Label = SegmentLabel.DocumentLabel});
     _lst.Add(new Segment { Contents = "BEG*00*SA*4110076497**20071031~CUR*BY*USD~", Label = "BEG".GetSegmentLabel() });
     _lst.Add(new Segment { Contents = "PER*BD*Brenda Fritz*TE*512-425-6314~", Label = "PER".GetSegmentLabel() });
     _lst.Add(new Segment {Contents = "SE*16*0001~", Label = SegmentLabel.DocumentClose});
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     var segs = new EdiSegmentCollection(_lst, "*");
     var result = _sut.SplitByDocument(segs, new GroupContainer(segs));
     Assert.That(result.Count() == 4);
 }
 public InterchangeContainer(EdiSegmentCollection segs)
 {
     _segments = segs;
     var seg = _segments.FirstWith(SegmentLabel.InterchangeLabel);
     if (seg == null) return;
     var arr = seg.GetElements(segs.ElementDelimiter);
     SenderId = arr[6].Trim();
     ControlNumber = arr[10].Trim();
 }
 public DocContainer(EdiSegmentCollection segs, GroupContainer parent)
 {
     _elDelimiter = segs.ElementDelimiter;
     Segments = segs.SegmentList;
     var els = Segments.First().GetElements(_elDelimiter);
     DocType = els[1];
     ControlNumber = els[2].CastToInt();
     ParentGroup = parent;
 }
 public GroupContainer(EdiSegmentCollection segs)
 {
     _segments = segs;
     var groupHeader = _segments.FirstWith(SegmentLabel.GroupLabel);
     if(groupHeader == null)
         return;
     var arr = groupHeader.GetElements(segs.ElementDelimiter);
     GroupId = arr[1].Trim();
     DateSent = arr[4].DateFromEDIDate();
     ControlNumber = arr[5].Trim();
 }
        private static IList<Segment> getPreviousSegmentsToStrip(EdiSegmentCollection segments, SegmentLabel closeType, int ndx, SegmentLabel labelType)
        {
            IList<Segment> lst;
            try
            {
                int counter = 0;
                lst = segments.SegmentList.TakeWhile(s =>
                                                         {
                                                             if (s.Label == closeType)
                                                                 counter++;
                                                             return counter < ndx;
                                                         }).ToList();

            }
            catch
            {
                throw new Exception(string.Format("{0} label was missing!", labelType));
            }
            return lst;
        }
 public void can_split_file_contents()
 {
     _lst.Add(new Segment
                  {
                      Contents =
                          "ISA*00*          *00*          *ZZ*SLRSCOREGTWY   *12*EEC5122516063  *071031*0925*U*00401*000000007*0*P*~~",
                      Label = SegmentLabel.InterchangeLabel
                  });
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment { Contents = "IEA*1*000000010~", Label = SegmentLabel.InterchangeClose });
     var segs = new EdiSegmentCollection(_lst, "*");
     var result = _sut.SplitByGroup(segs, new InterchangeContainer(segs));
     Assert.That(result.Count() == 4);
 }
 public IEdiInContainer CreateChild(EdiSegmentCollection segs)
 {
     var child = new GroupContainer(segs);
     _groups.Add(child);
     return child;
 }
        private IEnumerable<IEdiInContainer> split(EdiSegmentCollection segments, SegmentLabel labelType, 
            SegmentLabel closeType, IEdiInContainer parentContainer)
        {
            IList<IEdiInContainer> returnList = new List<IEdiInContainer>();
            IList<Segment> segs = parentContainer.InnerSegments.ToList();
            segs =  RemoveNullSegments(segs);
            var ctxtCount = segs.Where(s => s != null).ToList().Count(s => s.Label == labelType);
            for (int i = 0; i < ctxtCount; i++)
            {

                returnList.Add(parentContainer.CreateChild(extract(new EdiSegmentCollection(segs, segments.ElementDelimiter), labelType, closeType, i)));
            }
            return returnList;
        }
 public EdiFileInfo Read(EdiSegmentCollection segments)
 {
     var interchanges = _hierarchySplitter.SplitByInterchange(segments);
     return new EdiFileInfo(interchanges);
 }
 public DocumentFile(FileEntity f, EdiSegmentCollection segs)
 {
     Segments = segs;
     File = f;
 }
 public EdiFileContainer(EdiSegmentCollection segs)
 {
     _segments = segs;
 }
Beispiel #13
0
        public EdiFileInfo Read(EdiSegmentCollection segments)
        {
            var interchanges = _hierarchySplitter.SplitByInterchange(segments);

            return(new EdiFileInfo(interchanges));
        }
 public IEdiInContainer CreateChild(EdiSegmentCollection segs)
 {
     var child = new DocContainer(segs, this);
     _documents.Add(child);
     return child;
 }
 public void will_fail_with_badly_formed_file_contents()
 {
     _lst.Add(new Segment
                  {
                      Contents =
                          "ISA*00*          *00*          *ZZ*SLRSCOREGTWY   *12*EEC5122516063  *071031*0925*U*00401*000000007*0*P*~~",
                      Label = SegmentLabel.InterchangeLabel
                  });
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment {Contents = "IEA*1*000000007~", Label = SegmentLabel.InterchangeClose});
     _lst.Add(new Segment
                  {
                      Contents =
                          "ISA*00*          *00*          *ZZ*SLRSCOREGTWY   *12*EEC5122516063  *071031*0925*U*00401*000000008*0*P*~~",
                      Label = SegmentLabel.InterchangeLabel
                  });
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment {Contents = "IEA*1*000000008~", Label = SegmentLabel.InterchangeClose});
     _lst.Add(new Segment
                  {
                      Contents =
                          "ISA*00*          *00*          *ZZ*SLRSCOREGTWY   *12*EEC5122516063  *071031*0925*U*00401*000000009*0*P*~~",
                      Label = SegmentLabel.InterchangeLabel
                  });
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment {Contents = "GE*1*7~", Label = SegmentLabel.GroupClose});
     _lst.Add(new Segment {Contents = "IEA*1*000000009~", Label = SegmentLabel.InterchangeClose});
     _lst.Add(new Segment
                  {
                      Contents =
                          "ISA*00*          *00*          *ZZ*SLRSCOREGTWY   *12*EEC5122516063  *071031*0925*U*00401*000000010*0*P*~~",
                      Label = SegmentLabel.InterchangeLabel
                  });
     _lst.Add(new Segment
                  {
                      Contents = "GS*PO*SLR010*EEC5122516063*20071031*0925*7*X*004010~",
                      Label = SegmentLabel.GroupLabel
                  });
     _lst.Add(new Segment { Contents = "IEA*1*000000010~", Label = SegmentLabel.InterchangeClose });
     var segs = new EdiSegmentCollection(_lst, "*");
     _sut.SplitByGroup(segs, new InterchangeContainer(segs));
 }
 public IEnumerable<DocContainer> SplitByDocument(EdiSegmentCollection segments, GroupContainer parent)
 {
     var docs = split(segments, SegmentLabel.DocumentLabel, SegmentLabel.DocumentClose, parent).Select(c => (DocContainer)c);
     return docs;
 }
Beispiel #17
0
 public DocumentFile(FileEntity f, EdiSegmentCollection segs)
 {
     Segments = segs;
     File     = f;
 }
 public IEdiInContainer CreateChild(EdiSegmentCollection segs)
 {
     var child = new InterchangeContainer(segs);
     _interchanges.Add(child);
     return child;
 }
Beispiel #19
0
        public IEnumerable <DocContainer> SplitByDocument(EdiSegmentCollection segments, GroupContainer parent)
        {
            var docs = split(segments, SegmentLabel.DocumentLabel, SegmentLabel.DocumentClose, parent).Select(c => (DocContainer)c);

            return(docs);
        }
 public IEnumerable<IEdiMessage> Parse( EdiSegmentCollection segList)
 {
     var fileInfo = _fileReader.Read(segList);
     return _generator.GenerateMessages(fileInfo, BusinessPartner.Initech);
 }
 private EdiInvoice createInvoiceFrom(EdiSegmentCollection segs)
 {
     const string el = "~";
     var lst = segs.SegmentList;
     var begin = lst.Find(s => s.Label == SegmentLabel.InvoiceBegin);
     var beginEls = begin.GetElements(el);
     var groupSeg = lst.Find(s => s.Label == SegmentLabel.GroupLabel);
     var salesSeg = lst.Find(s => s.Label  == SegmentLabel.TDS);
     var taxSeg = lst.Find(s => s.Label  == SegmentLabel.TXI);
     var inv = new EdiInvoice();
     inv.InvoiceDate = beginEls[1].DateFromEDIDate();
     inv.InvoiceNumber = beginEls[2];
     inv.SentDate = groupSeg.GetElements("~")[4].DateFromEDIDate();
     inv.Sales = decimal.Parse(salesSeg.GetElements(el)[1]) / 100;
     inv.Tax = decimal.Parse(taxSeg.GetElements(el)[2]);
     return inv;
 }
Beispiel #22
0
 public void AddSegments(EdiSegmentCollection segs)
 {
 }
 public IEnumerable<GroupContainer> SplitByGroup(EdiSegmentCollection segments, InterchangeContainer isa)
 {
     var groups =   split(segments, SegmentLabel.GroupLabel, SegmentLabel.GroupClose, isa).Select(c => (GroupContainer)c);
     groups.ForEach(g => g.AddDocuments(SplitByDocument(new EdiSegmentCollection(g.InnerSegments, segments.ElementDelimiter), g)));
     return groups;
 }
Beispiel #24
0
 public IEdiInContainer CreateChild(EdiSegmentCollection segs)
 {
     return(null);
 }
 public IEnumerable<InterchangeContainer> SplitByInterchange(EdiSegmentCollection segments)
 {
     var interchanges = split(segments, SegmentLabel.InterchangeLabel, SegmentLabel.InterchangeClose, new EdiFileContainer(segments)).Select(i => (InterchangeContainer)i);
     interchanges.ForEach(i => i.AddGroups(SplitByGroup(new EdiSegmentCollection(i.InnerSegments, segments.ElementDelimiter), i)));
     return interchanges;
 }
 public void AddSegments(EdiSegmentCollection segs)
 {
     _segments = segs ;
 }
 public void AddSegments(EdiSegmentCollection segs)
 {
     CreateChild(segs);
 }
 public IEdiInContainer CreateChild(EdiSegmentCollection segs)
 {
     return null;
 }
 private BusinessPartner get_partner(EdiSegmentCollection doc)
 {
     var seg = doc.SegmentList.First();
     var els = seg.GetElements(seg.Contents.Substring(3, 1));
     return BusinessPartner.FromReceiverId(els[6]);
 }