Example #1
0
        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);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        public static string GetPlaylistFeed(Guid?objectId, VideoFormat videoFormat, VideoVersion videoVersion)
        {
            UserDataContext udc = UserDataContext.GetUserDataContext();

            DataObjectVideo     dataObjectVideo = DataObject.Load <DataObjectVideo>(objectId);
            DataObjectCommunity community       = DataObject.Load <DataObjectCommunity>(dataObjectVideo.CommunityID);

            QuickParameters quickParameters = new QuickParameters();

            quickParameters.Udc        = udc;
            quickParameters.ObjectType = Helper.GetObjectTypeNumericID("Video");
            quickParameters.SortBy     = QuickSort.StartDate;
            quickParameters.Amount     = 100;
            quickParameters.PageSize   = 100;
            quickParameters.PageNumber = 1;
            quickParameters.ShowState  = ObjectShowState.Published;
            if (community.ObjectType == Helper.GetObjectTypeNumericID("Community"))
            {
                quickParameters.CommunityID = community.ObjectID;
            }
            else if (community.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity"))
            {
                quickParameters.UserID = community.UserID;
            }

            MediaSyndicationFeed feed = new MediaSyndicationFeed();

            string title = string.Empty;

            if (community.ObjectType == Helper.GetObjectTypeNumericID("Community"))
            {
                title = "Video aus " + community.Title;
            }
            else if (community.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity"))
            {
                title = "Videos von " + community.Nickname;
            }

            feed.Title = TextSyndicationContent.CreatePlaintextContent(title);

            //feed.Description = TextSyndicationContent.CreatePlaintextContent("");
            string feedUrl = SiteConfig.SiteURL + Helper.GetDetailLink(community.ObjectType, community.ObjectID.Value.ToString());

            feed.Links.Add(new SyndicationLink(new Uri(feedUrl)));
            feed.Language = "de-CH";

            List <SyndicationItem>           items  = new List <SyndicationItem>();
            DataObjectList <DataObjectVideo> videos = DataObjects.Load <DataObjectVideo>(quickParameters);

            foreach (DataObjectVideo video in videos)
            {
                MediaSyndicationItem item = new MediaSyndicationItem();

                item.MediaContentUrl      = new Uri(string.Format("{0}{1}", Helper.GetVideoBaseURL(), video.GetLocation(videoFormat, videoVersion)));
                item.MediaContentDuration = video.DurationSecond;
                item.MediaContentType     = "video/x-flv";
                item.MediaThumbnailUrl    = new Uri(string.Format("{0}{1}", SiteConfig.MediaDomainName, video.GetImage(PictureVersion.S)));
                item.MediaKeywords        = video.TagList.Replace(Constants.TAG_DELIMITER.ToString(), ", ");
                item.MediaCredit          = video.Nickname;

                item.Title = TextSyndicationContent.CreatePlaintextContent(video.Title.StripHTMLTags());

                item.Id = video.ObjectID.Value.ToString();

                string itemUrl = SiteConfig.SiteURL + Helper.GetDetailLink(video.ObjectType, video.ObjectID.Value.ToString());
                item.AddPermalink(new Uri(itemUrl));

                item.PublishDate = video.StartDate;

                items.Add(item);
            }

            feed.Items = items;

            StringBuilder     sb       = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            XmlWriter xmlWriter = XmlWriter.Create(sb, settings);

            feed.SaveAsRss20(xmlWriter);
            xmlWriter.Close();

            string feedXml = sb.ToString();

            feedXml = Regex.Replace(feedXml, @"^<.*?xml.*?>\s*", "");
            return(feedXml);
        }