Ejemplo n.º 1
0
 //Only internal Constructors
 internal Component(SubComponent SubComponent, MessageDelimiters CustomDelimiters, bool Temporary,
                    int?Index, ModelBase Parent)
     : base(CustomDelimiters)
 {
     ValidateItemNotInUse(SubComponent);
     _Temporary             = Temporary;
     _Index                 = Index;
     _Parent                = Parent;
     _SubComponentDictonary = new Dictionary <int, SubComponent>();
     _SubComponentDictonary.Add(1, SubComponent);
 }
Ejemplo n.º 2
0
 internal SubComponent SubComponentSet(SubComponent SubComponent, int Index)
 {
     if (_ComponentDictonary.ContainsKey(1))
     {
         return(_ComponentDictonary[1].SubComponentSet(SubComponent, Index));
     }
     else
     {
         Component oComponent = new Component(string.Empty, this.Delimiters, true, 1, this);
         return(oComponent.SubComponentSet(SubComponent, Index));
     }
 }
Ejemplo n.º 3
0
 internal Content ContentInsertBefore(Content Content, int Index)
 {
     if (_SubComponentDictonary.ContainsKey(1))
     {
         return(_SubComponentDictonary[1].ContentInsertBefore(Content, Index));
     }
     else
     {
         //_SubComponentDictonary.Add(1, new SubComponent(Content, this.Delimiters, true, 0, this));
         SubComponent oSubComponent = new SubComponent(String.Empty, this.Delimiters, true, 1, this);
         return(oSubComponent.ContentInsertBefore(Content, Index));
     }
 }
Ejemplo n.º 4
0
 internal SubComponent SubComponentSet(SubComponent SubComponent, int Index)
 {
     if (_RepeatDictonary.ContainsKey(1))
     {
         return(_RepeatDictonary[1].SubComponentSet(SubComponent, Index));
     }
     else
     {
         //_RepeatDictonary.Add(1, new Field(string.Empty, this.Delimiters, true, 1, this));
         //return _RepeatDictonary[1].ContentSet(Content, Index);
         Field oField = new Field(string.Empty, this.Delimiters, true, 1, this);
         return(oField.SubComponentSet(SubComponent, Index));
     }
 }
Ejemplo n.º 5
0
 internal Content ContentAppend(Content Content)
 {
     if (_SubComponentDictonary.ContainsKey(1))
     {
         return(_SubComponentDictonary[1].ContentAppend(Content));
     }
     else
     {
         //_SubComponentDictonary = new Dictionary<int, SubComponent>();
         //_SubComponentDictonary.Add(1, new SubComponent(Content, this.Delimiters, true, 0, this));
         SubComponent oSubComponent = new SubComponent(String.Empty, this.Delimiters, true, 1, this);
         return(oSubComponent.ContentAppend(Content));
     }
 }
Ejemplo n.º 6
0
 internal Content ContentSet(Content Content, int Index)
 {
     if (_SubComponentDictonary.ContainsKey(1))
     {
         return(_SubComponentDictonary[1].ContentSet(Index, Content));
     }
     else
     {
         //_SubComponentDictonary.Add(1, new SubComponent(string.Empty, this.Delimiters, true, 1, this));
         //return _SubComponentDictonary[1].ContentSet(Index, Content);
         SubComponent oSubComponent = new SubComponent(string.Empty, this.Delimiters, true, 1, this);
         return(oSubComponent.ContentSet(Index, Content));
     }
 }
Ejemplo n.º 7
0
 //Maintenance
 private void SetParent()
 {
     if (this._Temporary)
     {
         if (this._Parent is SubComponent)
         {
             SubComponent oSubComponent = this._Parent as SubComponent;
             if (oSubComponent.SetToDictonary(this))
             {
                 this._Temporary = false;
             }
         }
     }
 }
Ejemplo n.º 8
0
 private void RemoveFromParent()
 {
     if (this._Index != null)
     {
         try
         {
             SubComponent oSubComponent = this._Parent as SubComponent;
             oSubComponent.RemoveChild(System.Convert.ToInt32(this._Index));
         }
         catch (InvalidCastException oInvalidCastExec)
         {
             throw new PeterPiperException("Casting of Content's parent to SubComponent throws Invalid Cast Exception, check inner exception for more detail", oInvalidCastExec);
         }
     }
 }
Ejemplo n.º 9
0
 //Content
 internal Content GetContent(int index)
 {
     if (_SubComponentDictonary.ContainsKey(1))
     {
         return(_SubComponentDictonary[1].GetContent(index));
     }
     else
     {
         //_SubComponentDictonary = new Dictionary<int, SubComponent>();
         //_SubComponentDictonary.Add(1, new SubComponent(string.Empty, this.Delimiters, false, 0, this));
         //return _SubComponentDictonary[1].GetContent(index);
         SubComponent oSubComponent = new SubComponent(string.Empty, this.Delimiters, false, 0, this);
         return(oSubComponent.GetContent(index));
     }
 }
Ejemplo n.º 10
0
 internal SubComponent SubComponentAppend(SubComponent SubComponent)
 {
     if (_ComponentDictonary.ContainsKey(1))
     {
         return(_ComponentDictonary[1].SubComponentAppend(SubComponent));
     }
     else
     {
         //_ComponentDictonary = new Dictionary<int, Component>();
         //_ComponentDictonary.Add(1, new Component(SubComponent, SubComponent.Delimiters, true, 1, this));
         //return _ComponentDictonary[1].GetSubComponent(1);
         Component oComponent = new Component(String.Empty, SubComponent.Delimiters, true, 1, this);
         return(oComponent.SubComponentAppend(SubComponent));
     }
 }
Ejemplo n.º 11
0
 internal SubComponent SubComponentAppend(SubComponent SubComponent)
 {
     if (_RepeatDictonary.ContainsKey(1))
     {
         return(_RepeatDictonary[1].SubComponentAppend(SubComponent));
     }
     else
     {
         //_RepeatDictonary = new Dictionary<int, Field>();
         //_RepeatDictonary.Add(1, new Field(string.Empty, this.Delimiters, true, 1, this));
         //_RepeatDictonary[1].SubComponentAppend(SubComponent);
         //return _RepeatDictonary[1].GetSubComponent(1);
         Field oField = new Field(string.Empty, this.Delimiters, true, 1, this);
         return(oField.SubComponentAppend(SubComponent));
     }
 }
Ejemplo n.º 12
0
 internal SubComponent SubComponentInsertBefore(SubComponent SubComponent, int Index)
 {
     if (_ComponentDictonary.ContainsKey(1))
     {
         return(_ComponentDictonary[1].SubComponentInsertBefore(SubComponent, Index));
     }
     else
     {
         //_ComponentDictonary = new Dictionary<int, Component>();
         //_ComponentDictonary.Add(1, new Component(string.Empty, this.Delimiters, true, 1, this));
         //_ComponentDictonary[1].SubComponentInsertBefore(SubComponent, Index);
         //return _ComponentDictonary[1].GetSubComponent(Index);
         Component oComponent = new Component(string.Empty, this.Delimiters, true, 1, this);
         return(oComponent.SubComponentInsertBefore(SubComponent, Index));
     }
 }
Ejemplo n.º 13
0
 internal SubComponent SubComponentAppend(SubComponent SubComponent)
 {
     if (_SubComponentDictonary.Count > 0)
     {
         return(SubComponentInsertBefore(SubComponent, _SubComponentDictonary.Keys.Max() + 1));
     }
     else
     {
         SubComponent._Index  = 1;
         SubComponent._Parent = this;
         if (SetToDictonary(SubComponent))
         {
             SubComponent._Temporary = false;
         }
         return(_SubComponentDictonary[1]);
     }
 }
Ejemplo n.º 14
0
 internal SubComponent SubComponentSet(SubComponent SubComponent, int Index)
 {
     if (SubComponent.AsStringRaw == String.Empty)
     {
         RemoveChild(Index);
         SubComponent._Index     = null;
         SubComponent._Parent    = null;
         SubComponent._Temporary = true;
         return(SubComponent);
     }
     else
     {
         SubComponent._Index  = Index;
         SubComponent._Parent = this;
         if (SetToDictonary(SubComponent))
         {
             _SubComponentDictonary[Index]._Temporary = false;
         }
         return(_SubComponentDictonary[System.Convert.ToInt32(SubComponent._Index)]);
     }
 }
Ejemplo n.º 15
0
        internal SubComponent SubComponentInsertBefore(SubComponent SubComponent, int Index)
        {
            if (Index == 0)
            {
                throw new PeterPiperArgumentException("Element is a one based index, zero is not a valid index.");
            }

            if (_RepeatDictonary.ContainsKey(1))
            {
                return(_RepeatDictonary[1].SubComponentInsertBefore(SubComponent, Index));
            }
            else
            {
                //_RepeatDictonary = new Dictionary<int, Field>();
                //_RepeatDictonary.Add(1, new Field(string.Empty, this.Delimiters, true, 1, this));
                //_RepeatDictonary[1].SubComponentInsertBefore(SubComponent, Index);
                //return _RepeatDictonary[1].GetSubComponent(Index);
                Field oField = new Field(string.Empty, this.Delimiters, true, 1, this);
                return(oField.SubComponentInsertBefore(SubComponent, Index));
            }
        }
Ejemplo n.º 16
0
 //Maintenance
 internal bool SetToDictonary(SubComponent oSubComponent)
 {
     try
     {
         if (_SubComponentDictonary.ContainsKey(System.Convert.ToInt32(oSubComponent._Index)))
         {
             _SubComponentDictonary[System.Convert.ToInt32(oSubComponent._Index)]._Temporary = true;
             _SubComponentDictonary[System.Convert.ToInt32(oSubComponent._Index)]._Parent    = null;
             _SubComponentDictonary[System.Convert.ToInt32(oSubComponent._Index)]._Index     = null;
             _SubComponentDictonary[System.Convert.ToInt32(oSubComponent._Index)]            = oSubComponent;
         }
         else
         {
             _SubComponentDictonary.Add(System.Convert.ToInt32(oSubComponent._Index), oSubComponent);
         }
         SetParent();
         return(true);
     }
     catch (Exception Exec)
     {
         throw new PeterPiperException("Error setting SubComponent into Component Parent", Exec);
     }
 }
Ejemplo n.º 17
0
        internal SubComponent SubComponentInsertBefore(SubComponent SubComponent, int Index)
        {
            if (Index == 0)
            {
                throw new PeterPiperArgumentException("SubComponent is a one based index, zero is not a valid index.");
            }

            int SubComponentInsertedAt = 0;

            //Empty dictionary so just add as first item
            if (_SubComponentDictonary.Count == 0)
            {
                SubComponentInsertedAt = Index;
                SubComponent._Index    = SubComponentInsertedAt;
                SubComponent._Parent   = this;
                if (SetToDictonary(SubComponent))
                {
                    SubComponent._Temporary = false;
                }
            }
            //Asked to insert before an index larger than the largest in dictionary so just add to the end
            else if (_SubComponentDictonary.Keys.Max() < Index)
            {
                SubComponentInsertedAt = Index;
                SubComponent._Index    = SubComponentInsertedAt;
                SubComponent._Parent   = this;
                if (SetToDictonary(SubComponent))
                {
                    SubComponent._Temporary = false;
                }
                //_ContentDictonary.Add(_ContentDictonary.Keys.Max() + 1, Content);
            }
            //Asked to insert within items already in the Dictionary so cycle through moving each item higher or equal up by one then just add the new item
            //The Content dictionary is different than all the others as it is to never have gaps between items and it is Zero based.
            else
            {
                foreach (var item in _SubComponentDictonary.Reverse())
                {
                    if (item.Key >= Index)
                    {
                        item.Value._Index++;
                        if (_SubComponentDictonary.ContainsKey(item.Key + 1))
                        {
                            _SubComponentDictonary.Remove(item.Key);
                            _SubComponentDictonary[item.Key + 1] = item.Value;
                        }
                        else
                        {
                            _SubComponentDictonary.Remove(item.Key);
                            _SubComponentDictonary.Add(item.Key + 1, item.Value);
                        }
                    }
                }
                SubComponent._Index  = Index;
                SubComponent._Parent = this;
                SetParent();
                SubComponent._Temporary       = false;
                _SubComponentDictonary[Index] = SubComponent;
                SubComponentInsertedAt        = Index;
            }
            return(_SubComponentDictonary[SubComponentInsertedAt]);
        }