public ActionResult Delete(int photoItemID) { _mu = MembershipWrapper.GetUser(); _pitm = new PhotoItem(photoItemID); if (_mu == null || _pitm.CreatedByUserID != Convert.ToInt32(_mu.ProviderUserKey)) return RedirectToAction("Index"); var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; _pitm.Delete(); if (string.IsNullOrEmpty(_pitm.FilePathStandard)) return RedirectToAction("Index"); // delete the existing photos try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathStandard)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathStandard); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathRaw)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathRaw); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathThumb)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _pitm.FilePathThumb); } } catch { // whatever } return RedirectToAction("Index"); }
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 DeleteVideo(int? id) { var model = new BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content(Convert.ToInt32(id)); S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (!string.IsNullOrWhiteSpace(model.ContentVideoURL) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL); model.ContentVideoURL = string.Empty; model.Set(); } if (!string.IsNullOrWhiteSpace(model.ContentVideoURL2) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, model.ContentVideoURL2); model.ContentVideoURL2 = string.Empty; model.Set(); } return RedirectToAction("EditArticle", new { @id = model.ContentID }); }
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 EditPhotoDelete() { string str = Request.Form["delete_photo"]; mu = Membership.GetUser(); uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (str == "1") { try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL); } } catch { // whatever } uad.ProfileThumbPicURL = string.Empty; uad.ProfilePicURL = string.Empty; uad.Update(); } else if (str == "2" || str == "3") { ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); foreach (UserPhoto up1 in ups) { try { if ((up1.RankOrder == 1 && str == "2") || (up1.RankOrder == 2 && str == "3")) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL); } up1.Delete(); } } catch { // whatever } } // update ranking ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); if (ups.Count == 1 && ups[0].RankOrder == 2) { ups[0].RankOrder = 1; ups[0].Update(); } } Response.Redirect("~/account/editphoto"); return new EmptyResult(); }
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 EditPhotoDelete() { string str = Request.Form["delete_photo"]; _uad = new UserAccountDetail(); if (_mu != null) _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey)); var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; switch (str) { case "1": try { if (!string.IsNullOrWhiteSpace(_uad.RawProfilePicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL); } } catch { // whatever } // set to blank the profile images that were deleted _uad.RawProfilePicUrl = string.Empty; _uad.ProfileThumbPicURL = string.Empty; _uad.ProfilePicURL = string.Empty; _uad.Update(); break; case "3": case "2": _ups = new UserPhotos(); _ups.GetUserPhotos(_uad.UserAccountID); foreach (UserPhoto up1 in _ups) { try { if ((up1.RankOrder != 1 || str != "2") && (up1.RankOrder != 2 || str != "3")) continue; if (!string.IsNullOrWhiteSpace(up1.RawPicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL); } up1.Delete(); } catch { // whatever } } _ups = new UserPhotos(); _ups.GetUserPhotos(_uad.UserAccountID); if (_ups.Count == 1 && _ups[0].RankOrder == 2) { _ups[0].RankOrder = 1; _ups[0].Update(); } break; } return RedirectToAction("EditPhoto"); }
private static void DeletePhotos(S3Service s3, string rawPhotoToDelete, string mainPhotoToDelete, string thumbPhotoToDelete) { // delete the existing photos try { if (!string.IsNullOrWhiteSpace(mainPhotoToDelete) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, rawPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, rawPhotoToDelete); } } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { // whatever } }
public void ProcessRequest(HttpContext context) { if (string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()])) return; var ptyc = (SiteEnums.QueryStringNames) Enum.Parse(typeof (SiteEnums.QueryStringNames), context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()]); MembershipUser mu; switch (ptyc) { case SiteEnums.QueryStringNames.status_update: #region status_update string key = context.Request.QueryString[SiteEnums.QueryStringNames.status_update_id.ToString()]; if (string.IsNullOrEmpty(key)) { key = context.Request.QueryString[ SiteEnums.QueryStringNames.most_applauded_status_update_id.ToString()]; } int statusUpdateID = Convert.ToInt32(key); StatusUpdate statup; if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()])) { mu = MembershipWrapper.GetUser(); if (mu == null) return; var ack = new Acknowledgement { CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey), UserAccountID = Convert.ToInt32(mu.ProviderUserKey), AcknowledgementType = Convert.ToChar( context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]), StatusUpdateID = statusUpdateID }; statup = new StatusUpdate(statusUpdateID); if (!Acknowledgement.IsUserAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey))) { ack.Create(); var sun = new StatusUpdateNotification(); if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.A); } if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID) { sun.UserAccountID = statup.UserAccountID; SiteEnums.ResponseType rspType; if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { rspType = SiteEnums.ResponseType.A; sun.ResponseType = Convert.ToChar(rspType.ToString()); } else { rspType = SiteEnums.ResponseType.B; sun.ResponseType = Convert.ToChar(rspType.ToString()); } sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); if (sun.StatusUpdateNotificationID == 0) { sun.IsRead = false; sun.Create(); } else { sun.IsRead = false; sun.Update(); } SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey), rspType, sun.StatusUpdateID); } context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode(statup.StatusAcknowledgements))); } else { // reverse ack.GetAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)); ack.Delete(); // TODO: DELETE NOTIFICATION context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode(statup.StatusAcknowledgements))); } } else if ( !string.IsNullOrEmpty( context.Request.QueryString[ SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()])) { mu = MembershipWrapper.GetUser(); if (mu == null) return; var ack = new StatusCommentAcknowledgement { CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey), UserAccountID = Convert.ToInt32(mu.ProviderUserKey), AcknowledgementType = Convert.ToChar( context.Request.QueryString[ SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]), StatusCommentID = statusUpdateID }; var statcomup = new StatusComment(statusUpdateID); statup = new StatusUpdate(statcomup.StatusUpdateID); if (!StatusCommentAcknowledgement.IsUserCommentAcknowledgement(statcomup.StatusCommentID, Convert.ToInt32( mu.ProviderUserKey))) { ack.Create(); var sun = new StatusUpdateNotification(); sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID, statcomup.StatusUpdateID, ack.AcknowledgementType == Convert.ToChar( SiteEnums.ResponseType.A.ToString()) ? SiteEnums.ResponseType.A : SiteEnums.ResponseType.B); if (Convert.ToInt32(mu.ProviderUserKey) != statcomup.UserAccountID) { sun.UserAccountID = statcomup.UserAccountID; SiteEnums.ResponseType rspType; if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { rspType = SiteEnums.ResponseType.A; sun.ResponseType = Convert.ToChar(rspType.ToString()); } else { rspType = SiteEnums.ResponseType.B; sun.ResponseType = Convert.ToChar(rspType.ToString()); } if (sun.StatusUpdateNotificationID == 0) { sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.Create(); } else { sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.Update(); } SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey), rspType, sun.StatusUpdateID); } context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode( statcomup.StatusCommentAcknowledgementsOptions))); } else { // reverse ack.GetCommentAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)); ack.Delete(); // TODO: DELETE NOTIFICATION context.Response.Write(string.Format(@"{{""StatusAcks"": ""{0}""}}", HttpUtility.HtmlEncode( statcomup.StatusCommentAcknowledgementsOptions))); } } else if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) && !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) ) { mu = MembershipWrapper.GetUser(); if (mu == null) return; var statCom = new StatusComment { CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey), Message = HttpUtility.HtmlEncode( context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]), StatusUpdateID = statusUpdateID, UserAccountID = Convert.ToInt32(mu.ProviderUserKey) }; // TODO: CHECK IF THERE IS A RECENT MESSAGE THAT IS THE SAME if (statCom.StatusCommentID != 0) return; //BUG: THERE IS AN EVENT HANDLER THAT HAS QUEUED UP TOO MANY var suLast = new StatusUpdate(); suLast.GetMostRecentUserStatus(Convert.ToInt32(mu.ProviderUserKey)); if (suLast.Message.Trim() != statCom.Message.Trim() || (suLast.Message.Trim() == statCom.Message.Trim() && suLast.StatusUpdateID != statCom.StatusUpdateID)) { statCom.Create(); } statup = new StatusUpdate(statusUpdateID); // create a status update notification for the post maker and all commenters StatusUpdateNotification sun; if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID) { sun = new StatusUpdateNotification(); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C); if (sun.StatusUpdateNotificationID == 0) { sun.ResponseType = Convert.ToChar(SiteEnums.ResponseType.C.ToString()); sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.StatusUpdateID = statup.StatusUpdateID; sun.UserAccountID = statup.UserAccountID; sun.Create(); } else { sun.IsRead = false; sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.Update(); } SendNotificationEmail(statup.UserAccountID, Convert.ToInt32(mu.ProviderUserKey), SiteEnums.ResponseType.C, sun.StatusUpdateID); } var statComs = new StatusComments(); statComs.GetAllStatusCommentsForUpdate(statusUpdateID); foreach (StatusComment sc1 in statComs) { sun = new StatusUpdateNotification(); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C); if (Convert.ToInt32(mu.ProviderUserKey) == sc1.UserAccountID || Convert.ToInt32(mu.ProviderUserKey) == statup.UserAccountID) continue; if (sun.StatusUpdateNotificationID == 0) { sun.IsRead = false; sun.StatusUpdateID = statusUpdateID; sun.UserAccountID = sc1.UserAccountID; sun.Create(); } else { sun.IsRead = false; sun.Update(); } } context.Response.Write(@"{""StatusAcks"": """ + @"""}"); } else if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) && context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "P" ) { // delete post statup = new StatusUpdate(statusUpdateID); StatusUpdateNotifications.DeleteNotificationsForStatusUpdate(statup.StatusUpdateID); Acknowledgements.DeleteStatusAcknowledgements(statup.StatusUpdateID); var statComs = new StatusComments(); statComs.GetAllStatusCommentsForUpdate(statup.StatusUpdateID); foreach (StatusComment sc1 in statComs) { StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements( sc1.StatusCommentID); } StatusComments.DeleteStatusComments(statup.StatusUpdateID); statup.Delete(); if (statup.PhotoItemID != null) { var pitm = new PhotoItem(Convert.ToInt32(statup.PhotoItemID)); var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb); } pitm.Delete(); } context.Response.Write(@"{""StatusAcks"": """ + @"""}"); } else if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) && context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "C" ) { // delete comment var statCom = new StatusComment( Convert.ToInt32( context.Request.QueryString[ SiteEnums.QueryStringNames.status_com_id.ToString()])); StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements( statCom.StatusCommentID); statCom.Delete(); context.Response.Write(string.Format(@"{{""StatusUpdateID"": ""{0}""}}", statCom.StatusUpdateID)); } else if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.all_comments.ToString()])) { mu = MembershipWrapper.GetUser(); if (mu == null) return; var preFilter = new StatusComments(); preFilter.GetAllStatusCommentsForUpdate(statusUpdateID); var statComs = new StatusComments(); statComs.AddRange( preFilter.Where( su1 => !BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID))); statComs.IncludeStartAndEndTags = true; var sb = new StringBuilder(100); sb.Append(statComs.ToUnorderdList); context.Response.Write(string.Format(@"{{""StatusComs"": ""{0}""}}", HttpUtility.HtmlEncode(sb.ToString()))); } else if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()])) { int pcount = Convert.ToInt32( context.Request.QueryString[ SiteEnums.QueryStringNames.comment_page.ToString()]); var statups = new StatusUpdates(); pcount = pcount + 10; var preFilter = new StatusUpdates(); preFilter.GetStatusUpdatesPageWise(pcount, 1); mu = MembershipWrapper.GetUser(); statups.AddRange( preFilter.Where( su1 => mu != null && !BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID))); statups.IncludeStartAndEndTags = false; context.Response.Write(string.Format(@"{{""StatusUpdates"": ""{0}""}}", HttpUtility.HtmlEncode(statups.ToUnorderdList))); } #endregion break; case SiteEnums.QueryStringNames.begin_playlist: #region begin_playlist context.Response.Write( PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[ SiteEnums.QueryStringNames.playlist.ToString()]))); #endregion break; case SiteEnums.QueryStringNames.menu: #region menu mu = MembershipWrapper.GetUser(); int userCountChat = 0; int userMessages = 0; int unconfirmedUsers = 0; int notifications = 0; if (mu != null) { // log off users who are offline var uasOffline = new UserAccounts(); uasOffline.GetWhoIsOffline(true); foreach (UserAccount uaoff1 in uasOffline) { var cru = new ChatRoomUser(); cru.GetChatRoomUserByUserAccountID(uaoff1.UserAccountID); if (cru.ChatRoomUserID > 0) { cru.DeleteChatRoomUser(); } var offlineUser = new UserAccount(uaoff1.UserAccountID); offlineUser.RemoveCache(); } userCountChat = ChatRoomUsers.GetChattingUserCount(); userMessages = DirectMessages.GetDirectMessagesToUserCount(mu); unconfirmedUsers = UserConnections.GetCountUnconfirmedConnections(Convert.ToInt32(mu.ProviderUserKey)); } // get users online int onlineUsers = UserAccounts.GetOnlineUserCount(); if (mu != null) { notifications = StatusUpdateNotifications.GetStatusUpdateNotificationCountForUser( Convert.ToInt32(mu.ProviderUserKey)); } string timedMessge = string.Format( @"{{""UserCountChat"": ""{0}"", ""UserMessages"": ""{1}"", ""OnlineUsers"": ""{2}"", ""Notifications"": ""{3}"", ""UnconfirmedUsers"": ""{4}""}}", userCountChat, userMessages, onlineUsers, notifications, unconfirmedUsers); context.Response.Write(timedMessge); #endregion break; case SiteEnums.QueryStringNames.random: #region random if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write(Video.GetRandomJSON( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else { context.Response.Write(Video.GetRandomJSON()); } #endregion break; case SiteEnums.QueryStringNames.video_playlist: #region video_playlist if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write( PlaylistVideo.GetNextVideo( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]), context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()])) { context.Response.Write( PlaylistVideo.GetFirstVideo( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]))); } else { context.Response.Write( PlaylistVideo.CurrentVideoInPlaylist( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]) )); } #endregion break; case SiteEnums.QueryStringNames.video: #region video var vid = new Video("YT", context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]); VideoLog.AddVideoLog(vid.VideoID, context.Request.UserHostAddress); context.Response.Write( Video.GetVideoJSON(context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()])); #endregion break; case SiteEnums.QueryStringNames.playlist: #region playlist if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write( PlaylistVideo.GetNextVideo( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]), context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else if ( !string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()])) { context.Response.Write( PlaylistVideo.GetFirstVideo( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]))); } else { context.Response.Write( PlaylistVideo.CurrentVideoInPlaylist( Convert.ToInt32( context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]) )); } #endregion break; } }
public ActionResult Delete(int photoItemID) { mu = Membership.GetUser(); pitm = new PhotoItem(photoItemID); if (pitm.CreatedByUserID == Convert.ToInt32(mu.ProviderUserKey)) { S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; pitm.Delete(); if (!string.IsNullOrEmpty(pitm.FilePathStandard)) { // delete the existing photos try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb); } } catch { // whatever } } } return RedirectToAction("Index"); }
public void ProcessRequest(HttpContext context) { // context.Response.ContentType = "text/plain"; // context.Response.CacheControl = "no-cache"; // context.Response.AddHeader("Pragma", "no-cache"); // //context.Response.AddHeader("Pragma", "no-store"); // //context.Response.AddHeader("cache-control", "no-cache"); //context.Response.Cache.SetCacheability(HttpCacheability.NoCache); // context.Response.Cache.SetNoServerCaching(); if (string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()])) return; SiteEnums.QueryStringNames ptyc = (SiteEnums.QueryStringNames)Enum.Parse(typeof(SiteEnums.QueryStringNames), context.Request.QueryString[SiteEnums.QueryStringNames.param_type.ToString()]); // Dictionary<string, Subgurim.Chat.Usuario> usrrs = null; StringBuilder sb = null; MembershipUser mu = null; switch (ptyc) { case SiteEnums.QueryStringNames.status_update: #region status_update string key = context.Request.QueryString[SiteEnums.QueryStringNames.status_update_id.ToString()]; if (string.IsNullOrEmpty(key)) { key = context.Request.QueryString[SiteEnums.QueryStringNames.most_applauded_status_update_id.ToString()]; } int statusUpdateID = Convert.ToInt32(key); StatusUpdate statup = null; if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()])) { mu = Membership.GetUser(); Acknowledgement ack = new Acknowledgement(); ack.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); ack.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); ack.AcknowledgementType = Convert.ToChar(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_rsp.ToString()]); ack.StatusUpdateID = statusUpdateID; statup = new StatusUpdate(statusUpdateID); if (!Acknowledgement.IsUserAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey))) { ack.Create(); StatusUpdateNotification sun = new StatusUpdateNotification(); if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { // sun.GetStatusUpdateNotificationForUserStatus(Convert.ToInt32(mu.ProviderUserKey), statusUpdateID, SiteEnums.ResponseType.A); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.A); } else if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.B.ToString())) { //sun.GetStatusUpdateNotificationForUserStatus(Convert.ToInt32(mu.ProviderUserKey), statusUpdateID, SiteEnums.ResponseType.B); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.B); } if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID) { sun.UserAccountID = statup.UserAccountID; SiteEnums.ResponseType rspType = SiteEnums.ResponseType.U; if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { rspType = SiteEnums.ResponseType.A; sun.ResponseType = Convert.ToChar(rspType.ToString()); } else { rspType = SiteEnums.ResponseType.B; sun.ResponseType = Convert.ToChar(rspType.ToString()); } sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); if (sun.StatusUpdateNotificationID == 0) { sun.IsRead = false; sun.Create(); } else { sun.IsRead = false; sun.Update(); } SendNotificationEmail(statup.UserAccountID, rspType, sun.StatusUpdateID); } context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statup.StatusAcknowledgements) + @"""}"); } else { // reverse ack.GetAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)); ack.Delete(); // TODO: DELETE NOTIFICATION context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statup.StatusAcknowledgements) + @"""}"); } } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()])) { mu = Membership.GetUser(); StatusCommentAcknowledgement ack = new StatusCommentAcknowledgement(); ack.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); ack.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); ack.AcknowledgementType = Convert.ToChar(context.Request.QueryString[SiteEnums.QueryStringNames.stat_update_comment_rsp.ToString()]); ack.StatusCommentID = statusUpdateID; // this is really the commentID (or should be) StatusComment statcomup = new StatusComment(statusUpdateID); statup = new StatusUpdate(statcomup.StatusUpdateID); if (!StatusCommentAcknowledgement.IsUserCommentAcknowledgement(statcomup.StatusCommentID, Convert.ToInt32(mu.ProviderUserKey))) { ack.Create(); StatusUpdateNotification sun = new StatusUpdateNotification(); if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID, statcomup.StatusUpdateID, SiteEnums.ResponseType.A); } else { sun.GetStatusUpdateNotificationForUserStatus(statcomup.UserAccountID, statcomup.StatusUpdateID, SiteEnums.ResponseType.B); } if (Convert.ToInt32(mu.ProviderUserKey) != statcomup.UserAccountID) { sun.UserAccountID = statcomup.UserAccountID; SiteEnums.ResponseType rspType = SiteEnums.ResponseType.U; if (ack.AcknowledgementType == Convert.ToChar(SiteEnums.ResponseType.A.ToString())) { rspType = SiteEnums.ResponseType.A; sun.ResponseType = Convert.ToChar(rspType.ToString()); } else { rspType = SiteEnums.ResponseType.B; sun.ResponseType = Convert.ToChar(rspType.ToString()); } if (sun.StatusUpdateNotificationID == 0) { sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.Create(); } else { sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.Update(); } SendNotificationEmail(statup.UserAccountID, rspType, sun.StatusUpdateID); } context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statcomup.StatusCommentAcknowledgementsOptions) + @"""}"); } else { // reverse ack.GetCommentAcknowledgement(statusUpdateID, Convert.ToInt32(mu.ProviderUserKey)); ack.Delete(); // TODO: DELETE NOTIFICATION context.Response.Write(@"{""StatusAcks"": """ + HttpUtility.HtmlEncode(statcomup.StatusCommentAcknowledgementsOptions) + @"""}"); } } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) && !string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]) ) { mu = Membership.GetUser(); if (mu == null) return; StatusComment statCom = new StatusComment(); statCom.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); statCom.Message = HttpUtility.HtmlEncode(context.Request.QueryString[SiteEnums.QueryStringNames.comment_msg.ToString()]); statCom.StatusUpdateID = statusUpdateID; statCom.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); //statCom.GetStatusCommentMessage(); // ? ignore this duplicate now // TODO: CHECK IF THERE IS A RECENT MESSAGE THAT IS THE SAME if (statCom.StatusCommentID == 0) { //BUG: THERE IS AN EVENT HANDLER THAT HAS QUEUED UP TOO MANY StatusUpdate suLast = new StatusUpdate(); suLast.GetMostRecentUserStatus(Convert.ToInt32(mu.ProviderUserKey)); if (suLast.Message.Trim() != statCom.Message.Trim() || (suLast.Message.Trim() == statCom.Message.Trim() && suLast.StatusUpdateID != statCom.StatusUpdateID)) { statCom.Create(); } statup = new StatusUpdate(statusUpdateID); // create a status update notification for the post maker and all commenters StatusUpdateNotification sun = null; if (Convert.ToInt32(mu.ProviderUserKey) != statup.UserAccountID) { sun = new StatusUpdateNotification(); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C); if (sun.StatusUpdateNotificationID == 0) { sun.ResponseType = Convert.ToChar(SiteEnums.ResponseType.C.ToString()); sun.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.IsRead = false; sun.StatusUpdateID = statup.StatusUpdateID; sun.UserAccountID = statup.UserAccountID; sun.Create(); } else { sun.IsRead = false; sun.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); sun.Update(); } SendNotificationEmail(statup.UserAccountID, SiteEnums.ResponseType.C, sun.StatusUpdateID); } StatusComments statComs = new StatusComments(); statComs.GetAllStatusCommentsForUpdate(statusUpdateID); foreach (StatusComment sc1 in statComs) { sun = new StatusUpdateNotification(); sun.GetStatusUpdateNotificationForUserStatus(statup.UserAccountID, statusUpdateID, SiteEnums.ResponseType.C); if (Convert.ToInt32(mu.ProviderUserKey) == sc1.UserAccountID || Convert.ToInt32(mu.ProviderUserKey) == statup.UserAccountID) continue; if (sun.StatusUpdateNotificationID == 0) { sun.IsRead = false; sun.StatusUpdateID = statusUpdateID; sun.UserAccountID = sc1.UserAccountID; sun.Create(); } else { sun.IsRead = false; sun.Update(); } } context.Response.Write(@"{""StatusAcks"": """ + @"""}"); } } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) && context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "P" ) { // delete post statup = new StatusUpdate(statusUpdateID); StatusUpdateNotifications.DeleteNotificationsForStatusUpdate(statup.StatusUpdateID); Acknowledgements.DeleteStatusAcknowledgements(statup.StatusUpdateID); StatusComments statComs = new StatusComments(); statComs.GetAllStatusCommentsForUpdate(statup.StatusUpdateID); foreach (StatusComment sc1 in statComs) { StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(sc1.StatusCommentID); } StatusComments.DeleteStatusComments(statup.StatusUpdateID); statup.Delete(); if (statup.PhotoItemID != null) { PhotoItem pitm = new PhotoItem(Convert.ToInt32(statup.PhotoItemID)); S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathRaw); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathStandard); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, pitm.FilePathThumb); } pitm.Delete(); } context.Response.Write(@"{""StatusAcks"": """ + @"""}"); } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()]) && context.Request.QueryString[SiteEnums.QueryStringNames.act_type.ToString()] == "C" ) { // delete comment StatusComment statCom = new StatusComment( Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.status_com_id.ToString()])); StatusCommentAcknowledgements.DeleteStatusCommentAcknowledgements(statCom.StatusCommentID); statCom.Delete(); context.Response.Write(@"{""StatusUpdateID"": """ + statCom.StatusUpdateID.ToString() + @"""}"); } else if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.all_comments.ToString()])) { mu = Membership.GetUser(); if (mu == null) return; StatusComments preFilter = new StatusComments(); preFilter.GetAllStatusCommentsForUpdate(statusUpdateID); StatusComments statComs = new StatusComments(); foreach (BootBaronLib.AppSpec.DasKlub.BOL.StatusComment su1 in preFilter) { if (!BootBaronLib.AppSpec.DasKlub.BOL.BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID)) { statComs.Add(su1); } } statComs.IncludeStartAndEndTags = true; sb = new StringBuilder(100); sb.Append(statComs.ToUnorderdList); context.Response.Write(@"{""StatusComs"": """ + HttpUtility.HtmlEncode(sb.ToString()) + @"""}"); } else if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()])) { int pcount = Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.comment_page.ToString()]); StatusUpdates statups = new StatusUpdates(); pcount = pcount + 10; StatusUpdates preFilter = new StatusUpdates(); preFilter.GetStatusUpdatesPageWise(pcount, 1); StatusUpdates sus = new StatusUpdates(); mu = Membership.GetUser(); foreach (BootBaronLib.AppSpec.DasKlub.BOL.StatusUpdate su1 in preFilter) { if (!BootBaronLib.AppSpec.DasKlub.BOL.BlockedUser.IsBlockingUser(Convert.ToInt32(mu.ProviderUserKey), su1.UserAccountID)) { statups.Add(su1); } } statups.IncludeStartAndEndTags = false; context.Response.Write(@"{""StatusUpdates"": """ + HttpUtility.HtmlEncode(statups.ToUnorderdList) + @"""}"); } #endregion break; case SiteEnums.QueryStringNames.begin_playlist: #region begin_playlist context.Response.Write( PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[ SiteEnums.QueryStringNames.playlist.ToString()]))); #endregion break; case SiteEnums.QueryStringNames.menu: #region menu mu = Membership.GetUser(); // menu updates // get count in video room int userCountChat = 0; // get new mail int userMessages = 0; // get new users int unconfirmedUsers = 0; // status notifications int notifications = 0; if (mu != null) { // log off users who are offline UserAccounts uasOffline = new UserAccounts(); uasOffline.GetWhoIsOffline(true); UserAccount offlineUser = null; foreach (UserAccount uaoff1 in uasOffline) { ChatRoomUser cru = new ChatRoomUser(); cru.GetChatRoomUserByUserAccountID(uaoff1.UserAccountID); if (cru.ChatRoomUserID > 0) { cru.DeleteChatRoomUser(); } offlineUser = new UserAccount(uaoff1.UserAccountID); offlineUser.RemoveCache(); } userCountChat = ChatRoomUsers.GetChattingUserCount(); userMessages = BootBaronLib.AppSpec.DasKlub.BOL.DirectMessages.GetDirectMessagesToUserCount(mu); unconfirmedUsers = BootBaronLib.AppSpec.DasKlub.BOL.UserConnections.GetCountUnconfirmedConnections(Convert.ToInt32(mu.ProviderUserKey)); } // get users online int onlineUsers = UserAccounts.GetOnlineUserCount(); if (mu != null) { notifications = StatusUpdateNotifications.GetStatusUpdateNotificationCountForUser(Convert.ToInt32(mu.ProviderUserKey)); } string timedMessge = string.Format( @"{{""UserCountChat"": ""{0}"", ""UserMessages"": ""{1}"", ""OnlineUsers"": ""{2}"", ""Notifications"": ""{3}"", ""UnconfirmedUsers"": ""{4}""}}",userCountChat,userMessages,onlineUsers,notifications,unconfirmedUsers); context.Response.Write(timedMessge); #endregion break; case SiteEnums.QueryStringNames.random: #region random if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write(Video.GetRandomJSON( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else { context.Response.Write(Video.GetRandomJSON()); } #endregion break; case SiteEnums.QueryStringNames.video_playlist: #region video_playlist if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write( PlaylistVideo.GetNextVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]), context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()])) { context.Response.Write( PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]))); } else { context.Response.Write( PlaylistVideo.CurrentVideoInPlaylist( Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]) )); } #endregion break; case SiteEnums.QueryStringNames.video: #region video Video vid = new Video("YT", context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()]); VideoLog.AddVideoLog(vid.VideoID, context.Request.UserHostAddress); context.Response.Write(Video.GetVideoJSON(context.Request.QueryString[SiteEnums.QueryStringNames.vid.ToString()])); #endregion break; case SiteEnums.QueryStringNames.begindate: #region begindate //string[] dates = HttpUtility.UrlDecode( // context.Request.QueryString[SiteEnums.QueryStringNames.begindate.ToString()] // ).Split('G'); DateTime dtBegin = Convert.ToDateTime(context.Request.QueryString[SiteEnums.QueryStringNames.begindate.ToString()]); dtBegin = new DateTime(dtBegin.Year, dtBegin.Month, 1); DateTime dtEnd = dtBegin.AddMonths(1).AddDays(-1); Events tds = new Events(); tds.GetEventsForLocation( dtBegin, dtEnd, context.Request.QueryString[SiteEnums.QueryStringNames.country_iso.ToString()], context.Request.QueryString[SiteEnums.QueryStringNames.region.ToString()], context.Request.QueryString[SiteEnums.QueryStringNames.city.ToString()]); CalendarItems citms = GetCitms(tds, dtBegin, dtEnd, true); //[ 100, 500, 300, 200, 400 ] sb = new StringBuilder(); sb.Append("["); int processed = 1; foreach (CalendarItem ci1 in citms) { if (processed == citms.Count) { sb.Append(ci1.StartDate.Day); } else { sb.Append(ci1.StartDate.Day); sb.Append(", "); } processed++; } sb.Append("]"); context.Response.Write(sb.ToString()); #endregion break; case SiteEnums.QueryStringNames.playlist: #region playlist if (!string.IsNullOrEmpty( context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])) { context.Response.Write( PlaylistVideo.GetNextVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]), context.Request.QueryString[SiteEnums.QueryStringNames.currentvidid.ToString()])); } else if (!string.IsNullOrEmpty(context.Request.QueryString[SiteEnums.QueryStringNames.begin_playlist.ToString()])) { context.Response.Write( PlaylistVideo.GetFirstVideo(Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]))); } else { context.Response.Write( PlaylistVideo.CurrentVideoInPlaylist( Convert.ToInt32(context.Request.QueryString[SiteEnums.QueryStringNames.playlist.ToString()]) )); } #endregion break; default: // ? break; } }
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); } } } }