protected override JsonCommand DoExecute(string args)
        {
            string infoFilePath = "/data/logs/RadarClient/info.log";

            if (!FileUtils.IsFileExist(infoFilePath))
            {
                logger.ErrorFormat("log file#{0} do not exist", infoFilePath);
                return(null);
            }


            int    clientNo = ClientService.AssignedClientNo;
            string dt       = DateTime.Now.ToString("yyyy-MM-dd");

            string zippedLogFile = "/temp/" + dt + "-" + clientNo + "-" + KK.CurrentMills() + "-info.log.gz";

            ZipUtils.Compress(zippedLogFile, infoFilePath);

            // upload
            ScreenImageUploadResponse resp = bidActionManager.UploadFileToSaber(zippedLogFile, 10);

            // FileUtils.DeleteFile(zippedLogFile);
            logger.InfoFormat("delete file#{0}", zippedLogFile);

            return(null);
        }
Beispiel #2
0
        public CoordPoint SearchTextCoordXYInFlashScreen(int x1, int y1, int width, int height, string colorForamt, string target)
        {
            long   s1  = KK.CurrentMills();
            string ret = this.OcrEx(x1, y1, x1 + width, y1 + height, colorForamt, 0.8);

            logger.DebugFormat("Search {0} OCR 识别的内容是 {1}, {2}. elapsed {3}ms, ret is {4}.", width, x1, y1, KK.CurrentMills() - s1, ret);

            CoordPoint point = new CoordPoint();

            if (ret == null || ret.Length == 0)
            {
                return(point);
            }

            int idx = ret.IndexOf(target);

            if (idx < 0)
            {
                return(point);
            }

            string[] arr = ret.Split('|');
            int      len = arr[0].Length;

            string[] xy = arr[idx + 1].Split(',');
            // TODO: 目前必须在全屏下才能成功正确找到 确定按钮
            int x = int.Parse(xy[0]);
            int y = int.Parse(xy[1]);

            point.x = x;
            point.y = y;

            return(point);
        }
Beispiel #3
0
        private void LoopAwaitAnswer(string imageUuid)
        {
            logger.InfoFormat("Phase1 - begin LoopAwaitAnswer");

            while (isAwaitWork)
            {
                long ss = KK.CurrentMills();
                try
                {
                    var taskContext = CaptchaTaskContext.me;
                    var answer      = taskContext.GetAnswer(imageUuid);
                    if (answer?.Length > 0)
                    {
                        phase1Manager.SubmitOfferedPrice(answer);
                        break;
                    }
                }
                catch (Exception e)
                {
                    logger.Error("LoopInquiryCaptchaAnswer error:", e);
                }
                finally
                {
                    KK.Sleep(100);
                }
            }

            logger.InfoFormat("Phase1 - end LoopAwaitAnswer");
        }
Beispiel #4
0
        /// <summary>
        /// 如果 isAbsolute  != true,  在相对坐标(x, y)上点击一次
        /// 否则 在绝对坐标(x, y)上点击一次
        /// </summary>
        /// <param name="p12"></param>
        /// <param name="isAbsolute"></param>
        public void ClickBtnOnceAtPoint(CoordPoint p12, string memo = "", bool isAbsolute = false, int delayMills = 0, int clickCount = 1)
        {
            if (delayMills > 0)
            {
                KK.Sleep(delayMills);
            }

            long       t1 = KK.CurrentMills();
            CoordPoint po = p12;

            if (!isAbsolute)
            {
                po = Datum.AddDelta(p12.x, p12.y);
            }

            int ret = robot.MoveTo(po.x, po.y);

            robot.LeftClick();
            if (clickCount > 1)
            {
                robot.LeftClick();
            }

            logger.InfoFormat("点击按钮#{0} @ {1} with count#{2}, elapsed {3}.", memo, po.ToString(), clickCount, KK.CurrentMills() - t1);
        }
Beispiel #5
0
        //
        private void clickConfirmBidOkAtPhase1(CoordPoint p12)
        {
            long t1  = KK.CurrentMills();
            int  ret = robot.MoveTo(p12.x, p12.y);

            robot.LeftClick();
            logger.InfoFormat("第一阶段 尝试点击 - 出价结果 确认 按钮 - {0}, {1}, {2}", p12.x, p12.y, KK.CurrentMills() - t1);
        }
Beispiel #6
0
        //
        private void clickLoginAtLogin(CoordPoint p6)
        {
            long t1 = KK.CurrentMills();

            if (p6.x > 0 && p6.y > 0)
            {
                logger.InfoFormat("找到 - 参加投标竞买 按钮 - {0}, {1}", p6.x, p6.y);
                robot.MoveTo(p6.x + 10, p6.y + 2);
                robot.LeftClick();
                logger.InfoFormat("点击了 - 参加投标竞买 按钮 - {0}, {1}, {2}", p6.x, p6.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #7
0
        //
        private void inputCaptchAtPhase1(CoordPoint p13, string captcha)
        {
            long t1 = KK.CurrentMills();

            if (p13.x > 0 && p13.y > 0)
            {
                robot.MoveTo(p13.x, p13.y);
                robot.LeftClick();
                robot.KeyPressString(captcha);
                logger.InfoFormat("第一阶段 尝试输入 - 验证码 输入框 - {0}, {1}, {2}", p13.x, p13.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #8
0
        public void ClickButtonByFenceWayRToL(CoordPoint pot)
        {
            long t1 = KK.CurrentMills();

            // 按钮的位置 可能 会变化, 这里使用 栅栏模式多次点击
            foreach (var p in fenceEndPointsReverse)
            {
                robot.MoveTo(p.x, p.y);
                robot.LeftClick();
            }

            logger.InfoFormat("栅栏模式(从左到右) 点击 - 按钮 - {0}, elpased {1}.", pot.ToString(), KK.CurrentMills() - t1);
        }
Beispiel #9
0
        //
        private void inputPrice2AtPhase1(CoordPoint p12, int price)
        {
            long t1 = KK.CurrentMills();

            if (p12.x > 0 && p12.y > 0)
            {
                logger.InfoFormat("找到 - 再次输入价格 输入框 - {0}, {1}", p12.x, p12.y);
                robot.MoveTo(p12.x, p12.y);
                robot.LeftClick();
                robot.KeyPressString(price.ToString());
                logger.InfoFormat("第一阶段 输入 - 再次输入价格 输入框 - {0}, {1}, {2}", p12.x, p12.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #10
0
        //
        private void inputCaptchaAtLogin(CoordPoint p5, string captcha)
        {
            long t1 = KK.CurrentMills();

            if (p5.x > 0 && p5.y > 0)
            {
                logger.InfoFormat("找到 - 图像校验码 输入框 - {0}, {1}", p5.x, p5.y);
                robot.MoveTo(p5.x, p5.y);
                robot.LeftClick();
                robot.KeyPressString(captcha);
                logger.InfoFormat("输入了 - 图像校验码 输入框 - {0}, {1}, {2}", p5.x, p5.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #11
0
        //
        private void inputPasswordAtLogin(CoordPoint p4, string password)
        {
            long t1 = KK.CurrentMills();

            if (p4.x > 0 && p4.y > 0)
            {
                logger.InfoFormat("找到 - 密码输入框 - {0}, {1}", p4.x, p4.y);
                robot.MoveTo(p4.x, p4.y);
                robot.LeftClick();
                robot.KeyPressString(password);
                logger.InfoFormat("输入了 - 密码输入框 - {0}, {1}, {2}", p4.x, p4.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #12
0
        //
        private void inputBidNumberAtLogin(CoordPoint p3, string bidNumber)
        {
            long t1 = KK.CurrentMills();

            if (p3.x > 0 && p3.y > 0)
            {
                logger.InfoFormat("找到 - 投标号输入框 - {0}, {1}", p3.x, p3.y);
                robot.MoveTo(p3.x, p3.y);
                robot.LeftClick();
                robot.KeyPressString(bidNumber);
                logger.InfoFormat("输入了 - 投标号输入框 - {0}, {1}, {2}", p3.x, p3.y, KK.CurrentMills() - t1);
            }
        }
Beispiel #13
0
        public void ClickButtonAtPoint(CoordPoint p13, bool needMoreOnceClick, string memo)
        {
            long t1 = KK.CurrentMills();

            robot.MoveTo(p13.x, p13.y);
            robot.LeftClick();
            if (needMoreOnceClick)
            {
                robot.LeftClick();
            }

            logger.InfoFormat("{0}#点击按钮 @ {1} with more#{2}, elapsed {3}.", memo, p13.ToString(), needMoreOnceClick, KK.CurrentMills() - t1);
        }
Beispiel #14
0
        //
        private void ClickConfirmAtIndex(CoordPoint p1)
        {
            long t1 = KK.CurrentMills();

            if (p1.x > 0 && p1.y > 0)
            {
                logger.InfoFormat("找到 - 确认按钮 - {0}, {1}", p1.x, p1.y);
                robot.MoveTo(p1.x, p1.y);
                robot.LeftClick();
                logger.InfoFormat("点击了 - 确认按钮 - {0}, {1}, {2}", p1.x, p1.y, KK.CurrentMills() - t1);
            }
            //return 1;

            //return /*null*/;
        }
Beispiel #15
0
        //
        private void ClickAgreeAtIndex(CoordPoint p2)
        {
            long t1 = KK.CurrentMills();

            if (p2.x > 0 && p2.y > 0)
            {
                logger.InfoFormat("找到 - 我同意拍卖须知按钮 - {0}, {1}", p2.x, p2.y);
                robot.MoveTo(p2.x, p2.y);
                robot.LeftClick();
                robot.LeftClick();
                logger.InfoFormat("点击了 - 我同意拍卖须知按钮 - {0}, {1}, {2}", p2.x, p2.y, KK.CurrentMills() - t1);
            }
            //return Task.Factory.StartNew(() => {

            //    return 1;
            //});
        }
Beispiel #16
0
        private void UploadCaptchaImage(CaptchaAnswerImage img)
        {
            string url = conf.UploadCaptchaTaskUrl;
            CaptchaImageUploadRequest req = new CaptchaImageUploadRequest();

            req.token     = "devJustTest";
            req.uid       = img.Uuid;
            req.timestamp = KK.CurrentMills();
            req.from      = "test";

            int httpStatus;
            DataResult <CaptchaImageUploadResponse> dr = HttpClients
                                                         .PostWithFiles <DataResult <CaptchaImageUploadResponse> >(url, req, new List <string> {
                img.ImagePath1, img.ImagePath2
            }, out httpStatus);

            logger.InfoFormat("upload catpcha task#{0}, result is {1}", img.Uuid, Jsons.ToJson(dr));
        }
Beispiel #17
0
        public static RawMessage From(int messageType, int clientNo, string body)
        {
            RawMessage msg = new RawMessage();

            int bLen = body.Length;
            int tLen = 4 + 4 + 8 + 4 + 4 + 4 + bLen;

            msg.setTotalLength(tLen);
            msg.setMagic(ByteUtils.MAGIC_NUMBER);
            msg.setOccurMills(KK.CurrentMills());

            msg.setClientNo(clientNo);
            msg.setMessageType(messageType);
            msg.setBodyLength(bLen);

            msg.setBodyText(body);

            return(msg);
        }
Beispiel #18
0
        public void InputTextAtPoint(CoordPoint p13, string text, bool needClearFirst, string memo)
        {
            long t1 = KK.CurrentMills();

            robot.MoveTo(p13.x, p13.y);
            robot.LeftClick();

            // 先清空已输入的验证码
            if (needClearFirst)
            {
                for (int i = 0; i < text.Length; i++)
                {
                    robot.PressBackspacKey();
                    robot.PressDeleteKey();
                }
            }

            robot.KeyPressString(text);
            logger.InfoFormat("{0}#输入: {1} @ {2}, Elapsed {3}.", memo, text, p13.ToString(), KK.CurrentMills() - t1);
        }
Beispiel #19
0
        public void CleanTextAtPoint(CoordPoint p13, int textLength, bool needMoveTo, string memo)
        {
            long s1 = KK.CurrentMills();

            if (needMoveTo)
            {
                robot.MoveTo(p13.x, p13.y);
                robot.LeftClick();
            }

            for (int i = 0; i < textLength; i++)
            {
                robot.PressBackspacKey();
                robot.PressDeleteKey();
            }

            if (memo?.Length > 0)
            {
                logger.InfoFormat("{0}#删除文本: {1} @ {2}, elapsed {3}ms", memo, textLength, p13, KK.CurrentMills() - s1);
            }
        }
Beispiel #20
0
        public ScreenImageUploadResponse UploadFileToSaber(string filePath, int uploadType = 0)
        {
            string url = conf.UploadRobotScreenUrl;
            CaptchaImageUploadRequest req = new CaptchaImageUploadRequest();

            req.machineCode = robot.GetMachineCode();
            req.token       = "devJustTest";
            req.uid         = KK.GetFileNameNoSuffix(filePath);
            req.timestamp   = KK.CurrentMills();
            req.from        = "test";
            req.uploadType  = uploadType;

            int httpStatus;
            DataResult <ScreenImageUploadResponse> dr = HttpClients
                                                        .PostWithFiles <DataResult <ScreenImageUploadResponse> >(url, req, new List <string> {
                filePath
            }, out httpStatus);

            logger.InfoFormat("upload file#{0}, result is {1}", req.uid, Jsons.ToJson(dr));

            return(DataResults.IsOK(dr) ? dr.Data : null);
        }
Beispiel #21
0
        private void DetectAndSetDatum()
        {
            long t1 = KK.CurrentMills();
            // 尝试使用 相对位置 - 上海市个人非营业性客车额度投标拍卖
            // 个人非营业性客车
            // 您使用的是
            // var checkPoint = this.searchTextCoordXYInScreen("2e6e9e-2e6e9e", "用的是");

            var checkPoint = robot.searchTextCoordXYInScreen("0074bf-101010|9c4800-101010|ffdf9c-101010|df9c48-101010|489cdf-101010|000000-101010|9cdfff-101010|00489c-101010", "用的是");

            //
            logger.InfoFormat("检查点坐标是 - {0}. {1}", checkPoint.ToString(), KK.CurrentMills() - t1);

            // 204, 287
            var bench = checkPoint.AddDelta(-206, -286);

            // 719, 364 - = 513,78 , (510, 78)
            logger.InfoFormat("基准点坐标是 - {0}", bench.ToString());

            // 900 x 700
            // int w = 900;
            // int h = 700;

            if (bench.x <= 0 || bench.y <= 0)
            {
                var re = GetScreenResolution();
                logger.InfoFormat("降级使用 - 屏幕分辨率 - {0}", re.ToString());

                //bench.y = 79;
                // 支持win7
                // 支持2008 R2
                // 支持的屏幕分辨率
                // 1280 * 800 基准点 297 * 22
                // 1366 * 768 基准点 344 * 19
                if (re.x > 1900)
                {
                    // 不会有 scroll
                    // bench.x = (re.x - w) / 2;
                    bench.x = 672;
                    bench.y = 23;
                }
                // 1366
                else if (re.x > 1340 && re.x < 1390)
                {
                    // bench.x = (re.x - w - 15) / 2;
                    bench.x = 344;
                    bench.y = 19;
                }
                // 1280
                else if (re.x > 1260 && re.x < 1299)
                {
                    bench.x = 297;
                    bench.y = 22;
                }
                else
                {
                    // guess
                    bench.x = (int)(re.x * 0.232);
                    bench.y = 22;
                }

                // 内嵌模式
                // 682 x 23
                // bench.x = 682;
                // bench.y = 23;

                logger.InfoFormat("降级使用 - 新的基准点坐标是 - {0}", bench.ToString());
            }

            _datum = bench;
        }
Beispiel #22
0
        public PageTimePriceResult DetectPriceAndTimeInScreen(PageTimePriceResult LastResult)
        {
            long   t1   = KK.CurrentMills();
            string uuid = KK.uuid();

            if (this.coordOfCurrentTime == null || coordOfCurrentTime.x <= 0 || coordOfCurrentTime.y <= 0)
            {
                return(PageTimePriceResult.ErrorCoordTime());
            }

            var p = this.coordOfCurrentTime;

            // 11:29:57
            int x1 = p.x + 20, y1 = p.y, x2 = p.x + 20 + 150, y2 = p.y + 18;

            long s1 = KK.CurrentMills();

            robot.UseDict(DictIndex.INDEX_NUMBER);
            string ret1 = robot.Ocr(x1, y1, x2, y2, "ff0000-000000", 0.8);

            // string ret1 = robot.Ocr(x1, y1, x2, y2, "0066cc-101010", 0.8);
            logger.DebugFormat("目前时间 - OCR内容 {0}, {1}, {2}, {3}. elapsed {4}ms, {5}, {6}", x1, y1, x2, y2, KK.CurrentMills() - s1, ret1, uuid);


            if (ret1 == null || ret1.Length == 0 || ret1.Length < 6)
            {
                return(PageTimePriceResult.ErrorTime());
            }

            DateTime no = DateTime.Now;

            string td = KK.ExtractDigits(ret1);

            if (td == null || td.Length != 6)
            {
                return(PageTimePriceResult.ErrorTime());
            }

            logger.DebugFormat("Parsed time is {0}.", td);

            DateTime dt = new DateTime(no.Year, no.Month, no.Day, int.Parse(td.Substring(0, 2)), int.Parse(td.Substring(2, 2)), int.Parse(td.Substring(4, 2)));

            // 检测是否已经拿到过该秒的数据,则可以忽略不检测价格了
            if (LastResult?.data != null && dt == LastResult.data.pageTime)
            {
                return(PageTimePriceResult.RepeatedTime());
            }

            // 找到坐标 of 价格区间
            if (this.coordOfPriceSection == null || coordOfPriceSection.x <= 0 || coordOfPriceSection.y <= 0)
            {
                return(PageTimePriceResult.ErrorCoordPrice());
            }

            var p2 = this.coordOfPriceSection;

            logger.DebugFormat("价格区间 - 坐标是 - {0}. {1}", p2.ToString(), KK.CurrentMills() - t1);

            // 11:29:57
            int x21 = p2.x + 20, y21 = p2.y, x22 = p2.x + 20 + 250, y22 = p2.y + 18;

            // ff0000-101010
            s1 = KK.CurrentMills();
            robot.UseDict(DictIndex.INDEX_NUMBER);
            string ret2 = robot.Ocr(x21, y21, x22, y22, "ff0000-000000", 0.8);

            if (dt.Minute > 26)
            {
                logger.InfoFormat("价格区间 - OCR内容, {0} @ {1}, elapsed {2}ms", ret2, dt, KK.CurrentMills() - s1);
            }
            else
            {
                logger.DebugFormat("价格区间 - OCR内容, {0} @ {1}, elapsed {2}ms", ret2, dt, KK.CurrentMills() - s1);
            }


            if (ret2 == null || ret2.Length == 0 || ret2.Length < 10)
            {
                return(PageTimePriceResult.ErrorPrice());
            }

            string numberStr = KK.ExtractDigits(ret2);

            if (numberStr.Length < 10)
            {
                logger.WarnFormat("识别到 错误的 价格 - {0}. 数字的位数不对.", numberStr);
                return(PageTimePriceResult.ErrorPrice());
            }

            int[] arr2      = ParsePrice(numberStr);
            int   priceLow  = arr2[0];
            int   priceHigh = arr2[1];

            if (priceHigh < 70000 || priceHigh < 70000 || priceHigh > 200000 || priceLow > 200000)
            {
                logger.WarnFormat("识别到 错误的 价格 - {0}, {1}.", priceLow, priceHigh);
                return(PageTimePriceResult.ErrorPrice());
            }

            int basePrice = (priceLow + priceHigh) / 2;

            if (dt.Minute > 25)
            {
                logger.InfoFormat("parsed price - base#{0}, low#{1}, high#{2}", basePrice, priceLow, priceHigh);
            }
            else
            {
                logger.DebugFormat("parsed price - base#{0}, low#{1}, high#{2}", basePrice, priceLow, priceHigh);
            }

            var pp = new PagePrice(dt, basePrice);

            pp.low  = priceLow;
            pp.high = priceHigh;

            return(PageTimePriceResult.Ok(pp));
        }
        private void InitContainer()
        {
            long s1 = KK.CurrentMills();

            var builder = new ContainerBuilder();

            // 为加快加载速度 - 过滤出本项目的Assembly

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            logger.DebugFormat("assemblies length is {0}", assemblies?.Length);

            Assembly[] projAsses = assemblies.Where(a => a.FullName.StartsWith("Radar")).ToArray <Assembly>();

            foreach (Assembly asse in projAsses)
            {
                logger.InfoFormat("Assembly FullName is {0}", asse.FullName);
            }

            var componentClasses = new List <Type>();

            builder.RegisterAssemblyTypes(projAsses)
            .Where(t => {
                var arr = t.GetCustomAttributes(typeof(ComponentAttribute), false);
                var ret = arr != null && arr.Length > 0;

                if (ret)
                {
                    componentClasses.Add(t);
                }
                return(ret);
            })
            .AsSelf()
            .SingleInstance()
            .OnActivated(e => {
                // 这里的功能类似 IStartable
                object inst = e.Instance;
                if (typeof(InitializingBean).IsAssignableFrom(inst.GetType()))
                {
                    try
                    {
                        ((InitializingBean)inst).AfterPropertiesSet();
                    } catch (Exception ex)
                    {
                        logger.Error(string.Format("call AfterPropertiesSet for class#{0} error", inst), ex);
                        throw ex;
                    }
                }
            })
            ;


            Container = builder.Build();

            logger.InfoFormat("init IoC Container done. Components count#{0}. version is {1}. elasped {2}ms.", componentClasses.Count, Ver.ver, KK.CurrentMills() - s1);

            // 初始化 InitializingBean
            foreach (var t in componentClasses)
            {
                if (typeof(InitializingBean).IsAssignableFrom(t))
                {
                    Container.Resolve(t);
                }
            }
        }
        /// <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.");
        }
Beispiel #25
0
        public void AfterSuccessDetect(PagePrice pp)
        {
            if (!isLegalMinte(pp.pageTime))
            {
                return;
            }

            // 如果该秒已经计算过
            if (!biddingContext.TryStartPagePrice(pp))
            {
                return;
            }

            long s1 = KK.CurrentMills();

            DateTime now = DateTime.Now;

            biddingContext.AddPrice(pp);

            var req = biddingPriceManager.Calcs(pp);

            if (req == null)
            {
                logger.InfoFormat("afterDetect elapsed {0}ms", KK.CurrentMills() - s1);
                return;
            }

            logger.InfoFormat("req is {0}", Jsons.ToJson(req));

            // 这里存在,正在输入价格或上传验证码时,会有来自价格同步的触发,存在并发场景
            // 所以先用了同步锁
            lock (logger)
            {
                if (req.OperateStatus == StrategyOperateStatus.NEED_OFFER_PRICE)
                {
                    // 出价前 检查 距离上次 出价时间 是否在 6秒 内
                    // 如果在6秒内,则不能出价了,因为会报 操作频繁
                    List <BiddingPriceRequest> unSubmited = biddingPriceManager.GetPreviousUnSubmitRequest(pp.pageTime.Second);
                    bool canOffer = true;
                    if (unSubmited?.Count > 0)
                    {
                        var last     = unSubmited.Last();
                        int duration = (int)(pp.pageTime - last.OfferedScreenTime).TotalSeconds;
                        if (duration < 6)
                        {
                            canOffer = false;
                        }
                        logger.InfoFormat("unSubmited between now duration is {0}, canOffer is {1}", duration, canOffer);
                    }

                    // 然后直接出价
                    if (canOffer)
                    {
                        // CaptchaAnswerImage ansImg =
                        phase2Manager.OfferPrice(req.TargetPrice, true, (ansImg) => {
                            biddingContext.PutAwaitImage(ansImg, null);
                            req.CaptchaUuid = ansImg.Uuid;
                            return(true);
                        });

                        req.OperateStatus = StrategyOperateStatus.CAPTCHA_AWAIT;

                        biddingPriceManager.CancelnOutOfDateRequest(req.StrategySecond);

                        //
                        AsyncReportPriceOffered(pp, req.TargetPrice, DateTime.Now);
                    }
                    else
                    {
                        // 不能出价时,则取消该策略 TODO: 不能依赖 canOffer 做移除
                        logger.InfoFormat("strategy#{0} canOffer is false, need remove", req.StrategySecond);
                        biddingPriceManager.RemoveStrategy(req.StrategySecond);
                    }
                }
                else if (req.OperateStatus == StrategyOperateStatus.STRATEGY_RANGE_MATCHED)
                {
                    // 命中区间策略
                    // 移除该策略
                    logger.InfoFormat("range strategy#{0} matched, need remove", pp.pageTime.Second);
                    biddingPriceManager.RemoveStrategy(pp.pageTime.Second);
                }

                if (req.CanSubmit)
                {
                    req.SubmittedScreenTime  = pp.pageTime;
                    req.SubmittedScreenPrice = pp.basePrice;
                    SubmitOfferedPrice(req);
                }
            }

            logger.InfoFormat("afterDetect elapsed {0}ms", KK.CurrentMills() - s1);
        }
Beispiel #26
0
        private void LoopDetectPriceAndTimeInScreen()
        {
            logger.InfoFormat("begin loopDetectPriceAndTimeInScreen");
            int i = 0;

            PageTimePriceResult lastResultx = null;

            while (isCollectingWork)
            {
                long ss = KK.CurrentMills();

                try
                {
                    long s1 = KK.CurrentMills();
                    PageTimePriceResult lastResult = actionManager.DetectPriceAndTimeInScreen(lastResultx);

                    // 重复检测
                    if (lastResult.status == 300)
                    {
                        continue;
                    }

                    SetShowUpText(ToShowUpText(lastResult));

                    // 处理异常情况
                    if (lastResult.status != 0)
                    {
                        ProcessErrorDetect(lastResult);

                        // TODO: 这里也需要处理 可能需要的提交,因为远程会下发一个可能的当前秒数
                        // 目的是防止出现卡秒现象

                        continue;
                    }

                    lastResultx = lastResult;

                    PagePrice pp = lastResult.data;

                    logger.DebugFormat("detectPriceAndTimeInScreen elapsed {0}ms", KK.CurrentMills() - s1);

                    if (pp != null)
                    {
                        if (pp.pageTime.Minute == 28)
                        {
                            if (IsOneRoundStarted)
                            {
                                ResetContext();
                                IsOneRoundStarted = false;
                            }
                        }
                        else if (pp.pageTime.Minute == 29)
                        {
                            if (!IsOneRoundStarted)
                            {
                                IsOneRoundStarted = true;
                            }
                        }

                        s1 = KK.CurrentMills();
                        AfterSuccessDetectInner(pp);
                        logger.DebugFormat("afterDetect elapsed {0}ms", KK.CurrentMills() - s1);
                    }
                    else
                    {
                        // TODO:
                    }
                }
                catch (Exception e)
                {
                    logger.Error("detect price and time error", e);
                }
                finally
                {
                    // TODO: 这里可能不需要每次重置dict
                    // actionManager.ResetDictIndex();

                    KK.Sleep(12);
                }

                logger.DebugFormat("round {0} loopDetectPriceAndTimeInScreen elapsed {1}ms", i++, KK.CurrentMills() - ss);
            }

            logger.InfoFormat("END loopDetectPriceAndTimeInScreen ");
        }