Ejemplo n.º 1
0
        private void FixHeadshots(string key)
        {
            byte[] originalBlob = null;
            var    logTable     = LogPoliticiansImagesHeadshot.GetLatestData(key);

            if (logTable.Count > 0)
            {
                originalBlob = logTable[0].HeadshotOriginal;
            }
            else
            {
                originalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key);
            }
            if (originalBlob != null)
            {
                MemoryStream memoryStream = new MemoryStream(originalBlob);
                Image        image        = Image.FromStream(memoryStream);

                var newBlob100 = ImageManager.GetResizedImageBlobAsJpg(image, 100, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot100\" + key + ".jpg", newBlob100);
                PoliticiansImagesBlobs.UpdateHeadshot100(newBlob100, key);

                var newBlob75 = ImageManager.GetResizedImageBlobAsJpg(image, 75, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot75\" + key + ".jpg", newBlob75);
                PoliticiansImagesBlobs.UpdateHeadshot75(newBlob75, key);

                var newBlob50 = ImageManager.GetResizedImageBlobAsJpg(image, 50, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot50\" + key + ".jpg", newBlob50);
                PoliticiansImagesBlobs.UpdateHeadshot50(newBlob50, key);

                var newBlob35 = ImageManager.GetResizedImageBlobAsJpg(image, 35, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot35\" + key + ".jpg", newBlob35);
                PoliticiansImagesBlobs.UpdateHeadshot35(newBlob35, key);

                var newBlob25 = ImageManager.GetResizedImageBlobAsJpg(image, 25, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot25\" + key + ".jpg", newBlob25);
                PoliticiansImagesBlobs.UpdateHeadshot25(newBlob25, key);

                var newBlob20 = ImageManager.GetResizedImageBlobAsJpg(image, 20, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot20\" + key + ".jpg", newBlob20);
                PoliticiansImagesBlobs.UpdateHeadshot20(newBlob20, key);

                var newBlob15 = ImageManager.GetResizedImageBlobAsJpg(image, 15, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot15\" + key + ".jpg", newBlob15);
                PoliticiansImagesBlobs.UpdateHeadshot15(newBlob15, key);

                AppendStatusText("processed: {0}", key);
            }
            else
            {
                AppendStatusText("no original: {0}", key);
            }
        }
Ejemplo n.º 2
0
        protected void ButtonUploadPicture_ServerClick(object sender, EventArgs e)
        {
            try
            {
                var postedFile    = Request.Files[ImageFile.Name];
                var politicianKey = LabelPoliticianKey.Text;
                var uploadTime    = DateTime.UtcNow;

                if ((postedFile == null) || (postedFile.ContentLength == 0) ||
                    string.IsNullOrEmpty(politicianKey))
                {
                    return;
                }
                Size originalSize;
                ImageManager.UpdateAllPoliticianHeadshotImages(politicianKey,
                                                               postedFile.InputStream, uploadTime, out originalSize);
                CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                             politicianKey);

                var memoryStream = new MemoryStream();
                postedFile.InputStream.Position = 0;
                postedFile.InputStream.CopyTo(memoryStream);
                postedFile.InputStream.Position = 0;
                var imageBlob = memoryStream.ToArray();
                LogPoliticiansImagesHeadshot.Insert(politicianKey, imageBlob, uploadTime,
                                                    UserSecurityClass, UserName, 0);

                MarkProcessed();
                UpdateRowCountAfterChange();

                Msg.Text =
                    Ok("The headshot image for ID " + politicianKey + " was uploaded.");
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }