Exemplo n.º 1
0
        public void Dispose()
        {
            if (!_disposed)
            {
                try
                {
                    if (_xlsBook != null)
                    {
                        _xlsBook.Close(false, Missing.Value, Missing.Value);
                        ReleaseComObj(_xlsBook);
                        _xlsBook = null;
                    }
                    if (_xlsApp != null)
                    {
                        _xlsApp.Quit();
                        ReleaseComObj(_xlsApp);
                        _xlsApp = null;
                    }

                    _disposed = true;

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception e)
                {
                    GlobalLog.Err(e, "Exception while dispose XLSWorker");
                }
            }
        }
Exemplo n.º 2
0
        private void EndPostImage(IAsyncResult ar)
        {
            HttpWebRequest request = (ar.AsyncState as HttpWebRequest);

            try
            {
                HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse;
                byte[]          buffer   = new byte[8 * 1024];
                byte[]          data;
                using (Stream stream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        int readed;
                        while ((readed = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ms.Write(buffer, 0, readed);
                        }
                        data = ms.GetBuffer();
                    }
                }
                string dataStr = StreamEncoding.GetString(data);
                HandlePostState(dataStr);
            }
            catch (Exception e)
            {
#if DEBUG
                GlobalLog.Err(e, "error while data reading");
#endif
                Err(ErrorState.ConnectProblem);
            }
        }
Exemplo n.º 3
0
        void EndCheckAnonimous(DownloaderObj obj)
        {
            AnonymousRegexes anonRegxs = GlobalResourceCache.AnonymCheck;

            if (obj.DataStr != null)
            {
                if (anonRegxs.Anonymous.IsMatch(obj.DataStr))
                {
                    obj.Proxy.AnonymousLevel = AnonymousLevel.Anonymous;
                }
                else if (anonRegxs.HightAnonymous.IsMatch(obj.DataStr))
                {
                    obj.Proxy.AnonymousLevel = AnonymousLevel.HightAnonymous;
                }
                else
                {
                    obj.Proxy.AnonymousLevel = AnonymousLevel.NotAnonymous;
                }
            }
            else
            {
                if (_logging)
                {
                    GlobalLog.Err("Cant download page from anon checking site, p:" + obj.Proxy.Address.Host);
                }
            }
        }
Exemplo n.º 4
0
        internal void BeginReceive(DownloaderObj obj)
        {
            if (obj.Attempts > 0)
            {
                obj.Attempts--;
                try
                {
                    obj.Request = CreateRequest(obj);
                    if (obj.PostData != null)
                    {
                        PostRequestData(obj.Request, obj.PostData);
                    }

                    //Console.WriteLine("Send request to -- {0}", obj.Uri.OriginalString);
                    obj.Request.BeginGetResponse(EndReceive, obj);
                }
                catch (WebException e)
                {
                    GlobalLog.Err(e, "Host: " + obj.Uri.Host);
                    HandleWebState(e, obj);
                    RetryOrCallback(obj);
                }
                catch (Exception e)
                {
                    GlobalLog.Err(e, "Host: " + obj.Uri.Host);
                    RetryOrCallback(obj);
                }
            }
        }
