summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/I2.Loc/TranslationJob_Main.cs
blob: 595872ae9ec190438b8783dddbf6729ef12a04df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.Collections.Generic;

namespace I2.Loc;

public class TranslationJob_Main : TranslationJob
{
	private TranslationJob_WEB mWeb;

	private TranslationJob_POST mPost;

	private TranslationJob_GET mGet;

	private Dictionary<string, TranslationQuery> _requests;

	private GoogleTranslation.fnOnTranslationReady _OnTranslationReady;

	public string mErrorMessage;

	public TranslationJob_Main(Dictionary<string, TranslationQuery> requests, GoogleTranslation.fnOnTranslationReady OnTranslationReady)
	{
		_requests = requests;
		_OnTranslationReady = OnTranslationReady;
		mPost = new TranslationJob_POST(requests, OnTranslationReady);
	}

	public override eJobState GetState()
	{
		if (mWeb != null)
		{
			switch (mWeb.GetState())
			{
			case eJobState.Running:
				return eJobState.Running;
			case eJobState.Succeeded:
				mJobState = eJobState.Succeeded;
				break;
			case eJobState.Failed:
				mWeb.Dispose();
				mWeb = null;
				mPost = new TranslationJob_POST(_requests, _OnTranslationReady);
				break;
			}
		}
		if (mPost != null)
		{
			switch (mPost.GetState())
			{
			case eJobState.Running:
				return eJobState.Running;
			case eJobState.Succeeded:
				mJobState = eJobState.Succeeded;
				break;
			case eJobState.Failed:
				mPost.Dispose();
				mPost = null;
				mGet = new TranslationJob_GET(_requests, _OnTranslationReady);
				break;
			}
		}
		if (mGet != null)
		{
			switch (mGet.GetState())
			{
			case eJobState.Running:
				return eJobState.Running;
			case eJobState.Succeeded:
				mJobState = eJobState.Succeeded;
				break;
			case eJobState.Failed:
				mErrorMessage = mGet.mErrorMessage;
				if (_OnTranslationReady != null)
				{
					_OnTranslationReady(_requests, mErrorMessage);
				}
				mGet.Dispose();
				mGet = null;
				break;
			}
		}
		return mJobState;
	}

	public override void Dispose()
	{
		if (mPost != null)
		{
			mPost.Dispose();
		}
		if (mGet != null)
		{
			mGet.Dispose();
		}
		mPost = null;
		mGet = null;
	}
}