Пример #1
0
        public void Insert(UserDataContext udc, bool addToConverterQueue)
        {
            if (OriginalLocation.Length == 0)
            {
                throw new SiemeArgumentException("DataObjectVideo", "Insert", "OriginalLocation", "OriginalLocation is missing");
            }

            if (UserEmail.Length == 0)
            {
                throw new SiemeArgumentException("DataObjectVideo", "Insert", "UserEmail", "UserEmail is missing");
            }

            base.Insert(udc);
            if (addToConverterQueue)
            {
                Business.ConvertQueue objQueue = new ConvertQueue();
                objQueue.ObjectID   = ObjectID;
                objQueue.ObjectType = Helper.GetObjectTypeNumericID("Video");
                objQueue.Status     = MediaConvertedState.NotConvertet;
                objQueue.VideoPreviewPictureTimepointSec = VideoPreviewPictureTimepointSec;
                objQueue.UserEmail            = UserEmail;
                objQueue.EstimatedWorkTimeSec = EstimatedWorkTimeSec;
                objQueue.Insert();
            }
        }
Пример #2
0
 public void AddToConverterQueue()
 {
     Business.ConvertQueue objQueue = new ConvertQueue();
     objQueue.ObjectID   = ObjectID;
     objQueue.ObjectType = Helper.GetObjectType("Video").NumericId;
     objQueue.Status     = MediaConvertedState.NotConvertet;
     objQueue.VideoPreviewPictureTimepointSec = VideoPreviewPictureTimepointSec;
     objQueue.UserEmail            = UserEmail;
     objQueue.EstimatedWorkTimeSec = EstimatedWorkTimeSec;
     objQueue.Insert();
 }
Пример #3
0
 public void Update(UserDataContext udc, bool reconvert)
 {
     if (reconvert)
     {
         ShowState = ObjectShowState.ConversionFailed;
         Image     = string.Empty;
         Business.ConvertQueue objQueue = new ConvertQueue();
         objQueue.ObjectID   = ObjectID;
         objQueue.ObjectType = Helper.GetObjectTypeNumericID("Video");
         objQueue.Status     = MediaConvertedState.NotConvertet;
         objQueue.VideoPreviewPictureTimepointSec = VideoPreviewPictureTimepointSec;
         objQueue.UserEmail            = UserEmail;
         objQueue.EstimatedWorkTimeSec = EstimatedWorkTimeSec;
         objQueue.Insert();
     }
     base.Update(udc);
 }
