Ejemplo n.º 1
0
        public string GetBuyerNameFromTaskWindow()
        {
            string buyerName = "";

            if (!CanGetTaskWindow())
            {
                return(buyerName);
            }

            List <int> taskWinHwnds;
            int        taskHwnd = TryGetTaskWindow(out taskWinHwnds);

            if (taskHwnd > 0)
            {
                buyerName = GetBuyerNameFromTaskWindow(taskHwnd);
                WinApi.CloseWindow(taskHwnd, 2000);
                _desk.DelayFocusEditor(200);
            }
            if (buyerName != null)
            {
                buyerName = buyerName.Trim();
                string endStr = "(阿里巴巴中国站)";
                if (buyerName.EndsWith(endStr))
                {
                    buyerName = buyerName.Substring(0, buyerName.Length - endStr.Length);
                }
            }
            return(buyerName);
        }
Ejemplo n.º 2
0
        public static bool Inject(ChatDesk desk, string url, Func <bool> isConnectOk)
        {
            bool rt = false;

            try
            {
                Log.Info("ocr s2," + desk.Seller);
                var injectJs      = GetInjectJs(url, desk.Seller);
                int chromeDevHwnd = GetExistChromeDevTools(desk);
                Util.Assert(chromeDevHwnd != 0);
                DoInject(injectJs, chromeDevHwnd, desk, isConnectOk);
                if (HideChromeDebugWindow)
                {
                    WinApi.CloseWindow(chromeDevHwnd, 2000);
                }
                Thread.Sleep(100);
                if (isConnectOk())
                {
                    ContinuousFailCount = 0;
                    rt = true;
                }
                else
                {
                    ContinuousFailCount++;
                }
            }
            catch (Exception ex)
            {
                Log.Error("ocr," + ex.Message);
                ContinuousFailCount++;
            }
            return(rt);
        }
