Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
                }
            }
        }