From 5dd46e3d4b9029e33a353b9962fea3b8c3c399e4 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 13 Apr 2017 19:46:15 +0100 Subject: WinGui: Strip out some out some legacy code that was causing some threading issues. --- win/CS/HandBrakeWPF/App.xaml.cs | 20 +-- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 - .../Model/Audio/AudioBehaviourTrack.cs | 3 + win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs | 2 +- .../Model/Subtitles/SubtitleBehaviours.cs | 2 +- .../Services/Encode/Model/EncodeTask.cs | 3 +- .../Services/Encode/Model/Models/AudioTrack.cs | 4 +- .../Services/Encode/Model/Models/ChapterMarker.cs | 2 +- .../Services/Encode/Model/Models/SubtitleTrack.cs | 3 +- .../HandBrakeWPF/Services/Presets/Model/Preset.cs | 8 +- .../HandBrakeWPF/Services/Queue/Model/QueueTask.cs | 4 +- win/CS/HandBrakeWPF/Utilities/Execute.cs | 153 --------------------- .../HandBrakeWPF/Utilities/PropertyChangedBase.cs | 121 ---------------- win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs | 2 + 14 files changed, 29 insertions(+), 300 deletions(-) delete mode 100644 win/CS/HandBrakeWPF/Utilities/Execute.cs delete mode 100644 win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs index 85f4e3902..39eb6c0bc 100644 --- a/win/CS/HandBrakeWPF/App.xaml.cs +++ b/win/CS/HandBrakeWPF/App.xaml.cs @@ -94,15 +94,17 @@ namespace HandBrakeWPF /// private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - if (e.ExceptionObject.GetType() == typeof(FileNotFoundException)) - { - GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.0", (Exception)e.ExceptionObject); - this.ShowError(exception); - } - else - { - this.ShowError(e.ExceptionObject); - } + Caliburn.Micro.Execute.OnUIThreadAsync(() => { + if (e.ExceptionObject.GetType() == typeof(FileNotFoundException)) + { + GeneralApplicationException exception = new GeneralApplicationException("A file appears to be missing.", "Try re-installing Microsoft .NET Framework 4.0", (Exception)e.ExceptionObject); + this.ShowError(exception); + } + else + { + this.ShowError(e.ExceptionObject); + } + }); } /// diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 04a73604e..44c58bc0f 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -255,7 +255,6 @@ - @@ -265,7 +264,6 @@ - diff --git a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs index c59b15b8c..1297ecb71 100644 --- a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs +++ b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs @@ -13,6 +13,9 @@ namespace HandBrakeWPF.Model.Audio using System.ComponentModel; using System.Globalization; using System.Linq; + + using Caliburn.Micro; + using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; diff --git a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs index b0f81d0c4..aa448d690 100644 --- a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs +++ b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs @@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Audio using System.ComponentModel; using System.Linq; - using HandBrakeWPF.Utilities; + using Caliburn.Micro; /// /// Audio Behaviours diff --git a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs index 11200b450..a6245c9c9 100644 --- a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs +++ b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs @@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Subtitles using System.ComponentModel; using System.Linq; - using HandBrakeWPF.Utilities; + using Caliburn.Micro; /// /// A class to track the behaviours of audio track selection diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index 9663ae66c..4d0da57fe 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -12,11 +12,12 @@ namespace HandBrakeWPF.Services.Encode.Model using System.Collections.Generic; using System.Collections.ObjectModel; + using Caliburn.Micro; + using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrakeWPF.Services.Encode.Model.Models; - using HandBrakeWPF.Utilities; using AllowedPassthru = HandBrakeWPF.Services.Encode.Model.Models.AllowedPassthru; using AudioTrack = HandBrakeWPF.Services.Encode.Model.Models.AudioTrack; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs index 8d7047a5b..7cc073125 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs @@ -14,12 +14,12 @@ namespace HandBrakeWPF.Services.Encode.Model.Models using System.ComponentModel; using System.Globalization; using System.Linq; - using System.Security; + + using Caliburn.Micro; using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; - using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Model.Audio; using HandBrakeWPF.Services.Scan.Model; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs index e2fdb25e3..c699ec39c 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs @@ -11,7 +11,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { using System; - using HandBrakeWPF.Utilities; + using Caliburn.Micro; /// /// A Movie Chapter diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs index b19fc80f4..fe62a5a23 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs @@ -11,10 +11,11 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { using System; + using Caliburn.Micro; + using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Services.Scan.Model; - using HandBrakeWPF.Utilities; /// /// Subtitle Information diff --git a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs index 8c0ff34c8..1afeefb94 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs @@ -9,10 +9,11 @@ namespace HandBrakeWPF.Services.Presets.Model { + using Caliburn.Micro; + using HandBrakeWPF.Model.Audio; using HandBrakeWPF.Model.Subtitles; using HandBrakeWPF.Services.Presets.Interfaces; - using HandBrakeWPF.Utilities; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode; @@ -20,11 +21,6 @@ namespace HandBrakeWPF.Services.Presets.Model /// /// A Preset for encoding with. /// - /// - /// Using App Services PropertyChangedBase because Caliburn Micro has [DataContract] on their base class which causes json.net not to serialise properties without [DataContract] - /// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/89 - /// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/96 - /// public class Preset : PropertyChangedBase, IPresetObject // Delibery not { #region Constants and Fields diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs index ac1b28d94..e8813930d 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs @@ -9,9 +9,9 @@ namespace HandBrakeWPF.Services.Queue.Model { - using HandBrake.ApplicationServices.Model; + using Caliburn.Micro; - using HandBrakeWPF.Utilities; + using HandBrake.ApplicationServices.Model; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; diff --git a/win/CS/HandBrakeWPF/Utilities/Execute.cs b/win/CS/HandBrakeWPF/Utilities/Execute.cs deleted file mode 100644 index 0282744f3..000000000 --- a/win/CS/HandBrakeWPF/Utilities/Execute.cs +++ /dev/null @@ -1,153 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Enables easy marshalling of code to the UI thread. -// Borrowed from Caliburn Micro. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrakeWPF.Utilities -{ - using System; - using System.ComponentModel; - using System.Diagnostics; - using System.Threading.Tasks; - using System.Windows; - using System.Windows.Threading; - - /// - /// Enables easy marshalling of code to the UI thread. - /// - public static class Execute - { - private static System.Action executor = (System.Action)(action => action()); - private static Dispatcher dispatcher; - private static bool? inDesignMode; - - /// - /// Gets a value indicating whether or not the framework is in design-time mode. - /// - public static bool InDesignMode - { - get - { - if (!Execute.inDesignMode.HasValue) - { - Execute.inDesignMode = new bool?((bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue); - if (!Execute.inDesignMode.GetValueOrDefault(false) && Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal)) - Execute.inDesignMode = new bool?(true); - } - return Execute.inDesignMode.GetValueOrDefault(false); - } - } - - /// - /// Initializes the framework using the current dispatcher. - /// - public static void InitializeWithDispatcher() - { - Execute.dispatcher = Dispatcher.CurrentDispatcher; - Execute.executor = (System.Action)null; - } - - /// - /// Resets the executor to use a non-dispatcher-based action executor. - /// - public static void ResetWithoutDispatcher() - { - executor = (System.Action)(action => action()); - dispatcher = (Dispatcher)null; - } - - /// - /// Sets a custom UI thread marshaller. - /// - /// The marshaller. - [Obsolete] - public static void SetUIThreadMarshaller(System.Action marshaller) - { - Execute.executor = marshaller; - Execute.dispatcher = (Dispatcher)null; - } - - /// - /// Executes the action on the UI thread asynchronously. - /// - /// The action to execute. - public static void BeginOnUIThread(this System.Action action) - { - Execute.ValidateDispatcher(); - Execute.dispatcher.BeginInvoke((Delegate)action); - } - - /// - /// Executes the action on the UI thread asynchronously. - /// - /// - /// The action to execute. - /// - /// - /// The . - /// - public static Task OnUIThreadAsync(this System.Action action) - { - Execute.ValidateDispatcher(); - TaskCompletionSource taskSource = new TaskCompletionSource(); - System.Action action1 = (System.Action)(() => - { - try - { - action(); - taskSource.SetResult((object)null); - } - catch (Exception ex) - { - taskSource.SetException(ex); - } - }); - Execute.dispatcher.BeginInvoke((Delegate)action1); - return (Task)taskSource.Task; - } - - /// - /// Executes the action on the UI thread. - /// - /// The action to execute. - public static void OnUIThread(this System.Action action) - { - if (Execute.executor != null) - Execute.executor(action); - else if (Execute.CheckAccess()) - action(); - else - Execute.OnUIThreadAsync(action).Wait(); - } - - /// - /// The check access. - /// - /// - /// The . - /// - private static bool CheckAccess() - { - if (Execute.dispatcher != null) - return Execute.dispatcher.CheckAccess(); - return true; - } - - /// - /// The validate dispatcher. - /// - /// - /// Not initialized with dispatcher. - /// - private static void ValidateDispatcher() - { - if (Execute.dispatcher == null) - throw new InvalidOperationException("Not initialized with dispatcher."); - } - } -} diff --git a/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs b/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs deleted file mode 100644 index 08f206891..000000000 --- a/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs +++ /dev/null @@ -1,121 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling. -// Borrowed from Caliburn Micro -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrakeWPF.Utilities -{ - using System; - using System.ComponentModel; - using System.Linq.Expressions; - using System.Runtime.Serialization; - - using INotifyPropertyChangedEx = HandBrakeWPF.Utilities.Interfaces.INotifyPropertyChangedEx; - - /// - /// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling. - /// - [Serializable] - public class PropertyChangedBase : INotifyPropertyChangedEx, INotifyPropertyChanged - { - [NonSerialized] - private bool isNotifying; - - /// - /// Gets or sets a value indicating whether the Enables/Disables property change notification. - /// - [Browsable(false)] - public bool IsNotifying - { - get - { - return this.isNotifying; - } - set - { - this.isNotifying = value; - } - } - - /// - /// Occurs when a property value changes. - /// - public event PropertyChangedEventHandler PropertyChanged = (param0, param1) => { }; - - /// - /// Initializes a new instance of the class. - /// Creates an instance of . - /// - public PropertyChangedBase() - { - this.IsNotifying = true; - } - - /// - /// Raises a change notification indicating that all bindings should be refreshed. - /// - public void Refresh() - { - this.NotifyOfPropertyChange(string.Empty); - } - - /// - /// Notifies subscribers of the property change. - /// - /// Name of the property. - public virtual void NotifyOfPropertyChange(string propertyName) - { - if (!this.IsNotifying) - return; - Execute.OnUIThread((System.Action)(() => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName)))); - } - - /// - /// Notifies subscribers of the property change. - /// - /// The type of the property.The property expression. - public void NotifyOfPropertyChange(Expression> property) - { - this.NotifyOfPropertyChange(ExtensionMethods.GetMemberInfo((Expression)property).Name); - } - - /// - /// Called when the object is deserialized. - /// - /// The streaming context. - [OnDeserialized] - public void OnDeserialized(StreamingContext c) - { - this.IsNotifying = true; - } - - /// - /// Used to indicate whether or not the IsNotifying property is serialized to Xml. - /// - /// - /// Whether or not to serialize the IsNotifying property. The default is false. - /// - public virtual bool ShouldSerializeIsNotifying() - { - return false; - } - - /// - /// Raises the event directly. - /// - /// The instance containing the event data. - [EditorBrowsable(EditorBrowsableState.Never)] - protected void OnPropertyChanged(PropertyChangedEventArgs e) - { - PropertyChangedEventHandler changedEventHandler = this.PropertyChanged; - if (changedEventHandler == null) - return; - changedEventHandler((object)this, e); - } - } -} diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index 85ac495ff..3fcb4c96c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -14,6 +14,8 @@ namespace HandBrakeWPF.ViewModels using System.Text; using System.Windows; + using Caliburn.Micro; + using HandBrake.ApplicationServices.Services.Logging; using HandBrake.ApplicationServices.Services.Logging.EventArgs; using HandBrake.ApplicationServices.Services.Logging.Model; -- cgit v1.2.3