public static void ProcessUploadedFile(HttpPostedFile httpPostedFile, Gallery gallery, Random random, Usr usr, int rotate, string tags) { if (usr.CanUploadTo(gallery)) { Photo photo = new Photo(); try { #region Set general stuff photo.UsrK = usr.K; photo.RandomNumber = random.NextDouble(); photo.WeightedCoolRating = 5.0; photo.WeightedSexyRating = 5.0; photo.Order = 5.0; if (tags.Length > 512) tags = tags.Substring(0, 512); photo.UploadTemporaryTags = tags; photo.Status = Photo.StatusEnum.Processing; #endregion #region Set gallery / event / article / url fragment stuff photo.GalleryK = gallery.K; if (gallery.Event != null) { photo.EventK = gallery.EventK; photo.DateTime = gallery.Event.DateTime; photo.ParentDateTime = gallery.Event.DateTime; } else if (gallery.Article != null) { photo.ArticleK = gallery.ArticleK; photo.DateTime = gallery.Article.AddedDateTime; photo.ParentDateTime = gallery.Article.AddedDateTime; } else { photo.DateTime = DateTime.Now; photo.ParentDateTime = gallery.CreateDateTime; } photo.UpdateUrlFragmentNoUpdate(); #endregion photo.MediaType = Photo.GetMediaType(httpPostedFile.FileName); if (photo.MediaType.Equals(Photo.MediaTypes.Image)) { #region Initialise Guids photo.UploadTemporary = Guid.NewGuid(); photo.Master = Guid.NewGuid(); photo.Web = Guid.NewGuid(); photo.Thumb = Guid.NewGuid(); photo.Icon = Guid.NewGuid(); #endregion photo.Rotate = rotate; #region Extention try { string s = httpPostedFile.FileName.Substring(httpPostedFile.FileName.LastIndexOf(".") + 1).ToLower(); if (s.Length < 10) { if (s == "jpeg" || s == "jpe") photo.UploadTemporaryExtention = "jpg"; else photo.UploadTemporaryExtention = s; } else photo.UploadTemporaryExtention = "jpg"; } catch { photo.UploadTemporaryExtention = "jpg"; } #endregion } else if (photo.MediaType.Equals(Photo.MediaTypes.Video)) { #region Initialise Guids photo.UploadTemporary = Guid.NewGuid(); photo.VideoMaster = Guid.NewGuid(); photo.VideoMed = Guid.NewGuid(); photo.Master = Guid.NewGuid(); photo.Web = Guid.NewGuid(); photo.Thumb = Guid.NewGuid(); photo.Icon = Guid.NewGuid(); #endregion #region Extention photo.VideoFileExtention = httpPostedFile.FileName.Substring(httpPostedFile.FileName.LastIndexOf(".") + 1).ToLower(); photo.UploadTemporaryExtention = photo.VideoFileExtention; #endregion } httpPostedFile.SaveAs(Storage.TemporaryFilesystemPath(photo.UploadTemporary, photo.UploadTemporaryExtention)); photo.Status = Photo.StatusEnum.Processing; photo.Update(); if (!gallery.WatchUploads.HasValue || gallery.WatchUploads.Value) { CommentAlert.Enable(usr, photo.K, Model.Entities.ObjectType.Photo); } } catch (Exception exc) { #region Send an email to admin try { Mailer m = new Mailer(); m.Subject = "Exception uploading photo from " + System.Environment.MachineName + "..."; m.Body = "<p>" + exc.ToString() + "</p>"; try { m.Body += "<p>The content length was " + httpPostedFile.ContentLength.ToString("#,##0") + " bytes</p>"; } catch { } m.UsrRecipient = new Usr(4); m.To = "*****@*****.**"; m.Send(); } catch { } #endregion #region Delete file try { Storage.RemoveFromStore(Storage.Stores.Temporary, photo.UploadTemporary, photo.UploadTemporaryExtention); } catch { } #endregion photo.Delete(); //try //{ // if (httpPostedFile.FileName.LastIndexOf(".") > -1) // httpPostedFile.SaveAs(@"C:\FailedPix\" + Guid.NewGuid() + httpPostedFile.FileName.Substring(httpPostedFile.FileName.LastIndexOf("."))); // else // httpPostedFile.SaveAs(@"C:\FailedPix\" + Guid.NewGuid()); //} //catch (Exception ex) //{ // Utilities.AdminEmailAlert("Error writing failed photo file to disk", "Error writing failed photo file to disk", ex); //} } //finally //{ // CurrentGallery.UpdateStats(null, true); // CurrentGallery.UpdatePhotoOrder(null); // if (CurrentGallery.Event != null) CurrentGallery.Event.UpdateTotalPhotos(null); //} } }