/// <summary> /// Seeds the data early on as some parts are used for lookups / updating /// Failed ingest will have the row data deleted /// </summary> private void SeedItvData() { try { using (ITVConversionContext seedDb = new ITVConversionContext()) { seedDb.ItvConversionData.Add(new ItvConversionData { Paid = ITVParser.ITV_PAID, Title = ProgramTitle, VersionMajor = Version_Major, LicenseStartDate = LicenseStart, LicenseEndDate = LicenseEnd, ProviderName = ProviderName, ProviderId = ProviderId, OriginalItv = ITVParser.ITV_Data.ToString(), //updated to check for illegal chars MediaFileName = MediaFileName, MediaFileLocation = MediaLocation, ProcessedDateTime = DateTime.Now, PublicationDate = Publication_Date }); int count = seedDb.SaveChanges(); ItvConversionData rowId = seedDb.ItvConversionData.Local.FirstOrDefault(); ItvData_RowId = rowId.Id; log.Info($"{count} record(s) saved to the database with Row ID: {ItvData_RowId}"); } } catch (Exception SID_EX) { throw new Exception($"Error encountered Seeding Data: {SID_EX.Message}"); } }
/// <summary> /// Timer Event for cleanup, flags a boolean in case there is processing underway /// allowing the clean up to occur post processing /// </summary> /// <param name="src"></param> /// <param name="e"></param> private void ElapsedTime(object src, ElapsedEventArgs e) { if (!IsProcessing) { using (ITVConversionContext db = new ITVConversionContext()) { log.Info("Checking for expired data in the ITV Conversion db"); var rowData = db.ItvConversionData.Where(le => Convert.ToDateTime(le.LicenseEndDate.Value.ToString().Trim(' ')) < DateTime.Now).ToList(); if (rowData == null) { log.Info("No expired data present."); } else { foreach (var row in rowData) { string paid = row.Paid; log.Debug($"DB Row ID {row.Id} with PAID Value: {paid} has expired with License End date: {row.LicenseEndDate.Value}, removing from database."); var maprow = db.ItvConversionData .Where(r => r.Paid == paid) .FirstOrDefault(); if (maprow != null) { db.ItvConversionData.Remove(maprow); db.SaveChanges(); } } } } } }
private bool SetProviderContentTierData() { ProviderContentTierMapping contentTierMapping = new ProviderContentTierMapping(); using (ITVConversionContext ctm_Context = new ITVConversionContext()) { string distributor_val = ITVParser.GET_ITV_VALUE("Distributor"); foreach (ProviderContentTierMapping ctm_entry in ctm_Context.ProviderContentTierMapping) { try { if (ctm_entry.Distributor == distributor_val) { AdiMapping.SetProviderContentTierValue(ctm_entry.ProviderContentTier); break; } } catch (Exception SPCTD_EX) { log.Error($"Failed while Mapping distributor data: {ctm_entry.Distributor} to Provider content tier: {ctm_entry.ProviderContentTier} - {SPCTD_EX.Message}"); if (SPCTD_EX.InnerException != null) { log.Debug($"Inner Exception: {SPCTD_EX.InnerException.Message}"); } return(false); } } } return(true); }
/// <summary> /// ADI template with basic data used to deserialise adi data /// </summary> private void LoadAdiTemplate() { try { AdiMapping = new ADI_Mapping(); if (!IsUpdate) { AdiMapping.DeserializeAdi(Properties.Resources.ADITemplate); } else { using (ITVConversionContext db = new ITVConversionContext()) { var origAdi = db.ItvConversionData.Where(p => p.Paid == ITVParser.ITV_PAID).FirstOrDefault().OriginalAdi; AdiMapping.DeserializeAdi(origAdi); } } } catch (Exception LAT_EX) { log.Error($"Failed to Load ADI Template - {LAT_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {LAT_EX.StackTrace}"); } } }
/// <summary> /// Main Method for processing the product entries 1 by 1 /// this will enure the required methods are invoked for parsing and packaging /// plus will process failed objects. /// </summary> /// <param name="productData"></param> /// <param name="ComponentData"></param> private void ProcessProductList(KeyData productData, KeyData ComponentData) { if (!string.IsNullOrEmpty(ComponentData.KeyName)) { string ctype = ITVParser.ComponentType(ComponentData.Value); if (ComponentData.Value == "1") { log.Info("Setting packaging variables for use during workflow."); if (SetRequiredPackageVars(productData.KeyName, ComponentData.KeyName, ctype)) { log.Info("Variables set Successfully"); string programName = ITVParser.GET_ITV_VALUE("Title"); log.Info($"*************** Generating Package For PAID: { ITVParser.ITV_PAID}, Program name: {programName} ***************\r\n"); log.Info($"Matching ComponentID: {ComponentData.KeyName},{ctype}"); if (StartProcessing()) { B_IsSuccess = true; CleanUp(); log.Info($"All operations completed Successfully, removing temporary Files/Directories for PAID: {ITVParser.ITV_PAID}"); log.Info($"***************Packaging FINISHED For PAID: { ITVParser.ITV_PAID}, Program name: {programName} ***************\r\n"); } else { log.Error("Failed during Conversion Process, the relevant error should be logged above for the problem area, check logs for errors and rectify."); FileDirectoryOperations.ProcessITVFailure(ITV2ADI_CONFIG.FailedDirectory, WorkDirname, ITV_FILE); ItvFailure = true; if (Directory.Exists(WorkingDirectory)) { CleanUp(); } if (ItvData_RowId > 0) { using (ITVConversionContext db = new ITVConversionContext()) { var rData = db.ItvConversionData.Where(i => i.Id == ItvData_RowId).FirstOrDefault(); if (rData != null) { db.Remove(rData); db.SaveChanges(); } } } B_IsSuccess = false; log.Error($"***************Packaging FAILED For PAID: { ITVParser.ITV_PAID}, Program name: {programName} ***************\r\n"); } } } } }
/// <summary> /// Function to determine if the package is an update or full ingest /// </summary> private void CheckUpdate() { IsUpdate = false; RejectIngest = false; using (ITVConversionContext uDB = new ITVConversionContext()) { var rowData = uDB.ItvConversionData.Where(p => p.Paid == ITVParser.ITV_PAID) .Select(pd => new { pd.Id, pd.PublicationDate, pd.VersionMajor }) .FirstOrDefault(); if (rowData != null) { if (Publication_Date > rowData.PublicationDate) { log.Info("Package detected as an Update."); ItvData_RowId = rowData.Id; Version_Major = rowData.VersionMajor + 1; log.Info($"Existing Version Major: {rowData.VersionMajor} Updated Version Major: {Version_Major}"); IsUpdate = true; return; } else { log.Error($"Rejected: Ingest exists in the database however the publication_date is not greater than the existing ingest"); RejectIngest = true; return; } } else { Version_Major = 1; } } }
/// <summary> /// Function to update the db data upon successful parsing of the package /// </summary> private void UpdateItvData() { try { using (ITVConversionContext upDb = new ITVConversionContext()) { ItvConversionData entity = upDb.ItvConversionData.FirstOrDefault(i => i.Id == ItvData_RowId); string adi = Path.Combine(WorkingDirectory, "ADI.xml"); AdiMapping.LoadXDocument(adi); entity.IsTvod = AdiMapping.IsTVOD; entity.IsAdult = iTVConversion.IsAdult.ToLower() == "y" ? true : false; entity.PublicationDate = Publication_Date; if (!IsUpdate) { entity.OriginalAdi = AdiMapping.ADI_XDOC.ToString(); entity.MediaFileLocation = MediaLocation; entity.MediaChecksum = MediaChecksum; } else { entity.VersionMajor = Version_Major; entity.UpdateAdi = AdiMapping.ADI_XDOC.ToString(); entity.UpdatedDateTime = DateTime.Now; //entity.UpdatedFileLocation = MediaLocation; //entity.UpdatedFileName = MediaFileName; entity.UpdatedItv = ITVParser.ITV_Data.ToString(); //entity.UpdatedMediaChecksum = MediaChecksum; } int count = upDb.SaveChanges(); ItvConversionData rowId = upDb.ItvConversionData.Local.FirstOrDefault(); log.Info($"{count} record(s) updated in the database with Row ID: {ItvData_RowId}"); } } catch (Exception UID_EX) { throw new Exception($"Error encountered Updating DB Data: {UID_EX.Message}"); } }
private bool ProcessTvodUpdate() { try { using (ITVConversionContext iTVConversionContext = new ITVConversionContext()) { string _DBAdiFile = iTVConversionContext .ItvConversionData .Where(i => i.Id == ItvData_RowId) .FirstOrDefault() .OriginalAdi; AdiMapping.DeserializeDBEnrichedAdi(_DBAdiFile); log.Info($"Successfully Loaded Original Adi file from DB for TVOD update."); ///Content value as per mantis 0000003 var contentValue = iTVConversionContext .ItvConversionData .Select(m => Path.GetFileName(m.MediaFileName)) .FirstOrDefault(); RemoveTvodUpdateContent(contentValue); } return(true); } catch (Exception PTU_EX) { log.Error($"Failed while Processing TVOD Update: {PTU_EX.Message}"); if (PTU_EX.InnerException != null) { log.Debug($"Inner exception: {PTU_EX.InnerException.Message}"); } return(false); } }
/// <summary> /// Function to update the asset metadata section /// </summary> /// <returns></returns> private bool SetAssetData() { try { if (!IsUpdate) { log.Info("ITV Metadata conversion completed Successfully, starting media operations"); using (ITVConversionContext mediaContext = new ITVConversionContext()) { MediaLocation = string.Empty; foreach (var location in mediaContext.MediaLocations.ToList()) { FullAssetName = Path.Combine(location.MediaLocation, MediaFileName); if (File.Exists(FullAssetName)) { //set media location used in later logging and calls MediaLocation = location.MediaLocation; //set the bool delete from source object DeleteFromSource = location.DeleteFromSource; log.Info($"Source Media found in location: {MediaLocation} and DeleteFromSource Flag is: {DeleteFromSource}"); //Change to move later on but confirm with dale log.Info($"Copying Media File: {FullAssetName} to {MediaDirectory}"); //create the destination filename //updated to ensure correct video file name is used. string destFname = Path.Combine(MediaDirectory, GetVideoFileName()); //Begin the file movement and file operations if (FileDirectoryOperations.CopyFile(FullAssetName, destFname)) { log.Info($"Media file successfully copied, obtaining file hash for file: {destFname}"); MediaChecksum = VideoFileProperties.GetFileHash(destFname); log.Info($"Source file Hash for {destFname}: {MediaChecksum}"); string fsize = VideoFileProperties.GetFileSize(destFname).ToString(); log.Info($"Source file Size for {destFname}: {fsize}"); AdiMapping.Asset_ID = AdiMapping.ADI_FILE.Asset.Asset.FirstOrDefault().Metadata.AMS.Asset_ID; AdiMapping.SetContent("\\media"); AdiMapping.SetOrUpdateAdiValue("VOD", "Content_CheckSum", MediaChecksum, false); AdiMapping.SetOrUpdateAdiValue("VOD", "Content_FileSize", fsize, false); bool blockPlatform = Convert.ToBoolean(ITV2ADI_CONFIG.BlockQamContentOnOTT); log.Info($"Block platform flag = {blockPlatform}"); if (blockPlatform) { log.Info($"Adding Block_Platform flag with a value of BLOCK_OTT to media metadata section."); AdiMapping.SetOrUpdateAdiValue("VOD", "Block_Platform", "BLOCK_OTT", false); } log.Info("Media metadata and operations completed successfully."); MediaFileName = destFname; return(true); } else { throw new Exception($"File transfer of media file: {MediaFileName} failed, pre and post hashes do not match!"); } } } if (IsUpdate && string.IsNullOrEmpty(MediaLocation)) { log.Info("Update package does not have a media file, continuing with metadata package only."); return(true); } } log.Error($"Media file: {MediaFileName} was not found in the media locations configured, failing ingest."); return(false); } else { return(true); } } catch (Exception SAD_EX) { log.Error($"Failed to Map Asset Data - {SAD_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {SAD_EX.StackTrace}"); } return(false); } }
/// <summary> /// Function that iterates the mappings table in the database and ensures the correct adi fields /// are set with the mapped data, also the valueparser dictionary allows func calls for fields that require /// further parsing outside of a one to one mapping /// </summary> /// <returns></returns> private bool SetProgramData() { iTVConversion = new ITVConversionFunctions(); using (db = new ITVConversionContext()) { iTVConversion.Db = db; bool B_IsFirst = true; if (!IsUpdate) { SeedItvData(); } foreach (var entry in db.FieldMappings.OrderBy(x => x.ItvElement)) { try { string itvValue = ITVParser.GET_ITV_VALUE(entry.ItvElement); bool IsMandatoryField = entry.IsMandatoryField; SetAdiAssetId(entry.IsTitleMetadata); if (B_IsFirst) { //In place to get the showtype string tmpVal = ITVParser.GET_ITV_VALUE("ReportingClass"); iTVConversion.ParseReportingClass(tmpVal, entry.AdiElement, true); B_IsFirst = false; } Dictionary <string, Func <string> > ValueParser = new Dictionary <string, Func <string> >() { { "none", () => ITVParser.GetNoneTypeValue(entry.ItvElement) }, { "BillingId", () => ITV_Parser.GetBillingId(ITVParser.ITV_PAID) }, { "SummaryLong", () => AdiMapping.ConcatTitleDataXmlValues(itvValue, ITVParser.GET_ITV_VALUE("ContentGuidance")) }, { "Length", () => GetVideoRuntime() }, //VideoFileProperties.GetMediaInfoDuration(FullAssetName, IsUpdate) }, { "RentalTime", () => ITVParser.GetRentalTime(entry.ItvElement, itvValue, iTVConversion.IsMovie, iTVConversion.IsAdult) }, { "ReportingClass", () => iTVConversion.ParseReportingClass(itvValue, entry.AdiElement, entry.IsTitleMetadata) }, { "ServiceCode", () => AdiMapping.ProcessServiceCode(iTVConversion.IsAdult, ITVParser.GET_ITV_VALUE("ServiceCode")) }, { "HDContent", () => AdiMapping.SetEncodingFormat(itvValue) }, { "CanBeSuspended", () => ITVParser.CanBeSuspended(itvValue) }, { "Language", () => ITV_Parser.GetISO6391LanguageCode(itvValue) }, { "AnalogCopy", () => AdiMapping.CGMSMapping(itvValue) } }; if (ValueParser.ContainsKey(entry.ItvElement)) { itvValue = ValueParser[entry.ItvElement](); } if (!string.IsNullOrEmpty(itvValue)) { AdiMapping.SetOrUpdateAdiValue(entry.AdiAppType, entry.AdiElement, itvValue, entry.IsTitleMetadata); } else if (entry.IsMandatoryField && string.IsNullOrEmpty(itvValue)) { log.Error($"Rejected: Mandatory itv Field: {entry.ItvElement} not Found in the source ITV File."); return(false); } } catch (Exception SPD_EX) { log.Error($"Failed while Mapping Title MetaData itv value: {entry.ItvElement} to Adi value: {entry.AdiElement} - {SPD_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {SPD_EX.StackTrace}"); } return(false); } } } return(CheckTvodUpdate()); }
private bool FilterItvFile() { try { using (ITVConversionContext conversionContext = new ITVConversionContext()) { var itvFilters = conversionContext.Itvfilter.ToList(); var fileLines = File.ReadAllLines(ITV_FILE); foreach (Itvfilter filter in itvFilters) { if (filter.Enabled == true) { int filterLength = 0; //string regexPattern = $"(?i)({filter.MatchString})".Replace("\\","\\\\"); string searchString = filter.MatchString.Replace("\\", "\\\\"); if (searchString.Contains("=")) { var oldSearch = searchString.Length; searchString = searchString.Contains(" = ") ? $"(?i)(?m)(?<!\\S)({searchString})$" : $"(?i)(?m)(?<!\\S)({searchString.Replace("=", " = ")})$"; filterLength = filter.MatchString.Length + (searchString.Length - oldSearch); } foreach (var line in fileLines) { Match match = Regex.Match(line, searchString); if (match.Success) { log.Warn($"Failing ingest for {ITV_FILE} due to matching filter string"); if (filter.DeleteOnMatch == true) { log.Warn($"Delete on match is TRUE, deleting source itv file: {ITV_FILE}"); File.Delete(ITV_FILE); if (!File.Exists(ITV_FILE)) { log.Info($"File: {ITV_FILE} successfully deleted."); } else { log.Error($"Failed to delete source itv file: {ITV_FILE}"); } } else { log.Warn($"Delete on match is FALSE, moving file {ITV_FILE} to {filter.MoveOnMatchDirectory}"); string destfile = Path.Combine(filter.MoveOnMatchDirectory, Path.GetFileName(ITV_FILE)); FileDirectoryOperations.MoveFile(ITV_FILE, destfile); if (File.Exists(destfile)) { log.Info($"Successfully moved source itv file: {ITV_FILE} to {destfile}"); } else { log.Warn($"Failed to move source itv file {ITV_FILE} to {destfile} check logs."); } } return(false); } } } } } return(true); } catch (Exception FIFEX) { log.Error($"Failed Filtering ITV File: {ITV_FILE} - {FIFEX.Message}"); if (FIFEX.InnerException != null) { log.Debug($"Inner exception: {FIFEX.InnerException.Message}"); } return(false); } }