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); }
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); }
private CaptchaAnswerImage CaptureCaptchaImage() { DateTime dt = DateTime.Now; var uuid = KK.uuid(); // 1. 验证码 - 提示语 CoordRectangle rect1 = CoordRectangle.From(actionManager.AddDelta(442, 338), 380, 53); var img01Path = KK.CapturesDir() + "\\" + uuid + "-" + dt.ToString("HHmmss") + "-p21.jpg"; actionManager.CaptureImage(rect1, img01Path); // 2. 验证码 - 图形区域 CoordRectangle rect2 = CoordRectangle.From(actionManager.AddDelta(445, 390), 230, 90); var img02Path = KK.CapturesDir() + "\\" + uuid + "-" + dt.ToString("HHmmss") + "-p22.jpg"; actionManager.CaptureImage(rect2, img02Path); CaptchaAnswerImage img = new CaptchaAnswerImage(); img.Uuid = uuid; img.CaptureTime = dt; img.ImagePath1 = img01Path; img.ImagePath2 = img02Path; return(img); }
/// <summary> /// 出价 - /// 1. 输入价格 - 移动到输入框位置,点击,清空历史数据,输入新价格 /// 2. 点击出价按钮 - 移动到按钮位置,点击 /// 3. 对验证码区域截图 且 上传 /// </summary> public void OfferPrice(int targetPrice, bool enableCancelFirst, Func <CaptchaAnswerImage, bool> callbackFunc = null) { // 0. 出价前,先尝试取消,防止上一步的可能的遮罩 if (enableCancelFirst) { // this.CancelOfferedPrice(); actionManager.ClickButtonByFenceWayRToL(actionManager.AddDelta(742, 502)); } // 1. 输入价格 且 出价 // TODO: 坐标方法 - 应该抽取出来单独管理 actionManager.InputTextAtPoint(actionManager.AddDelta(676, 417), targetPrice.ToString(), true, "第二阶段出价"); actionManager.ClickButtonAtPoint(actionManager.AddDelta(800, 415), true, "第二阶段出价"); // 2. 对验证码区域截屏且上传 // 这里尝试异步 ThreadUtils.StartNewTaskSafe(() => { // 这里等待会阻塞进程 KK.Sleep(390); CaptchaAnswerImage img = CaptureCaptchaImage(); UploadCaptchaImage(img); callbackFunc?.Invoke(img); } ); // return img; }
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"); }
public MainWindow() { InitializeComponent(); _kkPage = new KK(); _airfoilPage = new AIRFOIL(); _obPage = new OB(); }
/// <summary> /// Gets the Display of a Content /// </summary> /// <param name="content"></param> /// <returns></returns> public ActionResult Display(KK.Models.Content content) { content.IsAdmin = Request.IsAuthenticated && User.IsInRole("admin") ? true : false; // KK.Models.Content content = KK.Models.Content.Get(contentController, contentAction, contentTitle); return PartialView(content); }
/// <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); }
private CaptchaAnswerImage CaptureCaptchaImage() { DateTime dt = DateTime.Now; var uuid = KK.uuid(); // 1. 验证码 - 提示语 CoordRectangle rect1 = CoordRectangle.From(actionManager.AddDelta(442, 338), 380, 53); var img01Path = string.Format("{0}\\{1}-{2:HHmmss}-p21.jpg", KK.CapturesDir(), uuid, dt); actionManager.CaptureImage(rect1, img01Path); // 2. 验证码 - 图形区域 CoordRectangle rect2 = CoordRectangle.From(actionManager.AddDelta(445, 390), 230, 90); var img02Path = string.Format("{0}\\{1}-{2:HHmmss}-p22.jpg", KK.CapturesDir(), uuid, dt); actionManager.CaptureImage(rect2, img02Path); CaptchaAnswerImage img = new CaptchaAnswerImage(); img.Uuid = uuid; img.CaptureTime = dt; img.ImagePath1 = img01Path; img.ImagePath2 = img02Path; return(img); }
private void WatchSocketClient() { KK.Sleep(3 * 1000); while (watching) { KK.Sleep(DETECT_INTERVAL_MILLS); if (IsCurrentInDisabledTimeRange()) { continue; } try { if (notifyRestarting) { logger.InfoFormat("already tell socket client to reconnect"); continue; } bool connected = socketClient.IsConnected(); // 如果已未连接,则通知重新连接 if (!connected) { TellToReconnect("already disconnected"); continue; } RawMessage msg = MessageUtils.BuildPingMessage(ClientService.AssignedClientNo); socketClient.Send(msg); continuousDisconnectedCount = 0; counter.IncrementPing(); long pingCnt = counter.GetPingCount(); long pongCnt = counter.GetPongCount(); DateTime dt = DateTime.Now; if (dt.Minute > 57 && dt.Second % 8 == 0) { logger.InfoFormat("dice socket connected#{0}, ping#{1}, pong#{2}", connected, pingCnt, pongCnt); } // 如果ping和pong相差超过三次,则通知重新连接 long delta = pingCnt - pongCnt; if (delta > 3) { TellToReconnect("already over " + delta + " no pong response from server"); } } catch (Exception e) { logger.Error("WatchSocketClient error", e); } finally { } } }
public string GetClientSeatNo() { if (_seatNo == null) { _seatNo = KK.ReadClientSeatNo(); } return(_seatNo); }
// 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); }
private void InputLoginAccount() { BidAccountInfo acc = KK.LoadResourceAccount(); if (acc == null) { return; } loginActManager.LoginBidAccount(acc.BidNo, acc.Password, acc.IdCardNo, conf.LoginAccountAfterAutoInput); }
public static void TryStopThreadByWait(Thread th, int mills1, int mills2, string memo) { if (th != null) { KK.Sleep(mills1); ThreadUtils.TryStopThread(th); KK.Sleep(mills2); logger.InfoFormat("NOW {0}#State is {1}", memo, th.ThreadState); } }
/// <summary> /// 提交已出的价格 /// </summary> public void SubmitOfferedPrice() { actionManager.ClickButtonByFenceWayLToR(actionManager.AddDelta(553, 500)); // TODO: 等待, 点击完成验证码确认按钮, 会弹出 出价有效 // TODO: 应该检测 区域 是否有 出价有效 KK.Sleep(600); actionManager.ClickButtonAtPoint(actionManager.AddDelta(661, 478), false, "第一阶段提交#确定"); // 清除以前输入的价格 actionManager.CleanTextAtPoint(actionManager.AddDelta(676, 417), 6, true, "第一阶段提交"); }
// 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); } }
// 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); } }
public void ClickLoginButton() { // 可能有身份证输入框 var d2 = new CoordPoint(642, 473); actionManager.ClickBtnOnceAtPoint(d2, "投标竞拍T2"); KK.Sleep(200); // 没有身份证输入框 var d1 = new CoordPoint(642, 427); actionManager.ClickBtnOnceAtPoint(d1, "投标竞拍T1"); }
// 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); } }
// 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); } }
// 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); } }
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); }
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); }
// 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); } }
// private int SubmitOfferedPrice(int fixSec, PriceStrategyOperate oper, string answer, PagePrice pp, int offeredPrice, int usedDelayMills, DateTime occurTime) private int SubmitOfferedPrice(BiddingPriceRequest req) { bool submitted = false; string memo = ""; DateTime occurTime = DateTime.Now; if (req.OperateStatus == StrategyOperateStatus.CAPTCHA_INPUTTED) { if (req.ComputedDelayMills > 0) { KK.Sleep(req.ComputedDelayMills); } phase2Manager.SubmitOfferedPrice(); submitted = true; logger.InfoFormat("strategy#{0} exec submit", req.StrategySecond); } else { string answer = CaptchaTaskContext.me.GetAnswer(req.CaptchaUuid); if (answer == null || answer.Length == 0) { submitted = false; logger.ErrorFormat("strategy#{0} can not exec submit, because has no captcha-answer#{1}", req.StrategySecond, req.CaptchaUuid); return(-1); } else { if (req.ComputedDelayMills > 0) { KK.Sleep(req.ComputedDelayMills); } phase2Manager.SubmitOfferedPrice(answer); memo = "WiAns"; logger.WarnFormat("strategy#{0} exec submit and fill captcha-answer#{1}", req.StrategySecond, answer); } } if (submitted) { req.OperateStatus = StrategyOperateStatus.PRICE_SUBMITTED; biddingPriceManager.RemoveStrategy(req.StrategySecond); AsyncReportPriceSubbmitted(req, occurTime, memo); } return(0); }
private bool UseBack2PriceRule(PagePrice pp, BiddingPriceRequest req) { var sec = pp.pageTime.Second; var offeredPrice = req.TargetPrice; var PriceAt50 = biddingContext.GetPrice(50); int PriceBack2 = biddingContext.GetPrice(sec - 2); bool price50Matched = sec > 50 && PriceAt50 > 0 && offeredPrice >= (PriceAt50 + DrawbackDeltaPrice + 100); if (!price50Matched) { return(false); } bool priceBack2Matched = sec >= 54 && PriceBack2 > 0 && (pp.basePrice - PriceBack2) >= 200; if (!priceBack2Matched) { return(false); } bool matched = false; int delay = -1; DateTime occurTime = DateTime.Now; if (offeredPrice == (pp.basePrice + 300 + 100)) // 提前 100 { delay = KK.RandomInt(Delay1Start, Delay1End); matched = true; } else if (offeredPrice == (pp.basePrice + 300 + 200)) { delay = KK.RandomInt(Delay2Start, Delay2End); matched = true; } else if (offeredPrice == (pp.basePrice + 300 + 300)) { delay = KK.RandomInt(Delay3Start, Delay3End); matched = true; } if (matched) { req.CanSubmit = true; req.ComputedDelayMills = delay; req.SubmitMemo = "Back2 Rule"; } return(matched); }
public void StartClient() { logger.InfoFormat("begin start socket-client with address#{0}:{1}", ip, port); socketStarting = true; working = true; connectStatus = ConnectStatusEnum.CONNECTING; try { IPAddress ipAddr = IPAddress.Parse(ip); IPEndPoint remoteEP = new IPEndPoint(ipAddr, port); // Create a TCP/IP socket. _client = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. _client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), _client); while (connectStatus == ConnectStatusEnum.CONNECTING) { KK.Sleep(100); if (connectStatus == ConnectStatusEnum.CONNECT_FAILED) { break; } } socketStarting = false; logger.InfoFormat("connectStatus is {0}", connectStatus); logger.InfoFormat("end socket-client connect with address#{0}:{1}, _client#{2}", ip, port, _client); this.InvokeAfterSuccessConnected(); } catch (Exception e) { logger.Error("StartClient error", e); } finally { socketStarting = false; } // 无论何种情况,都应开启守护 if (EnableSocketGuard) { KeepAliveManager.ME.RestartGuard(this); } }
public void SafeCheck(object state) { try { int dice = KK.RandomInt(54, 59); int minute = DateTime.Now.Minute; loggingChk = minute > dice; CheckState(state); } catch (Exception e) { logger.Error("Safe check error", e); } }
// 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*/; }
/// <summary> /// 提交已出的价格 /// </summary> public void SubmitOfferedPrice() { // TODO: 为了尽快的点击到确定按钮,提供3种模式 if (conf.IsConfirmModeNormal()) { actionManager.ClickButtonAtPoint(actionManager.AddDelta(554, 506), false, "第二阶段提交#1"); } else if (conf.IsConfirmModeMixed()) { actionManager.ClickButtonAtPoint(actionManager.AddDelta(554, 506), false, "第二阶段提交#1"); actionManager.ClickButtonByFenceWayLToR(actionManager.AddDelta(553, 500)); } else if (conf.IsConfirmModeFence()) { actionManager.ClickButtonByFenceWayLToR(actionManager.AddDelta(553, 500)); } else { actionManager.ClickButtonByFenceWayLToR(actionManager.AddDelta(553, 500)); } // TODO: 等待, 点击完成验证码确认按钮, 会弹出 出价有效 // TODO: 应该检测 区域 是否有 出价有效 KK.Sleep(600); // 尝试得到提交的结果截图, 0.6s 1.6s 2.6s ThreadUtils.StartNewBackgroudThread(() => { for (int i = 0; i < 3; i++) { try { string imgPath = actionManager.CaptureFlashScreen(); logger.InfoFormat("result of phase2-act is {0}", imgPath); KK.Sleep((i + 1) * 1000); } catch (Exception e) { logger.Error("act2 background CaptureFlashScreen error", e); } } }); actionManager.ClickButtonAtPoint(actionManager.AddDelta(661, 478), false, "第二阶段提交#确定"); // 清除以前输入的价格 actionManager.CleanTextAtPoint(actionManager.AddDelta(676, 417), 6, true, "第二阶段提交"); }
public string GetIP(string domain) { bool isIp = KK.IsIP(domain); logger.InfoFormat("domain#{0} IsIP = {1}", domain, isIp); if (isIp) { return(domain); } IPHostEntry hostEntry = Dns.GetHostEntry(domain); IPEndPoint ipEndPoint = new IPEndPoint(hostEntry.AddressList[0], 0); return(ipEndPoint.Address.ToString()); }