Exemplo n.º 1
0
        public void RemoveChild(StockBlock childBlock)
        {
            if (_children == null)
            {
                return;
            }

            int index = -1;

            for (int i = 0; i < _children.Count; ++i)
            {
                if (object.ReferenceEquals(_children[i], childBlock))
                {
                    index = i;
                    break;
                }
            }

            if (index >= 0)
            {
                _children.RemoveAt(index);
                if (_children.Count == 0)
                {
                    _children = null;
                }

                childBlock.ParentBlock = null;
            }
        }
        private static StockBlockRelationship ParseLine(string line, StockBlockManager manager)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                return(null);
            }

            var fields = line.Split(_splitter);

            if (fields.Length != FieldCount)
            {
                return(null);
            }

            StockBlock block = manager.GetStockBlockById(fields[2]);

            if (block == null)
            {
                return(null);
            }

            return(new StockBlockRelationship
            {
                StockCode = StockName.NormalizeCode(fields[1]),
                BlockName = block.Name
            });
        }
Exemplo n.º 3
0
        public StockBlock GetStockBlockById(string id)
        {
            StockBlock block = null;

            _blockIdIndices.TryGetValue(id, out block);

            return(block);
        }
Exemplo n.º 4
0
        public StockBlock GetStockBlockByName(string name)
        {
            StockBlock block = null;

            _blockNameIndices.TryGetValue(name, out block);

            return(block);
        }
Exemplo n.º 5
0
        public void AddChild(StockBlock childBlock)
        {
            if (_children == null)
            {
                _children = new List <StockBlock>();
            }

            _children.Add(childBlock);
            childBlock.ParentBlock = this;
        }
Exemplo n.º 6
0
        public void AddStockBlock(StockBlock block)
        {
            if (block == null)
            {
                throw new ArgumentNullException();
            }

            StockBlock oldBlock;

            if (_blockNameIndices.TryGetValue(block.Name, out oldBlock))
            {
                if (block.Id.StartsWith(HierachicalBlockIdHead))
                {
                    RemoveStockBlock(oldBlock.Name);
                }
                else
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(block.Id))
            {
                if (_blockIdIndices.ContainsKey(block.Id))
                {
                    throw new InvalidOperationException(string.Format("StockBlock with id {0} exists", block.Id));
                }
            }

            _blockNameIndices.Add(block.Name, block);

            if (!string.IsNullOrEmpty(block.Id))
            {
                _blockIdIndices.Add(block.Id, block);

                // build the hierarchy of block
                var children = FindChildren(block.Id);
                if (children != null && children.Count > 0)
                {
                    foreach (var child in children)
                    {
                        block.AddChild(child);
                    }
                }

                var parent = FindParent(block.Id);
                if (parent != null)
                {
                    parent.AddChild(block);
                }
            }
        }
Exemplo n.º 7
0
        private StockBlock FindParent(string childId)
        {
            if (!childId.StartsWith(HierachicalBlockIdHead))
            {
                return(null);
            }

            if (childId.Length == 5 || childId.Length == 7) // Txxxx or Txxxxxx, second or third level block
            {
                StockBlock block = null;
                if (_blockIdIndices.TryGetValue(childId.Substring(0, childId.Length - 2), out block))
                {
                    return(block);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }