/// <summary> /// removes the working directory and tmp files. /// </summary> public void CleanUp() { try { if (Directory.Exists(WorkingDirectory)) { log.Info($"Removing temp working directory: {WorkingDirectory}"); if (FileDirectoryOperations.DeleteDirectory(WorkingDirectory)) { DirectoryInfo directoryInfo = new DirectoryInfo(ITV2ADI_CONFIG.TempWorkingDirectory); foreach (var file in directoryInfo.GetFiles("*.*")) { File.Delete(file.FullName); } log.Info($"Cleanup of Temp directory: {ITV2ADI_CONFIG.TempWorkingDirectory} Successful"); } else { throw new Exception($"Temp Working Directory/File(s) were not removed, please remove manually"); } } } catch (Exception CU_EX) { log.Error($"Failed During Cleanup - {CU_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {CU_EX.StackTrace}"); } } }
/// <summary> /// Final function to package and deliver to the enhancement software input directory /// If the item is tvod the package is delivered with a prefix of tvod. /// </summary> /// <returns></returns> private bool PackageAndDeliverAsset() { try { using (ZipHandler ziphandler = new ZipHandler()) { string fname = WorkDirname; string package = $"{WorkingDirectory}.zip"; string tmpPackage = Path.Combine(ITV2ADI_CONFIG.EnrichmentDirectory, $"{fname}.tmp"); string finalPackage = Path.Combine(ITV2ADI_CONFIG.EnrichmentDirectory, $"{fname}.zip"); if ((File.Exists(package)) || (File.Exists(tmpPackage))) { File.Delete(package); File.Delete(tmpPackage); } log.Info("Starting Packaging and Delivery operations."); log.Info($"Packaging Source directory: {WorkingDirectory} to Zip Archive: {package}"); ///Compress Package ziphandler.CompressPackage(WorkingDirectory, package); log.Info($"Zip Archive: {package} created Successfully."); log.Info($"Moving: {package} to {tmpPackage}"); ///Move package to to destination as a .tmp file extension to prevent enrichment picking it up FileDirectoryOperations.MoveFile(package, tmpPackage); log.Info($"Successfully Moved: {package} to {tmpPackage}"); log.Info($"Moving tmp Package: {tmpPackage} to {finalPackage}"); ///rename the package from .tmp to .zip FileDirectoryOperations.MoveFile(tmpPackage, finalPackage); log.Info($"Successfully Moved: {tmpPackage} to {finalPackage}"); log.Info("Updating Database with final data"); ///add remaining data to the database for later use UpdateItvData(); ///if the config value DeleteFromSource = true delete the source media if (DeleteFromSource) { FileDirectoryOperations.DeleteSourceMedia(MediaLocation); } log.Info("Starting Packaging and Delivery operations completed Successfully."); return(true); } } catch (Exception PADA_EX) { log.Error($"Failed to Package and Deliver Asset - {PADA_EX.Message}"); if (log.IsDebugEnabled) { log.Debug($"STACK TRACE: {PADA_EX.StackTrace}"); } return(false); } }
/// <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> /// Creates the Temp working directory /// </summary> /// <returns></returns> private bool CreateWorkingDirectory() { log.Info($"Creating Temp working Directory: {WorkingDirectory}"); FileDirectoryOperations.CreateDirectory(WorkingDirectory); if (!IsUpdate) { ///need to avoid this for updates! log.Info($"Creating Media Directory: {MediaDirectory}"); FileDirectoryOperations.CreateDirectory(MediaDirectory); } return(Directory.Exists(WorkingDirectory)); }
void CleanTempDirectory() { FileDirectoryOperations.CleanTempDirectory(ITV2ADI_CONFIG.TempWorkingDirectory); }
/// <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); } }
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); } }