protected List <AllowedEntitity> GetNextAllowedEntities(MapLoop currentLoop)
        {
            List <AllowedEntitity> res = new List <AllowedEntitity>();
            MapBaseEntity          be  = currentLoop.Content[currentLoop.CurrentPos];

            if (be.ReqDes == RequirementDesignator.Mandatory && be.OccuredTimes == 0)
            {
                res.Add(new AllowedEntitity(be, currentLoop));
                return(res);
            }

            if (be.OccuredTimes > 0 && be.OccuredTimes < be.MaxOccurs)
            {
                res.Add(new AllowedEntitity(be, currentLoop));
            }

            for (int i = currentLoop.CurrentPos + 1; i < currentLoop.Content.Count; i++)
            {
                res.Add(new AllowedEntitity(currentLoop.Content[i], currentLoop));
                if (currentLoop.Content[i].ReqDes == RequirementDesignator.Mandatory)
                {
                    break;
                }
            }

            //if in loop all except first  seg are optional, and max occurs not reached yet - return new loop iteration
            if (currentLoop.ParentLoop != null)
            {
                res.AddRange(GetNextAllowedEntities(currentLoop.ParentLoop));
            }
            return(res);
        }
 protected EdiBaseEntity(MapBaseEntity definition)
 {
     if (definition != null)
     {
         Name       = definition.Name;
         Definition = definition;
     }
 }
Beispiel #3
0
 protected MappedObjectBase(MapBaseEntity definition)
 {
     if (definition != null)
     {
         Name       = definition.Name;
         Definition = definition;
     }
 }
 public EdiHlLoop(MapBaseEntity definition,
                  EdiLoop parent,
                  int HL01,
                  int?HL02
                  ) : base(definition, parent)
 {
     HL01_HierarchicalIdNumber       = HL01;
     HL02_HierarchicalParentIdNumber = HL02;
 }
Beispiel #5
0
        //TODO:Refactor to make same code base with EdiMapReader.ProcessRawSegment
        protected void SetMapContext(string name)
        {
            List <AllowedEntitity> allowedEntities = GetNextAllowedEntities(CurrentLoopDef);

            if (allowedEntities.All(e => e.Entity.Name != name))
            {
                string          expected = string.Join(", ", allowedEntities.Select(e => e.Entity.Name).ToList());
                string          msgPart  = allowedEntities.Count > 1 ? "Expected one of" : "Expected";
                ValidationError err      = new ValidationError()
                {
                    Message = $"Unexpected Segment. {msgPart} {expected}. Found {name}."
                };
                Trans.ValidationErrors.Add(err);
                return;
            }

            AllowedEntitity ae = allowedEntities.FirstOrDefault(e => e.Entity.Name == name);

            if (ae?.Entity is MapSegment)
            {
                ae.Entity.OccuredTimes++;

                CurrentLoopDef            = ae.LoopContext;
                CurrentLoopDef.CurrentPos = CurrentLoopDef.Content.IndexOf(ae.Entity);

                while (((MapLoop)CurrentLoopInstance.Definition) != ae.LoopContext && CurrentLoopInstance.Parent != null)
                {
                    CurrentLoopInstance = CurrentLoopInstance.Parent;
                }

                CurrentEntityDef = ae.Entity;
            }
            else if (ae?.Entity is MapLoop)
            {
                //find loop definition in map and reset counters
                ae.LoopContext.CurrentPos = ae.LoopContext.Content.IndexOf(ae.Entity);
                CurrentLoopDef            = (MapLoop)ae.Entity;
                CurrentLoopDef.CurrentPos = 0;
                CurrentLoopDef.OccuredTimes++;
                CurrentLoopDef.Content.ForEach(c => c.OccuredTimes = 0);

                ////create new loop instance and add to transaction
                while (((MapLoop)CurrentLoopInstance.Definition) != ae.LoopContext && CurrentLoopInstance.Parent != null)
                {
                    CurrentLoopInstance = CurrentLoopInstance.Parent;
                }

                var newLoop = new EdiLoop(ae.Entity, CurrentLoopInstance);
                CurrentLoopInstance.Content.Add(newLoop);
                CurrentLoopInstance = newLoop;
            }
        }
Beispiel #6
0
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapDataElement elDef = null;
                if (i < segDef.Content.Count)
                {
                    elDef = segDef.Content[i];
                }

                if (elDef == null)
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Unexpected element '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                EdiDataElement el = new EdiDataElement(elDef, val);
                if (elDef != null && !el.IsValid(elDef))
                {
                    ValidationError err = new ValidationError()
                    {
                        SegmentPos  = rowPos,
                        SegmentName = content[0],
                        ElementPos  = i + 1,
                        Message     = $"Invalid value '{val}'"
                    };
                    validationScope.ValidationErrors.Add(err);
                }

                i++;
                seg.Content.Add(el);
            }
            return(seg);
        }
        public static EdiSegment ProcessSegment(MapBaseEntity definition, string[] content, int rowPos, string compositeSeparator, IValidatedEntity validationScope)
        {
            MapSegment segDef = (MapSegment)definition;
            EdiSegment seg    = new EdiSegment(segDef);

            int i = 0;

            foreach (string val in content.Skip(1))
            {
                MapSimpleDataElement    elDef = null;
                MapCompositeDataElement cDef  = null;
                if (i < segDef.Content.Count)
                {
                    if (segDef.Content[i] is MapSimpleDataElement)
                    {
                        elDef = (MapSimpleDataElement)segDef.Content[i];
                    }
                    else if (segDef.Content[i] is MapCompositeDataElement)
                    {
                        cDef = (MapCompositeDataElement)segDef.Content[i];
                    }
                }

                //if cDef is null - create simple element. Even if elDef is null
                // validation will add error of unknown element later on
                if (cDef == null)
                {
                    EdiSimpleDataElement el = new EdiSimpleDataElement(elDef, val);
                    seg.Content.Add(el);
                }
                else
                {
                    EdiCompositeDataElement composite = new EdiCompositeDataElement(cDef);
                    string[] compositeContent         = val.Split(new[] { compositeSeparator }, StringSplitOptions.None);
                    ProcessComposite(composite, compositeContent);
                    seg.Content.Add(composite);
                }

                i++;
            }

            SegmentValidator.ValidateSegment(seg, rowPos, validationScope);
            return(seg);
        }
Beispiel #8
0
 public EdiSegment(MapBaseEntity definition) : base(definition)
 {
     Content = new List <EdiDataElement>();
 }
Beispiel #9
0
 public EdiLoop(MapBaseEntity definition, EdiLoop parent) : base(definition)
 {
     Content = new List <MappedObjectBase>();
     Parent  = parent;
 }
 public EdiTrans(MapBaseEntity definition) : base(definition, null)
 {
     ValidationErrors = new List <ValidationError>();
 }
Beispiel #11
0
 public AllowedEntitity(MapBaseEntity entity, MapLoop loopContext)
 {
     Entity      = entity;
     LoopContext = loopContext;
 }
Beispiel #12
0
 public EdiLoop(MapBaseEntity definition, EdiLoop parent) : base(definition)
 {
     Content = new List <EdiBaseEntity>();
     Parent  = parent;
 }