Пример #1
0
        public static bool work( SeleniumPoster ps, Server s )
        {
            int length = -1;
            byte[] buf = new byte[4096];
            bool loginCaught = false, passCaught = false;
            String captchakey, pass = "******", login = "******", advert;

            try
            {

                while (true)
                {
                    int res = s.receiveMessage(buf, ref length);

                    if (res == 3) // captchakey
                    {
                        System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                        captchakey = enc.GetString(buf, 0, length);

                        ps.setCaptchaKey(captchakey);
                        Console.WriteLine("captchakey set: " + captchakey + " verifying");
                        if (ps.verifyCaptchaKey())
                            s.sendResult(true);
                        else
                            s.sendResult(false);
                    }

                    if (res == 1) // password
                    {
                        passCaught = true;
                        System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                        pass = enc.GetString(buf, 0, length);

                        Console.WriteLine("pass: "******"login: " + login);
                    }

                    if (res == 0) // advert
                    {
                        System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                        advert = enc.GetString(buf, 0, length);

                        string[] words = advert.Split('\n');

                        /*        public Advert( string roomNumber,
                       string price,
                       string name,
                       string desc,
                       string district,
                       string subway_station,
                       string street,
                       string house,
                       string square,
                       string floor,
                       string floorNumber,
                       string phone,
                       string e_mail,
                       string person,
                       string date )*/

                        Advert adv = new Advert(words[0], words[1], words[2],
                                                words[3], words[4], words[5],
                                                words[6], words[7], words[8],
                                                words[9], words[10], words[11],
                                                words[12], words[13], words[14]);

                        ps.postAdvert(adv);

                    }

                    if (loginCaught && passCaught)
                    {
                        ps.login(login, pass);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }

            return true;
        }