handle year in name when searching
This commit is contained in:
parent
58a46171ab
commit
a4b40ad9d9
|
@ -229,22 +229,22 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||
/// <returns>Task{System.Object}.</returns>
|
||||
private async Task<object> GetStaticRemoteStreamResult(string mediaPath, Dictionary<string, string> responseHeaders, bool isHeadRequest)
|
||||
{
|
||||
responseHeaders["Accept-Ranges"] = "none";
|
||||
|
||||
var response = await HttpClient.GetResponse(new HttpRequestOptions
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = mediaPath,
|
||||
UserAgent = GetUserAgent(mediaPath),
|
||||
BufferContent = false
|
||||
};
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
var response = await HttpClient.GetResponse(options).ConfigureAwait(false);
|
||||
|
||||
responseHeaders["Accept-Ranges"] = "none";
|
||||
|
||||
if (isHeadRequest)
|
||||
{
|
||||
using (response.Content)
|
||||
{
|
||||
return ResultFactory.GetResult(new MemoryStream(), response.ContentType, responseHeaders);
|
||||
return ResultFactory.GetResult(new byte[] { }, response.ContentType, responseHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||
{
|
||||
responseHeaders["Accept-Ranges"] = "none";
|
||||
|
||||
return ResultFactory.GetResult(null, contentType, responseHeaders);
|
||||
return ResultFactory.GetResult(new byte[] { }, contentType, responseHeaders);
|
||||
}
|
||||
|
||||
if (!File.Exists(outputPath))
|
||||
|
|
|
@ -292,7 +292,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||
|
||||
StatusCode = httpResponse.StatusCode,
|
||||
|
||||
ContentType = httpResponse.ContentType
|
||||
ContentType = httpResponse.ContentType,
|
||||
|
||||
Headers = httpResponse.Headers
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -318,7 +320,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||
|
||||
StatusCode = httpResponse.StatusCode,
|
||||
|
||||
ContentType = httpResponse.ContentType
|
||||
ContentType = httpResponse.ContentType,
|
||||
|
||||
Headers = httpResponse.Headers
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -495,7 +499,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||
|
||||
StatusCode = httpResponse.StatusCode,
|
||||
|
||||
ContentType = httpResponse.ContentType
|
||||
ContentType = httpResponse.ContentType,
|
||||
|
||||
Headers = httpResponse.Headers
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -332,5 +333,34 @@ namespace MediaBrowser.Common.Implementations.IO
|
|||
|
||||
return path.TrimEnd(Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
public string SubstitutePath(string path, string from, string to)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(from))
|
||||
{
|
||||
throw new ArgumentNullException("from");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(to))
|
||||
{
|
||||
throw new ArgumentNullException("to");
|
||||
}
|
||||
|
||||
path = path.Replace(from, to, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (to.IndexOf('/') != -1)
|
||||
{
|
||||
path = path.Replace('\\', '/');
|
||||
}
|
||||
else
|
||||
{
|
||||
path = path.Replace('/', '\\');
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,5 +103,14 @@ namespace MediaBrowser.Common.IO
|
|||
/// <param name="path">The path.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string NormalizePath(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Substitutes the path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="from">From.</param>
|
||||
/// <param name="to">To.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string SubstitutePath(string path, string from, string to);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace MediaBrowser.Common.Net
|
||||
|
@ -31,5 +32,11 @@ namespace MediaBrowser.Common.Net
|
|||
/// </summary>
|
||||
/// <value>The temp file path.</value>
|
||||
public string TempFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the headers.
|
||||
/// </summary>
|
||||
/// <value>The headers.</value>
|
||||
public NameValueCollection Headers { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -182,11 +183,12 @@ namespace MediaBrowser.Controller.Library
|
|||
/// Determines whether [is season folder] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="directoryService">The directory service.</param>
|
||||
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
private static bool IsSeasonFolder(string path)
|
||||
private static bool IsSeasonFolder(string path, IDirectoryService directoryService)
|
||||
{
|
||||
// It's a season folder if it's named as such and does not contain any audio files, apart from theme.mp3
|
||||
return GetSeasonNumberFromPath(path) != null && !Directory.EnumerateFiles(path).Any(i => EntityResolutionHelper.IsAudioFile(i) && !string.Equals(Path.GetFileNameWithoutExtension(i), BaseItem.ThemeSongFilename));
|
||||
return GetSeasonNumberFromPath(path) != null && !directoryService.GetFiles(path).Any(i => EntityResolutionHelper.IsAudioFile(i.FullName) && !string.Equals(Path.GetFileNameWithoutExtension(i.FullName), BaseItem.ThemeSongFilename));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -195,7 +197,7 @@ namespace MediaBrowser.Controller.Library
|
|||
/// <param name="path">The path.</param>
|
||||
/// <param name="fileSystemChildren">The file system children.</param>
|
||||
/// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsSeriesFolder(string path, IEnumerable<FileSystemInfo> fileSystemChildren)
|
||||
public static bool IsSeriesFolder(string path, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
|
||||
{
|
||||
// A folder with more than 3 non-season folders in will not becounted as a series
|
||||
var nonSeriesFolders = 0;
|
||||
|
@ -216,7 +218,7 @@ namespace MediaBrowser.Controller.Library
|
|||
|
||||
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
||||
{
|
||||
if (IsSeasonFolder(child.FullName))
|
||||
if (IsSeasonFolder(child.FullName, directoryService))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -136,12 +136,6 @@ namespace MediaBrowser.Model.Dto
|
|||
/// <value>The genres.</value>
|
||||
public List<string> Genres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mapped paths.
|
||||
/// </summary>
|
||||
/// <value>The mapped paths.</value>
|
||||
public List<string> MappedPaths { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the community rating.
|
||||
/// </summary>
|
||||
|
|
|
@ -195,7 +195,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
var currentItem = item;
|
||||
|
||||
var providersWithChanges = providers.OfType<IHasChangeMonitor>()
|
||||
.Where(i => i.HasChanged(currentItem, options.DirectoryService, currentItem.DateLastSaved))
|
||||
.Where(i => HasChanged(currentItem, i, currentItem.DateLastSaved, options.DirectoryService))
|
||||
.Cast<IMetadataProvider<TItemType>>()
|
||||
.ToList();
|
||||
|
||||
|
@ -242,11 +242,8 @@ namespace MediaBrowser.Providers.Manager
|
|||
|
||||
if (!runAllProviders)
|
||||
{
|
||||
// Avoid implicitly captured closure
|
||||
var currentItem = item;
|
||||
|
||||
providers = providers.OfType<IHasChangeMonitor>()
|
||||
.Where(i => i.HasChanged(currentItem, options.DirectoryService, dateLastImageRefresh.Value))
|
||||
.Where(i => HasChanged(item, i, dateLastImageRefresh.Value, options.DirectoryService))
|
||||
.Cast<IImageProvider>()
|
||||
.ToList();
|
||||
}
|
||||
|
@ -438,6 +435,19 @@ namespace MediaBrowser.Providers.Manager
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasChanged(IHasMetadata item, IHasChangeMonitor changeMonitor, DateTime date, IDirectoryService directoryService)
|
||||
{
|
||||
try
|
||||
{
|
||||
return changeMonitor.HasChanged(item, directoryService, date);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error in {0}.HasChanged", ex, changeMonitor.GetType().Name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RefreshResult
|
||||
|
|
|
@ -572,11 +572,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
var type = item.GetType().Name;
|
||||
|
||||
if (item is Trailer)
|
||||
{
|
||||
type = typeof(Movie).Name;
|
||||
}
|
||||
|
||||
return ConfigurationManager.Configuration.MetadataOptions
|
||||
.FirstOrDefault(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase)) ??
|
||||
new MetadataOptions();
|
||||
|
|
|
@ -48,6 +48,11 @@ namespace MediaBrowser.Providers.Movies
|
|||
{
|
||||
var name = idInfo.Name;
|
||||
var year = idInfo.Year;
|
||||
int? yearInName = null;
|
||||
|
||||
NameParser.ParseName(name, out name, out yearInName);
|
||||
|
||||
year = year ?? yearInName;
|
||||
|
||||
_logger.Info("MovieDbProvider: Finding id for item: " + name);
|
||||
var language = idInfo.MetadataLanguage.ToLower();
|
||||
|
|
|
@ -56,6 +56,18 @@ namespace MediaBrowser.Providers.TV
|
|||
if (string.IsNullOrEmpty(seriesId))
|
||||
{
|
||||
seriesId = await FindSeries(itemId.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (string.IsNullOrEmpty(seriesId))
|
||||
{
|
||||
int? yearInName = null;
|
||||
string nameWithoutYear;
|
||||
NameParser.ParseName(itemId.Name, out nameWithoutYear, out yearInName);
|
||||
|
||||
if (!string.IsNullOrEmpty(nameWithoutYear) && !string.Equals(nameWithoutYear, itemId.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
seriesId = await FindSeries(nameWithoutYear, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -248,16 +260,6 @@ namespace MediaBrowser.Providers.TV
|
|||
}
|
||||
}
|
||||
|
||||
// Try stripping off the year if it was supplied
|
||||
var parenthIndex = name.LastIndexOf('(');
|
||||
|
||||
if (parenthIndex != -1)
|
||||
{
|
||||
var newName = name.Substring(0, parenthIndex);
|
||||
|
||||
return await FindSeries(newName, cancellationToken);
|
||||
}
|
||||
|
||||
_logger.Info("TVDb Provider - Could not find " + name + ". Check name on Thetvdb.org.");
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -899,9 +899,17 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
}
|
||||
|
||||
if (fields.Contains(ItemFields.Path))
|
||||
{
|
||||
var locationType = item.LocationType;
|
||||
|
||||
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
||||
{
|
||||
dto.Path = GetMappedPath(item.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
dto.Path = item.Path;
|
||||
dto.MappedPaths = GetMappedPaths(item);
|
||||
}
|
||||
}
|
||||
|
||||
dto.PremiereDate = item.PremiereDate;
|
||||
|
@ -1135,39 +1143,11 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
}
|
||||
}
|
||||
|
||||
private List<string> GetMappedPaths(BaseItem item)
|
||||
private string GetMappedPath(string path)
|
||||
{
|
||||
var list = new List<string>();
|
||||
|
||||
var locationType = item.LocationType;
|
||||
|
||||
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
||||
foreach (var map in _config.Configuration.PathSubstitutions)
|
||||
{
|
||||
var path = item.Path;
|
||||
var mappedPaths = _config.Configuration.PathSubstitutions
|
||||
.Select(p => GetMappedPath(path, p))
|
||||
.Where(p => !string.Equals(p, path, StringComparison.OrdinalIgnoreCase))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
list.AddRange(mappedPaths);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private string GetMappedPath(string path, PathSubstitution map)
|
||||
{
|
||||
var toValue = map.To ?? string.Empty;
|
||||
|
||||
path = path.Replace(map.From, toValue, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (toValue.IndexOf('/') != -1)
|
||||
{
|
||||
path = path.Replace('\\', '/');
|
||||
}
|
||||
else
|
||||
{
|
||||
path = path.Replace('/', '\\');
|
||||
path = _fileSystem.SubstitutePath(path, map.From, map.To);
|
||||
}
|
||||
|
||||
return path;
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
|||
return null;
|
||||
}
|
||||
|
||||
if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren))
|
||||
if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService))
|
||||
{
|
||||
return new Series();
|
||||
}
|
||||
|
|
65
MediaBrowser.ServerApplication/Logging/LogForm.Designer.cs
generated
Normal file
65
MediaBrowser.ServerApplication/Logging/LogForm.Designer.cs
generated
Normal file
|
@ -0,0 +1,65 @@
|
|||
namespace MediaBrowser.ServerApplication.Logging
|
||||
{
|
||||
partial class LogForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LogForm));
|
||||
this.listBox1 = new System.Windows.Forms.ListBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// listBox1
|
||||
//
|
||||
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.listBox1.Font = new System.Drawing.Font("Consolas", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.listBox1.FormattingEnabled = true;
|
||||
this.listBox1.ItemHeight = 18;
|
||||
this.listBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.listBox1.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.listBox1.Name = "listBox1";
|
||||
this.listBox1.Size = new System.Drawing.Size(984, 561);
|
||||
this.listBox1.TabIndex = 0;
|
||||
//
|
||||
// LogForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(984, 561);
|
||||
this.Controls.Add(this.listBox1);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "LogForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Media Browser Log";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ListBox listBox1;
|
||||
}
|
||||
}
|
88
MediaBrowser.ServerApplication/Logging/LogForm.cs
Normal file
88
MediaBrowser.ServerApplication/Logging/LogForm.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using MediaBrowser.Common.Implementations.Logging;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using NLog.Targets;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Logging
|
||||
{
|
||||
public partial class LogForm : Form
|
||||
{
|
||||
private readonly TaskScheduler _uiThread;
|
||||
private readonly ILogManager _logManager;
|
||||
|
||||
public LogForm(ILogManager logManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logManager = logManager;
|
||||
_uiThread = TaskScheduler.FromCurrentSynchronizationContext();
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
|
||||
|
||||
((NlogManager)_logManager).AddLogTarget(new TraceTarget
|
||||
{
|
||||
Layout = "${longdate}, ${level}, ${logger}, ${message}",
|
||||
Name = "LogWindowTraceTarget"
|
||||
|
||||
}, LogSeverity.Debug);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs the message.
|
||||
/// </summary>
|
||||
/// <param name="msg">The MSG.</param>
|
||||
public async void LogMessage(string msg)
|
||||
{
|
||||
await Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (listBox1.Items.Count > 10000)
|
||||
{
|
||||
//I think the quickest and safest thing to do here is just clear it out
|
||||
listBox1.Items.Clear();
|
||||
}
|
||||
|
||||
foreach (var line in msg.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
listBox1.Items.Insert(0, line);
|
||||
}
|
||||
}
|
||||
|
||||
}, CancellationToken.None, TaskCreationOptions.None, _uiThread);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log layout
|
||||
/// </summary>
|
||||
/// <value>The log layout.</value>
|
||||
public string LogLayout
|
||||
{
|
||||
get { return "${longdate}, ${level}, ${logger}, ${message}"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down.
|
||||
/// </summary>
|
||||
public async void ShutDown()
|
||||
{
|
||||
await Task.Factory.StartNew(Close, CancellationToken.None, TaskCreationOptions.None, _uiThread);
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
base.OnClosing(e);
|
||||
|
||||
((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
|
||||
}
|
||||
}
|
||||
}
|
2473
MediaBrowser.ServerApplication/Logging/LogForm.resx
Normal file
2473
MediaBrowser.ServerApplication/Logging/LogForm.resx
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +0,0 @@
|
|||
<Window x:Class="MediaBrowser.ServerApplication.Logging.LogWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Media Browser Log" Height="300" Width="968">
|
||||
<Grid>
|
||||
<ListBox x:Name="lbxLogData" Margin="10,10,0,0"/>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,123 +0,0 @@
|
|||
using MediaBrowser.Common.Implementations.Logging;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogWindow.xaml
|
||||
/// </summary>
|
||||
public partial class LogWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// The _ui thread
|
||||
/// </summary>
|
||||
private readonly TaskScheduler _uiThread;
|
||||
|
||||
private readonly ILogManager _logManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LogWindow" /> class.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The kernel.</param>
|
||||
public LogWindow(ILogManager logManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
_uiThread = TaskScheduler.FromCurrentSynchronizationContext();
|
||||
_logManager = logManager;
|
||||
|
||||
Loaded += LogWindow_Loaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the Loaded event of the LogWindow control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
|
||||
void LogWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
((NlogManager)_logManager).RemoveTarget("LogWindowTraceTarget");
|
||||
|
||||
((NlogManager)_logManager).AddLogTarget(new TraceTarget
|
||||
{
|
||||
Layout = "${longdate}, ${level}, ${logger}, ${message}",
|
||||
Name = "LogWindowTraceTarget"
|
||||
|
||||
}, LogSeverity.Debug);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.Windows.Window.Closing" /> event.
|
||||
/// </summary>
|
||||
/// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
base.OnClosing(e);
|
||||
|
||||
((NlogManager) _logManager).RemoveTarget("LogWindowTraceTarget");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs the message.
|
||||
/// </summary>
|
||||
/// <param name="msg">The MSG.</param>
|
||||
public async void LogMessage(string msg)
|
||||
{
|
||||
await Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (lbxLogData.Items.Count > 10000)
|
||||
{
|
||||
//I think the quickest and safest thing to do here is just clear it out
|
||||
lbxLogData.Items.Clear();
|
||||
}
|
||||
|
||||
lbxLogData.Items.Insert(0, msg.TrimEnd('\n'));
|
||||
}, CancellationToken.None, TaskCreationOptions.None, _uiThread);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log layout
|
||||
/// </summary>
|
||||
/// <value>The log layout.</value>
|
||||
public string LogLayout
|
||||
{
|
||||
get { return "${longdate}, ${level}, ${logger}, ${message}"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the log target.
|
||||
/// </summary>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
private void AddLogTarget(Target target, string name)
|
||||
{
|
||||
var config = NLog.LogManager.Configuration;
|
||||
|
||||
target.Name = name;
|
||||
config.AddTarget(name, target);
|
||||
|
||||
var level = LogLevel.Debug;
|
||||
|
||||
var rule = new LoggingRule("*", level, target);
|
||||
config.LoggingRules.Add(rule);
|
||||
|
||||
NLog.LogManager.Configuration = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down.
|
||||
/// </summary>
|
||||
public async void ShutDown()
|
||||
{
|
||||
await Task.Factory.StartNew(Close, CancellationToken.None, TaskCreationOptions.None, _uiThread);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -10,12 +10,12 @@ namespace MediaBrowser.ServerApplication.Logging
|
|||
/// <summary>
|
||||
/// The _window
|
||||
/// </summary>
|
||||
private readonly LogWindow _window;
|
||||
private readonly LogForm _window;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowTraceListener" /> class.
|
||||
/// </summary>
|
||||
/// <param name="window">The window.</param>
|
||||
public WindowTraceListener(LogWindow window)
|
||||
public WindowTraceListener(LogForm window)
|
||||
{
|
||||
_window = window;
|
||||
_window.Show();
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.ServerApplication.Logging;
|
||||
using MediaBrowser.ServerApplication.Native;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using MediaBrowser.ServerApplication.Native;
|
||||
|
||||
namespace MediaBrowser.ServerApplication
|
||||
{
|
||||
|
@ -47,6 +45,8 @@ namespace MediaBrowser.ServerApplication
|
|||
private readonly IDisplayPreferencesRepository _displayPreferencesManager;
|
||||
private readonly IItemRepository _itemRepository;
|
||||
|
||||
private LogForm _logForm;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MainWindow" /> class.
|
||||
/// </summary>
|
||||
|
@ -120,9 +120,9 @@ namespace MediaBrowser.ServerApplication
|
|||
|
||||
Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var logWindow = App.Current.Windows.OfType<LogWindow>().FirstOrDefault();
|
||||
var isLogWindowOpen = _logForm != null;
|
||||
|
||||
if ((logWindow == null && _configurationManager.Configuration.ShowLogWindow) || (logWindow != null && !_configurationManager.Configuration.ShowLogWindow))
|
||||
if ((!isLogWindowOpen && _configurationManager.Configuration.ShowLogWindow) || (isLogWindowOpen && !_configurationManager.Configuration.ShowLogWindow))
|
||||
{
|
||||
_logManager.ReloadLogger(_configurationManager.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace MediaBrowser.ServerApplication
|
|||
// Add our log window if specified
|
||||
if (_configurationManager.Configuration.ShowLogWindow)
|
||||
{
|
||||
Trace.Listeners.Add(new WindowTraceListener(new LogWindow(_logManager)));
|
||||
Trace.Listeners.Add(new WindowTraceListener(new LogForm(_logManager)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -171,13 +171,10 @@ namespace MediaBrowser.ServerApplication
|
|||
/// </summary>
|
||||
void CloseLogWindow()
|
||||
{
|
||||
Dispatcher.InvokeAsync(() =>
|
||||
if (_logForm != null)
|
||||
{
|
||||
foreach (var win in Application.Current.Windows.OfType<LogWindow>())
|
||||
{
|
||||
win.Close();
|
||||
_logForm.ShutDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -170,6 +170,12 @@
|
|||
<Compile Include="FFMpeg\FFMpegDownloadInfo.cs" />
|
||||
<Compile Include="FFMpeg\FFMpegInfo.cs" />
|
||||
<Compile Include="IO\FileSystemFactory.cs" />
|
||||
<Compile Include="Logging\LogForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Logging\LogForm.Designer.cs">
|
||||
<DependentUpon>LogForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Native\Assemblies.cs" />
|
||||
<Compile Include="Native\NativeApp.cs" />
|
||||
<Compile Include="IO\NativeFileSystem.cs" />
|
||||
|
@ -195,10 +201,6 @@
|
|||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Logging\LogWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
|
@ -214,9 +216,6 @@
|
|||
<Compile Include="LibraryExplorer.xaml.cs">
|
||||
<DependentUpon>LibraryExplorer.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Logging\LogWindow.xaml.cs">
|
||||
<DependentUpon>LogWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Logging\WindowTraceListener.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
|
@ -241,6 +240,9 @@
|
|||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Logging\LogForm.resx">
|
||||
<DependentUpon>LogForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
|
Loading…
Reference in New Issue
Block a user