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 CheckConvertQueue() { try { string strServerName = System.Environment.MachineName; ConvertQueue convertQueue = new ConvertQueue(); if (convertQueue.LoadNextJob(strServerName)) { bool blnIsOK = true; strTransactionID = Guid.NewGuid().ToString(); if (convertQueue.ObjectType == _4screen.CSB.Common.ObjectType.Picture) { // TODO: Convert Picture } else if (convertQueue.ObjectType == _4screen.CSB.Common.ObjectType.Video) { DataObjectVideo dov = null; try { dov = new _4screen.CSB.DataAccess.Business.DataObjectVideo(udc); dov.ObjectID = convertQueue.ObjectID; dov.Load(null, true); dov.ShowState = ObjectShowState.InProgress; dov.UpdateBackground(); WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 1, "Load DO (Step 1 / 15)", _4screen.CSB.Common.MonitoringLogState.OK, ""); } catch (System.Exception ex) { blnIsOK = false; string strCheckMessage = string.Format("Error: Can't load DataObjectVideo<br/>DataObjectVideo.ObjectID = {{{0}}}<br/>System.Exception Message: {1}", convertQueue.ObjectID, ex.Message); WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 1, "Load DO (Step 1 / 15)", _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, strCheckMessage); convertQueue.TryingCount++; convertQueue.ConvertMessage = strCheckMessage; convertQueue.Status = _4screen.CSB.Common.MediaConvertedState.ConvertError; convertQueue.LastTimeStamp = DateTime.Now; convertQueue.Update(); } if (blnIsOK) { if (DoEncoding(convertQueue, dov)) // succeeded { WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 14, "Convert SUCCEEDED (Step 14 / 14)", _4screen.CSB.Common.MonitoringLogState.OK, ""); // TODO: SEND MAIL } else // aborted { WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 14, "Convert ABORTED (Step 14 / 14)", _4screen.CSB.Common.MonitoringLogState.Aborted, "please check detail process steps"); // TODO: SEND MAIL } blnIsEncoding = false; } } } } catch (System.Exception ex) { string strCheckMessage = string.Format("System.Exception<br/><br/>{0}", ex.Message); eventLog.WriteEntry(strCheckMessage, EventLogEntryType.Error); WriteMonitoringLog("", "", BaseActions.VideoConvert, 0, "Get Convert Jobs from Convert Queue", _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, strCheckMessage); } }