TranslationJob_Main.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. namespace I2.Loc
  4. {
  5. public class TranslationJob_Main : TranslationJob
  6. {
  7. public TranslationJob_Main(Dictionary<string, TranslationQuery> requests, Action<Dictionary<string, TranslationQuery>, string> OnTranslationReady)
  8. {
  9. this._requests = requests;
  10. this._OnTranslationReady = OnTranslationReady;
  11. this.mPost = new TranslationJob_POST(requests, OnTranslationReady);
  12. }
  13. public override TranslationJob.eJobState GetState()
  14. {
  15. if (this.mWeb != null)
  16. {
  17. TranslationJob.eJobState state = this.mWeb.GetState();
  18. if (state == TranslationJob.eJobState.Running)
  19. {
  20. return TranslationJob.eJobState.Running;
  21. }
  22. if (state != TranslationJob.eJobState.Succeeded)
  23. {
  24. if (state == TranslationJob.eJobState.Failed)
  25. {
  26. this.mWeb.Dispose();
  27. this.mWeb = null;
  28. this.mPost = new TranslationJob_POST(this._requests, this._OnTranslationReady);
  29. }
  30. }
  31. else
  32. {
  33. this.mJobState = TranslationJob.eJobState.Succeeded;
  34. }
  35. }
  36. if (this.mPost != null)
  37. {
  38. TranslationJob.eJobState state2 = this.mPost.GetState();
  39. if (state2 == TranslationJob.eJobState.Running)
  40. {
  41. return TranslationJob.eJobState.Running;
  42. }
  43. if (state2 != TranslationJob.eJobState.Succeeded)
  44. {
  45. if (state2 == TranslationJob.eJobState.Failed)
  46. {
  47. this.mPost.Dispose();
  48. this.mPost = null;
  49. this.mGet = new TranslationJob_GET(this._requests, this._OnTranslationReady);
  50. }
  51. }
  52. else
  53. {
  54. this.mJobState = TranslationJob.eJobState.Succeeded;
  55. }
  56. }
  57. if (this.mGet != null)
  58. {
  59. TranslationJob.eJobState state3 = this.mGet.GetState();
  60. if (state3 == TranslationJob.eJobState.Running)
  61. {
  62. return TranslationJob.eJobState.Running;
  63. }
  64. if (state3 != TranslationJob.eJobState.Succeeded)
  65. {
  66. if (state3 == TranslationJob.eJobState.Failed)
  67. {
  68. this.mErrorMessage = this.mGet.mErrorMessage;
  69. if (this._OnTranslationReady != null)
  70. {
  71. this._OnTranslationReady(this._requests, this.mErrorMessage);
  72. }
  73. this.mGet.Dispose();
  74. this.mGet = null;
  75. }
  76. }
  77. else
  78. {
  79. this.mJobState = TranslationJob.eJobState.Succeeded;
  80. }
  81. }
  82. return this.mJobState;
  83. }
  84. public override void Dispose()
  85. {
  86. if (this.mPost != null)
  87. {
  88. this.mPost.Dispose();
  89. }
  90. if (this.mGet != null)
  91. {
  92. this.mGet.Dispose();
  93. }
  94. this.mPost = null;
  95. this.mGet = null;
  96. }
  97. private TranslationJob_WEB mWeb;
  98. private TranslationJob_POST mPost;
  99. private TranslationJob_GET mGet;
  100. private Dictionary<string, TranslationQuery> _requests;
  101. private Action<Dictionary<string, TranslationQuery>, string> _OnTranslationReady;
  102. public string mErrorMessage;
  103. }
  104. }