diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-01-04 09:27:54 -0500 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-01-04 09:27:54 -0500 |
| commit | c5ff30f66e368efc2ca7dea7813fba6d9f6a657c (patch) | |
| tree | c5552b898f66b7d510e9257eb8bbeafd6a003676 /MediaBrowser.Common | |
| parent | 767590125b27c2498e3ad9544edbede30fb70f45 (diff) | |
| parent | 59b6bc28c332701d5e383fbf99170bdc740fb6cc (diff) | |
Merge pull request #965 from MediaBrowser/dev
3.0.5482.0
Diffstat (limited to 'MediaBrowser.Common')
| -rw-r--r-- | MediaBrowser.Common/Configuration/ConfigurationHelper.cs | 74 | ||||
| -rw-r--r-- | MediaBrowser.Common/Configuration/IConfigurationFactory.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Common/Extensions/BaseExtensions.cs | 11 | ||||
| -rw-r--r-- | MediaBrowser.Common/MediaBrowser.Common.csproj | 8 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs | 326 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/IWebSocket.cs | 54 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/IWebSocketConnection.cs | 72 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/IWebSocketListener.cs | 17 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/MimeTypes.cs | 338 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs | 21 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/WebSocketMessageInfo.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Common/Plugins/BasePlugin.cs | 43 |
12 files changed, 48 insertions, 937 deletions
diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs deleted file mode 100644 index 8c904b0db..000000000 --- a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs +++ /dev/null @@ -1,74 +0,0 @@ -using MediaBrowser.Model.Serialization; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Common.Configuration -{ - /// <summary> - /// Class ConfigurationHelper - /// </summary> - public static class ConfigurationHelper - { - /// <summary> - /// Reads an xml configuration file from the file system - /// It will immediately re-serialize and save if new serialization data is available due to property changes - /// </summary> - /// <param name="type">The type.</param> - /// <param name="path">The path.</param> - /// <param name="xmlSerializer">The XML serializer.</param> - /// <returns>System.Object.</returns> - public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer) - { - object configuration; - - byte[] buffer = null; - - // Use try/catch to avoid the extra file system lookup using File.Exists - try - { - buffer = File.ReadAllBytes(path); - - configuration = xmlSerializer.DeserializeFromBytes(type, buffer); - } - catch (Exception) - { - configuration = Activator.CreateInstance(type); - } - - using (var stream = new MemoryStream()) - { - xmlSerializer.SerializeToStream(configuration, stream); - - // Take the object we just got and serialize it back to bytes - var newBytes = stream.ToArray(); - - // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) - { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); - } - - return configuration; - } - } - - /// <summary> - /// Reads an xml configuration file from the file system - /// It will immediately save the configuration after loading it, just - /// in case there are new serializable properties - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="path">The path.</param> - /// <param name="xmlSerializer">The XML serializer.</param> - /// <returns>``0.</returns> - public static T GetXmlConfiguration<T>(string path, IXmlSerializer xmlSerializer) - where T : class - { - return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T; - } - } -} diff --git a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs index d418d0a42..6ed638536 100644 --- a/MediaBrowser.Common/Configuration/IConfigurationFactory.cs +++ b/MediaBrowser.Common/Configuration/IConfigurationFactory.cs @@ -14,4 +14,9 @@ namespace MediaBrowser.Common.Configuration public Type ConfigurationType { get; set; } } + + public interface IValidatingConfiguration + { + void Validate(object oldConfig, object newConfig); + } } diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index 8e96373f4..4c94f3aa2 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -1,4 +1,6 @@ using System; +using System.Globalization; +using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -54,6 +56,15 @@ namespace MediaBrowser.Common.Extensions return sb.ToString(); } + public static string RemoveDiacritics(this string text) + { + return String.Concat( + text.Normalize(NormalizationForm.FormD) + .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != + UnicodeCategory.NonSpacingMark) + ).Normalize(NormalizationForm.FormC); + } + /// <summary> /// Gets the M d5. /// </summary> diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 9fdfccaaf..c46dd4a4f 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -53,7 +53,6 @@ <Compile Include="..\SharedVersion.cs"> <Link>Properties\SharedVersion.cs</Link> </Compile> - <Compile Include="Configuration\ConfigurationHelper.cs" /> <Compile Include="Configuration\ConfigurationUpdateEventArgs.cs" /> <Compile Include="Configuration\IConfigurationManager.cs" /> <Compile Include="Configuration\IConfigurationFactory.cs" /> @@ -64,19 +63,12 @@ <Compile Include="IO\IFileSystem.cs" /> <Compile Include="IO\ProgressStream.cs" /> <Compile Include="IO\StreamDefaults.cs" /> - <Compile Include="Net\BasePeriodicWebSocketListener.cs" /> <Compile Include="Configuration\IApplicationPaths.cs" /> <Compile Include="Net\HttpRequestOptions.cs" /> <Compile Include="Net\HttpResponseInfo.cs" /> - <Compile Include="Net\IWebSocketListener.cs" /> <Compile Include="IApplicationHost.cs" /> <Compile Include="Net\IHttpClient.cs" /> <Compile Include="Net\INetworkManager.cs" /> - <Compile Include="Net\IWebSocket.cs" /> - <Compile Include="Net\IWebSocketConnection.cs" /> - <Compile Include="Net\MimeTypes.cs" /> - <Compile Include="Net\WebSocketConnectEventArgs.cs" /> - <Compile Include="Net\WebSocketMessageInfo.cs" /> <Compile Include="Plugins\IDependencyModule.cs" /> <Compile Include="Plugins\IPlugin.cs" /> <Compile Include="Progress\ActionableProgress.cs" /> diff --git a/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs deleted file mode 100644 index a2af3707b..000000000 --- a/MediaBrowser.Common/Net/BasePeriodicWebSocketListener.cs +++ /dev/null @@ -1,326 +0,0 @@ -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - /// Starts sending data over a web socket periodically when a message is received, and then stops when a corresponding stop message is received - /// </summary> - /// <typeparam name="TReturnDataType">The type of the T return data type.</typeparam> - /// <typeparam name="TStateType">The type of the T state type.</typeparam> - public abstract class BasePeriodicWebSocketListener<TReturnDataType, TStateType> : IWebSocketListener, IDisposable - where TStateType : WebSocketListenerState, new() - where TReturnDataType : class - { - /// <summary> - /// The _active connections - /// </summary> - protected readonly List<Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim>> ActiveConnections = - new List<Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim>>(); - - /// <summary> - /// Gets the name. - /// </summary> - /// <value>The name.</value> - protected abstract string Name { get; } - - /// <summary> - /// Gets the data to send. - /// </summary> - /// <param name="state">The state.</param> - /// <returns>Task{`1}.</returns> - protected abstract Task<TReturnDataType> GetDataToSend(TStateType state); - - /// <summary> - /// The logger - /// </summary> - protected ILogger Logger; - - /// <summary> - /// Initializes a new instance of the <see cref="BasePeriodicWebSocketListener{TStateType}" /> class. - /// </summary> - /// <param name="logger">The logger.</param> - /// <exception cref="System.ArgumentNullException">logger</exception> - protected BasePeriodicWebSocketListener(ILogger logger) - { - if (logger == null) - { - throw new ArgumentNullException("logger"); - } - - Logger = logger; - } - - /// <summary> - /// The null task result - /// </summary> - protected Task NullTaskResult = Task.FromResult(true); - - /// <summary> - /// Processes the message. - /// </summary> - /// <param name="message">The message.</param> - /// <returns>Task.</returns> - public Task ProcessMessage(WebSocketMessageInfo message) - { - if (message.MessageType.Equals(Name + "Start", StringComparison.OrdinalIgnoreCase)) - { - Start(message); - } - - if (message.MessageType.Equals(Name + "Stop", StringComparison.OrdinalIgnoreCase)) - { - Stop(message); - } - - return NullTaskResult; - } - - protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - - protected virtual bool SendOnTimer - { - get - { - return true; - } - } - - /// <summary> - /// Starts sending messages over a web socket - /// </summary> - /// <param name="message">The message.</param> - private void Start(WebSocketMessageInfo message) - { - var vals = message.Data.Split(','); - - var dueTimeMs = long.Parse(vals[0], UsCulture); - var periodMs = long.Parse(vals[1], UsCulture); - - var cancellationTokenSource = new CancellationTokenSource(); - - Logger.Info("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name); - - var timer = SendOnTimer ? - new Timer(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite) : - null; - - var state = new TStateType - { - IntervalMs = periodMs, - InitialDelayMs = dueTimeMs - }; - - var semaphore = new SemaphoreSlim(1, 1); - - lock (ActiveConnections) - { - ActiveConnections.Add(new Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim>(message.Connection, cancellationTokenSource, timer, state, semaphore)); - } - - if (timer != null) - { - timer.Change(TimeSpan.FromMilliseconds(dueTimeMs), TimeSpan.FromMilliseconds(periodMs)); - } - } - - /// <summary> - /// Timers the callback. - /// </summary> - /// <param name="state">The state.</param> - private void TimerCallback(object state) - { - var connection = (IWebSocketConnection)state; - - Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim> tuple; - - lock (ActiveConnections) - { - tuple = ActiveConnections.FirstOrDefault(c => c.Item1 == connection); - } - - if (tuple == null) - { - return; - } - - if (connection.State != WebSocketState.Open || tuple.Item2.IsCancellationRequested) - { - DisposeConnection(tuple); - return; - } - - SendData(tuple); - } - - protected void SendData(bool force) - { - List<Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim>> tuples; - - lock (ActiveConnections) - { - tuples = ActiveConnections - .Where(c => - { - if (c.Item1.State == WebSocketState.Open && !c.Item2.IsCancellationRequested) - { - var state = c.Item4; - - if (force || (DateTime.UtcNow - state.DateLastSendUtc).TotalMilliseconds >= state.IntervalMs) - { - return true; - } - } - - return false; - }) - .ToList(); - } - - foreach (var tuple in tuples) - { - SendData(tuple); - } - } - - private async void SendData(Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim> tuple) - { - var connection = tuple.Item1; - - try - { - await tuple.Item5.WaitAsync(tuple.Item2.Token).ConfigureAwait(false); - - var state = tuple.Item4; - - var data = await GetDataToSend(state).ConfigureAwait(false); - - if (data != null) - { - await connection.SendAsync(new WebSocketMessage<TReturnDataType> - { - MessageType = Name, - Data = data - - }, tuple.Item2.Token).ConfigureAwait(false); - - state.DateLastSendUtc = DateTime.UtcNow; - } - - tuple.Item5.Release(); - } - catch (OperationCanceledException) - { - if (tuple.Item2.IsCancellationRequested) - { - DisposeConnection(tuple); - } - } - catch (Exception ex) - { - Logger.ErrorException("Error sending web socket message {0}", ex, Name); - DisposeConnection(tuple); - } - } - - /// <summary> - /// Stops sending messages over a web socket - /// </summary> - /// <param name="message">The message.</param> - private void Stop(WebSocketMessageInfo message) - { - lock (ActiveConnections) - { - var connection = ActiveConnections.FirstOrDefault(c => c.Item1 == message.Connection); - - if (connection != null) - { - DisposeConnection(connection); - } - } - } - - /// <summary> - /// Disposes the connection. - /// </summary> - /// <param name="connection">The connection.</param> - private void DisposeConnection(Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType, SemaphoreSlim> connection) - { - Logger.Info("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name); - - var timer = connection.Item3; - - if (timer != null) - { - try - { - timer.Dispose(); - } - catch (ObjectDisposedException) - { - - } - } - - try - { - connection.Item2.Cancel(); - connection.Item2.Dispose(); - } - catch (ObjectDisposedException) - { - - } - - try - { - connection.Item5.Dispose(); - } - catch (ObjectDisposedException) - { - - } - - ActiveConnections.Remove(connection); - } - - /// <summary> - /// Releases unmanaged and - optionally - managed resources. - /// </summary> - /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - lock (ActiveConnections) - { - foreach (var connection in ActiveConnections.ToList()) - { - DisposeConnection(connection); - } - } - } - } - - /// <summary> - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// </summary> - public void Dispose() - { - Dispose(true); - } - } - - public class WebSocketListenerState - { - public DateTime DateLastSendUtc { get; set; } - public long InitialDelayMs { get; set; } - public long IntervalMs { get; set; } - } -} diff --git a/MediaBrowser.Common/Net/IWebSocket.cs b/MediaBrowser.Common/Net/IWebSocket.cs deleted file mode 100644 index b31a95319..000000000 --- a/MediaBrowser.Common/Net/IWebSocket.cs +++ /dev/null @@ -1,54 +0,0 @@ -using MediaBrowser.Model.Net; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - /// Interface IWebSocket - /// </summary> - public interface IWebSocket : IDisposable - { - /// <summary> - /// Occurs when [closed]. - /// </summary> - event EventHandler<EventArgs> Closed; - - /// <summary> - /// Gets or sets the state. - /// </summary> - /// <value>The state.</value> - WebSocketState State { get; } - - /// <summary> - /// Gets or sets the receive action. - /// </summary> - /// <value>The receive action.</value> - Action<byte[]> OnReceiveBytes { get; set; } - - /// <summary> - /// Gets or sets the on receive. - /// </summary> - /// <value>The on receive.</value> - Action<string> OnReceive { get; set; } - - /// <summary> - /// Sends the async. - /// </summary> - /// <param name="bytes">The bytes.</param> - /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken); - - /// <summary> - /// Sends the asynchronous. - /// </summary> - /// <param name="text">The text.</param> - /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken); - } -} diff --git a/MediaBrowser.Common/Net/IWebSocketConnection.cs b/MediaBrowser.Common/Net/IWebSocketConnection.cs deleted file mode 100644 index b7715e20b..000000000 --- a/MediaBrowser.Common/Net/IWebSocketConnection.cs +++ /dev/null @@ -1,72 +0,0 @@ -using MediaBrowser.Model.Net; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - public interface IWebSocketConnection : IDisposable - { - /// <summary> - /// Occurs when [closed]. - /// </summary> - event EventHandler<EventArgs> Closed; - - /// <summary> - /// Gets the id. - /// </summary> - /// <value>The id.</value> - Guid Id { get; } - - /// <summary> - /// Gets the last activity date. - /// </summary> - /// <value>The last activity date.</value> - DateTime LastActivityDate { get; } - - /// <summary> - /// Gets or sets the receive action. - /// </summary> - /// <value>The receive action.</value> - Action<WebSocketMessageInfo> OnReceive { get; set; } - - /// <summary> - /// Gets the state. - /// </summary> - /// <value>The state.</value> - WebSocketState State { get; } - - /// <summary> - /// Gets the remote end point. - /// </summary> - /// <value>The remote end point.</value> - string RemoteEndPoint { get; } - - /// <summary> - /// Sends a message asynchronously. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="message">The message.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException">message</exception> - Task SendAsync<T>(WebSocketMessage<T> message, CancellationToken cancellationToken); - - /// <summary> - /// Sends a message asynchronously. - /// </summary> - /// <param name="buffer">The buffer.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - Task SendAsync(byte[] buffer, CancellationToken cancellationToken); - - /// <summary> - /// Sends a message asynchronously. - /// </summary> - /// <param name="text">The text.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException">buffer</exception> - Task SendAsync(string text, CancellationToken cancellationToken); - } -}
\ No newline at end of file diff --git a/MediaBrowser.Common/Net/IWebSocketListener.cs b/MediaBrowser.Common/Net/IWebSocketListener.cs deleted file mode 100644 index 4b6c4111d..000000000 --- a/MediaBrowser.Common/Net/IWebSocketListener.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - ///This is an interface for listening to messages coming through a web socket connection - /// </summary> - public interface IWebSocketListener - { - /// <summary> - /// Processes the message. - /// </summary> - /// <param name="message">The message.</param> - /// <returns>Task.</returns> - Task ProcessMessage(WebSocketMessageInfo message); - } -} diff --git a/MediaBrowser.Common/Net/MimeTypes.cs b/MediaBrowser.Common/Net/MimeTypes.cs deleted file mode 100644 index 14052e759..000000000 --- a/MediaBrowser.Common/Net/MimeTypes.cs +++ /dev/null @@ -1,338 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - /// Class MimeTypes - /// </summary> - public static class MimeTypes - { - /// <summary> - /// The json MIME type - /// </summary> - public static string JsonMimeType = "application/json"; - - /// <summary> - /// Any extension in this list is considered a video file - can be added to at runtime for extensibility - /// </summary> - private static readonly List<string> VideoFileExtensions = new List<string> - { - ".mkv", - ".m2t", - ".m2ts", - ".img", - ".iso", - ".mk3d", - ".ts", - ".rmvb", - ".mov", - ".avi", - ".mpg", - ".mpeg", - ".wmv", - ".mp4", - ".divx", - ".dvr-ms", - ".wtv", - ".ogm", - ".ogv", - ".asf", - ".m4v", - ".flv", - ".f4v", - ".3gp", - ".webm", - ".mts", - ".m2v", - ".rec" - }; - - private static readonly Dictionary<string, string> VideoFileExtensionsDictionary = VideoFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - - /// <summary> - /// Determines whether [is video file] [the specified path]. - /// </summary> - /// <param name="path">The path.</param> - /// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns> - public static bool IsVideoFile(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException("path"); - } - - var extension = Path.GetExtension(path); - - if (string.IsNullOrEmpty(extension)) - { - return false; - } - - return VideoFileExtensionsDictionary.ContainsKey(extension); - } - - /// <summary> - /// Gets the type of the MIME. - /// </summary> - /// <param name="path">The path.</param> - /// <returns>System.String.</returns> - /// <exception cref="System.ArgumentNullException">path</exception> - /// <exception cref="System.InvalidOperationException">Argument not supported: + path</exception> - public static string GetMimeType(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException("path"); - } - - var ext = Path.GetExtension(path) ?? string.Empty; - - // http://en.wikipedia.org/wiki/Internet_media_type - // Add more as needed - - // Type video - if (ext.Equals(".mpg", StringComparison.OrdinalIgnoreCase) || ext.EndsWith("mpeg", StringComparison.OrdinalIgnoreCase)) - { - return "video/mpeg"; - } - if (ext.Equals(".ogv", StringComparison.OrdinalIgnoreCase)) - { - return "video/ogg"; - } - if (ext.Equals(".mov", StringComparison.OrdinalIgnoreCase)) - { - return "video/quicktime"; - } - if (ext.Equals(".webm", StringComparison.OrdinalIgnoreCase)) - { - return "video/webm"; - } - if (ext.Equals(".mkv", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-matroska"; - } - if (ext.Equals(".wmv", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-ms-wmv"; - } - if (ext.Equals(".flv", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-flv"; - } - if (ext.Equals(".avi", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-msvideo"; - } - if (ext.Equals(".m4v", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-m4v"; - } - if (ext.EndsWith("asf", StringComparison.OrdinalIgnoreCase)) - { - return "video/x-ms-asf"; - } - if (ext.Equals(".3gp", StringComparison.OrdinalIgnoreCase)) - { - return "video/3gpp"; - } - if (ext.Equals(".3g2", StringComparison.OrdinalIgnoreCase)) - { - return "video/3gpp2"; - } - if (ext.Equals(".ts", StringComparison.OrdinalIgnoreCase)) - { - return "video/mp2t"; - } - if (ext.Equals(".mpd", StringComparison.OrdinalIgnoreCase)) - { - return "video/vnd.mpeg.dash.mpd"; - } - - // Catch-all for all video types that don't require specific mime types - if (VideoFileExtensionsDictionary.ContainsKey(ext)) - { - return "video/" + ext.TrimStart('.').ToLower(); - } - - // Type text - if (ext.Equals(".css", StringComparison.OrdinalIgnoreCase)) - { - return "text/css"; - } - if (ext.Equals(".csv", StringComparison.OrdinalIgnoreCase)) - { - return "text/csv"; - } - if (ext.Equals(".html", StringComparison.OrdinalIgnoreCase) || ext.Equals(".htm", StringComparison.OrdinalIgnoreCase)) - { - return "text/html; charset=UTF-8"; - } - if (ext.Equals(".txt", StringComparison.OrdinalIgnoreCase)) - { - return "text/plain"; - } - if (ext.Equals(".xml", StringComparison.OrdinalIgnoreCase)) - { - return "application/xml"; - } - - // Type document - if (ext.Equals(".pdf", StringComparison.OrdinalIgnoreCase)) - { - return "application/pdf"; - } - if (ext.Equals(".mobi", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-mobipocket-ebook"; - } - if (ext.Equals(".epub", StringComparison.OrdinalIgnoreCase)) - { - return "application/epub+zip"; - } - if (ext.Equals(".cbz", StringComparison.OrdinalIgnoreCase) || ext.Equals(".cbr", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-cdisplay"; - } - - // Type image - if (ext.Equals(".gif", StringComparison.OrdinalIgnoreCase)) - { - return "image/gif"; - } - if (ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".jpeg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".tbn", StringComparison.OrdinalIgnoreCase)) - { - return "image/jpeg"; - } - if (ext.Equals(".png", StringComparison.OrdinalIgnoreCase)) - { - return "image/png"; - } - if (ext.Equals(".webp", StringComparison.OrdinalIgnoreCase)) - { - return "image/webp"; - } - if (ext.Equals(".ico", StringComparison.OrdinalIgnoreCase)) - { - return "image/vnd.microsoft.icon"; - } - - // Type audio - if (ext.Equals(".mp3", StringComparison.OrdinalIgnoreCase)) - { - return "audio/mpeg"; - } - if (ext.Equals(".m4a", StringComparison.OrdinalIgnoreCase) || ext.Equals(".aac", StringComparison.OrdinalIgnoreCase)) - { - return "audio/mp4"; - } - if (ext.Equals(".webma", StringComparison.OrdinalIgnoreCase)) - { - return "audio/webm"; - } - if (ext.Equals(".wav", StringComparison.OrdinalIgnoreCase)) - { - return "audio/wav"; - } - if (ext.Equals(".wma", StringComparison.OrdinalIgnoreCase)) - { - return "audio/x-ms-wma"; - } - if (ext.Equals(".flac", StringComparison.OrdinalIgnoreCase)) - { - return "audio/flac"; - } - if (ext.Equals(".aac", StringComparison.OrdinalIgnoreCase)) - { - return "audio/x-aac"; - } - if (ext.Equals(".ogg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".oga", StringComparison.OrdinalIgnoreCase)) - { - return "audio/ogg"; - } - - // Playlists - if (ext.Equals(".m3u8", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-mpegURL"; - } - - // Misc - if (ext.Equals(".dll", StringComparison.OrdinalIgnoreCase)) - { - return "application/octet-stream"; - } - - // Web - if (ext.Equals(".js", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-javascript"; - } - if (ext.Equals(".json", StringComparison.OrdinalIgnoreCase)) - { - return JsonMimeType; - } - if (ext.Equals(".map", StringComparison.OrdinalIgnoreCase)) - { - return "application/x-javascript"; - } - - if (ext.Equals(".woff", StringComparison.OrdinalIgnoreCase)) - { - return "font/woff"; - } - - if (ext.Equals(".ttf", StringComparison.OrdinalIgnoreCase)) - { - return "font/ttf"; - } - if (ext.Equals(".eot", StringComparison.OrdinalIgnoreCase)) - { - return "application/vnd.ms-fontobject"; - } - if (ext.Equals(".svg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".svgz", StringComparison.OrdinalIgnoreCase)) - { - return "image/svg+xml"; - } - - if (ext.Equals(".srt", StringComparison.OrdinalIgnoreCase)) - { - return "text/plain"; - } - - if (ext.Equals(".vtt", StringComparison.OrdinalIgnoreCase)) - { - return "text/vtt"; - } - - if (ext.Equals(".ttml", StringComparison.OrdinalIgnoreCase)) - { - return "application/ttml+xml"; - } - - if (ext.Equals(".bif", StringComparison.OrdinalIgnoreCase)) - { - return "application/octet-stream"; - } - - throw new ArgumentException("Argument not supported: " + path); - } - - private static readonly Dictionary<string, string> MimeExtensions = - new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) - { - {"image/jpeg", "jpg"}, - {"image/jpg", "jpg"}, - {"image/png", "png"}, - {"image/gif", "gif"}, - {"image/webp", "webp"} - }; - - public static string ToExtension(string mimeType) - { - return "." + MimeExtensions[mimeType]; - } - } -} diff --git a/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs b/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs deleted file mode 100644 index ce22c9520..000000000 --- a/MediaBrowser.Common/Net/WebSocketConnectEventArgs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - /// Class WebSocketConnectEventArgs - /// </summary> - public class WebSocketConnectEventArgs : EventArgs - { - /// <summary> - /// Gets or sets the web socket. - /// </summary> - /// <value>The web socket.</value> - public IWebSocket WebSocket { get; set; } - /// <summary> - /// Gets or sets the endpoint. - /// </summary> - /// <value>The endpoint.</value> - public string Endpoint { get; set; } - } -} diff --git a/MediaBrowser.Common/Net/WebSocketMessageInfo.cs b/MediaBrowser.Common/Net/WebSocketMessageInfo.cs deleted file mode 100644 index c1f935a7b..000000000 --- a/MediaBrowser.Common/Net/WebSocketMessageInfo.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MediaBrowser.Model.Net; - -namespace MediaBrowser.Common.Net -{ - /// <summary> - /// Class WebSocketMessageInfo - /// </summary> - public class WebSocketMessageInfo : WebSocketMessage<string> - { - /// <summary> - /// Gets or sets the connection. - /// </summary> - /// <value>The connection.</value> - public IWebSocketConnection Connection { get; set; } - } -}
\ No newline at end of file diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 6bbd69f04..9d0133c67 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; -using System.Threading; namespace MediaBrowser.Common.Plugins { @@ -164,11 +163,7 @@ namespace MediaBrowser.Common.Plugins /// <summary> /// The _configuration sync lock /// </summary> - private object _configurationSyncLock = new object(); - /// <summary> - /// The _configuration initialized - /// </summary> - private bool _configurationInitialized; + private readonly object _configurationSyncLock = new object(); /// <summary> /// The _configuration /// </summary> @@ -182,17 +177,43 @@ namespace MediaBrowser.Common.Plugins get { // Lazy load - LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => ConfigurationHelper.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath, XmlSerializer) as TConfigurationType); + if (_configuration == null) + { + lock (_configurationSyncLock) + { + if (_configuration == null) + { + _configuration = LoadConfiguration(); + } + } + } return _configuration; } protected set { _configuration = value; + } + } - if (value == null) - { - _configurationInitialized = false; - } + private TConfigurationType LoadConfiguration() + { + var path = ConfigurationFilePath; + + try + { + return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path); + } + catch (DirectoryNotFoundException) + { + return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); + } + catch (FileNotFoundException) + { + return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); + } + catch (Exception ex) + { + return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); } } |