Ejemplo n.º 3
0
        public void Close()
        {
            WinApi.CloseWindow(Handle);
            if (Handle != IntPtr.Zero)
            {
                WinApi.DestroyWindow(new HandleRef(this, Handle));
            }

            if (_registeredClass)
            {
                _registeredClass = false;
                WinApi.UnregisterClass(_windowClass.lpszClassName, new HandleRef(this, WinApi.GetModuleHandle(null)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 复制文本到搜索框中
        /// </summary>
        private void SeachTarget()
        {
            //往搜索框中写入文本
            SendKeys.SendWait("文件传输助手");
            //暂停2秒
            Thread.Sleep(2000);

            Point curPos = new Point(endPosition.X + 20, endPosition.Y + 60);

            WinApi.SetCursorPos(curPos.X, curPos.Y);
            //鼠标点击
            WinApi.mouse_event(WinApi.MouseEventFlag.LeftDown | WinApi.MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);

            Thread.Sleep(1000);
            //按下鼠标左键
            WinApi.mouse_event(WinApi.MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);

            Thread.Sleep(500);
            //移动鼠标
            WinApi.mouse_event(WinApi.MouseEventFlag.Move, curPos.X, curPos.Y - 100, 0, UIntPtr.Zero);

            //松开鼠标
            Thread.Sleep(500);
            WinApi.mouse_event(WinApi.MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
            Thread.Sleep(2000);

            IntPtr childForm = WinApi.GetWeChatWindowEx();

            if (childForm == IntPtr.Zero)
            {
                MessageBox.Show("获取微信窗口句柄失败", "提示");
                return;
            }
            //RECT rc = new RECT();
            //WinApi.GetWindowRect(childForm, ref rc);

            //往聊天窗口中写入文本
            SendKeys.SendWait(DateTime.Now.ToLocalTime().ToString());

            WinApi.keybd_event(Keys.Enter, 0, 0, 0);
            Thread.Sleep(2000);
            //这个流程结束后,关闭当前窗口
            WinApi.CloseWindow(childForm);
            Thread.Sleep(2000);
            for (int i = 0; i < c; i++)
            {
                StartSimulateWeChat();
                c--;
            }
        }
Ejemplo n.º 5
0
 private void CloseInfoWindow(int targeth)
 {
     try
     {
         WinApi.CloseWindow(targeth, 2000);
         if (!WinApi.IsHwndAlive(targeth))
         {
             _openedHwnd.xTryRemove(targeth);
         }
     }
     catch (Exception e)
     {
         Log.Exception(e);
     }
 }
Ejemplo n.º 6
0
        public string GetBuyerNameFromBuyerInfoWindow()
        {
            string buyerName = "";

            if (!CanGetTaskWindow())
            {
                return(buyerName);
            }

            int buyerInfoHwnd = TryGetBuyerInfoWindow();

            if (buyerInfoHwnd > 0)
            {
                WinApi.HideDeskWindow(buyerInfoHwnd);
                buyerName = GetBuyerNameFromBuyerInfoWindow(buyerInfoHwnd);
                WinApi.CloseWindow(buyerInfoHwnd);
                _desk.DelayFocusEditor();
            }
            if (buyerName != null)
            {
                buyerName = buyerName.Trim();
                string endStr = "(阿里巴巴中国站)";
                if (buyerName.EndsWith(endStr))
                {
                    buyerName = buyerName.Substring(0, buyerName.Length - endStr.Length);
                }
            }
            if (string.IsNullOrEmpty(buyerName))
            {
                _getTaskWindowFailCount++;
                if (_latestFailTime.xElapse().TotalMinutes < 3.0)
                {
                    _continuousFailCount++;
                }
                else
                {
                    _latestFailTime      = DateTime.Now;
                    _continuousFailCount = 1;
                }
            }
            else
            {
                _getTaskWindowSuccessOnce = true;
                _getTaskWindowFailCount   = 0;
            }
            return(buyerName);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 开始模拟鼠标操作桌面微信,(微信聊天列表不能有置顶聊天)
        /// </summary>
        public void StartSimulateWeChat()
        {
            IntPtr awin = WinApi.GetWeChatWindow();

            if (awin == IntPtr.Zero)
            {
                MessageBox.Show("获取微信主窗口句柄失败", "提示");
                return;
            }
            WinApi.CloseWindow(awin);
            WinApi.ShowWindow(awin, WinApi.NCmdShowFlag.SW_SHOWNORMAL);//在显示
            RECT rc = new RECT();

            WinApi.GetWindowRect(awin, ref rc);
            endPosition.X = rc.Left;
            endPosition.Y = rc.Top;
            if (true)
            {
                //应该打开窗口有延迟,所以需要定时去操作
                ////暂停2秒
                Thread.Sleep(2000);
                moveMouseToWeChatSeachBox(endPosition);
            }
        }
Ejemplo n.º 8
0
        public async void WowBotLooping(int sessionId)
        {
            ProcessInfo currentInfo = Infos[sessionId];

            if (!currentInfo.State.Equals(ProcessStates.PreloadStringSending))
            {
                return;
            }

            await Logic.ExecuteAsync(async logic => logic.logs.Log(sessionId, "Wow bot Looping is enabled"));

            await currentInfo.SetState(ProcessStates.Running, 50);

            LocksManager.getInstance().Lock(LocksManager.WowClientLooping, sessionId);

            currentInfo.isRunning = true;

            string   profilePath        = null;
            bool     usingTrial         = true;
            bool     avoidServerRestart = true;
            DateTime serverRestartTime  = DateTime.Today;

            Logic.Execute(logic =>
            {
                profilePath        = logic.settings.appSettings.profilesSettings[sessionId].profilePath;
                usingTrial         = logic.settings.appSettings.generalSettings.usingTrial;
                avoidServerRestart = logic.settings.appSettings.profilesSettings[sessionId].avoidServerRestart;
                serverRestartTime  = logic.settings.appSettings.profilesSettings[sessionId].serverRestartTime;
            }, true);

            serverRestartTime = serverRestartTime.AddMinutes(-10);

            while (currentInfo.isRunning)
            {
                while (LocksManager.getInstance().CheckLock(LocksManager.OpeningBimsbot))
                {
                    await Task.Delay(1000);

                    if (CheckInterruptingLock(LocksManager.InterruptingRunning, sessionId))
                    {
                        await Logic.ExecuteAsync(async logic => logic.logs.Log(sessionId, string.Format("Launch aborted ({0})", currentInfo.State.description)));

                        currentInfo.isRunning = false;

                        currentInfo.CloseWowProcess();

                        LocksManager.getInstance().Unlock(LocksManager.WowClientLooping, sessionId);
                        await CallToStopProcess(sessionId);

                        return;
                    }
                }

                LocksManager.getInstance().Lock(LocksManager.OpeningBimsbot);

                Infos[sessionId].BimsbotProcess = Process.Start(profilePath);

                await Task.Delay(5000);

                if (usingTrial)
                {
                    WinApi.CloseWindow(currentInfo.BimsbotProcess.MainWindowHandle);
                }

                await Task.Delay(5000);

                if (Infos.Where(info => info.WowProcess != null).Count() > 1)
                {
                    List <string> pids    = WinApi.GetPidsList();
                    int           ourLine = -1;

                    for (int i = 0; i < pids.Count(); i++)
                    {
                        if (pids[i].Contains(Infos[sessionId].WowProcess.Id.ToString()))
                        {
                            ourLine = i;
                        }
                    }

                    await WinApi.SelectLineInPidsList(ourLine);
                }

                await Task.Delay(7000);

                currentInfo.BimsbotHandler = 0;
                while (currentInfo.BimsbotHandler == 0)
                {
                    try
                    {
                        currentInfo.BimsbotHandler = await WinApi.FindBotWindow(Infos.Where(info => info.BimsbotHandler > 0).Select(info => info.BimsbotHandler).ToList());
                    }
                    catch (Exception ex)
                    {
                        await Logic.ExecuteAsync(async logic => logic.logs.Log(sessionId, string.Format("Can't find handler. Waiting 3 sec... ({0})", ex.Message)));

                        await Task.Delay(3000);
                    }
                }


                LocksManager.getInstance().Unlock(LocksManager.OpeningBimsbot);

                await WinApi.StartBot(currentInfo.BimsbotHandler);

                Random random = new Random();
                int    delay  = random.Next(300000, 450000);
                for (int i = 0; i < delay / 1000; i++)
                {
                    await Task.Delay(1000);

                    //press bot stop
                    if (CheckInterruptingLock(LocksManager.InterruptingRunning, sessionId))
                    {
                        await Logic.ExecuteAsync(async logic => logic.logs.Log(sessionId, string.Format("Launch aborted ({0})", currentInfo.State.description)));

                        currentInfo.isRunning = false;

                        currentInfo.CloseBimsbotProcess();
                        currentInfo.CloseWowProcess();

                        LocksManager.getInstance().Unlock(LocksManager.WowClientLooping, sessionId);
                        await CallToStopProcess(sessionId);

                        return;
                    }

                    //wow doesnt started or disconnect                              //avoiding server restart
                    if ((!currentInfo.CharacterStatus && i > 30) || (avoidServerRestart && Math.Abs(DateTime.Now.Subtract(serverRestartTime).TotalMinutes) <= 1))
                    {
                        if ((avoidServerRestart && Math.Abs(DateTime.Now.Subtract(serverRestartTime).TotalMinutes) <= 1))
                        {
                            await Logic.ExecuteAsync(async logic => logic.logs.Log(sessionId, "Avoiding server restart"));
                        }

                        currentInfo.CloseBimsbotProcess();
                        currentInfo.CloseWowProcess();

                        LocksManager.getInstance().Unlock(LocksManager.WowClientLooping, sessionId);
                        await CallToStopProcess(sessionId);

                        if (avoidServerRestart && Math.Abs(DateTime.Now.Subtract(serverRestartTime).TotalMinutes) <= 1)
                        {
                            ReloadWowSessionTask(sessionId, 20 * 60 * 1000);
                        }
                        else
                        {
                            ReloadWowSessionTask(sessionId);
                        }

                        return;
                    }
                }

                currentInfo.CloseBimsbotProcess();
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> CheckIsClientOpened(int processId, int sessionId)
        {
            while (LocksManager.getInstance().CheckLock(LocksManager.OpeningWowClient))
            {
                await Task.Delay(1000);

                if (LocksManager.getInstance().CheckLock(LocksManager.InterruptingOpeningWowClient, sessionId))
                {
                    return(false);
                }
            }

            LocksManager.getInstance().Lock(LocksManager.OpeningWowClient);

            ProcessInfo currentInfo    = Infos[sessionId];
            string      profilePath    = null;
            bool        usingTrial     = true;
            bool        useLowSettings = true;
            string      wowPath        = null;

            Logic.Execute(logic =>
            {
                profilePath    = logic.settings.appSettings.profilesSettings[sessionId].profilePath;
                usingTrial     = logic.settings.appSettings.generalSettings.usingTrial;
                wowPath        = logic.settings.appSettings.profilesSettings[sessionId].wowPath;
                useLowSettings = logic.settings.appSettings.profilesSettings[sessionId].useWowLowSettings;
            }, true);


            Process additionalWowProcess      = null;
            bool    usingAdditionalWowProcess = false;

            if (Infos.Where(info => info.WowProcess != null).Count() <= 1)
            {
                if (useLowSettings)
                {
                    FileManager.getInstance().UpdateWowSettings(wowPath, sessionId);
                }

                usingAdditionalWowProcess = true;
                additionalWowProcess      = new Process();
                additionalWowProcess.StartInfo.FileName    = wowPath;
                additionalWowProcess.StartInfo.Arguments   = "-noautolaunch64bit";
                additionalWowProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
                additionalWowProcess.Start();

                for (int i = 0; i < 10; i++)
                {
                    await Task.Delay(1000);

                    if (LocksManager.getInstance().CheckLock(LocksManager.InterruptingOpeningWowClient, sessionId))
                    {
                        LocksManager.getInstance().Unlock(LocksManager.OpeningWowClient);
                        if (usingAdditionalWowProcess)
                        {
                            additionalWowProcess.Kill();
                            additionalWowProcess = null;


                            await Task.Delay(1000);

                            if (useLowSettings)
                            {
                                FileManager.getInstance().ReturnWowSettings(wowPath, sessionId);
                            }
                        }

                        return(false);
                    }
                }
            }

            while (LocksManager.getInstance().CheckLock(LocksManager.OpeningBimsbot))
            {
                await Task.Delay(1000);

                if (LocksManager.getInstance().CheckLock(LocksManager.InterruptingOpeningWowClient, sessionId))
                {
                    LocksManager.getInstance().Unlock(LocksManager.OpeningWowClient);
                    if (usingAdditionalWowProcess)
                    {
                        additionalWowProcess.Kill();
                        additionalWowProcess = null;


                        await Task.Delay(1000);

                        if (useLowSettings)
                        {
                            FileManager.getInstance().ReturnWowSettings(wowPath, sessionId);
                        }
                    }

                    return(false);
                }
            }

            LocksManager.getInstance().Lock(LocksManager.OpeningBimsbot);

            currentInfo.BimsbotProcess = Process.Start(profilePath);
            await Task.Delay(5000);

            if (LocksManager.getInstance().CheckLock(LocksManager.InterruptingOpeningWowClient, sessionId))
            {
                currentInfo.BimsbotProcess.Kill();
                LocksManager.getInstance().Unlock(LocksManager.OpeningWowClient);
                if (usingAdditionalWowProcess)
                {
                    additionalWowProcess.Kill();
                    additionalWowProcess = null;


                    await Task.Delay(1000);

                    if (useLowSettings)
                    {
                        FileManager.getInstance().ReturnWowSettings(wowPath, sessionId);
                    }
                }


                return(false);
            }

            if (usingTrial)
            {
                WinApi.CloseWindow(currentInfo.BimsbotProcess.MainWindowHandle);
            }

            await Task.Delay(5000);

            if (LocksManager.getInstance().CheckLock(LocksManager.InterruptingOpeningWowClient, sessionId))
            {
                currentInfo.BimsbotProcess.Kill();
                LocksManager.getInstance().Unlock(LocksManager.OpeningWowClient);
                if (usingAdditionalWowProcess)
                {
                    additionalWowProcess.Kill();
                    additionalWowProcess = null;


                    await Task.Delay(1000);

                    if (useLowSettings)
                    {
                        FileManager.getInstance().ReturnWowSettings(wowPath, sessionId);
                    }
                }


                return(false);
            }

            bool result = WinApi.GetPidsList().Where(pid => pid.Contains(processId.ToString())).Count() > 0;

            currentInfo.BimsbotProcess.Kill();

            LocksManager.getInstance().Unlock(LocksManager.OpeningBimsbot);

            if (usingAdditionalWowProcess)
            {
                additionalWowProcess.Kill();
                additionalWowProcess      = null;
                usingAdditionalWowProcess = false;


                await Task.Delay(1000);

                if (useLowSettings)
                {
                    FileManager.getInstance().ReturnWowSettings(wowPath, sessionId);
                }
            }

            LocksManager.getInstance().Unlock(LocksManager.OpeningWowClient);

            return(result);
        }
Ejemplo n.º 10
0
 public void CloseWorkbench()
 {
     WinApi.CloseWindow(this._hwnd, 2000);
 }