aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Devices
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
committerLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
commit4cc3b2f0ccd7c092a4acf72db4903415e175037a (patch)
treef9f90f8665b726253b8b357674f2f141aa43abc9 /MediaBrowser.Server.Implementations/Devices
parente7037a9b80843c127712f11430239f8fa3cb4aed (diff)
parent3d7089a7dbabb652730c892206ca050f52f832b1 (diff)
Merge pull request #1005 from MediaBrowser/dev
3.0.5518.0
Diffstat (limited to 'MediaBrowser.Server.Implementations/Devices')
-rw-r--r--MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs1
-rw-r--r--MediaBrowser.Server.Implementations/Devices/DeviceManager.cs38
-rw-r--r--MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs20
3 files changed, 48 insertions, 11 deletions
diff --git a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs
index 10fc2ad91..2fe5d8f74 100644
--- a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs
+++ b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs
@@ -10,7 +10,6 @@ namespace MediaBrowser.Server.Implementations.Devices
public CameraUploadsFolder()
{
Name = "Camera Uploads";
- DisplayMediaType = "CollectionFolder";
}
public override bool IsVisible(User user)
diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs
index ddd5ef58d..3211f88d5 100644
--- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs
+++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs
@@ -27,6 +27,8 @@ namespace MediaBrowser.Server.Implementations.Devices
private readonly IConfigurationManager _config;
private readonly ILogger _logger;
+ public event EventHandler<GenericEventArgs<CameraImageUploadInfo>> CameraImageUploaded;
+
/// <summary>
/// Occurs when [device options updated].
/// </summary>
@@ -100,18 +102,23 @@ namespace MediaBrowser.Server.Implementations.Devices
devices = devices.Where(i => GetCapabilities(i.Id).SupportsSync == val);
}
- if (query.SupportsUniqueIdentifier.HasValue)
+ if (query.SupportsPersistentIdentifier.HasValue)
{
- var val = query.SupportsUniqueIdentifier.Value;
+ var val = query.SupportsPersistentIdentifier.Value;
- devices = devices.Where(i => GetCapabilities(i.Id).SupportsUniqueIdentifier == val);
+ devices = devices.Where(i =>
+ {
+ var caps = GetCapabilities(i.Id);
+ var deviceVal = caps.SupportsUniqueIdentifier ?? caps.SupportsPersistentIdentifier;
+ return deviceVal == val;
+ });
}
if (!string.IsNullOrWhiteSpace(query.UserId))
{
devices = devices.Where(i => CanAccessDevice(query.UserId, i.Id));
}
-
+
var array = devices.ToArray();
return new QueryResult<DeviceInfo>
{
@@ -132,7 +139,8 @@ namespace MediaBrowser.Server.Implementations.Devices
public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file)
{
- var path = GetUploadPath(deviceId);
+ var device = GetDevice(deviceId);
+ var path = GetUploadPath(device);
if (!string.IsNullOrWhiteSpace(file.Album))
{
@@ -158,11 +166,27 @@ namespace MediaBrowser.Server.Implementations.Devices
{
_libraryMonitor.ReportFileSystemChangeComplete(path, true);
}
+
+ if (CameraImageUploaded != null)
+ {
+ EventHelper.FireEventIfNotNull(CameraImageUploaded, this, new GenericEventArgs<CameraImageUploadInfo>
+ {
+ Argument = new CameraImageUploadInfo
+ {
+ Device = device,
+ FileInfo = file
+ }
+ }, _logger);
+ }
}
private string GetUploadPath(string deviceId)
{
- var device = GetDevice(deviceId);
+ return GetUploadPath(GetDevice(deviceId));
+ }
+
+ private string GetUploadPath(DeviceInfo device)
+ {
if (!string.IsNullOrWhiteSpace(device.CameraUploadPath))
{
return device.CameraUploadPath;
@@ -212,7 +236,7 @@ namespace MediaBrowser.Server.Implementations.Devices
{
var capabilities = GetCapabilities(deviceId);
- if (capabilities.SupportsUniqueIdentifier)
+ if (capabilities != null && capabilities.SupportsPersistentIdentifier)
{
return false;
}
diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs
index d587e5af7..6d324b1ab 100644
--- a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs
+++ b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Model.Devices;
using MediaBrowser.Model.Logging;
@@ -21,14 +22,16 @@ namespace MediaBrowser.Server.Implementations.Devices
private readonly IApplicationPaths _appPaths;
private readonly IJsonSerializer _json;
private readonly ILogger _logger;
+ private readonly IFileSystem _fileSystem;
private ConcurrentBag<DeviceInfo> _devices;
- public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger)
+ public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger, IFileSystem fileSystem)
{
_appPaths = appPaths;
_json = json;
_logger = logger;
+ _fileSystem = fileSystem;
}
private string GetDevicesPath()
@@ -57,6 +60,12 @@ namespace MediaBrowser.Server.Implementations.Devices
public Task SaveCapabilities(string reportedId, ClientCapabilities capabilities)
{
var device = GetDevice(reportedId);
+
+ if (device == null)
+ {
+ throw new ArgumentException("No device has been registed with id " + reportedId);
+ }
+
device.Capabilities = capabilities;
SaveDevice(device);
@@ -72,6 +81,11 @@ namespace MediaBrowser.Server.Implementations.Devices
public DeviceInfo GetDevice(string id)
{
+ if (string.IsNullOrWhiteSpace(id))
+ {
+ throw new ArgumentNullException("id");
+ }
+
return GetDevices()
.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));
}
@@ -129,12 +143,12 @@ namespace MediaBrowser.Server.Implementations.Devices
{
try
{
- Directory.Delete(path, true);
+ _fileSystem.DeleteDirectory(path, true);
}
catch (DirectoryNotFoundException)
{
}
-
+
_devices = null;
}