Пример #4
0
        private bool DoEncoding(_4screen.CSB.DataAccess.Business.ConvertQueue convertQueue, _4screen.CSB.DataAccess.Business.DataObjectVideo dov)
        {
            blnIsEncoding = true;
            bool     blnIsOK                         = true;
            string   strCheckMessage                 = string.Empty;
            string   strStatisticFileExtension       = string.Empty;
            string   strNewGUIDFilename              = string.Empty;
            string   strNewGUIDFilenameWithoutExt    = string.Empty;
            string   strTargetOutPath                = string.Empty;
            string   strSourcePathFile               = string.Empty;
            string   strConverterLocalSourcePathFile = string.Empty;
            string   strOriginalLocation             = string.Empty;
            int      intStatisticFileSizeByte        = -1;
            DateTime dtmStart                        = DateTime.Now;
            int      intSizeBite                     = -1;

            #region DO SOME FILE MANIPULATIONS AND SET THE RIGHT PATH

            // check if the source folder and file exists
            if (blnIsOK)
            {
                try
                {
                    //The ConverterRootPathUpload in Web.Config may differ from the one in the app.config
                    //Im WebConfig  =  key="ConverterRootPathUpload" value="\\csbmedia\csbooster\Upload"
                    //Im AppConfig  =   key="ConverterRootPathUpload" value="Z:\Upload"
                    //Sample Upload Path = \\csbmedia\csbooster\Upload\ec572c72-e3fc-4486-82ec-0b2fe0a6d60b\V\20c81a3eb0bc43ac8016f84383893908PA084165.MOV
                    //Convert to = Z:\Upload\ec572c72-e3fc-4486-82ec-0b2fe0a6d60b\V\20c81a3eb0bc43ac8016f84383893908PA084165.MOV
                    string strPartialPath = dov.OriginalLocation.Substring(dov.OriginalLocation.IndexOf(dov.UserID));

                    strSourcePathFile   = Path.Combine(strConverterRootPathUpload, strPartialPath);
                    intSnapshotAfterSec = Convert.ToInt32(convertQueue.VideoPreviewPictureTimepointSec);

                    if (blnIsOK)
                    {
                        if (!vbio.FileExists(strSourcePathFile))
                        {
                            strCheckMessage = string.Format("Uploaded file doesn't exist.<br/>Can't find uploaded media '{0}'", strSourcePathFile);
                            blnIsOK         = false;
                            WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 2, "Check if source folder and file exists (Step 2 / 15)", _4screen.CSB.Common.MonitoringLogState.Aborted, strCheckMessage);
                        }
                        else
                        {
                            WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 2, "Check if source folder and file exists (Step 2 / 15)", _4screen.CSB.Common.MonitoringLogState.OK, "");
                        }
                    }
                }
                catch (Exception ex)
                {
                    blnIsOK         = false;
                    strCheckMessage = string.Format("Base error occurred<br/>DataObjectVideo.ObjectID = {{{0}}}<br/>System.Exception Message: {1}", dov.ObjectID, ex.Message);
                    WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 2, "Check if source folder and file exists (Step 2 / 15)", _4screen.CSB.Common.MonitoringLogState.Aborted, strCheckMessage);
                }
            }

            // rename source file to a GUID file
            if (blnIsOK)
            {
                try
                {
                    FileInfo fi = new FileInfo(strSourcePathFile);
                    strStatisticFileExtension       = fi.Extension;
                    strNewGUIDFilename              = dov.ObjectID + fi.Extension;
                    strConverterLocalSourcePathFile = Path.Combine(strLocalPathSource, strNewGUIDFilename);

                    strTargetOutPath = strSourcePathFile.Replace(strConverterRootPathUpload, strConverterRootPathMedia).Replace(fi.Name, "");
                    if (!Directory.Exists(strTargetOutPath))
                    {
                        Directory.CreateDirectory(strTargetOutPath);
                    }

                    try
                    {
                        // copy the file to a GUID File
                        vbio.CopyFile(strSourcePathFile, strConverterLocalSourcePathFile, true);
                        WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 3, "copy source file to a GUID file (Step 3 / 15)", _4screen.CSB.Common.MonitoringLogState.OK, "");
                    }
                    catch (Exception ex)
                    {
                        blnIsOK         = false;
                        strCheckMessage = string.Format("Error: Can't copy original media to a new GUID file<br/>DataObjectVideo.ObjectID = {{{0}}}<br/>System.Exception Message: {1}", dov.ObjectID, ex.Message);
                        WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 3, "copy source file to a GUID file (Step 3 / 15)", _4screen.CSB.Common.MonitoringLogState.Aborted, strCheckMessage);
                    }

                    if (blnIsOK)
                    {
                        try
                        {
                            // move original to the archive
                            string strTmpArchivePath = strTargetOutPath + @"A\"; //-->X:\CSBooster\Media\ec572c72-e3fc-4486-82ec-0b2fe0a6d60b\V\A
                            if (!Directory.Exists(strTmpArchivePath))
                            {
                                Directory.CreateDirectory(strTmpArchivePath);
                            }

                            strOriginalLocation = strSourcePathFile;    // set the original location to the upload dir; needed if move would crash
                            vbio.MoveFile(strSourcePathFile, Path.Combine(strTmpArchivePath, strNewGUIDFilename), true);
                            strOriginalLocation = Path.Combine(strTmpArchivePath, strNewGUIDFilename);

                            WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 4, "move source to archive (Step 4 / 15)", _4screen.CSB.Common.MonitoringLogState.OK, "");
                        }
                        catch (Exception ex)
                        {
                            strCheckMessage = string.Format("Error: Can't move original media to the archive folder<br/>DataObjectVideo.ObjectID = {{{0}}}<br/>System.Exception Message: {1}", dov.ObjectID, ex.Message);
                            WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 4, "move source to archive (Step 4 / 15)", _4screen.CSB.Common.MonitoringLogState.OKWithWarning, strCheckMessage);
                        }
                    }

                    fi = null;
                }
                catch (Exception ex)
                {
                    blnIsOK         = false;
                    strCheckMessage = string.Format("Base error in copy media to a GUID file<br/>DataObjectVideo.ObjectID = {{{0}}}<br/>System.Exception Message: {1}", dov.ObjectID, ex.Message);
                    WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 3, "copy source file to a GUID file (Step 3 / 15)", _4screen.CSB.Common.MonitoringLogState.Aborted, strCheckMessage);
                }
            }
            #endregion DO SOME FILE MANIPULATIONS AND SET THE RIGHT PATH


            #region DO THE ENCODING
            if (blnIsOK)
            {
                if (!strConverterLocalSourcePathFile.EndsWith(".flv"))
                {
                    ConvertVideo(strConverterLocalSourcePathFile, strLocalPathTarget, dov.ObjectID);
                }
                else
                {
                    try
                    {
                        System.IO.File.Copy(strConverterLocalSourcePathFile, System.IO.Path.Combine(strLocalPathTarget, dov.ObjectID + ".flv"));
                    }
                    catch (Exception ex)
                    {
                        WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 9, "couldn't copy to " + strLocalPathTarget, _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, ex.Message);
                        blnIsOK = false;
                    }
                }

                // check if movie FLV exists
                // if yes, convert has succeed (99%)
                // generate thumbnails if FLV file exists
                if (vbio.FileExists(System.IO.Path.Combine(strLocalPathTarget, dov.ObjectID + ".flv")))
                {
                    WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 6, "video converted (Step 6 / 14)", _4screen.CSB.Common.MonitoringLogState.OK, "");

                    // do the preview snapshots
                    GenerateSnapshot(dov.ObjectID, dov.UserID);

                    // move the files from local convert server to the media server
                    try
                    {
                        //Check if The video Should be send to Amazone or moved to the Mediaserver
                        if (!useAmazoneS3)
                        {
                            if (!Directory.Exists(strTargetOutPath + @"FLV\"))
                            {
                                Directory.CreateDirectory(strTargetOutPath + @"FLV\");
                            }
                            vbio.MoveFile(System.IO.Path.Combine(strLocalPathTarget, dov.ObjectID + ".flv"), System.IO.Path.Combine(strTargetOutPath + @"FLV\", dov.ObjectID + ".flv"), true);
                        }
                        else
                        {
                            intSizeBite = (int)UploadToAmazone(System.IO.Path.Combine(strLocalPathTarget, dov.ObjectID + ".flv"), dov.ObjectID, dov.UserID);
                            if (intSizeBite == -1)
                            {
                                blnIsOK = false;
                            }
                            vbio.DeleteFile(System.IO.Path.Combine(strLocalPathTarget, dov.ObjectID + ".flv"));
                        }

                        WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 9, "move converted video to the media path (Step 9 / 14)", _4screen.CSB.Common.MonitoringLogState.OK, "");
                    }
                    catch (Exception ex)
                    {
                        blnIsOK = false;
                        WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 9, "move converted video to the media path (Step 9 / 14)", _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, ex.Message);
                    }
                }
                else
                {
                    blnIsOK         = false;
                    strCheckMessage = string.Format("CRITICAL ERROR: converted FLV movie does not exist! Please check this: " + System.IO.Path.Combine(strTargetOutPath, dov.ObjectID + ".flv"));
                    WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 6, "video converted (Step 6 / 14)", _4screen.CSB.Common.MonitoringLogState.AbortedMissionCritical, strCheckMessage);
                }

                // finale check for running convert processes
                try
                {
                    Process[] localByName = Process.GetProcessesByName("convert");
                    for (int i = 0; i < localByName.Length; i++)
                    {
                        localByName[i].Kill();
                    }
                }
                catch
                { }

                blnIsEncoding = false;

                // Get File Size statistics
                try
                {
                    FileInfo fiUpload = new FileInfo(strSourcePathFile);
                    intStatisticFileSizeByte = (int)fiUpload.Length;
                    fiUpload = null;
                }
                catch
                { }
            }
            #endregion DO THE ENCODING

            #region WRITE To THE DATABASE
            // Update Queue Item
            int intConvertTryCount = convertQueue.TryingCount;
            intConvertTryCount++;

            try
            {
                if (blnIsOK)
                {
                    // succeded
                    TimeSpan ts = (TimeSpan)(DateTime.Now - dtmStart);
                    int      intStatisticWorkTimeSec = (int)ts.TotalSeconds;

                    convertQueue.TryingCount            = intConvertTryCount;
                    convertQueue.ConvertMessage         = strCheckMessage;
                    convertQueue.Status                 = _4screen.CSB.Common.MediaConvertedState.Convertet;
                    convertQueue.LastTimeStamp          = DateTime.Now;
                    convertQueue.StatisticFileExtension = strStatisticFileExtension;
                    convertQueue.StatisticFileSizeByte  = intStatisticFileSizeByte;
                    convertQueue.StatisticWorkTimeSec   = intStatisticWorkTimeSec;
                    convertQueue.Update();

                    try
                    {
                        // delete the source file in the upload folder
                        File.Delete(strSourcePathFile);
                        // delete temporary convert source file
                        File.Delete(strConverterLocalSourcePathFile);
                    }
                    catch
                    { }
                }
                else
                {
                    // aborted
                    convertQueue.TryingCount = intConvertTryCount;
                    if (intConvertTryCount >= maxRetries)
                    {
                        convertQueue.Status = _4screen.CSB.Common.MediaConvertedState.ConvertError;
                    }
                    else
                    {
                        convertQueue.Status = _4screen.CSB.Common.MediaConvertedState.NotConvertet;
                        convertQueue.LookID = "";
                    }

                    convertQueue.ConvertMessage         = strCheckMessage;
                    convertQueue.LastTimeStamp          = DateTime.Now;
                    convertQueue.StatisticFileExtension = strStatisticFileExtension;
                    convertQueue.StatisticFileSizeByte  = intStatisticFileSizeByte;
                    convertQueue.StatisticWorkTimeSec   = -1;
                    convertQueue.Update();
                }

                WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 12, "update convert queue in database (Step 12 / 14)", _4screen.CSB.Common.MonitoringLogState.OK, "");
            }
            catch
            {
                //Error: update convert queue crashed
                strCheckMessage = string.Format("ConvertQueue final update crashed! Please check the convert queue in the database");
                WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 12, "update convert queue in database (Step 12 / 14)", _4screen.CSB.Common.MonitoringLogState.OKWithWarning, strCheckMessage);
            }

            // Update Object Item
            try
            {
                if (blnIsOK)
                {
                    // succeded
                    string strHTTPPathOutput       = string.Empty;
                    string strHTTPImageOutput      = string.Empty;
                    string strHTTPImageLargeOutput = string.Empty;
                    string strTmpOutPathAndFile    = strTargetOutPath + @"FLV\" + dov.ObjectID + ".flv";

                    //File Size
                    try
                    {
                        FileInfo fiUpload = new FileInfo(strTmpOutPathAndFile);
                        intSizeBite = (int)fiUpload.Length;
                        fiUpload    = null;
                    }
                    catch
                    { }

                    if (strTmpOutPathAndFile.StartsWith(strConverterRootPathMedia))
                    {
                        strHTTPPathOutput = strTmpOutPathAndFile.Substring(strConverterRootPathMedia.Length).Replace("\\", "/");
                    }

                    dov.SetImageType(_4screen.CSB.Common.PictureVersion.L, _4screen.CSB.Common.PictureFormat.Jpg);
                    dov.SetImageType(_4screen.CSB.Common.PictureVersion.S, _4screen.CSB.Common.PictureFormat.Jpg);
                    dov.SetImageType(_4screen.CSB.Common.PictureVersion.XS, _4screen.CSB.Common.PictureFormat.Jpg);
                    dov.Image            = dov.ObjectID;
                    dov.ConvertMessage   = string.Empty;
                    dov.DurationSecond   = -1; // TODO kann mit dieser Engine nicht ausgelesen werden
                    dov.Location         = strHTTPPathOutput;
                    dov.OriginalLocation = strOriginalLocation;
                    dov.SizeByte         = intSizeBite;
                    //Depending on the Community Settings set the default Showstate to this object
                    DataObject doCont = new DataObject(udc);
                    doCont.ObjectID = dov.CommunityID;
                    doCont.Load(null, true);
                    if (doCont.State != _4screen.CSB.Common.ObjectState.Added)
                    {
                        if (doCont.ObjectType == _4screen.CSB.Common.ObjectType.Community)
                        {
                            if (!string.IsNullOrEmpty(doCont.GetXMLValue("Managed")) && doCont.GetXMLValue("Managed") == "1")
                            {
                                if (DataObjectCommunity.IsUserOwner(dov.CommunityID, dov.UserID))
                                {
                                    dov.ShowState = _4screen.CSB.Common.ObjectShowState.Published;
                                }
                                else
                                {
                                    dov.ShowState = _4screen.CSB.Common.ObjectShowState.Draft;
                                }
                            }
                            else
                            {
                                dov.ShowState = _4screen.CSB.Common.ObjectShowState.Published;
                            }
                        }
                        else
                        {
                            dov.ShowState = _4screen.CSB.Common.ObjectShowState.Published;
                        }
                    }
                    dov.UpdateBackground();
                }
                else
                {
                    dov.ShowState        = ObjectShowState.ConversionFailed;
                    dov.ConvertMessage   = strCheckMessage;
                    dov.DurationSecond   = -1;
                    dov.Location         = "";
                    dov.OriginalLocation = strOriginalLocation;
                    dov.SizeByte         = -1;
                    dov.Image            = "";
                    dov.UpdateBackground();
                }

                WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 13, "update object item in database (Step 13 / 14)", _4screen.CSB.Common.MonitoringLogState.OK, "");
            }
            catch
            {
                //Error: update convert queue crashed
                strCheckMessage = string.Format("Object item final database update crashed! Please check the Object item in the database");
                WriteMonitoringLog(strTransactionID, dov.ObjectID, BaseActions.VideoConvert, 13, "update object item in database (Step 13 / 14)", _4screen.CSB.Common.MonitoringLogState.OKWithWarning, strCheckMessage);
            }

            #endregion WRITE TO DATABASE

            if (strCheckMessage.Length > 0)
            {
                eventLog.WriteEntry(strCheckMessage, EventLogEntryType.Error);
            }

            if (blnIsOK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }