Esempio n. 1
0
        public void ParseLine(string line)
        {
            if (IsCommentLine(line))
            {
                return;
            }

            Match match = pattern.Match(line);

            if (match.Success)
            {
                string itemName           = match.Groups[1].Captures[0].Value;
                string itemId             = match.Groups[2].Captures[0].Value;
                string shelf              = match.Groups[3].Captures[0].Value;
                string itemQuantityString = match.Groups[4].Captures[0].Value;
                int    itemQuantity       = int.Parse(itemQuantityString);
                warehouse.AddItemToShelf(itemId, itemName, itemQuantity, shelf);

                for (int i = 0; i < match.Groups[5].Captures.Count; ++i)
                {
                    shelf = match.Groups[5].Captures[i].Value;
                    itemQuantityString = match.Groups[6].Captures[i].Value;
                    itemQuantity       = int.Parse(itemQuantityString);
                    warehouse.AddItemToShelf(itemId, itemName, itemQuantity, shelf);
                }
            }
            else
            {
                invalidLines.Add(line);
            }
        }
Esempio n. 2
0
        public void ParseLine(string line)
        {
            if (IsCommentLine(line))
            {
                return;
            }

            var  lineAsSpan  = line.AsSpan();
            bool isLineValid = false;

            ReadOnlySpan <char> itemNameSpan = ParseString(ref lineAsSpan, ';');
            ReadOnlySpan <char> itemIdSpan   = ParseString(ref lineAsSpan, ';');

            if ((!itemNameSpan.IsEmpty) && (!itemIdSpan.IsEmpty))
            {
                isLineValid = stockPartValidator.Validate(in lineAsSpan);
                if (isLineValid)
                {
                    string itemName = stringPool.GetString(in itemNameSpan);
                    string itemId   = stringPool.GetString(in itemIdSpan);
                    while (!lineAsSpan.IsEmpty)
                    {
                        ReadOnlySpan <char> shelfSpan = ParseString(ref lineAsSpan, ',');
                        int quantity = ParseInt(ref lineAsSpan, '|');

                        string shelf = stringPool.GetString(in shelfSpan);
                        warehouse.AddItemToShelf(itemId, itemName, quantity, shelf);
                    }
                }
            }

            if (!isLineValid)
            {
                invalidLines.Add(line);
            }
        }