public AddObject ( Stream inputStream, long bytes, string bucketName, string key ) : void | ||
inputStream | Stream | |
bytes | long | |
bucketName | string | |
key | string | |
Результат | void |
internal string CropResizeAndUpload(int height, int width, HttpPostedFileBase file) { if (file == null || !Utilities.IsImageFile(file.FileName)) return null; var bitmapImage = new Bitmap(file.InputStream); const CannedAcl acl = CannedAcl.PublicRead; var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; Image fullPhoto = bitmapImage; string fileNameFull = Utilities.CreateUniqueContentFilename(file); fullPhoto = ImageResize.Crop(fullPhoto, height, width, ImageResize.AnchorPosition.Center); Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); return fileNameFull; }
public ActionResult EditPhoto(HttpPostedFileBase file) { mu = Membership.GetUser(); UserPhoto up1 = null; int swapID = 0; var acl = CannedAcl.PublicRead; S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (Request.Form["new_default"] != null && int.TryParse(Request.Form["new_default"], out swapID)) { // swap the default with the new default uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); string currentDefaultMain = uad.ProfilePicURL; string currentDefaultMainThumb = uad.ProfileThumbPicURL; up1 = new UserPhoto(swapID); uad.ProfilePicURL = up1.PicURL; uad.ProfileThumbPicURL = up1.ThumbPicURL; uad.LastPhotoUpdate = DateTime.UtcNow; uad.Update(); up1.PicURL = currentDefaultMain; up1.ThumbPicURL = currentDefaultMainThumb; up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Update(); LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); return View(uad); } string photoOne = "photo_edit_1"; string photoTwo = "photo_edit_2"; string photoThree = "photo_edit_3"; LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); if (file == null) { ViewBag.IsValid = false; ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.NoFile); return View(uad); } string photoEdited = Request.Form["photo_edit"]; string mainPhotoToDelete = string.Empty; string thumbPhotoToDelete = string.Empty; ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); if (string.IsNullOrEmpty(uad.ProfilePicURL) || ups.Count == 2 && photoEdited == photoOne) { mainPhotoToDelete = uad.ProfilePicURL; thumbPhotoToDelete = uad.ProfileThumbPicURL; } else { if (ups.Count > 1 && photoEdited == photoTwo) { up1 = new UserPhoto(ups[0].UserPhotoID); up1.RankOrder = 1; mainPhotoToDelete = up1.PicURL; thumbPhotoToDelete = up1.ThumbPicURL; } else if (ups.Count > 1 && photoEdited == photoThree) { up1 = new UserPhoto(ups[1].UserPhotoID); up1.RankOrder = 2; mainPhotoToDelete = ups[1].FullProfilePicURL; thumbPhotoToDelete = up1.ThumbPicURL; } } if (!string.IsNullOrEmpty(mainPhotoToDelete)) { // delete the existing photos try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete); } } catch { // whatever } } Bitmap b = new Bitmap(file.InputStream); // full System.Drawing.Image fullPhoto = (System.Drawing.Image)b; fullPhoto = ImageResize.FixedSize(fullPhoto, 300, 300, System.Drawing.Color.Black); string fileNameFull = Utilities.CreateUniqueContentFilename(file); Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) || ups.Count == 2 && photoEdited == photoOne) { uad.ProfilePicURL = fileNameFull; } else { if (up1 == null) { up1 = new UserPhoto(); } up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); up1.PicURL = fileNameFull; if ((ups.Count > 0 && photoEdited == photoTwo) || (ups.Count == 0)) { up1.RankOrder = 1; } else if ((ups.Count > 1 && photoEdited == photoThree) || ups.Count == 1) { up1.RankOrder = 2; } if (ups.Count == 1 && ups[0].RankOrder == 2) { ups[0].RankOrder = 1; ups[0].Update(); } } fullPhoto = (System.Drawing.Image)b; fullPhoto = ImageResize.FixedSize(fullPhoto, 75, 75, System.Drawing.Color.Black); fileNameFull = Utilities.CreateUniqueContentFilename(file); maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); //// thumb if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) || ups.Count == 2 && photoEdited == photoOne) { uad.ProfileThumbPicURL = fileNameFull; uad.LastPhotoUpdate = DateTime.UtcNow; uad.Set(); } else { up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); up1.ThumbPicURL = fileNameFull; if ( (ups.Count == 0 && photoEdited == photoTwo) || (ups.Count > 0 && photoEdited == photoTwo) ) { up1.RankOrder = 1; } else if ( (ups.Count == 0 && photoEdited == photoThree) || (ups.Count > 1 && photoEdited == photoThree) ) { up1.RankOrder = 2; } } b.Dispose(); if (up1 != null && up1.UserPhotoID == 0) { up1.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Create(); } else if (up1 != null && up1.UserPhotoID > 0) { up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Update(); } LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); return View(uad); }
public ActionResult EditArticle( FormCollection fc, int? contentID, HttpPostedFileBase imageFile, HttpPostedFileBase videoFile, HttpPostedFileBase videoFile2) { mu = Membership.GetUser(); var model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content(); if (contentID != null && contentID > 0) { model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content( Convert.ToInt32(contentID)); } TryUpdateModel(model); ////// begin: amazon var acl = CannedAcl.PublicRead; S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (string.IsNullOrWhiteSpace(model.Detail) ) { ModelState.AddModelError(Messages.Required, Messages.Required + ": " + Messages.Details); } if (imageFile == null && string.IsNullOrWhiteSpace(model.ContentPhotoURL)) { ModelState.AddModelError(Messages.Required, Messages.Required + ": " + Messages.Photo); } if (ModelState.IsValid) { model.ContentKey = FromString.URLKey(model.Title); if (model.ContentID == 0) { mu = Membership.GetUser(); model.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); if (model.ReleaseDate == DateTime.MinValue) { model.ReleaseDate = DateTime.UtcNow; } } if (model.Set() <= 0) return View(model); if (imageFile != null) { Bitmap b = new Bitmap(imageFile.InputStream); System.Drawing.Image fullPhoto = (System.Drawing.Image)b; string fileNameFull = Utilities.CreateUniqueContentFilename(imageFile); System.Drawing.Image imgPhoto = ImageResize.FixedSize(b, 600, 400, System.Drawing.Color.Black); Stream maker = imgPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentPhotoURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL); } } model.ContentPhotoURL = fileNameFull; // resized string fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile); System.Drawing.Image imgPhotoThumb = ImageResize.FixedSize(b, 350, 250, System.Drawing.Color.Black); maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentPhotoThumbURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL); } } model.ContentPhotoThumbURL = fileNameThumb; model.Set(); } if (videoFile != null) { // full try { string fileName3 = Utilities.CreateUniqueContentFilename(videoFile); // full fileName3 = Utilities.CreateUniqueContentFilename(videoFile); s3.AddObject( videoFile.InputStream, videoFile.ContentLength, AmazonCloudConfigs.AmazonBucketName, fileName3, videoFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentVideoURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL); } } model.ContentVideoURL = fileName3; model.Set(); } catch { } } if (videoFile2 != null) { // full try { string fileName3 = Utilities.CreateUniqueContentFilename(videoFile2); // full fileName3 = Utilities.CreateUniqueContentFilename(videoFile2); s3.AddObject( videoFile2.InputStream, videoFile2.ContentLength, AmazonCloudConfigs.AmazonBucketName, fileName3, videoFile2.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentVideoURL2)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2); } } model.ContentVideoURL2 = fileName3; model.Set(); } catch { } } return RedirectToAction("Articles"); } else { return View(model); } }
public ActionResult RotateStatusImage(int statusUpdateID) { mu = Membership.GetUser(); StatusUpdate su = new StatusUpdate(statusUpdateID); if (su.PhotoItemID != null && su.PhotoItemID > 0) { var acl = CannedAcl.PublicRead; S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; PhotoItem pitm = new PhotoItem(Convert.ToInt32(su.PhotoItemID)); // full Image imgFull = DownloadImage(Utilities.S3ContentPath(pitm.FilePathRaw)); float angle = 90; Bitmap b = RotateImage(imgFull, angle); System.Drawing.Image fullPhoto = (System.Drawing.Image)b; string fileNameFull = Guid.NewGuid() + ".jpg"; Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, "image/jpg", acl); if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw); } pitm.FilePathRaw = fileNameFull; // resized System.Drawing.Image photoResized = (System.Drawing.Image)b; string fileNameResize = Guid.NewGuid() + ".jpg"; photoResized = ImageResize.FixedSize(photoResized, 500, 375, System.Drawing.Color.Black); maker = photoResized.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameResize, "image/jpg", acl); if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard); } pitm.FilePathStandard = fileNameResize; // thumb System.Drawing.Image thumbPhoto = (System.Drawing.Image)b; thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center); string fileNameThumb = Guid.NewGuid() + ".jpg"; maker = thumbPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, "image/jpg", acl); if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb); } pitm.FilePathThumb = fileNameThumb; pitm.Update(); } return RedirectToAction("statusupdate", new { @statusUpdateID = statusUpdateID }); }
public ActionResult Home(string message, HttpPostedFileBase file) { if (string.IsNullOrWhiteSpace(message) && file == null) { return RedirectToAction("Home"); } message = message.Trim(); mu = Membership.GetUser(); ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey)); //StatusUpdates sus = null; ViewBag.CurrentUser = ua.ToUnorderdListItem; StatusUpdate su = new StatusUpdate(); su.GetMostRecentUserStatus(ua.UserAccountID); DateTime startTime = Utilities.GetDataBaseTime(); TimeSpan span = startTime.Subtract(su.CreateDate); //su = new StatusUpdate(); // TODO: this is not working properly, preventing posts if (su.Message == message && file == null) { // double post return RedirectToAction("Home"); } else { su = new StatusUpdate(); } if (file != null && Utilities.IsImageFile(file.FileName)) { Bitmap b = new Bitmap(file.InputStream); var acl = CannedAcl.PublicRead; S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; PhotoItem pitem = new PhotoItem(); pitem.CreatedByUserID = ua.UserAccountID; pitem.Title = message; // full System.Drawing.Image fullPhoto = (System.Drawing.Image)b; string fileNameFull = Utilities.CreateUniqueContentFilename(file); Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); pitem.FilePathRaw = fileNameFull; // resized System.Drawing.Image photoResized = (System.Drawing.Image)b; string fileNameResize = Utilities.CreateUniqueContentFilename(file); photoResized = ImageResize.FixedSize(photoResized, 500, 375, System.Drawing.Color.Black); maker = photoResized.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameResize, file.ContentType, acl); pitem.FilePathStandard = fileNameResize; // thumb System.Drawing.Image thumbPhoto = (System.Drawing.Image)b; thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center); string fileNameThumb = Utilities.CreateUniqueContentFilename(file); maker = thumbPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, file.ContentType, acl); pitem.FilePathThumb = fileNameThumb; pitem.Create(); su.PhotoItemID = pitem.PhotoItemID; } su.UserAccountID = ua.UserAccountID; su.Message = message; su.CreatedByUserID = ua.UserAccountID; su.IsMobile = Request.Browser.IsMobileDevice; su.Create(); if (Request.Browser.IsMobileDevice) { // this will bring them to the post return new RedirectResult(Url.Action("Home") + "#most_recent"); } else { // the menu prevents brining to post correctly return RedirectToAction("Home"); } }
public ActionResult EditArticle( FormCollection fc, int? contentID, HttpPostedFileBase imageFile, HttpPostedFileBase videoFile) { var model = new Content(); var articleExists = contentID != null && contentID > 0; if (articleExists) { model = new Content( Convert.ToInt32(contentID)); } TryUpdateModel(model); if (articleExists && Request.Form["approve_preview"] != null && Request.Form["approve_preview"] == "on") { ApprovedPreview(model); model.CurrentStatus = Convert.ToChar(SiteEnums.ContentStatus.A.ToString()); model.Set(); return RedirectToAction("Articles", "SiteAdmin"); } foreach (var itemLanguages in (SiteEnums.SiteLanguages[])Enum.GetValues(typeof(SiteEnums.SiteLanguages))) { HttpRuntime.Cache.DeleteCacheObj( string.Concat( Lib.BOL.UserContent.Content.Key, model.ContentKey, itemLanguages.ToString())); } const CannedAcl acl = CannedAcl.PublicRead; var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; if (string.IsNullOrWhiteSpace(model.Detail)) { ModelState.AddModelError(Messages.Required, Messages.Required + @": " + Messages.Details); } if (imageFile == null && string.IsNullOrWhiteSpace(model.ContentPhotoURL)) { ModelState.AddModelError(Messages.Required, Messages.Required + @": " + Messages.Photo); } if (!ModelState.IsValid) { return View("EditArticle" , model); } model.ContentKey = model.CurrentStatus != Convert.ToChar(SiteEnums.ContentStatus.A.ToString()) ? FromString.UrlKey(model.Title) : model.ContentKey; if (model.ContentID == 0) { if (_mu != null) { if (model.CreatedByUserID == 0) model.CreatedByUserID = Convert.ToInt32(_mu.ProviderUserKey); } if (model.ReleaseDate == DateTime.MinValue) { model.ReleaseDate = DateTime.UtcNow; } } if (model.Set() <= 0) { return View(model); } if (imageFile != null) { var b = new Bitmap(imageFile.InputStream); string fileNameFull = Utilities.CreateUniqueContentFilename(imageFile); Image imgPhoto = ImageResize.FixedSize(b, 600, 400, Color.Black); Stream maker = imgPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentPhotoURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoURL); } } model.ContentPhotoURL = fileNameFull; string fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile); Image imgPhotoThumb = ImageResize.FixedSize(b, 350, 250, Color.Black); maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentPhotoThumbURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentPhotoThumbURL); } } model.ContentPhotoThumbURL = fileNameThumb; model.Set(); } if (videoFile != null) { // full try { // full string fileName3 = Utilities.CreateUniqueContentFilename(videoFile); s3.AddObject( videoFile.InputStream, videoFile.ContentLength, AmazonCloudConfigs.AmazonBucketName, fileName3, videoFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.ContentVideoURL)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL); } } model.ContentVideoURL = fileName3; model.Set(); } catch { } } return RedirectToAction("Articles", "SiteAdmin"); // TODO: ENABLE SELF ARTICLE PAGE }
public ActionResult EditArticle( FormCollection fc, int? contentId, HttpPostedFileBase imageFile, HttpPostedFileBase videoFile) { var isExisting = contentId != null && contentId > 0; var model = new PreviewContentModel(); TryUpdateModel(model); if (!HasImage(imageFile, model, contentId) || !ModelState.IsValid || !HasValidTitle(model, contentId) || !IsContentCorrectLength(model) || !IsMetaDescriptionLengthCorrect(model)) { return View("CreateArticle", model); } Content content; if (isExisting) { content = new Content(Convert.ToInt32(contentId)) { UpdatedByUserID = Convert.ToInt32(_mu.ProviderUserKey) }; } else { content = new Content { CurrentStatus = Convert.ToChar(SiteEnums.ContentStatus.N.ToString()), CreatedByUserID = Convert.ToInt32(this._mu.ProviderUserKey), ReleaseDate = DateTime.UtcNow, ContentKey = FromString.UrlKey(model.PreviewTitle), }; } content.PreviewTitle = model.PreviewTitle.Trim(); content.DetailPreview = model.DetailPreview.Trim(); content.PreviewLanguage = model.PreviewLanguage.Trim(); content.PreviewMetaDescription = model.PreviewMetaDescription.Trim(); content.PreviewMetaKeywords = model.PreviewMetaKeywords.Trim(); if (imageFile != null && imageFile.InputStream != null) { // set images const CannedAcl acl = CannedAcl.PublicRead; var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; var bitmap = new Bitmap(imageFile.InputStream); var fileNameFull = Utilities.CreateUniqueContentFilename(imageFile); var imgPhoto = ImageResize.FixedSize(bitmap, 600, 400, Color.Black); var maker = imgPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.PreviewContentPhotoUrl)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoUrl); } } content.PreviewContentPhotoURL = fileNameFull; var fileNameThumb = Utilities.CreateUniqueContentFilename(imageFile); var imgPhotoThumb = ImageResize.FixedSize(bitmap, 350, 250, Color.Black); maker = imgPhotoThumb.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, imageFile.ContentType, acl); if (!string.IsNullOrWhiteSpace(model.PreviewContentPhotoThumbUrl)) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoThumbUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.PreviewContentPhotoThumbUrl); } } content.PreviewContentPhotoThumbURL = fileNameThumb; } content.Set(); return RedirectToAction("Preview", new {key= content.ContentKey }); }
public ActionResult Home(string message, HttpPostedFileBase file) { if (string.IsNullOrWhiteSpace(message) && file == null) { return RedirectToAction("Home"); } if (message != null) message = message.Trim(); if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey)); if (_ua.UserAccountID == 18136) { // check if over posting user can take a hint to stop var lastUpdate = new StatusUpdate(); lastUpdate.GetMostRecentUserStatus(_ua.UserAccountID); if (lastUpdate.CreateDate > DateTime.UtcNow.AddHours(-24)) { TempData["user_error"] = "Please STOP posting so much, you are only allowed to post once ever 24 hours! Thank you for keeping the wall clean."; return RedirectToAction("Home"); } } ViewBag.CurrentUser = _ua.ToUnorderdListItem; var su = new StatusUpdate(); su.GetMostRecentUserStatus(_ua.UserAccountID); DateTime startTime = DateTime.UtcNow; TimeSpan span = startTime.Subtract(su.CreateDate); // TODO: this is not working properly, preventing posts if (su.Message == message && file == null) { // double post return RedirectToAction("Home"); } su = new StatusUpdate(); if (file != null && Utilities.IsImageFile(file.FileName)) { var b = new Bitmap(file.InputStream); const CannedAcl acl = CannedAcl.PublicRead; var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; var pitem = new PhotoItem {CreatedByUserID = _ua.UserAccountID, Title = message}; Image fullPhoto = b; string fileNameFull = Utilities.CreateUniqueContentFilename(file); Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); pitem.FilePathRaw = fileNameFull; // resized Image photoResized = b; string fileNameResize = Utilities.CreateUniqueContentFilename(file); photoResized = ImageResize.FixedSize(photoResized, 500, 375, Color.Black); maker = photoResized.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameResize, file.ContentType, acl); pitem.FilePathStandard = fileNameResize; // thumb Image thumbPhoto = b; thumbPhoto = ImageResize.Crop(thumbPhoto, 150, 150, ImageResize.AnchorPosition.Center); string fileNameThumb = Utilities.CreateUniqueContentFilename(file); maker = thumbPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameThumb, file.ContentType, acl); pitem.FilePathThumb = fileNameThumb; pitem.Create(); su.PhotoItemID = pitem.PhotoItemID; } su.UserAccountID = _ua.UserAccountID; su.Message = message; su.CreatedByUserID = _ua.UserAccountID; su.IsMobile = Request.Browser.IsMobileDevice; su.Create(); if (Request.Browser.IsMobileDevice) { return new RedirectResult(Url.Action("Home") + "#most_recent"); } return RedirectToAction("Home"); }
private static string AddPhotoToBucket( HttpPostedFileBase file, CannedAcl acl, S3Service s3, Bitmap photoBitmap, bool resize, int width = 1, int height = 1) { string profilePhotoFileName = Utilities.CreateUniqueContentFilename(file); Image rawPhoto = photoBitmap; if (resize) { Image image = ImageResize.FixedSize(imgPhoto: rawPhoto, width: width, height: height, bgColor: Color.Black); Stream profilePhotoStream = image.ToAStream(ImageFormat.Jpeg); s3.AddObject( profilePhotoStream, profilePhotoStream.Length, AmazonCloudConfigs.AmazonBucketName, profilePhotoFileName, file.ContentType, acl); } else { Stream image = rawPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( image, image.Length, AmazonCloudConfigs.AmazonBucketName, profilePhotoFileName, file.ContentType, acl); } return profilePhotoFileName; }
public Program() { var usingTrustedConnection = string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(Password); var sourceConnection = usingTrustedConnection ? new ServerConnection(ServerName) { LoginSecure = true } : new ServerConnection(ServerName, Username, Password); var sqlServer = new Server(sourceConnection); if(sqlServer != null){ var backup = new Backup(); var dbc = sqlServer.Databases; if (dbc.Contains(DatabaseName)) { backup.Action = BackupActionType.Database; backup.Database = DatabaseName; var dateFilename = DateTime.UtcNow.ToString("dd-MMM-yyyy"); var tempFilename = String.Format("{0}-{1}.bak", DatabaseName, dateFilename); var tempBackupPath = String.Format("{0}{1}", TempFilePath, tempFilename); //remove old backups from this local temp location foreach (var file in Directory.GetFiles(TempFilePath)) { if (file != tempBackupPath) { Console.WriteLine("Removing previous temp backup " + file); File.Delete(file); } } try { var backupDevice = new BackupDeviceItem(tempBackupPath, DeviceType.File); backup.Devices.Add(backupDevice); backup.Checksum = true; backup.ContinueAfterError = false; backup.LogTruncation = BackupTruncateLogType.Truncate; //if file exists then do an incremental, otherwise do a full if (File.Exists(tempBackupPath)) { backup.Incremental = true; } else { backup.Incremental = false; } // Perform backup. backup.SqlBackup(sqlServer); //now move the backup to S3 - overwriting anything that is there with the same name var s3 = new S3Service { AccessKeyID = AccessKeyID, SecretAccessKey = SecretAccessKey }; var bucket = Bucket; s3.AddObject(tempBackupPath, bucket, tempFilename); var metadataOnly = true; foreach(var listEntry in s3.ListObjects(Bucket,"")) { var request = new GetObjectRequest(s3, Bucket, listEntry.Name, metadataOnly); using (var response = request.GetResponse()) { if (response.LastModified < DateTime.UtcNow.AddDays(DaysToKeepS3BackupFor * -1)) { Console.WriteLine("Going to delete old archive " + listEntry.Name); s3.DeleteObject(Bucket,listEntry.Name); } } } Console.Out.WriteLine("Backup to S3 is complete"); System.Threading.Thread.Sleep(10000); } catch(Exception ee) { Console.Out.WriteLine("Exception occurred - do not continue. Wait until next run to try again "+ee.ToString()); System.Threading.Thread.Sleep(10000); } } } }