Пример #1
0
        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();
            }
        }
Пример #2
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);
        }
Пример #3
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);
                }
            }
        }