aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations
diff options
context:
space:
mode:
authorhatharry <hatharry@hotmail.com>2016-07-25 23:29:52 +1200
committerGitHub <noreply@github.com>2016-07-25 23:29:52 +1200
commitf21f9923de6291aaf985f32dbbbaddbb26d07fb1 (patch)
tree1a313e9a1c6790a755926bcef221c5f680537eae /MediaBrowser.Common.Implementations
parent6332d0b9436c511a59e2abd67ea8c24ce3d82ace (diff)
parent8328f39834f042e1808fd8506bbc7c48151703ab (diff)
Merge pull request #15 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Common.Implementations')
-rw-r--r--MediaBrowser.Common.Implementations/BaseApplicationHost.cs8
-rw-r--r--MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs1
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs52
-rw-r--r--MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj10
-rw-r--r--MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs45
-rw-r--r--MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs4
-rw-r--r--MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs2
-rw-r--r--MediaBrowser.Common.Implementations/Security/MbAdmin.cs4
-rw-r--r--MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs2
-rw-r--r--MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs8
-rw-r--r--MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs15
-rw-r--r--MediaBrowser.Common.Implementations/Updates/GithubUpdater.cs9
-rw-r--r--MediaBrowser.Common.Implementations/Updates/InstallationManager.cs1
-rw-r--r--MediaBrowser.Common.Implementations/packages.config6
14 files changed, 106 insertions, 61 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index f44c975d4..baf5afc1b 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -199,7 +199,7 @@ namespace MediaBrowser.Common.Implementations
ILogManager logManager,
IFileSystem fileSystem)
{
- XmlSerializer = new MediaBrowser.Common.Implementations.Serialization.XmlSerializer (fileSystem);
+ XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer"));
FailedAssemblies = new List<string>();
ApplicationPaths = applicationPaths;
@@ -321,7 +321,7 @@ namespace MediaBrowser.Common.Implementations
protected virtual IJsonSerializer CreateJsonSerializer()
{
- return new JsonSerializer(FileSystemManager);
+ return new JsonSerializer(FileSystemManager, LogManager.GetLogger("JsonSerializer"));
}
private void SetHttpLimit()
@@ -552,7 +552,7 @@ namespace MediaBrowser.Common.Implementations
}
catch (Exception ex)
{
- Logger.Error("Error creating {0}", ex, type.Name);
+ Logger.ErrorException("Error creating {0}", ex, type.Name);
throw;
}
@@ -571,7 +571,7 @@ namespace MediaBrowser.Common.Implementations
}
catch (Exception ex)
{
- Logger.Error("Error creating {0}", ex, type.Name);
+ Logger.ErrorException("Error creating {0}", ex, type.Name);
// Don't blow up in release mode
return null;
}
diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
index 7f9299ff2..fa15023ca 100644
--- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
+++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
@@ -123,6 +123,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
/// </summary>
public void SaveConfiguration()
{
+ Logger.Info("Saving system configuration");
var path = CommonApplicationPaths.SystemConfigurationFilePath;
Directory.CreateDirectory(Path.GetDirectoryName(path));
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index f9dbd766f..371757f6c 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -128,11 +128,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
private void AddIpv4Option(HttpWebRequest request, HttpRequestOptions options)
{
- if (!options.PreferIpv4)
- {
- return;
- }
-
request.ServicePoint.BindIPEndPointDelegate = (servicePount, remoteEndPoint, retryCount) =>
{
if (remoteEndPoint.AddressFamily == AddressFamily.InterNetwork)
@@ -143,18 +138,33 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
};
}
- private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
+ private WebRequest GetRequest(HttpRequestOptions options, string method)
{
- var request = CreateWebRequest(options.Url);
+ var url = options.Url;
+
+ var uriAddress = new Uri(url);
+ var userInfo = uriAddress.UserInfo;
+ if (!string.IsNullOrWhiteSpace(userInfo))
+ {
+ _logger.Info("Found userInfo in url: {0} ... url: {1}", userInfo, url);
+ url = url.Replace(userInfo + "@", string.Empty);
+ }
+
+ var request = CreateWebRequest(url);
var httpWebRequest = request as HttpWebRequest;
if (httpWebRequest != null)
{
- AddIpv4Option(httpWebRequest, options);
+ if (options.PreferIpv4)
+ {
+ AddIpv4Option(httpWebRequest, options);
+ }
AddRequestHeaders(httpWebRequest, options);
- httpWebRequest.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
+ httpWebRequest.AutomaticDecompression = options.EnableHttpCompression ?
+ (options.DecompressionMethod ?? DecompressionMethods.Deflate) :
+ DecompressionMethods.None;
}
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
@@ -183,9 +193,27 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
+ if (!string.IsNullOrWhiteSpace(userInfo))
+ {
+ var parts = userInfo.Split(':');
+ if (parts.Length == 2)
+ {
+ request.Credentials = GetCredential(url, parts[0], parts[1]);
+ request.PreAuthenticate = true;
+ }
+ }
+
return request;
}
+ private CredentialCache GetCredential(string url, string username, string password)
+ {
+ //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
+ CredentialCache credentialCache = new CredentialCache();
+ credentialCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
+ return credentialCache;
+ }
+
private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
{
foreach (var header in options.RequestHeaders.ToList())
@@ -296,6 +324,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
{
+ _logger.Info("Checking for cache file {0}", responseCachePath);
+
try
{
if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow)
@@ -366,7 +396,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
};
}
- var httpWebRequest = GetRequest(options, httpMethod, options.EnableHttpCompression);
+ var httpWebRequest = GetRequest(options, httpMethod);
if (options.RequestContentBytes != null ||
!string.IsNullOrEmpty(options.RequestContent) ||
@@ -556,7 +586,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
options.CancellationToken.ThrowIfCancellationRequested();
- var httpWebRequest = GetRequest(options, "GET", options.EnableHttpCompression);
+ var httpWebRequest = GetRequest(options, "GET");
if (options.ResourcePool != null)
{
diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
index 2017b40f4..108eddcf9 100644
--- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
+++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
@@ -54,8 +54,9 @@
<Reference Include="MoreLinq">
<HintPath>..\packages\morelinq.1.4.0\lib\net35\MoreLinq.dll</HintPath>
</Reference>
- <Reference Include="NLog">
- <HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
+ <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
+ <HintPath>..\packages\NLog.4.3.5\lib\net45\NLog.dll</HintPath>
+ <Private>True</Private>
</Reference>
<Reference Include="Patterns.Logging">
<HintPath>..\packages\Patterns.Logging.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\Patterns.Logging.dll</HintPath>
@@ -64,8 +65,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ThirdParty\SharpCompress\SharpCompress.dll</HintPath>
</Reference>
- <Reference Include="SimpleInjector">
- <HintPath>..\packages\SimpleInjector.3.1.2\lib\net45\SimpleInjector.dll</HintPath>
+ <Reference Include="SimpleInjector, Version=3.2.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
+ <HintPath>..\packages\SimpleInjector.3.2.0\lib\net45\SimpleInjector.dll</HintPath>
+ <Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
index 8d727a112..dcd3a3025 100644
--- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
+++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
@@ -106,6 +106,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
InitTriggerEvents();
}
+ private bool _readFromFile = false;
/// <summary>
/// The _last execution result
/// </summary>
@@ -122,31 +123,29 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
{
get
{
- if (_lastExecutionResult == null)
- {
- var path = GetHistoryFilePath();
+ var path = GetHistoryFilePath();
- lock (_lastExecutionResultSyncLock)
+ lock (_lastExecutionResultSyncLock)
+ {
+ if (_lastExecutionResult == null && !_readFromFile)
{
- if (_lastExecutionResult == null)
+ try
+ {
+ _lastExecutionResult = JsonSerializer.DeserializeFromFile<TaskResult>(path);
+ }
+ catch (DirectoryNotFoundException)
+ {
+ // File doesn't exist. No biggie
+ }
+ catch (FileNotFoundException)
+ {
+ // File doesn't exist. No biggie
+ }
+ catch (Exception ex)
{
- try
- {
- return JsonSerializer.DeserializeFromFile<TaskResult>(path);
- }
- catch (DirectoryNotFoundException)
- {
- // File doesn't exist. No biggie
- }
- catch (FileNotFoundException)
- {
- // File doesn't exist. No biggie
- }
- catch (Exception ex)
- {
- Logger.ErrorException("Error deserializing {0}", ex, path);
- }
+ Logger.ErrorException("Error deserializing {0}", ex, path);
}
+ _readFromFile = true;
}
}
@@ -311,7 +310,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
trigger.Triggered -= trigger_Triggered;
trigger.Triggered += trigger_Triggered;
- trigger.Start(LastExecutionResult, isApplicationStartup);
+ trigger.Start(LastExecutionResult, Logger, Name, isApplicationStartup);
}
}
@@ -339,7 +338,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
await Task.Delay(1000).ConfigureAwait(false);
- trigger.Start(LastExecutionResult, false);
+ trigger.Start(LastExecutionResult, Logger, Name, false);
}
private Task _currentTask;
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
index 3aab59ee1..b3a00b35f 100644
--- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
+++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
@@ -88,8 +88,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
_fileSystem = fileSystem;
ScheduledTasks = new IScheduledTaskWorker[] { };
-
- BindToSystemEvent();
}
private void BindToSystemEvent()
@@ -259,6 +257,8 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem)));
ScheduledTasks = myTasks.ToArray();
+
+ BindToSystemEvent();
}
/// <summary>
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
index b4cc5d753..0a2b9222a 100644
--- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
+++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
@@ -71,7 +71,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
progress.Report(90);
- minDateModified = DateTime.UtcNow.AddDays(-2);
+ minDateModified = DateTime.UtcNow.AddDays(-1);
try
{
diff --git a/MediaBrowser.Common.Implementations/Security/MbAdmin.cs b/MediaBrowser.Common.Implementations/Security/MbAdmin.cs
index ab4a83257..76ff92c2e 100644
--- a/MediaBrowser.Common.Implementations/Security/MbAdmin.cs
+++ b/MediaBrowser.Common.Implementations/Security/MbAdmin.cs
@@ -3,11 +3,11 @@ namespace MediaBrowser.Common.Implementations.Security
{
public class MbAdmin
{
- public const string HttpUrl = "http://www.mb3admin.com/admin/";
+ public const string HttpUrl = "https://www.mb3admin.com/admin/";
/// <summary>
/// Leaving as http for now until we get it squared away
/// </summary>
- public const string HttpsUrl = "http://www.mb3admin.com/admin/";
+ public const string HttpsUrl = "https://www.mb3admin.com/admin/";
}
}
diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
index af58c3731..4e01041bc 100644
--- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
+++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
@@ -21,7 +21,7 @@ namespace MediaBrowser.Common.Implementations.Security
public class PluginSecurityManager : ISecurityManager
{
private const string MBValidateUrl = MbAdmin.HttpsUrl + "service/registration/validate";
- private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "http://mb3admin.com/admin/service/appstore/register";
+ private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "https://mb3admin.com/admin/service/appstore/register";
/// <summary>
/// The _is MB supporter
diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs
index 6610cd3ff..5dbbe5373 100644
--- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs
+++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs
@@ -2,6 +2,7 @@
using System;
using System.IO;
using CommonIO;
+using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Implementations.Serialization
{
@@ -11,10 +12,12 @@ namespace MediaBrowser.Common.Implementations.Serialization
public class JsonSerializer : IJsonSerializer
{
private readonly IFileSystem _fileSystem;
-
- public JsonSerializer(IFileSystem fileSystem)
+ private readonly ILogger _logger;
+
+ public JsonSerializer(IFileSystem fileSystem, ILogger logger)
{
_fileSystem = fileSystem;
+ _logger = logger;
Configure();
}
@@ -65,6 +68,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
private Stream OpenFile(string path)
{
+ _logger.Debug("Deserializing file {0}", path);
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072);
}
diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs
index 189fb7afc..756741e0d 100644
--- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs
+++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
using System.IO;
using System.Xml;
using CommonIO;
+using MediaBrowser.Model.Logging;
namespace MediaBrowser.Common.Implementations.Serialization
{
@@ -12,12 +13,14 @@ namespace MediaBrowser.Common.Implementations.Serialization
/// </summary>
public class XmlSerializer : IXmlSerializer
{
- private IFileSystem _fileSystem;
+ private readonly IFileSystem _fileSystem;
+ private readonly ILogger _logger;
- public XmlSerializer(IFileSystem fileSystem)
- {
- _fileSystem = fileSystem;
- }
+ public XmlSerializer(IFileSystem fileSystem, ILogger logger)
+ {
+ _fileSystem = fileSystem;
+ _logger = logger;
+ }
// Need to cache these
// http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html
@@ -77,6 +80,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
/// <param name="file">The file.</param>
public void SerializeToFile(object obj, string file)
{
+ _logger.Debug("Serializing to file {0}", file);
using (var stream = new FileStream(file, FileMode.Create))
{
SerializeToStream(obj, stream);
@@ -91,6 +95,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
/// <returns>System.Object.</returns>
public object DeserializeFromFile(Type type, string file)
{
+ _logger.Debug("Deserializing file {0}", file);
using (var stream = _fileSystem.OpenRead(file))
{
return DeserializeFromStream(type, stream);
diff --git a/MediaBrowser.Common.Implementations/Updates/GithubUpdater.cs b/MediaBrowser.Common.Implementations/Updates/GithubUpdater.cs
index 82ebf92b2..d1ec30210 100644
--- a/MediaBrowser.Common.Implementations/Updates/GithubUpdater.cs
+++ b/MediaBrowser.Common.Implementations/Updates/GithubUpdater.cs
@@ -54,7 +54,9 @@ namespace MediaBrowser.Common.Implementations.Updates
{
if (updateLevel == PackageVersionClass.Release)
{
- obj = obj.Where(i => !i.prerelease).ToArray();
+ // Technically all we need to do is check that it's not pre-release
+ // But let's addititional checks for -beta and -dev to handle builds that might be temporarily tagged incorrectly.
+ obj = obj.Where(i => !i.prerelease && !i.name.EndsWith("-beta", StringComparison.OrdinalIgnoreCase) && !i.name.EndsWith("-dev", StringComparison.OrdinalIgnoreCase)).ToArray();
}
else if (updateLevel == PackageVersionClass.Beta)
{
@@ -70,7 +72,7 @@ namespace MediaBrowser.Common.Implementations.Updates
.Where(i => i != null)
.OrderByDescending(i => Version.Parse(i.AvailableVersion))
.FirstOrDefault();
-
+
return availableUpdate ?? new CheckForUpdateResult
{
IsUpdateAvailable = false
@@ -111,7 +113,8 @@ namespace MediaBrowser.Common.Implementations.Updates
targetFilename = targetFilename,
versionStr = version.ToString(),
requiredVersionStr = "1.0.0",
- description = obj.body
+ description = obj.body,
+ infoUrl = obj.html_url
}
};
}
diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs
index 5c82ccb0e..8c7646209 100644
--- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs
+++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs
@@ -193,6 +193,7 @@ namespace MediaBrowser.Common.Implementations.Updates
/// <returns>Task{List{PackageInfo}}.</returns>
public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken)
{
+ _logger.Info("Opening {0}", PackageCachePath);
try
{
using (var stream = _fileSystem.OpenRead(PackageCachePath))
diff --git a/MediaBrowser.Common.Implementations/packages.config b/MediaBrowser.Common.Implementations/packages.config
index 64b337221..882acc9ff 100644
--- a/MediaBrowser.Common.Implementations/packages.config
+++ b/MediaBrowser.Common.Implementations/packages.config
@@ -2,7 +2,7 @@
<packages>
<package id="CommonIO" version="1.0.0.9" targetFramework="net45" />
<package id="morelinq" version="1.4.0" targetFramework="net45" />
- <package id="NLog" version="4.2.3" targetFramework="net45" />
+ <package id="NLog" version="4.3.5" targetFramework="net45" />
<package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
- <package id="SimpleInjector" version="3.1.2" targetFramework="net45" />
-</packages>
+ <package id="SimpleInjector" version="3.2.0" targetFramework="net45" />
+</packages> \ No newline at end of file