WinGui: Strip out some out some legacy code that was causing some threading issues.

This commit is contained in:
sr55 2017-04-13 19:46:15 +01:00
parent e568d96f31
commit 5dd46e3d4b
14 changed files with 29 additions and 300 deletions

View File

@ -94,15 +94,17 @@ namespace HandBrakeWPF
/// </param>
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);
}
});
}
/// <summary>

View File

@ -255,7 +255,6 @@
<Compile Include="Utilities\DPIAwareness.cs" />
<Compile Include="Utilities\DriveUtilities.cs" />
<Compile Include="Utilities\EnumHelper.cs" />
<Compile Include="Utilities\Execute.cs" />
<Compile Include="Utilities\ExtensionMethods.cs" />
<Compile Include="Utilities\GeneralUtilities.cs" />
<Compile Include="Utilities\HandBrakeApp.cs" />
@ -265,7 +264,6 @@
<Compile Include="Utilities\Interfaces\INotifyPropertyChangedEx.cs" />
<Compile Include="Utilities\Output\CsvHelper.cs" />
<Compile Include="Utilities\Portable.cs" />
<Compile Include="Utilities\PropertyChangedBase.cs" />
<Compile Include="Utilities\DirectoryUtilities.cs" />
<Compile Include="Utilities\SystemInfo.cs" />
<Compile Include="Utilities\Win32.cs" />

View File

@ -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;

View File

@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Audio
using System.ComponentModel;
using System.Linq;
using HandBrakeWPF.Utilities;
using Caliburn.Micro;
/// <summary>
/// Audio Behaviours

View File

@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Subtitles
using System.ComponentModel;
using System.Linq;
using HandBrakeWPF.Utilities;
using Caliburn.Micro;
/// <summary>
/// A class to track the behaviours of audio track selection

View File

@ -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;

View File

@ -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;

View File

@ -11,7 +11,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models
{
using System;
using HandBrakeWPF.Utilities;
using Caliburn.Micro;
/// <summary>
/// A Movie Chapter

View File

@ -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;
/// <summary>
/// Subtitle Information

View File

@ -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
/// <summary>
/// A Preset for encoding with.
/// </summary>
/// <remarks>
/// 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
/// </remarks>
public class Preset : PropertyChangedBase, IPresetObject // Delibery not
{
#region Constants and Fields

View File

@ -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;

View File

@ -1,153 +0,0 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="HandBrake Project (http://handbrake.fr)" file="Execute.cs">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// Enables easy marshalling of code to the UI thread.
// Borrowed from Caliburn Micro.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Utilities
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
/// <summary>
/// Enables easy marshalling of code to the UI thread.
/// </summary>
public static class Execute
{
private static System.Action<System.Action> executor = (System.Action<System.Action>)(action => action());
private static Dispatcher dispatcher;
private static bool? inDesignMode;
/// <summary>
/// Gets a value indicating whether or not the framework is in design-time mode.
/// </summary>
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);
}
}
/// <summary>
/// Initializes the framework using the current dispatcher.
/// </summary>
public static void InitializeWithDispatcher()
{
Execute.dispatcher = Dispatcher.CurrentDispatcher;
Execute.executor = (System.Action<System.Action>)null;
}
/// <summary>
/// Resets the executor to use a non-dispatcher-based action executor.
/// </summary>
public static void ResetWithoutDispatcher()
{
executor = (System.Action<System.Action>)(action => action());
dispatcher = (Dispatcher)null;
}
/// <summary>
/// Sets a custom UI thread marshaller.
/// </summary>
/// <param name="marshaller">The marshaller.</param>
[Obsolete]
public static void SetUIThreadMarshaller(System.Action<System.Action> marshaller)
{
Execute.executor = marshaller;
Execute.dispatcher = (Dispatcher)null;
}
/// <summary>
/// Executes the action on the UI thread asynchronously.
/// </summary>
/// <param name="action">The action to execute.</param>
public static void BeginOnUIThread(this System.Action action)
{
Execute.ValidateDispatcher();
Execute.dispatcher.BeginInvoke((Delegate)action);
}
/// <summary>
/// Executes the action on the UI thread asynchronously.
/// </summary>
/// <param name="action">
/// The action to execute.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public static Task OnUIThreadAsync(this System.Action action)
{
Execute.ValidateDispatcher();
TaskCompletionSource<object> taskSource = new TaskCompletionSource<object>();
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;
}
/// <summary>
/// Executes the action on the UI thread.
/// </summary>
/// <param name="action">The action to execute.</param>
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();
}
/// <summary>
/// The check access.
/// </summary>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
private static bool CheckAccess()
{
if (Execute.dispatcher != null)
return Execute.dispatcher.CheckAccess();
return true;
}
/// <summary>
/// The validate dispatcher.
/// </summary>
/// <exception cref="InvalidOperationException">
/// Not initialized with dispatcher.
/// </exception>
private static void ValidateDispatcher()
{
if (Execute.dispatcher == null)
throw new InvalidOperationException("Not initialized with dispatcher.");
}
}
}

View File

@ -1,121 +0,0 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="HandBrake Project (http://handbrake.fr)" file="PropertyChangedBase.cs">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
// Borrowed from Caliburn Micro
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Utilities
{
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using INotifyPropertyChangedEx = HandBrakeWPF.Utilities.Interfaces.INotifyPropertyChangedEx;
/// <summary>
/// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling.
/// </summary>
[Serializable]
public class PropertyChangedBase : INotifyPropertyChangedEx, INotifyPropertyChanged
{
[NonSerialized]
private bool isNotifying;
/// <summary>
/// Gets or sets a value indicating whether the Enables/Disables property change notification.
/// </summary>
[Browsable(false)]
public bool IsNotifying
{
get
{
return this.isNotifying;
}
set
{
this.isNotifying = value;
}
}
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged = (param0, param1) => { };
/// <summary>
/// Initializes a new instance of the <see cref="PropertyChangedBase"/> class.
/// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>.
/// </summary>
public PropertyChangedBase()
{
this.IsNotifying = true;
}
/// <summary>
/// Raises a change notification indicating that all bindings should be refreshed.
/// </summary>
public void Refresh()
{
this.NotifyOfPropertyChange(string.Empty);
}
/// <summary>
/// Notifies subscribers of the property change.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
public virtual void NotifyOfPropertyChange(string propertyName)
{
if (!this.IsNotifying)
return;
Execute.OnUIThread((System.Action)(() => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName))));
}
/// <summary>
/// Notifies subscribers of the property change.
/// </summary>
/// <typeparam name="TProperty">The type of the property.</typeparam><param name="property">The property expression.</param>
public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
{
this.NotifyOfPropertyChange(ExtensionMethods.GetMemberInfo((Expression)property).Name);
}
/// <summary>
/// Called when the object is deserialized.
/// </summary>
/// <param name="c">The streaming context.</param>
[OnDeserialized]
public void OnDeserialized(StreamingContext c)
{
this.IsNotifying = true;
}
/// <summary>
/// Used to indicate whether or not the IsNotifying property is serialized to Xml.
/// </summary>
/// <returns>
/// Whether or not to serialize the IsNotifying property. The default is false.
/// </returns>
public virtual bool ShouldSerializeIsNotifying()
{
return false;
}
/// <summary>
/// Raises the <see cref="E:PropertyChanged"/> event directly.
/// </summary>
/// <param name="e">The <see cref="T:System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler changedEventHandler = this.PropertyChanged;
if (changedEventHandler == null)
return;
changedEventHandler((object)this, e);
}
}
}

View File

@ -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;