using System; using System.Collections.Generic; using System.Linq; using System.Text; #if WIN32 using MSHTML; #else using mshtml; #endif using sharpknife.Utils; using System.Globalization; using sharpknife.Controls; using System.Drawing; using System.IO; using sharpknife.Data; namespace sharpknife.Strategies { class IncentriaStrategy : Strategy { public override bool CheckLogin(WebBrowserControl browser, PTCSource source) { string html = browser.Html; html = StringUtils.RemoveQuotes(html); //Login if (StringUtils.Contains(html, "Login")) { return true; } return false; } public override void Login(WebBrowserControl browser, PTCSource source) { IHTMLElement head = (IHTMLElement)HtmlUtils.GetHead(browser.Document); IHTMLElementCollection elements = ((IHTMLElementCollection)browser.Document.body.all).tags("img"); foreach (IHTMLElement element in elements) { IHTMLImgElement image = (IHTMLImgElement)element; if (element.id == "udc") { Bitmap captcha = ImageUtils.GetImage(image); string path = string.Format(@"..\..\Images\Captcha\UpsideDown"); DirectoryInfo directory = new DirectoryInfo(path); if (!directory.Exists) { directory.Create(); } int upside = 0; int down = 0; sharpknife.Utils.ImageUtils.MatchType[] matches = new sharpknife.Utils.ImageUtils.MatchType[6]; Image[] images = ImageUtils.Split(captcha, new Rectangle(0, 0, 48, 48)); int i = 0; foreach (Bitmap bitmap in images) { string tempImage = Path.GetTempFileName(); bitmap.Save(tempImage); Bitmap left = new Bitmap(tempImage); FileInfo[] files = directory.GetFiles(); bool found = false; //bool upsideDown = true; foreach (FileInfo file in files) { Bitmap right = new Bitmap(file.FullName); Image reference = Bitmap.FromFile(file.FullName); if (ImageUtils.CompareImages(left, right)) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.Upside; found = true; upside++; break; } reference.RotateFlip(RotateFlipType.Rotate180FlipNone); if (ImageUtils.CompareImages(bitmap, (Bitmap)reference)) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.Down; found = true; //upsideDown = false; down++; break; } right.Dispose(); } left.Dispose(); if (!found) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.None; //string filename = string.Format("{0}.png", Guid.NewGuid()); //if (!upsideDown) //{ // bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); //} } i++; } //UpsideDownCaptchaConfirm dialog = new UpsideDownCaptchaConfirm(); UpsideDownCaptchaConfirm dialog = new UpsideDownCaptchaConfirm(true); dialog.Captcha = captcha; dialog.Image1 = (Bitmap)images[0]; dialog.Image2 = (Bitmap)images[1]; dialog.Image3 = (Bitmap)images[2]; dialog.Image4 = (Bitmap)images[3]; dialog.Image5 = (Bitmap)images[4]; dialog.Image6 = (Bitmap)images[5]; dialog.Match1 = matches[0]; dialog.Match2 = matches[1]; dialog.Match3 = matches[2]; dialog.Match4 = matches[3]; dialog.Match5 = matches[4]; dialog.Match6 = matches[5]; if (dialog.ShowDialog() == true) { //1 IHTMLElementCollection anchors = ((IHTMLElementCollection)browser.Document.body.all).tags("a"); foreach (IHTMLAnchorElement anchor in anchors) { int temp = 0; if (StringUtils.Contains(anchor.href, source.BaseUrl) && int.TryParse(((IHTMLElement)anchor).innerText, out temp) && ( ((IHTMLElement)anchor).className == "b1" || ((IHTMLElement)anchor).className == "b2" || ((IHTMLElement)anchor).className == "b3" || ((IHTMLElement)anchor).className == "b4" || ((IHTMLElement)anchor).className == "b5" || ((IHTMLElement)anchor).className == "b6" )) { if (temp - 1 == dialog.Match) { ((IHTMLElement)anchor).click(); break; } } } } } } IHTMLElementCollection inputFields = HtmlUtils.GetElementCollection(browser.Document, "input"); foreach (IHTMLElement element in inputFields) { IHTMLInputElement inputElement = (IHTMLInputElement)element; if (element.id == "username") { inputElement.value = source.Username; } else if (element.id == "password") { inputElement.value = source.Password; inputElement.form.submit(); return; } } } public override decimal GetBalance(WebBrowserControl browser, PTCSource source) { //Cash Balance
$0.03500
string html = browser.Html; string value = StringUtils.GetTokens(html, "{}Cash Balance{}${}{}")[2]; return decimal.Parse(value, CultureInfo.InvariantCulture.NumberFormat); } public override bool SolveCaptcha(WebBrowserControl browser, PTCSource source) { IHTMLElement head = (IHTMLElement)HtmlUtils.GetHead(browser.Document); if (browser == null || browser.Document == null || browser.Document.body == null || browser.Document.body.all == null) { return false; } IHTMLElementCollection elements = ((IHTMLElementCollection)browser.Document.body.all).tags("img"); foreach (IHTMLElement element in elements) { IHTMLImgElement image = (IHTMLImgElement)element; if (element.id == "udc") { Bitmap captcha = ImageUtils.GetImage(image); if (captcha == null) { return false; } string path = string.Format(@"..\..\Images\Captcha\UpsideDown"); DirectoryInfo directory = new DirectoryInfo(path); if (!directory.Exists) { directory.Create(); } int upside = 0; int down = 0; sharpknife.Utils.ImageUtils.MatchType[] matches = new sharpknife.Utils.ImageUtils.MatchType[6]; Image[] images = ImageUtils.Split(captcha, new Rectangle(0, 0, 48, 48)); int i = 0; foreach (Bitmap bitmap in images) { string tempImage = Path.GetTempFileName(); bitmap.Save(tempImage); Bitmap left = new Bitmap(tempImage); FileInfo[] files = directory.GetFiles(); bool found = false; //bool upsideDown = true; foreach (FileInfo file in files) { Bitmap right = new Bitmap(file.FullName); Image reference = Bitmap.FromFile(file.FullName); if (ImageUtils.CompareImages(left, right)) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.Upside; found = true; upside++; break; } reference.RotateFlip(RotateFlipType.Rotate180FlipNone); if (ImageUtils.CompareImages(bitmap, (Bitmap)reference)) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.Down; found = true; //upsideDown = false; down++; break; } right.Dispose(); } left.Dispose(); if (!found) { matches[i] = sharpknife.Utils.ImageUtils.MatchType.None; //string filename = string.Format("{0}.png", Guid.NewGuid()); //if (!upsideDown) //{ // bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); //} } i++; } UpsideDownCaptchaConfirm dialog = new UpsideDownCaptchaConfirm(true); //UpsideDownCaptchaConfirm dialog = new UpsideDownCaptchaConfirm(); dialog.Captcha = captcha; dialog.Image1 = (Bitmap)images[0]; dialog.Image2 = (Bitmap)images[1]; dialog.Image3 = (Bitmap)images[2]; dialog.Image4 = (Bitmap)images[3]; dialog.Image5 = (Bitmap)images[4]; dialog.Image6 = (Bitmap)images[5]; dialog.Match1 = matches[0]; dialog.Match2 = matches[1]; dialog.Match3 = matches[2]; dialog.Match4 = matches[3]; dialog.Match5 = matches[4]; dialog.Match6 = matches[5]; if (dialog.ShowDialog() == true) { //1 IHTMLElementCollection anchors = ((IHTMLElementCollection)browser.Document.body.all).tags("a"); foreach (IHTMLAnchorElement anchor in anchors) { int temp = 0; if (StringUtils.Contains(anchor.href, source.BaseUrl) && int.TryParse(((IHTMLElement)anchor).innerText, out temp) && ( ((IHTMLElement)anchor).className == "b1" || ((IHTMLElement)anchor).className == "b2" || ((IHTMLElement)anchor).className == "b3" || ((IHTMLElement)anchor).className == "b4" || ((IHTMLElement)anchor).className == "b5" || ((IHTMLElement)anchor).className == "b6" )) { if (temp - 1 == dialog.Match) { ((IHTMLElement)anchor).click(); return true; } } } } } } return false; } public override Ad ParseMail(Mail mail) { throw new NotImplementedException(); } public override bool ParseAds(WebBrowserControl browser, PTCSource source) { throw new NotImplementedException(); } public override decimal GetReferrals(WebBrowserControl browser, PTCSource source) { throw new NotImplementedException(); } } }