/// <summary>
        /// 循环询问验证码图片的答案
        /// </summary>
        private void LoopInquiryCaptchaAnswer()
        {
            while (isInquiryWork)
            {
                long ss = KK.CurrentMills();
                try
                {
                    var  taskContext = CaptchaTaskContext.me;
                    long s1          = KK.CurrentMills();
                    if (CaptchaTaskContext.me.IsAllImagesAnswered())
                    {
                        KK.Sleep(30);
                        continue;
                    }

                    var images = new List <CaptchaAnswerImage>(taskContext.GetImagesOfAwaitAnswer());

                    logger.DebugFormat("inquiry answer, image size is {0}. First Uuid is {1}", images.Count, images[0].Uuid);

                    foreach (var img in images)
                    {
                        if (img == null)
                        {
                            continue;
                        }

                        if (img.Answer == null || img.Answer.Length == 0)
                        {
                            var req = KK.CreateImageAnswerRequest(img.Uuid);

                            DataResult <CaptchaImageAnswerResponse> dr = HttpClients
                                                                         .PostAsJson <DataResult <CaptchaImageAnswerResponse> >(conf.GetCaptchaAnswerUrl, req);

                            if (DataResults.IsOK(dr) && dr.Data?.answer?.Length > 0)
                            {
                                img.Answer = dr.Data.answer;

                                taskContext.PutAnswer(img.Uuid, dr.Data.answer);
                                taskContext.RemoveAwaitImage(img.Uuid);

                                logger.InfoFormat("GET task#{0}'s answer is {1}", img.Uuid, dr.Data.answer);

                                // TODO:这段应该剥离出去
                                // TryInputAnswerAhead(img.Uuid, dr.Data.answer);
                                captchaInputCallbackFunc?.Invoke(img);
                            }
                        }
                        else
                        {
                            taskContext.RemoveAwaitImage(img.Uuid);
                            // captchaInputCallbackFunc?.Invoke(img);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error("LoopInquiryCaptchaAnswer error:", e);
                }
                finally
                {
                    KK.Sleep(30);
                }
            }

            logger.InfoFormat("END LoopInquiryCaptchaAnswer.");
        }
示例#2
0
        public static void HandleInput(SignalRClient signalRClient)
        {
            while (true)
            {
                var input  = Console.ReadLine();
                var output = "";

                if (String.IsNullOrEmpty(input))
                {
                    output = signalRClient.Connection.State.ToString();
                }

                if (input.ToLower().StartsWith("addtogroup"))
                {
                    var param = input.GetParameter();
                    signalRClient.AddToSignalRGroup(param);
                }

                if (input.ToLower().StartsWith("createlobby"))
                {
                    //var param = input.GetParameter();
                    var lobbyId = HttpClients.Post();
                    if (!String.IsNullOrEmpty(lobbyId))
                    {
                        output = $"Created Lobby. Id: {lobbyId}";
                        signalRClient.AddToSignalRGroup(lobbyId);
                    }

                    else
                    {
                        output = "Failed To Create Lobby";
                    }
                }

                if (input.ToLower().StartsWith("signalrcreatelobby"))
                {
                    //var param = input.GetParameter();
                    signalRClient.CreateLobby();
                    //if (!String.IsNullOrEmpty(lobbyId))
                    //{
                    //    output = $"Created Lobby. Id: {lobbyId}";
                    //    signalRClient.AddToSignalRGroup(lobbyId);
                    //}

                    //else output = "Failed To Create Lobby";
                }

                if (input.ToLower().StartsWith("signalrdeletelobby"))
                {
                    var param = input.GetParameter();

                    //if (!String.IsNullOrEmpty(lobbyId))
                    //{
                    //    output = $"Created Lobby. Id: {lobbyId}";
                    signalRClient.DeleteLobby(new Guid(param));
                    //}

                    //else output = "Failed To Create Lobby";
                }

                if (input.ToLower().StartsWith("deletelobby"))
                {
                    var param   = input.GetParameter();
                    var success = HttpClients.Delete(new Guid(param));
                    if (success)
                    {
                        output = "Successfully Deleted Lobby";
                    }
                    else
                    {
                        output = "Failed to Delete Lobby";
                    }
                }

                Console.WriteLine(output);
            }
        }
示例#3
0
        public void Setup()
        {
            var httpClient = HttpClients.NewHttpClient(_testPath + TestingConfig.scotchCassettePath, TestingConfig.scotchMode);

            _interfax = new FaxClient(TestingConfig.username, TestingConfig.password, httpClient);
        }