Exemplo n.º 5
0
 private void SessionCallback()
 {
     try
     {
         _callBack.Invoke(this);
     }
     catch (Exception e)
     {
         GlobalLog.Err(e, "Error while callback in HttpSession, please add catch below");
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Post data callback
        /// </summary>
        private void EndPostImage(DownloaderObj obj)
        {
            if (obj.DataStr != null)
            {
                HandlePostState(obj.DataStr);
            }
            else
            {
#if DEBUG
                GlobalLog.Err("null data in EndPostImage, POST_DATA:\n{0}", obj.PostData);
#endif
                Err(ErrorState.ConnectProblem);
            }
        }
Exemplo n.º 7
0
 void CallbackAndContinue(DownloaderObj obj)
 {
     if (obj.CallBack != null)
     {
         try
         {
             obj.CallBack.Invoke(obj);
         }
         catch (Exception e)
         {
             GlobalLog.Err(e, "CallBack err");
         }
     }
     Downloader.ProcessNext(obj.Uri);
 }
Exemplo n.º 8
0
        internal void EndReceive(IAsyncResult ar)
        {
            if (!ExecutionContext.IsFlowSuppressed())
            {
                ExecutionContext.SuppressFlow();
            }

            DownloaderObj obj = ar.AsyncState as DownloaderObj;

            try
            {
#if DEBUG
                GlobalLog.Write("Get responce from " + obj.Uri.Host);
#endif
                obj.Response = obj.Request.EndGetResponse(ar) as HttpWebResponse;

                HandleRedirectAndCookies(obj);

                if (TryReceiveData(obj))
                {
                    CallbackAndContinue(obj);
                    return;
                }
#if DEBUG
                GlobalLog.Write("CANT Downloaded data from " + obj.Uri.Host);
#endif
            }
            catch (WebException e)
            {
                GlobalLog.Err(e, "Host: " + obj.Uri.Host);
                HandleWebState(e, obj);
            }
            catch (Exception e)
            {
                GlobalLog.Err(e, "Host: " + obj.Uri.Host);
            }
            finally
            {
                if (obj.Response != null)
                {
                    obj.Response.Close();
                }
            }
            RetryOrCallback(obj);
        }
Exemplo n.º 9
0
        private void AskRecognize(string id)
        {
            Uri           resolveUri = new Uri(_resolveStr + id);
            DownloaderObj obj        = new DownloaderObj(resolveUri, null, true, null, CookieOptions.Empty, 5);

            Downloader.DownloadSync(obj);
            if (obj.DataStr != null)
            {
                HandleRecognizeState(obj.DataStr, id);
            }
            else
            {
#if DEBUG
                GlobalLog.Err("can't ASK data, id:{0}", id);
#endif
                Err(ErrorState.ConnectProblem);
            }
        }
Exemplo n.º 10
0
        void DownloadGooglePage(RatedProxy proxy)
        {
            Uri           googleUri = new Uri("http://www.google.com/search?q=flowers&sourceid=opera&ie=utf-8&oe=utf-8");
            DownloaderObj obj       = new DownloaderObj(googleUri, CheckGooglePage, true, proxy, CookieOptions.Empty, 2);

            if (Downloader.HaveResponce(obj))
            {
                obj.Attempts = 2;
                Downloader.Queue(obj);
            }
            else
            {
                if (_logging)
                {
                    GlobalLog.Err("Cant get responce from http://google.com, perhaps proxy or ya host is down, p:" + obj.Proxy.Address.Host);
                }
            }
        }
Exemplo n.º 11
0
        private void ReleaseComObj(object obj)
        {
            if (obj == null)
            {
                return;
            }

            try
            {
                Marshal.FinalReleaseComObject(obj);
                obj = null;
            }
            catch (Exception e)
            {
                obj = null;
                GlobalLog.Err(e, "Error when release xls com Obj");
            }
        }
Exemplo n.º 12
0
        void DownloadYaPage(RatedProxy proxy)
        {
            Uri           yandexUri = new Uri("http://kiks.yandex.ru/su/");
            DownloaderObj obj       = new DownloaderObj(yandexUri, CheckYaPage, true, proxy, CookieOptions.Take, 2);

            if (Downloader.HaveResponce(obj))
            {
                obj.Uri      = new Uri("http://wordstat.yandex.ru/");
                obj.Attempts = 2;
                Downloader.Queue(obj);
            }
            else
            {
                if (_logging)
                {
                    GlobalLog.Err("Cant get responce from http://kiks.yandex.ru, perhaps proxy or ya host is down, p:" + obj.Proxy.Address.Host);
                }
            }
        }
Exemplo n.º 13
0
        private void HandleSuccessDownload(DownloaderObj obj)
        {
            _proxies.Release(obj.PrxContainer as ProxyContainer, true);

            DevourTarget target = obj.Arg as DevourTarget;

            //MoveReadQueue();
            try
            {
                MoveReadQueue();
                target.Reader.ReadData(obj.DataStr, target);
                MoveReadComplete(target);
            }
            catch (Exception ex)
            {
                GlobalLog.Err(ex, "error while reading data in devourer");
            }

            AddSuccessTarget(obj.Uri);
        }
Exemplo n.º 14
0
 public CookieCollection GetCookies(DownloaderObj obj)
 {
     while (obj.Attempts > 0)
     {
         obj.Attempts--;
         try
         {
             obj.Request  = CreateRequest(obj);
             obj.Response = obj.Request.GetResponse() as HttpWebResponse;
             if (obj.Request.HaveResponse && obj.Response.Cookies != null)
             {
                 return(obj.Response.Cookies);
             }
         }
         catch (WebException e)
         {
             GlobalLog.Err(e, "Host: " + obj.Uri.Host);
             HandleWebState(e, obj);
         }
         catch (Exception e)
         {
             throw e;
         }
         finally
         {
             if (obj.Request != null)
             {
                 obj.Request.Abort();
             }
             if (obj.Response != null)
             {
                 obj.Response.Close();
             }
         }
     }
     return(null);
 }
Exemplo n.º 15
0
 public bool HaveResponce(DownloaderObj obj)
 {
     while (obj.Attempts > 0)
     {
         obj.Attempts--;
         try
         {
             obj.Request = CreateRequest(obj);
             bool haveResp = obj.Request.HaveResponse;
             obj.Request.Abort();
             return(haveResp);
         }
         catch (WebException e)
         {
             GlobalLog.Err(e, "Host: " + obj.Uri.Host);
             HandleWebState(e, obj);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
     return(false);
 }
Exemplo n.º 16
0
        static CookieContainer _sharedCookies = new CookieContainer();          //PUBLIC SHARED COOKIES

        internal void Receive(DownloaderObj obj)
        {
            while (obj.Attempts > 0)
            {
                obj.Attempts--;
                try
                {
                    obj.Request = CreateRequest(obj);
                    if (obj.PostData != null)
                    {
                        PostRequestData(obj.Request, obj.PostData);
                    }

                    obj.Response = obj.Request.GetResponse() as HttpWebResponse;

                    HandleRedirectAndCookies(obj);

                    if (TryReceiveData(obj))
                    {
                        break;
                    }
                }
                catch (WebException e)
                {
                    GlobalLog.Err(e, "Host: " + obj.Uri.Host);
                    HandleWebState(e, obj);
                }
                finally
                {
                    if (obj.Response != null)
                    {
                        obj.Response.Close();
                    }
                }
            }
        }