Esempio n. 1
0
 public UECrawler Fetch()
 {
     using (HttpWebResponse response = (WebRequest.Create(this.SourceUrl) as HttpWebRequest).GetResponse() as HttpWebResponse)
     {
         if (response.StatusCode != HttpStatusCode.OK)
         {
             this.State = "Url returns " + (object)response.StatusCode + ", " + response.StatusDescription;
             return(this);
         }
         if (response.ContentType.IndexOf("image") == -1)
         {
             this.State = "Url is not an image";
             return(this);
         }
         this.ServerUrl = UEPathFormatter.Format(Path.GetFileName(this.SourceUrl), UEConfig.GetString("catcherPathFormat"));
         string path = this.Server.MapPath(this.ServerUrl);
         if (!Directory.Exists(Path.GetDirectoryName(path)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(path));
         }
         try
         {
             BinaryReader binaryReader = new BinaryReader(response.GetResponseStream());
             byte[]       array;
             using (MemoryStream memoryStream = new MemoryStream())
             {
                 byte[] buffer = new byte[4096];
                 int    count;
                 while ((count = binaryReader.Read(buffer, 0, buffer.Length)) != 0)
                 {
                     memoryStream.Write(buffer, 0, count);
                 }
                 array = memoryStream.ToArray();
             }
             System.IO.File.WriteAllBytes(path, array);
             this.State = "SUCCESS";
         }
         catch (Exception ex)
         {
             this.State = "抓取错误:" + ex.Message;
         }
         return(this);
     }
 }
Esempio n. 2
0
    public override void Process()
    {
        string str;

        byte[] numArray;
        if (this.UploadConfig.Base64)
        {
            str      = this.UploadConfig.Base64Filename;
            numArray = Convert.FromBase64String(this.Request[this.UploadConfig.UploadFieldName]);
        }
        else
        {
            HttpPostedFile file = this.Request.Files[this.UploadConfig.UploadFieldName];
            str = file.FileName;
            if (!this.CheckFileType(str))
            {
                this.Result.State = UEUploadState.TypeNotAllow;
                this.WriteResult();
                return;
            }
            if (!this.CheckFileSize(file.ContentLength))
            {
                this.Result.State = UEUploadState.SizeLimitExceed;
                this.WriteResult();
                return;
            }
            numArray = new byte[file.ContentLength];
            try
            {
                file.InputStream.Read(numArray, 0, file.ContentLength);
            }
            catch (Exception ex)
            {
                this.Result.State = UEUploadState.NetworkError;
                this.WriteResult();
            }
        }
        this.Result.OriginFileName = str;
        string path1 = UEPathFormatter.Format(str, this.UploadConfig.PathFormat);
        string path2 = this.Server.MapPath(path1);

        try
        {
            if (!Directory.Exists(Path.GetDirectoryName(path2)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path2));
            }
            File.WriteAllBytes(path2, numArray);
            this.Result.Url   = path1;
            this.Result.State = UEUploadState.Success;
        }
        catch (Exception ex)
        {
            this.Result.State        = UEUploadState.FileAccessError;
            this.Result.ErrorMessage = ex.Message;
        }
        finally
        {
            this.WriteResult();
        }
    }
Esempio n. 3
0
    public override void Process()
    {
        byte[] array = null;
        string text  = null;

        if (UploadConfig.Base64)
        {
            text  = UploadConfig.Base64Filename;
            array = Convert.FromBase64String(base.Request[UploadConfig.UploadFieldName]);
        }
        else
        {
            HttpPostedFile httpPostedFile = base.Request.Files[UploadConfig.UploadFieldName];
            text = httpPostedFile.FileName;
            if (!CheckFileType(text))
            {
                Result.State = UEUploadState.TypeNotAllow;
                WriteResult();
                return;
            }
            if (!CheckFileSize(httpPostedFile.ContentLength))
            {
                Result.State = UEUploadState.SizeLimitExceed;
                WriteResult();
                return;
            }
            array = new byte[httpPostedFile.ContentLength];
            try
            {
                httpPostedFile.InputStream.Read(array, 0, httpPostedFile.ContentLength);
            }
            catch (Exception)
            {
                Result.State = UEUploadState.NetworkError;
                WriteResult();
            }
        }
        Result.OriginFileName = text;
        string text2 = UEPathFormatter.Format(text, UploadConfig.PathFormat);
        string path  = base.Server.MapPath(text2);

        try
        {
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            File.WriteAllBytes(path, array);
            Result.Url   = text2;
            Result.State = UEUploadState.Success;
        }
        catch (Exception ex2)
        {
            Result.State        = UEUploadState.FileAccessError;
            Result.ErrorMessage = ex2.Message;
        }
        finally
        {
            WriteResult();
        }
    }