<code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Net; namespace Neopets.classes.communications { public class LoggedOut : EventArgs { private bool status; public LoggedOut(bool status) { this.status = status; } public bool Status { get { return status; } } } public class Offline : EventArgs { private bool status; public Offline(bool status) { this.status = status; } public bool Status { get { return status; } } } public class Cookies : EventArgs { private string data; public Cookies(string data) { this.data = data; } public string Data { get { return data; } } } public class Response : EventArgs { private string data; public Response(string data) { this.data = data; } public string Data { get { return data; } } } class transmition { public delegate void Response_Handler(Object myobject, Response source); public event Response_Handler OnResponse; public delegate void Cookie_Handler(Object myobject, Cookies cookies); public event Cookie_Handler OnCookies; public delegate void Offline_Handler(Object myobject, Offline connected); public event Offline_Handler OnOffline; public delegate void LoggedOut_Handler(Object myobject, LoggedOut true_false); public event LoggedOut_Handler OnLoggedOut; public int Navigate(string page = "", string formparams = "", string cookieheader = "") { try { using (var client = new WebClient()) using (var stream = client.OpenRead("http://www.google.com")) { // Do Nothing :) } } catch { Offline connected = new Offline(false); OnOffline(this, connected); return 0; } WebRequest req = WebRequest.Create("http://www.neopets.com/" + page); string src = ""; if (cookieheader != "") { req.Headers.Add("Cookie", cookieheader); WebResponse getResponse = req.GetResponse(); using (StreamReader sr = new StreamReader(getResponse.GetResponseStream())) { src = sr.ReadToEnd(); } } else { byte[] bytes = Encoding.ASCII.GetBytes(formparams); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; req.ContentLength = bytes.Length; using (Stream os = req.GetRequestStream()) { os.Write(bytes, 0, bytes.Length); } WebResponse resp = req.GetResponse(); cookieheader = resp.Headers["Set-cookie"]; Cookies cookies = new Cookies(cookieheader); OnCookies(this, cookies); using (StreamReader sr = new StreamReader(resp.GetResponseStream())) { src = sr.ReadToEnd(); } } if (src.Contains("<form method=\"post\" action=\"/login.phtml\">")) { LoggedOut loggedout = new LoggedOut(true); OnLoggedOut(this, loggedout); } Response source = new Response(src); OnResponse(this, source); return 1; } } } =====================THE SERVICE THE EXECUTES THE EVENT HANDLERS=================== using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using Neopets.classes.communications; namespace Neopets.services { public partial class market : ServiceBase { private transmition comms = new transmition(); private string cookies; private bool loggedout; private bool offline; private string response; public string Response { get { return response; } } public string Cookies { get { return cookies; } } public market() { InitializeComponent(); } protected override void OnStart(string[] args) { if (args.Count() == 1 ) { if (args[0] == "debug") { forms.Debugger debug = new forms.Debugger(); debug.Show(); } } <big> comms.OnCookies += transmition.Cookie_Handler(comms_OnCookies); comms.OnLoggedOut += transmition.LoggedOut_Handler(comms_logout); comms.OnOffline += transmition.Offline_Handler(comms_offline); comms.OnResponse += transmition.Response_Handler(comms_response);</big> comms.Navigate(); } static void comms_OnCookies(object a, Cookies e) { } static void comms_logout(object a, LoggedOut e) { } static void comms_offline(object a, Offline e) { } static void comms_response(object a, Response e) { } protected override void OnStop() { } } }
static void comms_OnCookies(object a, Cookies e) { }
comms.OnCookies += new transmition.Cookie_Handler(comms_OnCookies); ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)