public string FetchWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            string result = string.Empty;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream, this.responseEncoding, true))
                            {
                                result = streamReader.ReadToEnd();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
        private HttpWebResponse FetchResponseWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            HttpWebResponse httpWebResponse = null;

            try
            {
                if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    httpWebRequest.Proxy       = new WebProxy("Insert Proxy IP Here", 1111);
                    httpWebRequest.UserAgent   = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0";
                    httpWebRequest.Accept      = this.accept;
                    httpWebRequest.KeepAlive   = this.keepAlive;
                    httpWebRequest.ContentType = this.contentType;
                    if (!string.IsNullOrEmpty(referer))
                    {
                        httpWebRequest.Referer = referer;
                    }
                    object cookielocker;
                    Monitor.Enter(cookielocker = this._cookielocker);
                    try
                    {
                        httpWebRequest.CookieContainer = this.cookieContainer;
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker);
                    }
                    httpWebRequest.Method = method.ToString().ToUpper();
                    if (method == HttpMethod.Post && !string.IsNullOrEmpty(postData))
                    {
                        byte[] bytes = this.postDataEncoding.GetBytes(postData);
                        httpWebRequest.ContentLength = (long)bytes.Length;
                        Stream requestStream = httpWebRequest.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Close();
                    }
                    httpWebResponse         = (HttpWebResponse)httpWebRequest.GetResponse();
                    httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
                    object cookielocker2;
                    Monitor.Enter(cookielocker2 = this._cookielocker);
                    try
                    {
                        this.cookies.Add(httpWebResponse.Cookies);
                        this.cookieContainer.Add(this.cookies);
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker2);
                    }
                }
            }
            catch (Exception ex)
            {
                this.CloseResponse(httpWebResponse);
                httpWebResponse = null;
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(httpWebResponse);
        }
        public Image FetchImageWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            Image result = null;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        using (Stream responseStream = httpWebResponse.GetResponseStream())
                        {
                            using (StreamReader streamReader = new StreamReader(responseStream, this.responseEncoding, true))
                            {
                                result = Image.FromStream(streamReader.BaseStream);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
                string message = this.Fetch(url, method, referer, postData);
                EngineLogger.Log("FK==>>>", message, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
示例#4
0
 public void Log(object key, string message, LogMode mode)
 {
     if (EngineLogger.CheckMode(mode))
     {
         string message2 = string.Format("{0} - {1}", key, message);
         this.Log(message2, mode);
     }
 }
示例#5
0
 public void Log(Exception ex, LogMode mode)
 {
     if (EngineLogger.CheckMode(mode))
     {
         string message = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);
         this.Log(message, mode);
     }
 }
示例#6
0
 public void Log(string message, LogMode mode)
 {
     if (EngineLogger.CheckMode(mode))
     {
         string message2 = EngineLogger.AppendTraces(message);
         this.logger.Info(message2);
     }
 }
示例#7
0
        public static void Log(object key, string message, LogMode mode, StaticLog type)
        {
            int logMode = 5;

            if (mode <= (LogMode)logMode)
            {
                string message2 = string.Format("{0} - {1}", key, message);
                string message3 = EngineLogger.AppendTraces(message2);
                ILog   log      = EngineLogger.loggers[type];
                log.Info(message3);
            }
        }
        public string FetchResponseUriWithProxy(string url, HttpMethod method, string referer, string postData)
        {
            string result = string.Empty;

            try
            {
                using (HttpWebResponse httpWebResponse = this.FetchResponseWithProxy(url, method, referer, postData))
                {
                    if (httpWebResponse != null)
                    {
                        result = httpWebResponse.ResponseUri.AbsoluteUri;
                    }
                }
            }
            catch (Exception ex)
            {
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(result);
        }
示例#9
0
 public void Log(object key, EngineAction action, Bet b, LogMode mode)
 {
     if (EngineLogger.CheckMode(mode))
     {
         string message = string.Format("{0}:{1}-->{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}", new object[]
         {
             key,
             action,
             b.Id,
             b.Home,
             b.Away,
             (int)b.Type,
             b.Choice.ToString().ToLower(),
             b.Handicap,
             b.OddsValue,
             b.MinBetAllowed,
             b.MaxBetAllowed,
             b.Stake,
             b.Step,
             b.Status
         });
         this.Log(message, mode);
     }
 }
        private HttpWebResponse FetchResponse(string url, HttpMethod method, string referer, string postData)
        {
            HttpWebResponse httpWebResponse = null;

            try
            {
                if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    //WebRequest.DefaultWebProxy = null;
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    httpWebRequest.UserAgent   = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0";
                    httpWebRequest.Accept      = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                    httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
                    httpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
                    httpWebRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true");
                    if (!string.IsNullOrEmpty(referer))
                    {
                        httpWebRequest.Referer = referer;
                    }
                    object cookielocker;
                    Monitor.Enter(cookielocker = this._cookielocker);
                    try
                    {
                        httpWebRequest.CookieContainer = this.cookieContainer;
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker);
                    }
                    httpWebRequest.Method = method.ToString().ToUpper();
                    if (method == HttpMethod.Post && !string.IsNullOrEmpty(postData))
                    {
                        byte[] bytes = this.postDataEncoding.GetBytes(postData);
                        httpWebRequest.ContentLength = (long)bytes.Length;
                        Stream requestStream = httpWebRequest.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Close();
                    }
                    httpWebResponse         = (HttpWebResponse)httpWebRequest.GetResponse();
                    httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
                    object cookielocker2;
                    Monitor.Enter(cookielocker2 = this._cookielocker);
                    try
                    {
                        this.cookies.Add(httpWebResponse.Cookies);
                        this.cookieContainer.Add(this.cookies);
                    }
                    finally
                    {
                        Monitor.Exit(cookielocker2);
                    }
                }
            }
            catch (Exception ex)
            {
                this.CloseResponse(httpWebResponse);
                httpWebResponse = null;
                EngineLogger.Log(ex, LogMode.Normal, StaticLog.Main);
            }
            return(httpWebResponse);
        }
示例#11
0
        public static void Log(Exception ex, LogMode mode, StaticLog type)
        {
            string message = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);

            EngineLogger.Log(ex.TargetSite.Name, message, mode, type);
        }