Exemple #1
0
 public void SetHost(HomeGenieService hg, int programId)
 {
     homegenie = hg;
     netHelper = new NetHelper(homegenie);
     programHelper = new ProgramHelper(homegenie, programId);
     eventsHelper = new EventsHelper(homegenie, programId);
     serialPortHelper = new SerialPortHelper();
     tcpClientHelper = new TcpClientHelper();
     schedulerHelper = new SchedulerHelper(homegenie);
 }
        public void Handle(CheckParams checkParams, NetHelper nHelper, CancellationToken token)
        {
            CheckParams = checkParams;
            SetRestartState();
            while (_currentState != null)
            {
                if (token.IsCancellationRequested)
                    token.ThrowIfCancellationRequested();

                _currentState.Handle(nHelper);
            }
        }
Exemple #3
0
 public void TestReadTimeout()
 {
     Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket.Connect("localhost", port);
     NetHelper helper = new NetHelper();
     helper.Set(socket, 100);
     NetHeader header = new NetHeader();
     byte[] bytes;
     bool ok = helper.ReadTimeout(200, ref header, out bytes);
     Assert.AreEqual(ok, false);
     helper.Close();
 }
Exemple #4
0
 public void TestWriteRead()
 {
     Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket.Connect("localhost", port);
     NetHelper helper = new NetHelper();
     helper.Set(socket, 100);
     helper.WriteWithHeader(1, NetHelper.ToUTF8("status"));
     NetHeader header = new NetHeader();
     byte[] bytes;
     helper.Read(ref header, out bytes);
     string beginExpected = "\n{\"status\":\"ok\"";
     string beginRead = NetHelper.FromUTF8(bytes).Substring(0, beginExpected.Length);
     Assert.AreEqual(beginExpected, beginRead);
     helper.Close();
 }
        public override void Handle(NetHelper nHelper)
        {
            var metadataFinder = new MetadataFinder(Context.CheckParams.Account);
            string metadata = metadataFinder.Find(_getMetadataTimeout);

            if (Properties.Settings.Default.Mode == 0 || Properties.Settings.Default.Mode == 2)
            {
                var proxy = Context.ProxyManager.GetProxy();

                if (proxy == null)
                {
                    //Context.State = null;
                    //throw new ApplicationException("proxy not found");
                }
                else
                {
                    nHelper.Proxy = proxy;
                }
            }

            var output = nHelper.GET(Globals.LOG_URL);

            if (StateContext.IsError(output))
            {
                Context.ProxyManager.RemoveProxy(nHelper.Proxy);
                return;
            }

            var attributes = StateContext.ParseAccountAttributes(Context.CheckParams.Account, metadata);

            foreach (Match match in _attributesRegex.Matches(output))
            {
                attributes.Add(match.Groups[1].ToString(), match.Groups[2].ToString());
            }

            string response = nHelper.POST(Globals.POST_URL, attributes);

            Context.SetValidationState(response);
        }
Exemple #6
0
        private QiZi[] winQizi; //标记连成一条线的五个棋子

        #endregion Fields

        #region Constructors

        public Board(int r, Graphics g, int w, int rectPix, bool isServer, string ip)
            : this(r, g, w, rectPix)
        {
            this.isServer = isServer;
            localnet = new NetHelper(isServer, r, g, ip);
        }
 public abstract void Handle(NetHelper nHelper);
 public void SetHost(HomeGenieService hg, SchedulerItem item)
 {
     homegenie = hg;
     schedulerItem = item;
     Reset();
     netHelper = new NetHelper(homegenie);
     serialPortHelper = new SerialPortHelper();
     tcpClientHelper = new TcpClientHelper();
     udpClientHelper = new UdpClientHelper();
     mqttClientHelper = new MqttClientHelper();
     knxClientHelper = new KnxClientHelper();
     schedulerHelper = new SchedulerHelper(homegenie);
     programHelper = new ProgramHelperBase(homegenie);
 }
        public override void Handle(NetHelper nHelper)
        {
            var account = Context.CheckParams.Account;
            var proxyManager = Context.ProxyManager;

            if (StateContext.IsBadLog(_response))
            {
                Context.FireOnCheckCompleted(Context, CheckResults.Bad, Context.CheckParams);
            }
            else if (StateContext.IsSecurityQuestion(_response))
            {
                nHelper.GET("http://amazon.com/homepage=true");
                Context.GatherInformation(nHelper, account);

                Context.FireOnCheckCompleted(Context, CheckResults.Good, Context.CheckParams);
            }
            else if (StateContext.IsCookiesDisabled(_response))
            {
                Context.SetRestartState();
                return;
            }
            else if (StateContext.IsCaptchaMsg(_response))
            {
                if (Properties.Settings.Default.Mode == 0 || Properties.Settings.Default.Mode == 1)
                {
                    string captchaUrl = "https://opfcaptcha-prod.s3.amazonaws.com" +
                                        _response.Split(new[] { "opfcaptcha-prod.s3.amazonaws.com" },
                                            StringSplitOptions.None)[1].Split('"')[0];
                    byte[] captchaBytes;

                    using (WebClient wc = new WebClient())
                        captchaBytes = wc.DownloadData(captchaUrl);

                    var captchaResult = Context.CaptchaService.DecodeCaptchaAsync(captchaBytes).Result;

                    if (captchaResult != null)
                    {
                        var metadataFinder = new MetadataFinder(account);
                        var metadata = metadataFinder.Find(_getMetadataTimeout);

                        var attributes = StateContext.ParseAccountAttributes(account, metadata);

                        foreach (Match m in _attributesRegex.Matches(_response))
                        {
                            attributes.Add(m.Groups[1].ToString(), m.Groups[2].ToString());
                        }

                        attributes.Add("guess", captchaResult.Text);

                        var response = nHelper.POST(Globals.POST_URL, attributes);
                        Init(response);

                        // limit captcha attemts
                        if (_captchaCounter >= 5)
                        {
                            Context.SetFinishState();
                            return;
                        }

                        _captchaCounter++;

                        return;
                    }
                    //todo: captcha not recognized, so need to request new one
                }
                else
                {
                    proxyManager.RemoveProxy(nHelper.Proxy);
                    Context.SetRestartState();
                    return;
                }
            }
            else if (StateContext.IsAskCredentials(_response))
            {
                Context.SetRestartState();
            }
            else if (StateContext.IsAnotherDevice(_response))
            {
                Context.FireOnCheckCompleted(Context, CheckResults.Good, Context.CheckParams);
            }
            else if (StateContext.IsError(_response))
            {
                proxyManager.RemoveProxy(nHelper.Proxy);
                Context.SetRestartState();
                return;
            }
            else
            {
                Context.GatherInformation(nHelper, account);

                Context.FireOnCheckCompleted(Context, CheckResults.Good, Context.CheckParams);
            }

            Context.SetFinishState();
        }
Exemple #10
0
        private void Check(CheckParams checkParams, CancellationToken token)
        {
            if (checkParams == null)
                throw new ArgumentNullException(nameof(checkParams));

            try
            {
                NetHelper nHelper = new NetHelper { UserAgent = UserAgentsManager.GetRandomUserAgent() };

                var context = new StateContext(_logger, _proxyManager, _captchaService);
                context.OnCheckCompleted += _context_OnCheckCompleted;
                context.Handle(checkParams, nHelper, token);
                context.OnCheckCompleted -= _context_OnCheckCompleted;
            }
            catch (Exception exception)
            {
                _logger.Debug("error while check");
                _logger.Error(exception);

                _accChecked++;
                _badAccounts++;

                FireOnCheckCompleted(CheckResults.Bad, checkParams);

                _eventAggregator.SendMessage(new InformUserMessage(new InformUserMessage.Message(exception.Message, InformUserMessage.MessageType.Error)));
            }
        }
        private async Task GatherGiftCardBalanceAsync(NetHelper nHelper, Account account)
        {
            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    account.GiftCardBalance = Regex.Match(nHelper.GET(Globals.GC_URL), Globals.GC_REGEX).Groups[1].Value;
                }
                catch (Exception exception)
                {
                    _logger.Debug("error while gather GiftCardBalance");
                    _logger.Error(exception);

                    account.GiftCardBalance = "N/A";
                }
            });
            await task;
        }
        public async Task GatherAddyInfosAsync(NetHelper nHelper, Account account)
        {
            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    string pageCode = nHelper.GET(Globals.ADDY_URL);
                    string addyId = Regex.Match(pageCode, Globals.REGEX.Replace(" />", ">")).Groups[2].Value;
                    string addyInfos = nHelper.GET(string.Format(Globals.FULLADDY_URL, addyId));
                    
                    //account.ZipCode = HtmlParser.GetElementValueById(addyInfos, "enterAddressPostalCode");
                    //account.Phone = HtmlParser.GetElementValueById(addyInfos, "enterAddressPhoneNumber");

                    Regex attributesRegex = new Regex(Globals.REGEX, RegexOptions.Multiline | RegexOptions.IgnoreCase);

                    foreach (Match m in attributesRegex.Matches(addyInfos))
                    {
                        var addy = m.Groups[1].Value;
                        if (addy == "oldPostalCode")
                            account.ZipCode = m.Groups[2].Value;
                        else if (addy == "oldPhoneNumber")
                            account.Phone = m.Groups[2].Value;
                        else
                            _logger.Info(string.Format("unknown ADDY info:'{0}'", addy));
                    }
                }
                catch (Exception exception)
                {
                    _logger.Debug("error while gather addy info");
                    _logger.Error(exception);

                    account.ZipCode = "N/A";
                    account.Phone = "N/A";
                }
            });
            await task;
        }
        public void GatherInformation(NetHelper nHelper, Account account)
        {
            var tasks =
                new List<Task>(new[]
                {
                    GatherGiftCardBalanceAsync(nHelper, account),
                    GatherOrdersAsync(nHelper, account),
                    GatherAddyInfosAsync(nHelper, account)
                });

            Task.WhenAll(tasks).Wait();
        }