Example #1
0
 public static void LogEvent(string action, Guid videoId, string message)
 {
     using (VideoDBContext db = new VideoDBContext())
     {
         Models.AuditLog logItem = new AuditLog();
         logItem.Action = action;
         logItem.LogDateTime = DateTime.UtcNow;
         logItem.UserIpAddress = HttpContext.Current.Request.UserHostAddress;
         logItem.UserName = HttpContext.Current.User.Identity.Name;
         logItem.VideoID = videoId;
         logItem.Message = message;
         db.AuditLog.Add(logItem);
         db.SaveChanges();
     }
 }
Example #2
0
        public static void CheckProcessingStatus()
        {

            var context = GetMediaContext();
    
            using (VideoDBContext db = new VideoDBContext())
            {
                var inProcess = from v in db.Videos where v.Status != (int)VideoProcessStatus.Completed && v.Status!=(int)VideoProcessStatus.Error select v;
                foreach (var vid in inProcess)
                {
                    //find job and check tasks for video
                    var job = (from j in context.Jobs where j.Id == vid.JobID select j).FirstOrDefault();

                    if (job != null)
                    {
                        //Get Tasks for each process
                        var encodingTask = job.Tasks.Where(t => t.Name == "Encoding").FirstOrDefault();
                        var encodingTask2 = job.Tasks.Where(t => t.Name == "Encoding2").FirstOrDefault();
                        var thumbnailTask = job.Tasks.Where(t => t.Name == "Thumbnail").FirstOrDefault();
                        var indexTask = job.Tasks.Where(t => t.Name == "Indexing").FirstOrDefault();

                        //Check tasks
                        if (encodingTask.State == JobState.Finished)
                            vid.Status = (int)VideoProcessStatus.Encoding;

                        if (encodingTask2.State == JobState.Finished)
                            vid.Status = (int)VideoProcessStatus.CreatingThumbnail;

                        if (thumbnailTask.State == JobState.Finished)
                            vid.Status = (int)VideoProcessStatus.IndexingAudio;

                        //Ensure all tasks are completed before marking the status as completed.  If multipe encoding units are used it is not possible to 
                        //guarantee that any one task will be the last to finish.
                        if (indexTask.State == JobState.Finished && thumbnailTask.State == JobState.Finished && encodingTask2.State == JobState.Finished && encodingTask.State == JobState.Finished)
                            vid.Status = (int)VideoProcessStatus.Completed;

                        if (encodingTask.State == JobState.Error || encodingTask2.State == JobState.Error || thumbnailTask.State == JobState.Error || indexTask.State == JobState.Error)
                            vid.Status = (int)VideoProcessStatus.Error;

                        
                        if (vid.Status == (int)VideoProcessStatus.Completed)
                        {
                            var encodedAsset = encodingTask.OutputAssets.FirstOrDefault();
                            var encodedAsset2 = encodingTask2.OutputAssets.FirstOrDefault();
                            var thumbnailAsset = thumbnailTask.OutputAssets.FirstOrDefault();
                            var vttAsset = indexTask.OutputAssets.FirstOrDefault();

                            var keywordAsset = indexTask.OutputAssets.FirstOrDefault().AssetFiles.Where(t => t.Name.EndsWith(".ttml")).FirstOrDefault();

                            string thumbUrl = AzureVidMan.Utils.VidProcessUtil.GetThumbnailUrl(context, thumbnailAsset.Id);
                            string videoUrl = AzureVidMan.Utils.VidProcessUtil.GetDynamicStreamingUrl(context, encodedAsset.Id);
                            string vttUrl = AzureVidMan.Utils.VidProcessUtil.GetCaptionUrl(context, vttAsset.Id);

                            if (keywordAsset != null)
                            {
                                var ttmlFile = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]).CreateCloudBlobClient()
                                    .GetBlobReferenceFromServer(new Uri(keywordAsset.Asset.Uri + "/" + keywordAsset.Name));

                                MemoryStream ms = new MemoryStream();
                                ttmlFile.DownloadToStream(ms);
                                ms.Position = 0;

                                StreamReader sr = new StreamReader(ms);
                                string keywordsXML = sr.ReadToEnd();
                                keywordsXML = keywordsXML.Replace("encoding=\"utf-8\"","encoding=\"utf-16\"");
                                vid.KeywordsXML = keywordsXML;

                                vid.Encoding1AssetID = encodedAsset.Id;
                                vid.Encoding2AssetID = encodedAsset2.Id;
                                vid.ThumbnailAssetID = thumbnailAsset.Id;
                                vid.CaptionAssetID = vttAsset.Id;

                            }
                            vid.CaptionUrl = vttUrl;
                            vid.ThumbnailURL = thumbUrl;
                            vid.FileURL = videoUrl;

                        }
                    }
                }

                db.SaveChanges();
            }
        }