Exemple #1
0
        public override JObject GetPostData()
        {
            var postData = base.GetPostData();

            postData["type"] = "NoCaptchaTask";

            if (ProxyType == null || ProxyPort == null || ProxyPort < 1 || ProxyPort > 65535 ||
                string.IsNullOrEmpty(ProxyAddress))
            {
                DebugHelper.Out("Proxy data is incorrect!", DebugHelper.Type.Error);

                return(null);
            }

            postData.Add("proxyType", ProxyType.ToString().ToLower());
            postData.Add("proxyAddress", ProxyAddress);
            postData.Add("proxyPort", ProxyPort);
            postData.Add("proxyLogin", ProxyLogin);
            postData.Add("proxyPassword", ProxyPassword);
            postData.Add("userAgent", UserAgent);
            postData.Add("cookies", Cookies);

            return(postData);
        }
        public bool WaitForResult(int maxSeconds = 400, 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);
        }