From: Scott Date: Sat, 26 Sep 2015 20:29:34 +0000 (+0100) Subject: App Services Modelling Tidy Up X-Git-Tag: 1.0.0~918 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c19ea798a23bfea7aba509309bef9168ece09836;p=handbrake App Services Modelling Tidy Up Making event objects immutable. Making Libhb constructs internal to the library. We should expose this with a managed api if we need it outside the library. (Part 1) --- diff --git a/win/CS/HandBrake.ApplicationServices/Attributes/ShortName.cs b/win/CS/HandBrake.ApplicationServices/Attributes/ShortName.cs index eab372e34..10a4d1631 100644 --- a/win/CS/HandBrake.ApplicationServices/Attributes/ShortName.cs +++ b/win/CS/HandBrake.ApplicationServices/Attributes/ShortName.cs @@ -30,6 +30,6 @@ namespace HandBrake.ApplicationServices.Attributes /// /// Gets or sets the short name. /// - public string Name { get; set; } + public string Name { get; private set; } } } diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 89562540f..1a99efd1d 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -109,7 +109,6 @@ - diff --git a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeCompletedEventArgs.cs b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeCompletedEventArgs.cs index fa1ea14c3..52b5719fe 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeCompletedEventArgs.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeCompletedEventArgs.cs @@ -17,8 +17,19 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs public class EncodeCompletedEventArgs : EventArgs { /// - /// Gets or sets a value indicating whether an error occurred during the encode. + /// Initializes a new instance of the class. /// - public bool Error { get; set; } + /// + /// The error. + /// + public EncodeCompletedEventArgs(bool error) + { + this.Error = error; + } + + /// + /// Gets a value indicating whether an error occurred during the encode. + /// + public bool Error { get; private set; } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs index d58798e81..5fad3248c 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/EncodeProgressEventArgs.cs @@ -17,27 +17,62 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs public class EncodeProgressEventArgs : EventArgs { /// - /// Gets or sets FractionComplete. + /// Initializes a new instance of the class. /// - public double FractionComplete { get; set; } + /// + /// The fraction complete. + /// + /// + /// The current frame rate. + /// + /// + /// The average frame rate. + /// + /// + /// The estimated time left. + /// + /// + /// The pass id. + /// + /// + /// The pass. + /// + /// + /// The pass count. + /// + public EncodeProgressEventArgs(double fractionComplete, double currentFrameRate, double averageFrameRate, TimeSpan estimatedTimeLeft, int passId, int pass, int passCount) + { + this.FractionComplete = fractionComplete; + this.CurrentFrameRate = currentFrameRate; + this.AverageFrameRate = averageFrameRate; + this.EstimatedTimeLeft = estimatedTimeLeft; + this.PassId = passId; + this.Pass = pass; + this.PassCount = passCount; + } /// - /// Gets or sets CurrentFrameRate. + /// Gets the % Complete. /// - public double CurrentFrameRate { get; set; } + public double FractionComplete { get; private set; } /// - /// Gets or sets AverageFrameRate. + /// Gets the Current FrameRate. /// - public double AverageFrameRate { get; set; } + public double CurrentFrameRate { get; private set; } /// - /// Gets or sets EstimatedTimeLeft. + /// Gets the Average FrameRate. /// - public TimeSpan EstimatedTimeLeft { get; set; } + public double AverageFrameRate { get; private set; } /// - /// Gets or sets the pass ID. + /// Gets the Estimated Time Left. + /// + public TimeSpan EstimatedTimeLeft { get; private set; } + + /// + /// Gets the pass ID. /// /// /// -1: Subtitle scan @@ -45,16 +80,16 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs /// 1: Encode first pass /// 2: Encode second pass /// - public int PassId { get; set; } + public int PassId { get; private set; } /// - /// Gets or sets the current encoding pass. (1-based) + /// Gets the current encoding pass. (1-based) /// - public int Pass { get; set; } + public int Pass { get; private set; } /// - /// Gets or sets the pass count. + /// Gets the pass count. /// - public int PassCount { get; set; } + public int PassCount { get; private set; } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/MessageLoggedEventArgs.cs b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/MessageLoggedEventArgs.cs index e547a2fe8..610ab0a77 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/MessageLoggedEventArgs.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/MessageLoggedEventArgs.cs @@ -17,8 +17,19 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs public class MessageLoggedEventArgs : EventArgs { /// - /// Gets or sets Message. + /// Initializes a new instance of the class. /// - public string Message { get; set; } + /// + /// The message. + /// + public MessageLoggedEventArgs(string message) + { + this.Message = message; + } + + /// + /// Gets the Message. + /// + public string Message { get; private set; } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/ScanProgressEventArgs.cs b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/ScanProgressEventArgs.cs index 3928a53e6..78737943e 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/ScanProgressEventArgs.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/EventArgs/ScanProgressEventArgs.cs @@ -17,28 +17,55 @@ namespace HandBrake.ApplicationServices.Interop.EventArgs public class ScanProgressEventArgs : EventArgs { /// - /// Gets or sets the total progress fraction for the scan. + /// Initializes a new instance of the class. /// - public double Progress { get; set; } + /// + /// The progress. + /// + /// + /// The current preview. + /// + /// + /// The previews. + /// + /// + /// The current title. + /// + /// + /// The titles. + /// + public ScanProgressEventArgs(double progress, int currentPreview, int previews, int currentTitle, int titles) + { + this.Progress = progress; + this.CurrentPreview = currentPreview; + this.Previews = previews; + this.CurrentTitle = currentTitle; + this.Titles = titles; + } /// - /// Gets or sets the current preview being processed on the scan. + /// Gets the total progress fraction for the scan. /// - public int CurrentPreview { get; set; } + public double Progress { get; private set; } /// - /// Gets or sets the total number of previews to process. + /// Gets the current preview being processed on the scan. /// - public int Previews { get; set; } + public int CurrentPreview { get; private set; } /// - /// Gets or sets the current title being processed on the scan. + /// Gets the total number of previews to process. /// - public int CurrentTitle { get; set; } + public int Previews { get; private set; } /// - /// Gets or sets the total number of titles to process. + /// Gets the current title being processed on the scan. /// - public int Titles { get; set; } + public int CurrentTitle { get; private set; } + + /// + /// Gets the total number of titles to process. + /// + public int Titles { get; private set; } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index 62e4e1b5c..a862dc1e6 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -268,7 +268,6 @@ namespace HandBrake.ApplicationServices.Interop public BitmapImage GetPreview(PreviewSettings settings, int previewNumber) { SourceTitle title = this.Titles.TitleList.FirstOrDefault(t => t.Index == settings.TitleNumber); - Validate.NotNull(title, "GetPreview: Title should not have been null. This is probably a bug."); // Create the Expected Output Geometry details for libhb. hb_geometry_settings_s uiGeometry = new hb_geometry_settings_s @@ -510,14 +509,7 @@ namespace HandBrake.ApplicationServices.Interop { if (this.ScanProgress != null) { - this.ScanProgress(this, new ScanProgressEventArgs - { - Progress = state.Scanning.Progress, - CurrentPreview = state.Scanning.Preview, - Previews = state.Scanning.PreviewCount, - CurrentTitle = state.Scanning.Title, - Titles = state.Scanning.TitleCount - }); + this.ScanProgress(this, new ScanProgressEventArgs(state.Scanning.Progress, state.Scanning.Preview, state.Scanning.PreviewCount, state.Scanning.Title, state.Scanning.TitleCount)); } } else if (state != null && state.State == NativeConstants.HB_STATE_SCANDONE) @@ -557,16 +549,8 @@ namespace HandBrake.ApplicationServices.Interop { if (this.EncodeProgress != null) { - var progressEventArgs = new EncodeProgressEventArgs - { - FractionComplete = state.Working.Progress, - CurrentFrameRate = state.Working.Rate, - AverageFrameRate = state.Working.RateAvg, - EstimatedTimeLeft = new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds), - PassId = state.Working.PassID, - Pass = state.Working.Pass, - PassCount = state.Working.PassCount - }; + var progressEventArgs = new EncodeProgressEventArgs(state.Working.Progress, state.Working.Rate, state.Working.RateAvg, new TimeSpan(state.Working.Hours, state.Working.Minutes, state.Working.Seconds), + state.Working.PassID, state.Working.Pass, state.Working.PassCount); this.EncodeProgress(this, progressEventArgs); } @@ -577,10 +561,9 @@ namespace HandBrake.ApplicationServices.Interop if (this.EncodeCompleted != null) { - this.EncodeCompleted(this, new EncodeCompletedEventArgs - { - Error = state.WorkDone.Error != (int)hb_error_code.HB_ERROR_NONE - }); + this.EncodeCompleted( + this, + new EncodeCompletedEventArgs(state.WorkDone.Error != (int)hb_error_code.HB_ERROR_NONE)); } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUnitConversionHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUnitConversionHelpers.cs index 758cfd302..7b981b7af 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUnitConversionHelpers.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUnitConversionHelpers.cs @@ -73,7 +73,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted model. /// - public static HBVideoEncoder NativeToVideoEncoder(hb_encoder_s encoder) + internal static HBVideoEncoder NativeToVideoEncoder(hb_encoder_s encoder) { return new HBVideoEncoder { @@ -93,7 +93,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted model. /// - public static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder) + internal static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder) { var result = new HBAudioEncoder { @@ -120,7 +120,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted rate object. /// - public static HBRate NativeToRate(hb_rate_s rate) + internal static HBRate NativeToRate(hb_rate_s rate) { return new HBRate { @@ -138,7 +138,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted model. /// - public static HBMixdown NativeToMixdown(hb_mixdown_s mixdown) + internal static HBMixdown NativeToMixdown(hb_mixdown_s mixdown) { return new HBMixdown { @@ -157,7 +157,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted structure. /// - public static HBContainer NativeToContainer(hb_container_s container) + internal static HBContainer NativeToContainer(hb_container_s container) { return new HBContainer { @@ -177,7 +177,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// The converted structure. /// - public static Language NativeToLanguage(iso639_lang_t language) + internal static Language NativeToLanguage(iso639_lang_t language) { string englishName = InteropUtilities.ToStringFromUtf8Ptr(language.eng_name); string nativeName = InteropUtilities.ToStringFromUtf8Ptr(language.native_name); diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs index ccbaee4c1..704e794ef 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs @@ -316,7 +316,7 @@ namespace HandBrake.ApplicationServices.Interop { if (MessageLogged != null) { - MessageLogged(null, new MessageLoggedEventArgs { Message = message }); + MessageLogged(null, new MessageLoggedEventArgs(message)); } Debug.WriteLine(message); @@ -332,7 +332,7 @@ namespace HandBrake.ApplicationServices.Interop { if (ErrorLogged != null) { - ErrorLogged(null, new MessageLoggedEventArgs { Message = message }); + ErrorLogged(null, new MessageLoggedEventArgs(message)); } Debug.WriteLine("ERROR: " + message); diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_anamorphic_mode_t.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_anamorphic_mode_t.cs index 6940e73a8..ef0bf03f4 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_anamorphic_mode_t.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_anamorphic_mode_t.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib { - public enum hb_anamorphic_mode_t + internal enum hb_anamorphic_mode_t { HB_ANAMORPHIC_NONE, HB_ANAMORPHIC_STRICT, diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_container_s.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_container_s.cs index b9a8f3255..156bc7554 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_container_s.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_container_s.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] - public struct hb_container_s + internal struct hb_container_s { [MarshalAs(UnmanagedType.LPStr)] public string name; diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_encoder_s.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_encoder_s.cs index 9491cb160..6fddc1827 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_encoder_s.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_encoder_s.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] - public struct hb_encoder_s + internal struct hb_encoder_s { [MarshalAs(UnmanagedType.LPStr)] public string name; diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_mixdown_s.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_mixdown_s.cs index 768ec3189..726ebf226 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_mixdown_s.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_mixdown_s.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] - public struct hb_mixdown_s + internal struct hb_mixdown_s { [MarshalAs(UnmanagedType.LPStr)] public string name; diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_rate_s.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_rate_s.cs index bebeccb7f..5a4f48b4a 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_rate_s.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_rate_s.cs @@ -10,7 +10,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] - public struct hb_rate_s + internal struct hb_rate_s { /// char* [MarshalAs(UnmanagedType.LPStr)] diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/iso639_lang_t.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/iso639_lang_t.cs index 1a4780ab2..86aa71dd8 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/iso639_lang_t.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/iso639_lang_t.cs @@ -11,7 +11,7 @@ namespace HandBrake.ApplicationServices.Interop.HbLib using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] - public struct iso639_lang_t + internal struct iso639_lang_t { public IntPtr eng_name; diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/PreviewSettings.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/PreviewSettings.cs index d413e003b..b3c330a7c 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/PreviewSettings.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/PreviewSettings.cs @@ -9,7 +9,7 @@ namespace HandBrake.ApplicationServices.Interop.Model.Preview { - using HandBrake.ApplicationServices.Interop.Model.Encoding; + using Encoding; /// /// The preview settings. diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 808b3d015..fa2b4bf5a 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -155,6 +155,7 @@ + diff --git a/win/CS/HandBrakeWPF/Helpers/PictureSize.cs b/win/CS/HandBrakeWPF/Helpers/PictureSize.cs index 12a994914..5090339b5 100644 --- a/win/CS/HandBrakeWPF/Helpers/PictureSize.cs +++ b/win/CS/HandBrakeWPF/Helpers/PictureSize.cs @@ -184,7 +184,7 @@ namespace HandBrakeWPF.Helpers keep = settingMode, maxWidth = job.MaxWidth, maxHeight = job.MaxHeight, - mode = (int)(hb_anamorphic_mode_t)job.AnamorphicMode, + mode = (int)job.AnamorphicMode, modulus = job.Modulus.HasValue ? job.Modulus.Value : 16, geometry = new hb_geometry_s { height = job.Height, width = job.Width, par = job.AnamorphicMode != Anamorphic.Custom ? new hb_rational_t { den = title.ParH, num = title.ParW } : new hb_rational_t { den = job.ParH, num = job.ParW }} }; diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Helpers/Validate.cs b/win/CS/HandBrakeWPF/Helpers/Validate.cs similarity index 92% rename from win/CS/HandBrake.ApplicationServices/Interop/Helpers/Validate.cs rename to win/CS/HandBrakeWPF/Helpers/Validate.cs index 9725710e1..7d307dfbc 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Helpers/Validate.cs +++ b/win/CS/HandBrakeWPF/Helpers/Validate.cs @@ -1,39 +1,39 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// The validate. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Interop.Helpers -{ - using System; - - /// - /// The validate. - /// - public class Validate - { - /// - /// The not null. - /// - /// - /// The item. - /// - /// - /// The message. - /// - /// - /// Thrown when the input object is null - /// - public static void NotNull(object item, string message) - { - if (item == null) - { - throw new ArgumentException(message); - } - } - } -} +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The validate. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Helpers +{ + using System; + + /// + /// The validate. + /// + public class Validate + { + /// + /// The not null. + /// + /// + /// The item. + /// + /// + /// The message. + /// + /// + /// Thrown when the input object is null + /// + public static void NotNull(object item, string message) + { + if (item == null) + { + throw new ArgumentException(message); + } + } + } +} diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index bf456c859..10037fc55 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -36,6 +36,7 @@ namespace HandBrakeWPF.Services.Encode.Factories using PointToPointMode = HandBrakeWPF.Services.Encode.Model.Models.PointToPointMode; using Subtitle = HandBrake.ApplicationServices.Interop.Json.Encode.Subtitles; using SubtitleTrack = HandBrakeWPF.Services.Encode.Model.Models.SubtitleTrack; + using Validate = HandBrakeWPF.Helpers.Validate; /// /// This factory takes the internal EncodeJob object and turns it into a set of JSON models