Пример #1
0
        private void SortImages(Advertisement ad, List <string> added, List <string> deleted)
        {
            List <RadioButtonList> radios      = Images.GetAll <RadioButtonList>();
            List <FileUpload>      fileUploads = Images.GetAll <FileUpload>();

            for (int i = 0; i < Constants.ImagesPerListing; i++)
            {
                try
                {
                    if (radios[i].SelectedIndex == UploadNew)
                    {
                        byte[] data = GetImage(fileUploads[i]);

                        if (data == null || data.Length <= 0)
                        {
                            continue;
                        }

                        string url = Imgur.GetUrl(data);

                        if (string.IsNullOrEmpty(url))
                        {
                            continue;
                        }

                        deleted.Add(ad.Images[i]);
                        added.Add(url);
                    }
                    else if (radios[i].SelectedIndex == NoPicture)
                    {
                        deleted.Add(ad.Images[i]);
                    }
                } catch { }
            }
        }
Пример #2
0
        private List <string> GetImages()
        {
            List <string> images = new List <string>();

            for (int index = 0; index < Request.Files.Count; index++)
            {
                HttpPostedFile file = Request.Files[index];

                string extension = Path.GetExtension(file.FileName);

                try
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        continue;
                    }

                    Stream stream = file.InputStream;

                    if (stream.Length == 0 || stream.Length > 2 << 22)
                    {
                        continue;
                    }

                    byte[] data = new BinaryReader(stream).ReadBytes((int)stream.Length);

                    string url = Imgur.GetUrl(data);

                    if (string.IsNullOrEmpty(url))
                    {
                        continue;
                    }

                    images.Add(url);
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            return(images);
        }