50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
using System;
|
|
|
|
namespace SpectacleTransformer {
|
|
public abstract class TranslationRequest {
|
|
public readonly Uri InstanceUri;
|
|
public readonly Language Source;
|
|
public readonly Language Target;
|
|
public readonly string Text;
|
|
|
|
/// <summary>
|
|
/// Create a new translation request.
|
|
/// </summary>
|
|
/// <param name="InstanceUri">URI pointing to the server instance to use.</param>
|
|
/// <param name="Source">The source language.</param>
|
|
/// <param name="Target">The target language.</param>
|
|
/// <param name="Text">The text to translate.</param>
|
|
public TranslationRequest(Uri InstanceUri, Language Source, Language Target, string Text) {
|
|
if (Source.Equals(Target)) throw new ArgumentException("The source and target languages cannot be the same.");
|
|
this.InstanceUri = InstanceUri;
|
|
this.Source = Source;
|
|
this.Target = Target;
|
|
this.Text = Text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines if this TranslationRequest can be instanciated with an instance URI.
|
|
/// </summary>
|
|
/// <param name="InstanceUri">The instance URI to check.</param>
|
|
/// <returns>Whether this translation request can be performed on this instance URI.</returns>
|
|
public static bool MatchesInstance(Uri InstanceUri) {
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Perform a translation request.
|
|
/// </summary>
|
|
/// <returns>The translated text, or null if the translation failed.</returns>
|
|
public abstract string Run();
|
|
|
|
/// <summary>
|
|
/// Called in the main thread with UI controls to allow further post-processing that could require them.
|
|
/// </summary>
|
|
/// <param name="response">The response returned by Run().</param>
|
|
/// <returns>A processed response.</returns>
|
|
public virtual string PostProcess(string response) {
|
|
return response;
|
|
}
|
|
}
|
|
}
|