public void Start() { running = true; while (running) { bool jobInQueue = false; ConvertQueue convertQueue = new ConvertQueue(); try { jobInQueue = convertQueue.LoadNextJob(System.Environment.MachineName); } catch (Exception e) { EventLog.WriteEntry("CSBooster Video Load Job Error: Msg=" + e.Message + ", Trace=" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); } if (jobInQueue) { conversionStart = DateTime.Now; if (convertQueue.ObjectType == Helper.GetObjectType("Video").NumericId) { transactionId = Guid.NewGuid().ToString(); DataObjectVideo video = null; try { video = DataObject.Load <DataObjectVideo>(adminUdc, convertQueue.ObjectID, null, true); video.ShowState = ObjectShowState.InProgress; video.VideoPreviewPictureTimepointSec = convertQueue.VideoPreviewPictureTimepointSec; video.UpdateBackground(); EncodeVideos(video); WriteMonitoringLog(transactionId, video.ObjectID, BaseActions.VideoConvert, 0, "Encoding video", _4screen.CSB.Common.MonitoringLogState.OK, string.Format("Video encoding took {0} seconds", (DateTime.Now - conversionStart).TotalSeconds)); convertQueue.StatisticWorkTimeSec = (int)(DateTime.Now - conversionStart).TotalSeconds; convertQueue.StatisticFileSizeByte = video.SizeByte; convertQueue.StatisticFileExtension = video.OriginalLocation.Substring(video.OriginalLocation.LastIndexOf('.') + 1); convertQueue.Status = _4screen.CSB.Common.MediaConvertedState.Convertet; convertQueue.Update(); } catch (Exception e) { EventLog.WriteEntry("CSBooster Video Encoding Error: Oid=" + convertQueue.ObjectID + ", Msg=" + e.Message + ", Trace=" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); try { if (video != null) { WriteMonitoringLog(transactionId, video.ObjectID, BaseActions.VideoConvert, 0, "Encoding video", _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, e.Message + " " + e.StackTrace); } convertQueue.ConvertMessage = e.Message; convertQueue.Status = _4screen.CSB.Common.MediaConvertedState.ConvertError; convertQueue.LastTimeStamp = DateTime.Now; convertQueue.StatisticWorkTimeSec = (int)(DateTime.Now - conversionStart).TotalSeconds; if (video != null) { convertQueue.StatisticFileExtension = video.OriginalLocation.Substring(video.OriginalLocation.LastIndexOf('.') + 1); } convertQueue.Update(); if (video != null) { video.ConvertMessage = e.Message; video.ShowState = ObjectShowState.ConversionFailed; video.UpdateBackground(); } } catch (Exception e2) { EventLog.WriteEntry("CSBooster Video Encoding Error 2: Oid=" + convertQueue.ObjectID + ", Msg=" + e2.Message + ", Trace=" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); } } } } if (running) { System.Threading.Thread.Sleep(1000 * this.checkIntervalSecond); } } }
private void UpdateDataObject(DataObjectVideo video, VideoInfo videoInfo, Size largePreview, string format, VideoVersion videoVersion) { video.SetImageType(_4screen.CSB.Common.PictureVersion.L, _4screen.CSB.Common.PictureFormat.Jpg); video.SetImageType(_4screen.CSB.Common.PictureVersion.M, _4screen.CSB.Common.PictureFormat.Jpg); video.SetImageType(_4screen.CSB.Common.PictureVersion.S, _4screen.CSB.Common.PictureFormat.Jpg); video.SetImageType(_4screen.CSB.Common.PictureVersion.XS, _4screen.CSB.Common.PictureFormat.Jpg); video.Image = video.ObjectID.ToString(); Size videoSize = (videoInfo.Width > 0 && videoInfo.Height > 0) ? new Size(videoInfo.Width, videoInfo.Height) : largePreview; video.Width = videoSize.Width; video.Height = videoSize.Height; video.AspectRatio = (decimal)videoSize.Width / (decimal)videoSize.Height; video.ConvertMessage = string.Format("Video Encoding dauerte {0} Sekunden", (DateTime.Now - conversionStart).TotalSeconds); video.DurationSecond = (int)videoInfo.Duration_Sec; if (archiveUpload) { string videoFileExtenison = video.OriginalLocation.Substring(video.OriginalLocation.LastIndexOf('.') + 1).ToLower(); switch (videoFileExtenison) { case "wmv": video.OriginalFormat = VideoFormat.Wmv; break; case "mpg": video.OriginalFormat = VideoFormat.Mpg; break; case "mp4": video.OriginalFormat = VideoFormat.Mp4; break; case "mov": video.OriginalFormat = VideoFormat.Mov; break; case "m4v": video.OriginalFormat = VideoFormat.M4v; break; case "flv": video.OriginalFormat = VideoFormat.Flv; break; case "avi": video.OriginalFormat = VideoFormat.Avi; break; case "3gp": video.OriginalFormat = VideoFormat._3gp; break; default: video.OriginalFormat = VideoFormat.Unknow; break; } video.OriginalLocation = string.Format(@"\{0}\{1}\a\{2}.{3}", video.UserID, Helper.GetMediaFolder(Helper.GetObjectType("Video").NumericId), video.ObjectID, videoFileExtenison); } else { video.OriginalLocation = string.Empty; } FileInfo encodedVideoFileInfo = new FileInfo(string.Format(@"{0}\{3}{1}.{2}", temporaryConversionFolder, video.ObjectID, format, videoVersion)); video.SizeByte = (int)encodedVideoFileInfo.Length; DataObject profileOrCommunity = DataObject.Load <DataObject>(adminUdc, video.CommunityID, null, true); if (profileOrCommunity.State != _4screen.CSB.Common.ObjectState.Added) { if (profileOrCommunity.ObjectType == Helper.GetObjectType("Community").NumericId) { DataObjectCommunity community = DataObject.Load <DataObjectCommunity>(adminUdc, video.CommunityID, null, true); if (community.Managed) { video.ShowState = DataObjectCommunity.IsUserOwner(video.CommunityID.Value, video.UserID.Value) ? _4screen.CSB.Common.ObjectShowState.Published : _4screen.CSB.Common.ObjectShowState.Draft; } else { video.ShowState = _4screen.CSB.Common.ObjectShowState.Published; } } else { video.ShowState = _4screen.CSB.Common.ObjectShowState.Published; } } video.UpdateBackground(); }