Esempio n. 1
0
        public override void Invoke(bool isSimulate, bool async)
        {
            log.Debug(this.ToString());
            bool saveScreen;

            Boolean.TryParse(StateContainer.ini.Read("saveScreen", "Settings"), out saveScreen);
            Uri proofImg = new Uri(Environment.CurrentDirectory + @"\proofImg\login.bmp");

            loginProof = new BitmapImage(proofImg);
            StateContainer.Login();
            int      tries   = 0;
            bool     loading = false;
            bool     signIn  = false;
            Bitmap   bmpScreenshot;
            Graphics gfx;
            byte     Luminosity;

            if (isSimulate)
            {
                while (!loading)
                {
                    if (!signIn)
                    {
                        changeMac();
                        doLogin();
                        signIn = true;
                    }
                    tries++;
                    if (tries > 30)
                    {
                        break;
                    }
                    sim.Mouse.Sleep(4000);
                    bmpScreenshot = new Bitmap(145, 23, PixelFormat.Format32bppArgb);
                    gfx           = Graphics.FromImage(bmpScreenshot);
                    gfx.CopyFromScreen(32, 32, 0, 0,
                                       System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size,
                                       CopyPixelOperation.SourceCopy);
                    loading = Utils.Compare(Utils.BitmapImage2Bitmap(loginProof), bmpScreenshot);
                    log.Debug("Loading...");
                    if (loading)
                    {
                        break;
                    }
                    else if (saveScreen)
                    {
                        Utils.saveScreen(Environment.CurrentDirectory + @"\loginTry", bmpScreenshot);
                    }
                    bmpScreenshot = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
                    gfx           = Graphics.FromImage(bmpScreenshot);
                    gfx.CopyFromScreen(590, 490, 0, 0,
                                       System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size,
                                       CopyPixelOperation.SourceCopy);
                    Color color = bmpScreenshot.GetPixel(0, 0);
                    Luminosity = (byte)(color.GetBrightness() * 255);
                    log.Debug("signIn color.Lum:" + Luminosity);
                    if (Luminosity < 150 && Luminosity > 140)
                    {
                        // create user
                        sim.Mouse.MoveMouseTo(550 * xf, 345 * yf).Sleep(250).LeftButtonClick().Sleep(500);
                        sim.Keyboard.TextEntry(UserInfo.Name).Sleep(500);
                        sim.Mouse.MoveMouseTo(465 * xf, 522 * yf).Sleep(250).LeftButtonClick();
                    }
                    if (Luminosity < 120)
                    {
                        sim.Mouse.MoveMouseTo(590 * xf, 490 * yf).Sleep(250).LeftButtonClick();
                        signIn = false;
                        continue;
                    }
                }
            }
        }