/// <summary> /// encode file to preset /// </summary> /// <param name="sourcePath">filepath to encode</param> /// <param name="workingDirectory">working directory</param> /// <param name="originalFilenameNoExt">original filename without extension</param> /// <param name="presetPath">path to preset to use for this encoding</param> /// <param name="logFile">logging file</param> /// <returns>true if successful</returns> private bool EncodeFile (string sourcePath, string workingDirectory, string originalFilenameNoExt, string presetPath, TraceListener logFile) { bool success = true; string presetOutputDirectory = Path.Combine (this.directoryManager.OutputDirectory, Path.GetFileNameWithoutExtension (presetPath)); this.EncoderJob = new Job (); try { logFile.WriteLine ("\r\n\r\n------------------------------------------------------------\r\n"); logFile.WriteLine ("Preset: " + Path.GetFileNameWithoutExtension (presetPath)); logFile.WriteLine ("Source: " + sourcePath); Directory.CreateDirectory (presetOutputDirectory); // encode Preset preset = Preset.FromFile (presetPath); MediaItem mediaItem = new MediaItem (sourcePath); mediaItem.ApplyPreset (preset); mediaItem.OutputFileName = "{Original file name}.Target.{Default extension}"; this.EncoderJob.MediaItems.Add (mediaItem); this.EncoderJob.OutputDirectory = workingDirectory; this.EncoderJob.CreateSubfolder = false; this.EncoderJob.EncodeProgress += new EventHandler<EncodeProgressEventArgs> (this.Job_EncodeProgress); this.EncoderJob.EncodeCompleted += new EventHandler<EncodeCompletedEventArgs> (this.Job_EncodeCompleted); UserNotification.EncodingStarting (sourcePath + "->" + mediaItem.ActualOutputFileFullPath, EncodeInformation (mediaItem, "<br>")); this.JobLog.WriteLine (EncodeInformation (mediaItem, "\r\n")); if (this.EncodeStarted != null) { this.EncodeStarted (this, null); } this.EncoderJob.Encode (); string outputSourcePath = Path.Combine (workingDirectory, mediaItem.ActualOutputFileName); string outputTargetPath = Path.Combine (presetOutputDirectory, originalFilenameNoExt + Path.GetExtension (mediaItem.ActualOutputFileName)); Utilities.RenameFileMove (outputSourcePath, ref outputTargetPath, logFile); logFile.WriteLine ("\r\n\r\nSuccess: Created Output file '" + outputTargetPath + "'"); if (this.EncodeEnded != null) { this.EncodeEnded (this, null); } } catch (Exception ex) { logFile.WriteLine ("\r\n\r\nException: " + ex.Message); success = false; if (this.EncodeError != null) { this.EncodeError (this, null); } } return success; }