DefaultEndpoint.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using UnityEngine;
  5. namespace XUnity.AutoTranslator.Plugin.Core.Web
  6. {
  7. public class DefaultEndpoint : KnownEndpoint
  8. {
  9. private static ServicePoint ServicePoint;
  10. private static readonly string ServicePointTemplateUrl = "{0}?from={1}&to={2}&text={3}";
  11. public DefaultEndpoint( string endpoint )
  12. : base( endpoint )
  13. {
  14. }
  15. public override void ApplyHeaders( Dictionary<string, string> headers )
  16. {
  17. }
  18. public override void ApplyHeaders( WebHeaderCollection headers )
  19. {
  20. }
  21. public override void ConfigureServicePointManager()
  22. {
  23. try
  24. {
  25. ServicePoint = ServicePointManager.FindServicePoint( new Uri( Identifier ) );
  26. ServicePoint.ConnectionLimit = 100;
  27. }
  28. catch
  29. {
  30. }
  31. }
  32. public override bool TryExtractTranslated( string result, out string translated )
  33. {
  34. translated = result;
  35. return true;
  36. }
  37. public override string GetServiceUrl( string untranslatedText, string from, string to )
  38. {
  39. return string.Format( ServicePointTemplateUrl, Identifier, from, to, WWW.EscapeURL( untranslatedText ) );
  40. }
  41. }
  42. }