protected void UpdatePhoto(object o, EventArgs e) { Photo p = new Photo(int.Parse(this.uiPhotoKLabel.Text)); p.SetAsPhotoOfWeek(uiPhotoOfWeek.Checked, uiPhotoOfWeekUserCaption.Text, false, uiResetDateTime.Checked); p.BlockedFromPhotoOfWeekUser = uiPhotoOfWeekUserBlocked.Checked; p.Update(); }
public void Disable(object o, System.EventArgs e) { Photo p = new Photo(int.Parse(Request.QueryString["PhotoK"])); if (!p.ContentDisabled) { p.ContentDisabled = true; p.Update(); p.Gallery.UpdatePhotoOrder(null); OutLabel.Text = "Picture " + p.K.ToString() + " has had it's contents disabled"; } }
public override bool Encode(Photo p, Photo.EncoderStatusDelegate Status, Photo.MeaningfulActivityDelegate Active, int MinutesUntilKill1) { try { StatusString = "[STRT]"; //lets see if upload temporary file exists... if (Storage.ExistsInStore(Storage.Stores.Temporary, p.UploadTemporary, p.UploadTemporaryExtention)) { p.SaveWeb(Photo.SaveWebFileSourceLocations.UploadTemporary, p.Rotate, Status, Active); } else if (Storage.ExistsInStore(Storage.Stores.Master, p.Master, "jpg")) { p.SaveWeb(Photo.SaveWebFileSourceLocations.Master, p.Rotate, Status, Active); } else { //We don't have the upload temporary file OR the master file... so delete the photo? throw new Exception("Can't find image file to encode!"); } Active(); Photo.FinishProcessUploadedFile(p, p.Gallery, p.Usr); p.IsProcessing = false; p.Update(); Active(); Status(p.K + " Updating gallery etc..."); Status(p.K + " Done! ************************************"); } catch (Exception ex) { Status(p.K + " Caught exception XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Status(p.K + " Caught exception: " + ex.ToString()); throw ex; } finally { Status(p.K + " Finalising..."); StatusString = "[----]"; Status(p.K + " Finalising done."); } return true; }
public void TestInsertsFireInvalidationTriggers() { Tag tag = new Tag(); tag.Update(); Photo photo = new Photo(); photo.Update(); Caching.Instances.Main.FlushAll(); string version = Guid.NewGuid().ToString(); Caching.Instances.Main.Set(Caching.CacheKeys.Tag.TagPhotos(tag.K), version); TagPhoto tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = photo.K}; Assert.AreEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); tagPhoto.Update(); Assert.AreNotEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); }
public void TestDeletesFireInvalidationTriggers() { Tag tag = new Tag(); tag.Update(); Photo photo2 = new Photo(); photo2.Update(); Photo photo = new Photo(); photo.Update(); Caching.Instances.Main.FlushAll(); TagPhoto tagPhoto = new TagPhoto() { TagK = tag.K, PhotoK = photo.K}; tagPhoto.Update(); string version = Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K)) as string; tagPhoto.Delete(); Assert.AreNotEqual(version, Caching.Instances.Main.Get(Caching.CacheKeys.Tag.TagPhotos(tag.K))); }
public void Command(object o, CommandEventArgs e) { if (CurrentPhoto.K == int.Parse(e.CommandArgument.ToString())) { if (e.CommandName.Equals("Delete")) { CurrentPhoto = new Photo(CurrentPhoto.K); if (Usr.Current.K == CurrentPhoto.UsrK || Usr.Current.IsSenior) { Delete.DeleteAll(CurrentPhoto); } } else if (e.CommandName.Equals("Retry")) { CurrentPhoto = new Photo(CurrentPhoto.K); if (Usr.Current.K == CurrentPhoto.UsrK || Usr.Current.IsSenior) { CurrentPhoto.ProcessingAttempts = 0; CurrentPhoto.Update(); } } PhotoAdminPage.Refresh(); } }
public static void FinishProcessUploadedFile(Photo p, Gallery g, Usr u) { bool reEncoded = false; if (p.EnabledByUsrK > 0) reEncoded = true; #region Update status if ((u.TotalPhotoUploads > 50 && u.AbuseAccusationsPending == 0 && !u.ModeratePhotos) || reEncoded || u.IsAdmin) { p.Status = Photo.StatusEnum.Enabled; if (!reEncoded) { p.EnabledDateTime = DateTime.Now; p.EnabledByUsrK = u.K; } } else { p.Status = Photo.StatusEnum.Moderate; } #endregion #region Set tags string[] tagsFromClient = p.UploadTemporaryTags.Split(',', ';', '"', '\n'); foreach (string tagText in tagsFromClient) { string s = tagText.Trim(); if (s.Length > 0) { try { Tag.AddTag(s, p, u); } catch { } } } #endregion p.Update(); #region Update gallery other photos in the gallery if (g.TotalPhotos == 0) g.MainPhotoK = p.K; g.UpdateStats(null, false); if (p.Status.Equals(Photo.StatusEnum.Enabled)) { g.UpdatePhotoOrder(null); if (!reEncoded) g.LastLiveDateTime = DateTime.Now; if (g.Event != null) g.Event.UpdateTotalPhotos(null); } g.Update(); #endregion if (!reEncoded) u.LastPhotoUpload = DateTime.Now; u.UpdateTotalPhotos(null); if (p.Status == Photo.StatusEnum.Enabled) { p.SendPhotoChatAlerts(); } }
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); //} } }
public void Action_Click(object o, System.EventArgs e) { if (Mode.Equals(Modes.Abuse)) { if (Page.IsValid) { if (CurrentAbuse.Status.Equals(Abuse.StatusEnum.Done)) throw new DsiUserFriendlyException("Oops - this abuse report has already been resolved - maybe someone beat you to it..."); if (!(OverturnRadio.Checked || NoAbuseRadio.Checked || NoAbuseDeleteRadio.Checked || AbuseDeleteRadio.Checked || AbuseDeleteWatchRadio.Checked || AbuseDeleteBanRadio.Checked || AbuseDeleteBanModerateRadio.Checked)) { throw new DsiUserFriendlyException("You must choose an option!"); } if (OverturnRadio.Checked) { CurrentAbuse.ResolveDateTime = DateTime.Now; CurrentAbuse.Status = Abuse.StatusEnum.Done; CurrentAbuse.ResolveStatus = Abuse.ResolveStatusEnum.Overturned; CurrentAbuse.ResolveDescription = ResolveDescriptionTextBox.Text; CurrentAbuse.ResolveUsrK = Usr.Current.K; CurrentAbuse.Update(); Photo p = null; try { p = new Photo(CurrentAbuse.ObjectK); } catch { } Mailer m = new Mailer(); m.Subject = "Your abuse report has been resolved"; m.Body = "<p>You recently filed an abuse report about a photo</p>"; m.Body += "<p>Our moderators have reviewed the photo, and found no abuse. Please only report photos when there is a clear abuse of the photo rules. If you mis-use this abuse report service, you will not be able to make further reports.</p>"; m.Body += "<p>Our moderator included the following note:</p>"; m.Body += "<p><i>" + CurrentAbuse.ResolveDescription + "</i></p>"; if (p != null) m.RedirectUrl = p.Url(); m.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; m.UsrRecipient = CurrentAbuse.ReportUsr; m.Send(); CurrentAbuse.ReportUsr.UpdateAbuseTrackers(); CurrentAbuse.AbuseUsr.UpdateAbuseTrackers(); Bobs.Global.UpdatePhotoAbuseReports(); } else if (NoAbuseRadio.Checked || NoAbuseDeleteRadio.Checked) { CurrentAbuse.ResolveDateTime = DateTime.Now; CurrentAbuse.Status = Abuse.StatusEnum.Done; CurrentAbuse.ResolveStatus = Abuse.ResolveStatusEnum.NoAbuse; CurrentAbuse.ResolveDescription = ResolveDescriptionTextBox.Text; CurrentAbuse.ResolveUsrK = Usr.Current.K; CurrentAbuse.Update(); Photo p = null; try { p = new Photo(CurrentAbuse.ObjectK); if (NoAbuseDeleteRadio.Checked) p.DeleteAll(null); } catch { } Mailer m = new Mailer(); m.Subject = "Your abuse report has been resolved"; m.Body = "<p>You recently filed an abuse report about a photo</p>"; m.Body += "<p>Our moderators have reviewed the photo, and found no abuse. Your report was helpful however.</p>"; m.Body += "<p>Our moderator included the following note:</p>"; m.Body += "<p><i>" + CurrentAbuse.ResolveDescription + "</i></p>"; if (p != null) m.RedirectUrl = p.Url(); m.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; m.UsrRecipient = CurrentAbuse.ReportUsr; m.Send(); CurrentAbuse.ReportUsr.UpdateAbuseTrackers(); CurrentAbuse.AbuseUsr.UpdateAbuseTrackers(); Bobs.Global.UpdatePhotoAbuseReports(); } else if (AbuseDeleteRadio.Checked || AbuseDeleteWatchRadio.Checked || AbuseDeleteBanRadio.Checked || AbuseDeleteBanModerateRadio.Checked) { try { Photo ph = new Photo(CurrentAbuse.ObjectK); ph.DeleteAll(null); } catch { } if (AbuseDeleteWatchRadio.Checked) { try { CurrentAbuse.AbuseUsr.ModeratePhotos = true; CurrentAbuse.AbuseUsr.Update(); } catch { } } if (AbuseDeleteBanRadio.Checked) { try { CurrentAbuse.AbuseUsr.Banned = true; CurrentAbuse.AbuseUsr.BannedByUsrK = Usr.Current.K; CurrentAbuse.AbuseUsr.BannedDateTime = DateTime.Now; CurrentAbuse.AbuseUsr.BannedReason = ResolveDescriptionTextBox.Text; CurrentAbuse.AbuseUsr.Update(); Mailer sm = new Mailer(); sm.Body = "<p>Banned user: <a href=\"[LOGIN(" + CurrentAbuse.AbuseUsr.Url() + ")]\">" + CurrentAbuse.AbuseUsr.NickName + "</a> (" + CurrentAbuse.AbuseUsr.K + " - " + CurrentAbuse.AbuseUsr.Email + ")</p>"; sm.Body += "<p>They were banned by: <a href=\"[LOGIN(" + Usr.Current.Url() + ")]\">" + Usr.Current.NickName + "</a> (" + Usr.Current.K + " - " + Usr.Current.Email + ")</p>"; sm.Body += "<p>DateTime: " + DateTime.Now.ToString() + "</p>"; sm.Body += "<p>Reason: " + ResolveDescriptionTextBox.Text + "</p>"; sm.TemplateType = Mailer.TemplateTypes.AdminNote; sm.Subject = "New banned user - " + CurrentAbuse.AbuseUsr.NickName + " was banned by " + Usr.Current.NickName; sm.To = "*****@*****.**"; sm.Send(); } catch { } } if (AbuseDeleteBanModerateRadio.Checked) { Query q = new Query(); q.QueryCondition = new Q(Gallery.Columns.OwnerUsrK, CurrentAbuse.AbuseUsrK); GallerySet gs = new GallerySet(q); foreach (Gallery g in gs) { Query qP = new Query(); qP.QueryCondition = new Q(Photo.Columns.GalleryK, g.K); PhotoSet ps = new PhotoSet(qP); foreach (Photo ph in ps) { ph.Status = Photo.StatusEnum.Moderate; ph.Update(); } g.UpdateStats(null, true); g.UpdatePhotoOrder(null); if (g.Event != null) g.Event.UpdateTotalPhotos(null); } } CurrentAbuse.ResolveDateTime = DateTime.Now; CurrentAbuse.Status = Abuse.StatusEnum.Done; CurrentAbuse.ResolveStatus = Abuse.ResolveStatusEnum.Abuse; CurrentAbuse.ResolveDescription = ResolveDescriptionTextBox.Text; CurrentAbuse.ResolveUsrK = Usr.Current.K; CurrentAbuse.Update(); Mailer m = new Mailer(); m.Subject = "Your abuse report has been resolved"; m.Body = "<p>You recently filed an abuse report about a photo</p>"; m.Body += "<p>Our moderators have reviewed the photo, and found it breaks our rules. It has been deleted.</p>"; m.Body += "<p>Our moderator included the following note:</p>"; m.Body += "<p><i>" + CurrentAbuse.ResolveDescription + "</i></p>"; m.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; m.UsrRecipient = CurrentAbuse.ReportUsr; m.Send(); CurrentAbuse.ReportUsr.UpdateAbuseTrackers(); CurrentAbuse.AbuseUsr.UpdateAbuseTrackers(); Bobs.Global.UpdatePhotoAbuseReports(); } PanelAbuse_Load(null, null); } } }
public void EnableSelected(object o, System.EventArgs e) { int enabled = 0; bool sentChatAlert = false; // bool galleryEmptyBefore = false; // if (CurrentGallery.LivePhotos==0) // galleryEmptyBefore = true; SelectedOutputP.InnerHtml = ""; foreach (string str in Request.Form.Keys) { if (str.StartsWith("ucEditGalleryPhotoSelectK") && Request.Form[str].Equals("1")) { enabled++; string str1 = str.Substring(25); SelectedOutputP.InnerHtml += "Enabling photo " + str1 + "..."; try { int photoK = int.Parse(str1); Photo p = new Photo(photoK); if (p.GalleryK != CurrentGallery.K) { SelectedOutputP.InnerHtml += " <b>FAILED</b> - photo is not in current gallery. Please contact admin with details."; } else if (!p.Status.Equals(Photo.StatusEnum.Moderate)) { SelectedOutputP.InnerHtml += " <b>FAILED</b> - photo is not new. Maybe someone already enabled it?"; } else { p.Status = Photo.StatusEnum.Enabled; p.EnabledByUsrK = Usr.Current.K; p.EnabledDateTime = DateTime.Now; p.Update(); if (!sentChatAlert) { p.SendPhotoChatAlerts(); sentChatAlert = true; } SelectedOutputP.InnerHtml += " Done."; } } catch { SelectedOutputP.InnerHtml += " <b>FAILED</b> - exception while deleting photo. Maybe someone already deleted it?"; } SelectedOutputP.InnerHtml += "<br>"; } } if (enabled == 0) SelectedOutputP.InnerHtml += "<b>NO PHOTOS ENABLED</b> - You didn't select any photos."; SelectedOutputP.Visible = true; if (enabled > 0) { CurrentGallery.LastLiveDateTime = DateTime.Now; CurrentGallery.UpdateStats(null, true); CurrentGallery.UpdatePhotoOrder(null); CurrentGallery.Owner.UpdateTotalPhotos(null); if (CurrentGallery.Event != null) { CurrentGallery.Event.UpdateTotalPhotos(null); CurrentGallery.Event.UpdateTotalComments(null); } if (CurrentGallery.Article != null) CurrentGallery.Article.UpdateTotalComments(null); // if (galleryEmptyBefore && CurrentGallery.LivePhotos>0) // { // //Send emails... // new System.Threading.Thread(new ThreadStart(CurrentGallery.SendNewGalleryEmails)).Start(); // } } Bind(); ContainerPage.AnchorSkip("ActionsPanel"); }
public void Enable(object o, System.EventArgs e) { // bool galleryEmptyBefore = false; // if (CurrentGallery.LivePhotos==0) // galleryEmptyBefore = true; bool sentChatAlert = false; ArrayList al = (ArrayList)this.ViewState["Photos"]; foreach (int photoK in al) { try { Photo p = new Photo(photoK); if (p.GalleryK == CurrentGallery.K && p.Status.Equals(Photo.StatusEnum.Moderate)) { p.Status = Photo.StatusEnum.Enabled; p.EnabledByUsrK = Usr.Current.K; p.EnabledDateTime = DateTime.Now; p.Update(); if (!sentChatAlert) { p.SendPhotoChatAlerts(); sentChatAlert = true; } } } catch { } } CurrentGallery.LastLiveDateTime = DateTime.Now; CurrentGallery.UpdateStats(null, true); CurrentGallery.UpdatePhotoOrder(null); CurrentGallery.Owner.UpdateTotalPhotos(null); if (CurrentGallery.Event != null) { CurrentGallery.Event.UpdateTotalPhotos(null); CurrentGallery.Event.UpdateTotalComments(null); } if (CurrentGallery.Article != null) CurrentGallery.Article.UpdateTotalComments(null); // if (galleryEmptyBefore && CurrentGallery.LivePhotos>0) // { // //Send emails... // new System.Threading.Thread(new ThreadStart(CurrentGallery.SendNewGalleryEmails)).Start(); // } Gallery g = GetNextGallery(); if (g != null) Response.Redirect(g.UrlApp("moderate")); else { DonePanel.Visible = true; InfoPanel.Visible = false; } }
public void TestThatColumnsIncludedInWhereClausesClearTheCacheWhenTheyAreChanged() { Caching.Instances.Main.FlushAll(); Gallery gallery = new Gallery(); gallery.Update(); Photo photo = new Photo(); photo.Status = Photo.StatusEnum.Moderate; photo.GalleryK = gallery.K; photo.Update(); Assert.AreEqual(1, gallery.ChildPhotos().Count); Assert.AreEqual(1, gallery.ChildPhotos(new Q(Photo.Columns.Status, Photo.StatusEnum.Moderate)).Count); Caching.Instances.Main.FlushAll(); Assert.AreEqual(0, gallery.ChildPhotos(new Q(Photo.Columns.Status, Photo.StatusEnum.Enabled)).Count); photo.Status = Photo.StatusEnum.Enabled; photo.Update(); Assert.AreEqual(0, gallery.ChildPhotos(new Q(Photo.Columns.Status, Photo.StatusEnum.Moderate)).Count); Assert.AreEqual(1, gallery.ChildPhotos(new Q(Photo.Columns.Status, Photo.StatusEnum.Enabled)).Count); }
public void UseOfAColumnWhichDoesNotHaveCausesInvalidationInAWhereClauseSetThrowsAnException() { Caching.Instances.Main.FlushAll(); Gallery gallery = new Gallery(); gallery.Update(); Photo photo = new Photo(); photo.Status = Photo.StatusEnum.Moderate; photo.GalleryK = gallery.K; photo.Update(); int count = gallery.ChildPhotos(new Q(Photo.Columns.ParentDateTime, DateTime.Now)).Count; }
public override bool Encode(Photo p, Photo.EncoderStatusDelegate Status, Photo.MeaningfulActivityDelegate Active, int MinutesUntilKill1) { try { if (Active != null) Active(); bool justCopiedFromMaster = false; if (!Storage.ExistsInStore(Storage.Stores.Temporary, p.UploadTemporary, p.UploadTemporaryExtention)) { //we don't have a temporary upload file... if (Storage.ExistsInStore(Storage.Stores.Master, p.VideoMaster, p.VideoFileExtention)) { //we have a master video file, so lets copy it to a new UploadTemporary location... p.UploadTemporary = Guid.NewGuid(); p.UploadTemporaryExtention = p.VideoFileExtention; byte[] bytes = Storage.GetFromStore(Storage.Stores.Master, p.VideoMaster, p.VideoFileExtention); Storage.AddToStore( bytes, Storage.Stores.Temporary, p.UploadTemporary, p.UploadTemporaryExtention, p, "UploadTemporary"); p.VideoMasterFileSize = bytes.Length; bytes = null; justCopiedFromMaster = true; p.Update(); } else { //we don't have an upload temporary file or a master file, so lets throw an exception. throw new Exception("Can't find video file to encode!"); } } StatusString = "[STRT]"; CurrentPhoto = p; if (Active != null) Active(); Status(p.K + " Initialising encoder..."); #region Initialise encoder if (Encoder == null) Encoder = new Turbine.TVE2(); Encoder.Key1 = 193279817; Encoder.Key2 = 1538568029; Encoder.BinDirectory = @"C:\Program Files\TVE2SDK\plugins";// set BinDirectory to the right location for the plugins/ directory and mp3 encoder dll to be found: #endregion #region Set processing progress to -1 CurrentPhoto.ProcessingProgress = -1; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); #endregion if (Active != null) Active(); Status(p.K + " adding to Master store..."); #region Add to Master store if (!justCopiedFromMaster) { byte[] bytes = Storage.GetFromStore(Storage.Stores.Temporary, p.UploadTemporary, p.UploadTemporaryExtention); Storage.AddToStore( bytes, Storage.Stores.Master, p.VideoMaster, p.VideoFileExtention, p, "VideoMaster"); p.VideoMasterFileSize = bytes.Length; bytes = null; } #endregion if (Active != null) Active(); Status(p.K + " Getting info..."); #region Get info... bool info = Encoder.InfoOpen(Storage.TemporaryFilesystemPath(p.UploadTemporary, p.UploadTemporaryExtention)); CurrentPhoto.VideoDuration = (int)Encoder.InfoGet("totalDurationMs"); CurrentPhoto.VideoMasterHeight = (int)Encoder.InfoGet("videoHeight"); CurrentPhoto.VideoMasterWidth = (int)Encoder.InfoGet("videoWidth"); CurrentPhoto.VideoMasterFramerate = (double)Encoder.InfoGet("videoWidth"); int audioSampleRate = (int)Encoder.InfoGet("audioSampleRate"); int audioBitsPerSample = (int)Encoder.InfoGet("audioBitsPerSample"); Encoder.InfoClose(); #endregion #region Set processing progress to -2 CurrentPhoto.ProcessingProgress = -2; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); #endregion if (Active != null) Active(); Status(p.K + " Getting JPG preview..."); #region Get JPG preview int msHalf = (int)Math.Floor(CurrentPhoto.VideoDuration / 2.0); Encoder.SetOutputFile(Storage.TemporaryFilesystemPath(p.VideoMed, "flv")); Encoder.OutputExportFrameJPEGTimeMs = msHalf; Encoder.OutputExportFrameJPEGQuality = 85; Encoder.Encode(Storage.TemporaryFilesystemPath(p.UploadTemporary, p.UploadTemporaryExtention), msHalf - 1, msHalf + 1, true, true, true); Encoder.EncodeFlush(); if (!File.Exists(Storage.TemporaryFilesystemPath(p.VideoMed, "flv") + ".jpg")) { Status(p.K + " Couldn't find JPG preview - throwing exception..."); throw new Exception("Couldn't find captured frame... Maybe a currupt video?"); } Storage.AddToStore( File.ReadAllBytes(Storage.TemporaryFilesystemPath(p.VideoMed, "flv") + ".jpg"), Storage.Stores.Master, p.Master, "jpg", p, "Master"); CurrentPhoto.SaveWeb(Photo.SaveWebFileSourceLocations.Master, 0, Status, Active, false); #endregion #region Set processing progress to -3 CurrentPhoto.ProcessingProgress = -3; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); #endregion if (Active != null) Active(); Status(p.K + " Preparing for encode..."); #region Reset encoder Encoder.Reset(); Encoder.Key1 = 193279817; Encoder.Key2 = 1538568029; Encoder.BinDirectory = @"C:\Program Files\TVE2SDK\plugins";// set BinDirectory to the right location for the plugins/ directory and mp3 encoder dll to be found: #endregion #region Video settings Encoder.VideoRelativeSize = 0; if (CurrentPhoto.VideoMasterWidth >= CurrentPhoto.VideoMasterHeight) { if (CurrentPhoto.VideoMasterWidth >= 600) { Encoder.VideoWidth = 600; Encoder.VideoHeight = (int)Math.Floor((600.0 / CurrentPhoto.VideoMasterWidth) * CurrentPhoto.VideoMasterHeight); } else { Encoder.VideoWidth = CurrentPhoto.VideoMasterWidth; Encoder.VideoHeight = CurrentPhoto.VideoMasterHeight; } } else { if (CurrentPhoto.VideoMasterHeight >= 600) { Encoder.VideoHeight = 600; Encoder.VideoWidth = (int)Math.Floor((600.0 / CurrentPhoto.VideoMasterHeight) * CurrentPhoto.VideoMasterWidth); } else { Encoder.VideoWidth = CurrentPhoto.VideoMasterWidth; Encoder.VideoHeight = CurrentPhoto.VideoMasterHeight; } } CurrentPhoto.VideoMedWidth = Encoder.VideoWidth; CurrentPhoto.VideoMedHeight = Encoder.VideoHeight; int maxEncodedSide = Encoder.VideoWidth > Encoder.VideoHeight ? Encoder.VideoWidth : Encoder.VideoHeight; if (CurrentPhoto.VideoMasterFramerate > 30.0) { Encoder.VideoRelativeFrameRate = 0; Encoder.VideoFrameRate = 30; CurrentPhoto.VideoMedFramerate = 30.0; } else { Encoder.VideoRelativeFrameRate = 100; Encoder.VideoFrameRate = 0; CurrentPhoto.VideoMedFramerate = CurrentPhoto.VideoMasterFramerate; } #region Set processing progress = -4 CurrentPhoto.ProcessingProgress = -4; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); #endregion Encoder.VideoMethod = "VBR1"; //Video encoding methods available: CBR (constant bitrate) VBR1 (variable bitrate 1-pass) VBR2 (variable bitrate 2-pass) KQ (constant quality) if (maxEncodedSide > 1000) Encoder.VideoBitRate = 1572864; else if (maxEncodedSide > 600) Encoder.VideoBitRate = 1048576; else if (maxEncodedSide > 300) Encoder.VideoBitRate = 786432; else Encoder.VideoBitRate = 524288; Encoder.VideoQuantizer = 0; //If encoding method is KQ, the constant quality quantizer, from 1 (best quality) to 31 (best compression) Encoder.VideoMotionEstimation = "optimal"; // The motion estimation algorithm: "optimal" (best speed) or "deep" (best quality but slower) Encoder.VideoBufferTimeMs = 0; //The assumed download buffer interval (size) in milliseconds. Use 0 for the default of 3000 milliseconds Encoder.VideoIntraFramePeriod = 0; //Force an intra-frame every x frames: The player can only seek to intra-frames, so this value should be reasonable if seeking is to be allowed. Only valid if relativeIntraFramePeriod is 0, otherwise that setting is used Encoder.VideoRelativeIntraFramePeriod = 2; //Force an intra-frame every x seconds Encoder.VideoDeblocking = true; //Enable/disable image deblocking in the player. Use 1 or 0 Encoder.VideoSmoothing = true; //will enable extra smoothing in the player Encoder.VideoLastFrameIntra = true; //will encode the last frame as an intra-frame, which will allow player seeking to the end of the video Encoder.VideoDeInterlace = "none"; //Deinterlace settings: none, odd (deinterlace odd fields), even (deinterlace even fields), auto (deinterlace if source has sizes 720x480-486 or 720x576-584) Encoder.VideoCropAreaBottom = 0; //The left,top,right,bottom pixel coordinates of the crop window in the source video. Set to 0,0,0,0 to disable Encoder.VideoCropAreaLeft = 0; Encoder.VideoCropAreaRight = 0; Encoder.VideoCropAreaTop = 0; Encoder.VideoNoiseReduction = 0; //Video noise reduction: 0=none, 1=light, 2=heavy Encoder.VideoGamma = 0; //Gamma correction from -100 (gamma=0.2) to +100 (gamma=5), use 0 for none Encoder.VideoContrast = 0; //Contrast from -100 to +100, use 0 for none Encoder.VideoBrightness = 0; //Brightness from -100 to +100, use 0 for none Encoder.VideoBlackRestore = 0; //Black pixel restore operation between 0 and 200, use 0 for none. Higher values will set more pixels to black Encoder.VideoWhiteRestore = 0; //White pixel restore operation between 0 and 200, use 0 for none. Higher values will set more pixels to white Encoder.VideoFx = ""; Encoder.VideoImageOverlay = @"c:\overlay.png"; //Vars.MapPath("~/gfx/overlay-video.png"); //The location of an image to use as overlay for the video. Possible formats are: JPEG, PNG, GIF, BMP. Use "" for none Encoder.VideoImageOverlayAlignX = 0; //The horizontal alignment for the image overlay: 0 (align left), -1 (align center), -2 (align right). Or a positive coordinate that will be used for the left side of the overlay image Encoder.VideoImageOverlayAlignY = -2; //The vertical alignment for the image overlay: 0 (align top), -1 (align center), -2 (align bottom). Or a positive coordinate that will be used for the top side of the overlay image Encoder.VideoImageOverlayAlpha = 100; //A transparency value for the overlay, between 0 (fully transparent) and 100 (opaque) #endregion #region Audio options Encoder.AudioEncoder = "MP3"; //The audio encoder: none, ADPCM, MP3. Use "none" for no audio encoding Encoder.AudioSamplingRate = 22050; //The sampling rate at which to encode audio: 5512(ADPCM only), 11025, 22050, 44100 Encoder.AudioChannels = 2; //Number of channels: 1 (mono), 2 (stereo). If source is mono will always encode as mono Encoder.AudioADPCMBits = 4; //ADPCM encoding only: bits per sample quality: 2, 3, 4, 5 bits per sample //Encoder.AudioMP3BitRate = 128000; //The MP3 encoding bitrate in bits per second, one of: 8000,16000,24000,32000,40000,48000,56000,64000,80000,96000,112000,128000,160000,192000,224000,256000,320000 if (maxEncodedSide > 1000) Encoder.AudioMP3BitRate = 192000; else if (maxEncodedSide > 600) Encoder.AudioMP3BitRate = 128000; else if (maxEncodedSide > 300) Encoder.AudioMP3BitRate = 96000; else Encoder.AudioMP3BitRate = 48000; Encoder.AudioMP3ABR = true; //Audio flags: "mp3ABR" encodes using Average BitRate, a variable bitrate encoding method that aims to reach the average bitrate specified in the mp3BitRate parameter, by using higher bitrates where necessary and lower bitrates where possible Encoder.AudioMixTrack = ""; //Location of an audio file to use as additional audio track Encoder.AudioMixTrackPercentage = 0; //The audio mixTrack level between 0 and 100 (0=no mixTrack, 100=mixTrack only) Encoder.AudioMasterVolumePercentage = 100; //The master volume amplification as a percentage: 100 means pass-through, 200 means amplify to double #endregion #region Output options Encoder.OutputExportFrameJPEGTimeMs = -1; //If set to a value >= 0 means the instant in milliseconds at which to export a processed video frame into a JPEG file with the quality set in exportFrameJPEGQuality. The exported image file will have the name of the output file appended with ".jpg" Encoder.OutputExportFrameJPEGQuality = 85; //JPEG quality for exported video frame Encoder.OutputFormat = "flv"; //Output format, one of "FLV" or "SWF" Encoder.SetOutputFile(Storage.TemporaryFilesystemPath(p.VideoMed, "flv")); // set output location #endregion if (Active != null) Active(); Status(p.K + " Starting encode..."); Encoder.EncodeAsync(Storage.TemporaryFilesystemPath(p.UploadTemporary, p.UploadTemporaryExtention)); // other params: sourceFileName , [sourceBeginMs], [sourceEndMs], [isLast], [encodeVideo], [encodeAudio] #region Loop while encoder working while (Encoder.EncodeAsyncIsEncoding) { int progress = (int)Encoder.EncodeAsyncPercentage; if (CurrentPhoto.ProcessingProgress != progress) { if (Active != null) Active(); CurrentPhoto.ProcessingProgress = progress; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); } else { if (CurrentPhoto.ProcessingLastChange < DateTime.Now.AddMinutes(0 - MinutesUntilKill1)) { Status(p.K + " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Status(p.K + " Last change more than " + MinutesUntilKill1 + " mins ago - attempting cancel..."); this.Cancel(); Status(p.K + " Cancelled..."); return false; } } Status(p.K + " encoding in progress: " + CurrentPhoto.ProcessingProgress.ToString("000") + "% done."); StatusString = "[" + CurrentPhoto.ProcessingProgress.ToString("000") + "%]"; System.Threading.Thread.Sleep(2000); } #endregion if (Active != null) Active(); Status(p.K + " Encode finished. Flushing encoder..."); #region Flush encoder Encoder.EncodeFlush();// done - flush encoding: #endregion #region Let's double check it's actually worked... if (!File.Exists(Storage.TemporaryFilesystemPath(p.VideoMed, "flv"))) throw new Exception("Encoder failed because output file did not exist."); FileInfo f = new FileInfo(Storage.TemporaryFilesystemPath(p.VideoMed, "flv")); if (f.Length < 1024) throw new Exception("Encoder failed because output file size less than 1KB"); #endregion if (Active != null) Active(); Status(p.K + " Replicating files..."); #region Replicating files Storage.AddToStore( Storage.GetFromStore(Storage.Stores.Temporary, p.VideoMed, "flv"), Storage.Stores.Pix, p.VideoMed, "flv", p, "VideoMed"); #endregion #region Deleting upload temporary Storage.RemoveFromStore(Storage.Stores.Temporary, p.UploadTemporary, p.UploadTemporaryExtention); Storage.RemoveFromStore(Storage.Stores.Temporary, p.VideoMed, "flv"); #endregion if (Active != null) Active(); Status(p.K + " Completing..."); #region Set processing progress to 100 CurrentPhoto.IsProcessing = false; CurrentPhoto.ProcessingProgress = 100; CurrentPhoto.ProcessingLastChange = DateTime.Now; CurrentPhoto.Update(); #endregion if (Active != null) Active(); Status(p.K + " Updating gallery etc..."); Photo.FinishProcessUploadedFile(p, p.Gallery, p.Usr); if (Active != null) Active(); Status(p.K + " Done! ************************************"); } catch (Exception ex) { Status(p.K + " Caught exception XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Status(p.K + " Caught exception: " + ex.ToString()); throw ex; } finally { if (Active != null) Active(); Status(p.K + " Finalising..."); if (Encoder.EncodeAsyncIsEncoding) { Status(p.K + " Encoder seems to be still encoding... Aborting..."); Encoder.EncodeAsyncAbort(); Status(p.K + " Done aborting..."); } if (Active != null) Active(); Status(p.K + " Resetting encoder..."); Encoder.Reset(); StatusString = "[----]"; Status(p.K + " Finalising done."); if (Active != null) Active(); } return true; }