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 YouRoMailStrategy : Strategy
{
public override bool CheckLogin(WebBrowserControl browser, PTCSource source)
{
string body = browser.Html;
if (StringUtils.Contains(body, "Log In"))
{
return true;
}
return false;
}
public override void Login(WebBrowserControl browser, PTCSource source)
{
//
//
//
IHTMLInputElement username = HtmlUtils.GetInputByName(browser.Document, "username");
IHTMLInputElement password = HtmlUtils.GetInputByName(browser.Document, "password");
username.value = source.Username;
password.value = source.Password;
password.form.submit();
}
public override decimal GetBalance(WebBrowserControl browser, PTCSource source)
{
//
Your account balance after all transactions:
IHTMLElementCollection elements = HtmlUtils.GetElementCollection(browser.Document, "td");
int count = elements.length;
foreach (IHTMLElement element in elements)
{
if (!string.IsNullOrEmpty(element.innerText) &&
element.innerText.IndexOf("Your account balance after all transactions", StringComparison.InvariantCultureIgnoreCase) >= 0)
{
IHTMLElementCollection innerTables = ((IHTMLElementCollection)element.all).tags("table");
if (innerTables.length == 0)
{
IHTMLTable table = (IHTMLTable)element.parentElement.parentElement.parentElement;
int rowIndex = 2;
int columnIndex = 1;
if (((IHTMLElement)table).innerHTML.IndexOf("Current Earnings", StringComparison.InvariantCultureIgnoreCase) >= 0)
{
rowIndex++;
}
IHTMLTableRow row = (IHTMLTableRow)browser.GetElementAt(table.rows, rowIndex);
IHTMLTableCell cell = (IHTMLTableCell)browser.GetElementAt(row.cells, columnIndex);
string value = ((IHTMLElement)cell).innerText.Substring(2).Trim();
return decimal.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
}
}
}
throw new Exception();
}
public override bool SolveCaptcha(WebBrowserControl browser, PTCSource source)
{
throw new NotImplementedException();
}
public override Ad ParseMail(Mail mail)
{
if (StringUtils.Contains(mail.Body, " "))
{
mail.Body = mail.Body.Replace(" ", " ");
}
string paidAd = StringUtils.GetTokens(mail.Body,
"{}\r\nPAID AD \r\n-------------------------------------------------- {}")[1];
paidAd = paidAd.Replace("=\r\n", string.Empty);
paidAd = paidAd.Replace("3D\"", "\"");
paidAd = paidAd.Replace("=3D", "=");
//string[] links = StringUtils.GetTokens(paidAd, " {} {}
");
string[] links = StringUtils.GetTokens(paidAd, " {} {}
");
if (links[1] == links[3])
{
Ad ad = new Ad()
{
Link = links[1]
};
return ad;
}
return null;
}
public override bool ParseAds(WebBrowserControl browser, PTCSource source)
{
throw new NotImplementedException();
}
public override decimal GetReferrals(WebBrowserControl browser, PTCSource source)
{
throw new NotImplementedException();
}
}
}
|