Example #1
0
    public static void LogError(string msg, Type t = null)
    {
        string loggerTypeL = "";
        bool   flag        = t != null;

        if (flag)
        {
            loggerTypeL = t.ToString();
        }
        TLogger.ErrorInfo(msg, loggerTypeL, null);
    }
Example #2
0
        private bool DownComplete()
        {
            Stream              stream          = null;
            HttpWebResponse     httpWebResponse = null;
            HttpWebRequest      httpWebRequest  = null;
            TArrayBuffer <byte> tArrayBuffer    = null;
            long num = 0L;
            bool result;

            try
            {
                httpWebRequest             = (HttpWebRequest)WebRequest.Create(this.url);
                httpWebRequest.Timeout     = this.requestTimeOut;
                httpWebRequest.ContentType = this.contentType;
                HttpRequestCachePolicy cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                httpWebRequest.CachePolicy = cachePolicy;
                bool flag = this.isGet;
                if (flag)
                {
                    httpWebRequest.Method = "GET";
                }
                else
                {
                    httpWebRequest.Method = "POST";
                    byte[] requestBytes = this.GetRequestBytes();
                    httpWebRequest.ContentType   = "application/x-www-form-urlencoded";
                    httpWebRequest.ContentLength = (long)requestBytes.Length;
                    using (Stream requestStream = httpWebRequest.GetRequestStream())
                    {
                        requestStream.Write(requestBytes, 0, requestBytes.Length);
                        requestStream.Close();
                    }
                }
                httpWebResponse    = (HttpWebResponse)httpWebRequest.GetResponse();
                stream             = httpWebResponse.GetResponseStream();
                stream.ReadTimeout = this.readTimeOut;
                tArrayBuffer       = new TArrayBuffer <byte>();
                byte[] array = new byte[1024];
                int    num2;
                while ((num2 = stream.Read(array, 0, array.Length)) > 0)
                {
                    tArrayBuffer.Write(array, 0, num2);
                    num          += (long)num2;
                    this.progress = (float)((double)num / (double)this.maxLength);
                }
                byte[] array2 = tArrayBuffer.Read(tArrayBuffer.Available);
                int    num3   = array2.Length;
                this.data = new byte[num3];
                Array.Copy(array2, this.data, num3);
                TLogger.Log("读取字节流长度:" + num3, "HttpDwon", "Run");
                bool flag2 = this.progress < 1f;
                if (flag2)
                {
                    this.HaveError = true;
                    TLogger.ErrorInfo("下载错误:文件下载流已经读完数据,但是下载的文件长度小于服务器,这可能是由于本地网络突然中断导致!!", null, null);
                    result = false;
                }
                else
                {
                    this.HaveError = false;
                    result         = true;
                }
            }
            catch (WebException ex)
            {
                this.HaveError = true;
                TLogger.ErrorInfo(ex.ToString(), null, null);
                TLogger.ErrorInfo("webEx.Status = " + ex.Status, null, null);
                bool flag3 = ex.Status == WebExceptionStatus.ProtocolError;
                if (flag3)
                {
                    TLogger.ErrorInfo("response.StatusCode = " + ((HttpWebResponse)ex.Response).StatusCode, null, null);
                    TLogger.ErrorInfo("response.StatusDescription = " + ((HttpWebResponse)ex.Response).StatusDescription, null, null);
                }
                bool flag4 = ex.Status == WebExceptionStatus.Timeout;
                if (flag4)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (IOException ex2)
            {
                this.HaveError = true;
                TLogger.ErrorInfo(ex2.ToString(), null, null);
                result = true;
            }
            catch (Exception ex3)
            {
                this.HaveError = true;
                TLogger.ErrorInfo(ex3.ToString(), null, null);
                result = true;
            }
            finally
            {
                bool flag5 = tArrayBuffer != null;
                if (flag5)
                {
                    tArrayBuffer.DestroySelf();
                    tArrayBuffer = null;
                }
                bool flag6 = stream != null;
                if (flag6)
                {
                    stream.Close();
                    stream = null;
                }
                bool flag7 = httpWebResponse != null;
                if (flag7)
                {
                    httpWebResponse.Close();
                    httpWebResponse = null;
                }
            }
            return(result);
        }