using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Navigation;
#if WIN32
using MSHTML;
#else
using mshtml;
#endif
using sharpknife.Controls;
using sharpknife.Utils;
using sharpknife.Engines;
using System.Diagnostics;
namespace sharpknife.Commands
{
public class ClixSenseGridCommand : Command
{
//function csmd1(obj) { $(obj).attr('msm', '1') }
//function csmd2(obj) { $(obj).attr('msc', '1') }
//function adOpen(obj, s, a, b) {
// if ($(obj).attr('msm') != '1' || $(obj).attr('msc') != '1') return false;
// if (cltm == 1) { alert('WAIT!!! Don\'t Click the Ads so Fast!'); return false } cltm = 1;
// window.setTimeout('cltm=0', 5000); $('#pays' + a).html('Clicked'); $(obj).attr('MVPXJw', '1');
// window.open('/en/View_Ads/' + a + '/' + b)
//}
//
//
//
// WordLinx - Upgrade for just $15!
// |
//
// Micro Ad
// 3 Sec
// $0.001
// |
private WebBrowserControl browser;
private PTCSource source;
public ClixSenseGridCommand()
{
}
public ClixSenseGridCommand(string name)
{
this.Group = "Browser";
this.Timeout = 45;
browser = WebBrowserControl.GetWebBrowserControl();
using (databaseEntities context = new databaseEntities())
{
var query = (from s in context.PTCSource where s.Name == name select s);
source = query.FirstOrDefault();
}
}
public override void Execute()
{
base.Execute();
browser.LoadCompleted += ParseAdsCommand_LoadCompleted;
Debug = "Navigate";
browser.Navigate(source.PTCUrl);
}
void ParseAdsCommand_LoadCompleted(object sender, NavigationEventArgs e)
{
string body = browser.Html;
if (StringUtils.Contains(body, "You will not be compensated for clicking on these ads unless you are signed in."))
{
browser.Navigate("https://www.clixsense.com/en/Sign_In?r=1");
return;
}
else if (e.Uri.AbsoluteUri == "https://www.clixsense.com/en/Sign_In?r=1")
{
IHTMLElementCollection inputFields = HtmlUtils.GetElementCollection(browser.Document, "input");
foreach (IHTMLInputElement element in inputFields)
{
if (element.name == "username")
{
element.value = source.Username;
}
else if (element.name == "password")
{
element.value = source.Password;
}
else if (element.type == "submit" && element.value == "Login")
{
((IHTMLElement)element).click();
return;
}
}
throw new Exception("Unable to login");
}
else if (e.Uri.AbsoluteUri == source.PTCUrl)
{
browser.Navigate("http://www.clixsense.com/en/ClixGrid");
return;
}
else if (e.Uri.AbsoluteUri == "http://www.clixsense.com/en/ClixGrid")
{
//4
// | 25
IHTMLElement left = HtmlUtils.GetElement(browser.Document, "clxs1");
IHTMLElement total = HtmlUtils.GetElement(browser.Document, "clxs2");
int counter = int.Parse(left.innerText);
StatusLog statusLog = StatusLog.Get("extra1");
if (counter == 0)
{
statusLog.Status = StatusLog.StatusCodes.Complete;
Debug = string.Format("Completed ({0}/{1})", left.innerText, total.innerText);
}
else
{
statusLog.Status = StatusLog.StatusCodes.InProgress;
Debug = string.Format("Executing ({0}/{1})", left.innerText, total.innerText);
}
statusLog.Save();
// (1,1) -> (30,20)
// TODO: avoid reusing same cells
Random random = new Random();
for (int i = 1; i <= counter; i++)
{
int x = random.Next(30) + 1;
int y = random.Next(20) + 1;
AdCommand command = new AdCommand(string.Format("http://www.clixsense.com/en/ClixGrid/{0}/{1}", x, y), 15, AdCommand.BonusValue.Cents, 0, "ClixSense");
command.RequiresCaptcha = false;
CommandEngine.GetEngine().Commands.Add(command);
}
browser.LoadCompleted -= ParseAdsCommand_LoadCompleted;
Status = StatusCode.Completed;
return;
}
throw new Exception("Unexpected behavior");
}
}
}
|