Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                TaskId    = 0;
                ClientKey = null;
                TaskInfo  = null;

                disposedValue = true;
            }
        }
Exemplo n.º 2
0
        public void WaitForResult(int maxSeconds = 120, int currentSecond = 0)
        {
            if (currentSecond >= maxSeconds)
            {
                throw new Exception("Time out");
            }

            if (currentSecond.Equals(0))
            {
                Thread.Sleep(3000);
            }
            else
            {
                Thread.Sleep(1000);
            }

            var jsonPostData = new JObject();

            jsonPostData["clientKey"] = ClientKey;
            jsonPostData["taskId"]    = TaskId;

            dynamic postResult = JsonPostRequest(ApiMethods.GetTaskResult, jsonPostData);

            if (postResult == null || postResult.Equals(false))
            {
                throw new Exception("API error");
            }

            TaskInfo = new TaskResultResponse(postResult);

            if (!TaskInfo.ErrorId.Equals(0))
            {
                throw new Exception(TaskInfo.ErrorDescription);
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Processing))
            {
                WaitForResult(maxSeconds, currentSecond + 1);
                return;
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Ready))
            {
                if (TaskInfo.Solution.GRecaptchaResponse == null && TaskInfo.Solution.Text == null)
                {
                    throw new Exception("Got no 'solution' field from API");
                }

                return;
            }

            throw new Exception("An unknown API status, please update your software");
        }
Exemplo n.º 3
0
        public bool WaitForResult(int maxSeconds = 120, int currentSecond = 0)
        {
            if (currentSecond >= maxSeconds)
            {
                DebugHelper.Out("Time's out.", DebugHelper.Type.Error);

                return(false);
            }

            if (currentSecond.Equals(0))
            {
                DebugHelper.Out("Waiting for 3 seconds...", DebugHelper.Type.Info);
                Thread.Sleep(3000);
            }
            else
            {
                Thread.Sleep(1000);
            }

            DebugHelper.Out("Requesting the task status", DebugHelper.Type.Info);

            var jsonPostData = new JObject();

            jsonPostData["clientKey"] = ClientKey;
            jsonPostData["taskId"]    = TaskId;

            dynamic postResult = JsonPostRequest(ApiMethod.GetTaskResult, jsonPostData);

            if (postResult == null || postResult.Equals(false))
            {
                DebugHelper.Out("API error", DebugHelper.Type.Error);

                return(false);
            }

            TaskInfo = new TaskResultResponse(postResult);

            if (!TaskInfo.ErrorId.Equals(0))
            {
                ErrorMessage = TaskInfo.ErrorDescription;

                DebugHelper.Out("API error " + TaskInfo.ErrorId + ": " + ErrorMessage, DebugHelper.Type.Error);

                return(false);
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Processing))
            {
                DebugHelper.Out("The task is still processing...", DebugHelper.Type.Info);

                return(WaitForResult(maxSeconds, currentSecond + 1));
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Ready))
            {
                if (TaskInfo.Solution.GRecaptchaResponse == null && TaskInfo.Solution.Text == null)
                {
                    DebugHelper.Out("Got no 'solution' field from API", DebugHelper.Type.Error);

                    return(false);
                }

                DebugHelper.Out("The task is complete!", DebugHelper.Type.Success);

                return(true);
            }

            ErrorMessage = "An unknown API status, please update your software";
            DebugHelper.Out(ErrorMessage, DebugHelper.Type.Error);

            return(false);
        }
Exemplo n.º 4
0
        public bool WaitForResult(int maxSeconds = 120, int currentSecond = 0)
        {
            if (currentSecond >= maxSeconds)
            {
                DebugHelper.Out(DebugHelper.Severity.Error, "Time's out.");

                return(false);
            }

            if (currentSecond.Equals(0))
            {
                DebugHelper.Out(DebugHelper.Severity.Info, "Waiting for 3 seconds...");
                Thread.Sleep(3000);
            }
            else
            {
                Thread.Sleep(1000);
            }

            DebugHelper.Out(DebugHelper.Severity.Info, "Requesting the task status");

            var jsonPostData = new JObject
            {
                ["clientKey"] = ClientKey,
                ["taskId"]    = TaskId
            };

            dynamic postResult = JsonPostRequest(ApiMethod.GetTaskResult, jsonPostData);

            if (postResult?.Equals(false) != false)
            {
                DebugHelper.Out(DebugHelper.Severity.Error, "API error");

                return(false);
            }

            TaskInfo = new TaskResultResponse(postResult);

            if (!TaskInfo.ErrorId.Equals(0))
            {
                ErrorMessage = TaskInfo.ErrorDescription;

                DebugHelper.Out(DebugHelper.Severity.Error, "API error " + TaskInfo.ErrorId + ": " + ErrorMessage);

                return(false);
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Processing))
            {
                DebugHelper.Out(DebugHelper.Severity.Info, "The task is still processing...");

                return(WaitForResult(maxSeconds, currentSecond + 1));
            }

            if (TaskInfo.Status.Equals(TaskResultResponse.StatusType.Ready))
            {
                if (TaskInfo.Solution.GRecaptchaResponse == null && TaskInfo.Solution.Text == null &&
                    TaskInfo.Solution.Answers == null && TaskInfo.Solution.Token == null &&
                    TaskInfo.Solution.Challenge == null && TaskInfo.Solution.Seccode == null &&
                    TaskInfo.Solution.Validate == null)
                {
                    DebugHelper.Out(DebugHelper.Severity.Error, "Got no 'solution' field from API");

                    return(false);
                }

                DebugHelper.Out(DebugHelper.Severity.Success, "The task is complete!");

                return(true);
            }

            ErrorMessage = "An unknown API status, please update your software";
            DebugHelper.Out(DebugHelper.Severity.Error, ErrorMessage);

            return(false);
        }