private static List <IErrorListItem> RemoveErrorDuplicates(ITaskRunnerNode task,
                                                                   string projectName,
                                                                   OutputParserResult parserOutput,
                                                                   OutputErrorSnapshot currentSnapshot)
        {
            List <IErrorListItem> newErrors = new List <IErrorListItem>();

            foreach (IErrorListItem error in parserOutput.ErrorList)
            {
                error.ProjectName = projectName;
                error.ErrorSource = task.Name;
                error.Filename    = Path.Combine(task.Command.WorkingDirectory, error.Filename);
                error.Command     = task.Command;

                if (!currentSnapshot.Errors.Contains(error))
                {
                    newErrors.Add(error);
                }
            }

            return(newErrors);
        }
        /// <summary>
        /// Handles the command output (inputLines) and generates errors as appropriate.
        /// </summary>
        /// <param name="task">Task being executed</param>
        /// <param name="projectName">Project name of the task</param>
        /// <param name="inputLines">Set of command output messages to be parsed</param>
        /// <returns></returns>
        public IEnumerable <string> HandleLines(ITaskRunnerNode task, string projectName, IEnumerable <string> lines)
        {
            bool errorListNeedsUpdate = false;

            // Remove existing Factory errors associated with the running task after idle time
            if (_timer.ElapsedMilliseconds > 1000)
            {
                _factory.ClearErrors(task);
                errorListNeedsUpdate = true;
            }


            OutputParserResult parserOutput = _outputParser.ParseOutput(lines);

            if (parserOutput != null && parserOutput.ErrorList.Count() > 0)
            {
                OutputErrorSnapshot   currentSnapshot = _factory.CurrentSnapshot as OutputErrorSnapshot;
                List <IErrorListItem> newErrors       = RemoveErrorDuplicates(task, projectName, parserOutput, currentSnapshot);

                if (newErrors.Count > 0)
                {
                    _factory.AddErrorItems(newErrors);
                    errorListNeedsUpdate = true;
                }
            }

            // Only update the errors list if Factory errors has changed.
            if (errorListNeedsUpdate)
            {
                UpdateErrorsList();
            }

            // Reset and start the timer to measure new elapsed time between new line(s) inputs
            _timer.Reset();
            _timer.Start();

            return(parserOutput.OutputLines);
        }
 /// <summary>
 /// Updates the factory errors snapshot
 /// </summary>
 /// <param name="errorsList"></param>
 internal void UpdateErrors(OutputErrorSnapshot errorsList)
 {
     CurrentSnapshot = errorsList;
 }
 internal OutputErrorsFactory(IErrorListProvider errorProvider)
 {
     _errorProvider  = errorProvider;
     CurrentSnapshot = new OutputErrorSnapshot(0, _currentErrors);
 }