Exemple #1
0
        public IEnumerable <InputLine> ReadLines(string inputfileJson)
        {
            var aggregatedLines = new List <InputLine>();

            foreach (var line in File.ReadLines(inputfileJson))
            {
                InputLine input = JsonConvert.DeserializeObject <InputLine>(line);

                if (MandatoryParametersArePresent(input.type, line) && !IsLateArrival(input))
                {
                    aggregatedLines.Add(input);
                    _lastArrivalTimestamp = input.timestamp;
                }
                else
                {
                    if (IsLateArrival(input))
                    {
                        _logger.LogMessage($"Ignoring line as it is a late arrival: {line}");
                    }
                    else
                    {
                        _logger.LogMessage($"Ignoring line because type is not known or at least one parameter is missing: {line}");
                    }
                }
            }

            return(aggregatedLines);
        }
Exemple #2
0
 // Definitively it is very arguable to put this here or not.
 //the class is only supposed to have knowledge and information about how to read rows of a file.
 // But I add extra responsibility which belongs to the domain here. My reasons are:
 // 1. Filter as early as possible to avoid useless processing.
 // 2. Performance of the removal, as any other solution would require either to iterate the whole list at least once to remove late
 // arrivals or else to keep track of the timestamp management in the Engine.cs, which I think is already too complex due to nesting.
 private bool IsLateArrival(InputLine line)
 {
     if (_lastArrivalTimestamp < line.timestamp)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #3
0
        public IStockEvent GetInputEvent(ProductsRepository repository, InputLine inputLine)
        {
            int?parentId;

            if (inputLine.parent_id == "None")
            {
                parentId = null;
            }
            else if (int.TryParse(inputLine.parent_id, out var productId))
            {
                parentId = productId;
            }
            else
            {
                throw new ArgumentException("Parent type must have value 'None' for parent items or numeric");
            }

            return(new ProductCreated(repository, inputLine.id, inputLine.stock, parentId));
        }
Exemple #4
0
 public IStockEvent GetInputEvent(ProductsRepository repository, InputLine inputLine)
 {
     return(new ProductUpdated(repository, inputLine.id, inputLine.stock));
 }
Exemple #5
0
 public IStockEvent GetInputEvent(ProductsRepository repository, InputLine inputLine)
 {
     return(new ProductEnded(repository, inputLine.id));
 }