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;
using sharpknife.Commands;
using sharpknife.Engines;
namespace sharpknife.Strategies
{
class GetPaidMailStrategy : Strategy
{
public override bool CheckLogin(WebBrowserControl browser, PTCSource source)
{
//CashCrusader Version: 3.0.0
//Last MySQL backup from admin: 2,507.32 days
//Commissions settings:
//Point ads: 10,5,3,2,1 %
//Cash ads: 10,5,3,2,1 %
//Must login every 30 days and
//be at least 10% as active as your downline to get commission from downline clicks
//Sales Commission: 10,5,3,2,1 %
//Only support registered sites. Click here to verify registration
return
StringUtils.Contains(browser.Html, "CashCrusader Version:") ||
StringUtils.Contains(browser.Html, "Log In");
}
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,
"{}PAID AD \r\n-------------------------------------------------- {}")[1];
paidAd = paidAd.Replace("=\r\n", string.Empty);
paidAd = paidAd.Replace("3D\"", "\"");
paidAd = paidAd.Replace("=3D", "=");
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)
{
IHTMLElementCollection tables = HtmlUtils.GetElementCollection(browser.Document, "table");
List commands = new List();
int paidAds = 0;
int ads = 0;
string html = browser.Html;
foreach (IHTMLElement element in tables)
{
string table = element.innerHTML;
IHTMLElementCollection innerTables = ((IHTMLElementCollection)element.all).tags("table");
if (innerTables.length == 0)
{
int start = html.IndexOf(table);
int end = html.IndexOf(" ", start, StringComparison.InvariantCultureIgnoreCase);
if (end >= 0 && html.Substring(start, end - start).IndexOf("The ad above is worth", StringComparison.InvariantCultureIgnoreCase) >= 0)
{
string ad = html.Substring(start, end - start);
// Cheat bot checks
//http://www.no-minimum.com/scripts/runner.php?REDIRECT=http%3A%2F%2Fwww.no-minimum.com%2Fimages%2Fohoh.gif&hash=7ae463cd6a3a40d64a083502d71c9bb4
if (ad.IndexOf("ohoh.gif", StringComparison.InvariantCultureIgnoreCase) >= 0)
{
throw new Exception("Not expected");
continue;
}
try
{
AdLogItem item = new AdLogItem(DateTime.Now, ad);
if (item.Value > 0)
{
AdCommand command = new AdCommand(
item.Link,
item.Timer + 5, item.Type == AdLogItem.ValueType.Cents ? AdCommand.BonusValue.Cents : AdCommand.BonusValue.Points,
item.Value,
source.Name);
commands.Add(command);
ads++;
if (command.Bonus == AdCommand.BonusValue.Cents)
paidAds++;
}
}
catch (Exception ex)
{
LogItem item = new LogItem(ex.Message);
item.Save();
}
}
}
}
ParseAdsCommand parseAdsCommand = new ParseAdsCommand(source.Name);
//if (paidAds > 0)
{
foreach (AdCommand command in commands)
{
CommandEngine.GetEngine().Commands.Add(command);
}
}
if (ads == 0)
{
parseAdsCommand.NextExecution = DateTime.Now.AddHours(2);
}
CommandEngine.GetEngine().Commands.Add(parseAdsCommand);
return true;
}
public override decimal GetReferrals(WebBrowserControl browser, PTCSource source)
{
//