public void Start(Uri appServerUri) { if (send == null) { RestAPI api = new RestAPI(); JObject obj = api.Authenticate("http://localhost:51748/Handler.ashx"); string cert = api.ParseAuthenticate(obj); send = new Thread(Send); send.Start(); } }
public ServerResponse EnqueueJob(byte[] zippedBytes) { ServerResponse response = ServerResponse.ServerError; try { byte[] recordBytes = RestAPI.Unzip(zippedBytes); HtmlRecord record = BSON.Deserialize <HtmlRecord>(recordBytes); record.Initialize(); WebCrawler.Instance.EnqueueWork(record); response = ServerResponse.Success; System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "]" + " Received: " + record.domain.AbsoluteUri); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); response = ServerResponse.ServerError; } return(response); }
public void Send() { RestAPI api = new RestAPI(); while (true) { HtmlRecord record = messageQueue.Take(); byte[] recordBytes = BSON.Serialize(record); JObject obj = null; try { obj = api.ReturnFinishedJob(recordBytes); bool successful = obj.GetValue("Successful").Value <bool>(); if (successful) { ServerResponse response = api.ParseResponse(obj); if (response != ServerResponse.Success) { messageQueue.Add(record); } else { System.Diagnostics.Debug.Print("[" + DateTime.Now.ToString() + "]" + " Sent: " + record.domain.AbsoluteUri); } } else { messageQueue.Add(record); } } catch (WebException ex) { System.Diagnostics.Debug.Print(ex.Message); messageQueue.Add(record); } } }