Init
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
namespace QFSW.QC
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a Preprocessor that is loaded and used by the QuantumConsoleProcessor.
|
||||
/// </summary>
|
||||
public interface IQcPreprocessor
|
||||
{
|
||||
/// <summary>
|
||||
/// The priority of this preprocessor to resolve processing order.
|
||||
/// </summary>
|
||||
int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Processes the provided text.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to process.</param>
|
||||
/// <returns>The processed text.</returns>
|
||||
string Process(string text);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 982c71777d2ff0148ba45412ef409334
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles preprocessing of console input.
|
||||
/// </summary>
|
||||
public class QuantumPreprocessor
|
||||
{
|
||||
private readonly IQcPreprocessor[] _preprocessors;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Quantum Preprocessor with a custom set of preprocessors.
|
||||
/// </summary>
|
||||
/// <param name="preprocessors">The IQcPreprocessors to use in this Quantum Preprocessor.</param>
|
||||
public QuantumPreprocessor(IEnumerable<IQcPreprocessor> preprocessors)
|
||||
{
|
||||
_preprocessors = preprocessors.OrderByDescending(x => x.Priority)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Quantum Preprocessor with the default injected preprocessors
|
||||
/// </summary>
|
||||
public QuantumPreprocessor() : this(new InjectionLoader<IQcPreprocessor>().GetInjectedInstances())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the provided text.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to process.</param>
|
||||
/// <returns>The processed text.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca234287b4b55cb45bf0ecea07ef2703
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user