using System; using System.Collections.Generic; using System.Linq; namespace QFSW.QC { /// /// Handles preprocessing of console input. /// public class QuantumPreprocessor { private readonly IQcPreprocessor[] _preprocessors; /// /// Creates a Quantum Preprocessor with a custom set of preprocessors. /// /// The IQcPreprocessors to use in this Quantum Preprocessor. public QuantumPreprocessor(IEnumerable preprocessors) { _preprocessors = preprocessors.OrderByDescending(x => x.Priority) .ToArray(); } /// /// Creates a Quantum Preprocessor with the default injected preprocessors /// public QuantumPreprocessor() : this(new InjectionLoader().GetInjectedInstances()) { } /// /// Processes the provided text. /// /// The text to process. /// The processed text. public string Process(string text) { foreach (IQcPreprocessor preprocessor in _preprocessors) { try { text = preprocessor.Process(text); } catch (Exception e) { throw new Exception($"Preprocessor {preprocessor} failed:\n{e.Message}", e); } } return text; } } }