diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-06-30 15:27:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-30 15:27:06 -0400 |
| commit | 2708df6cc28c48a89416bdfbdde7e78fc4227c62 (patch) | |
| tree | 9f892d6350a4d694c96985d679f622c0f7005278 /MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs | |
| parent | d9406d48ca0231bc096aeadc595c30f0596c8dda (diff) | |
| parent | 5bdc96bb6a9b863980661e2d11c1ad00a02eb601 (diff) | |
Merge pull request #1899 from MediaBrowser/beta
Beta
Diffstat (limited to 'MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs index 368d21322..6e67af82b 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.Devices private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private List<DeviceInfo> _devices; + private Dictionary<string, DeviceInfo> _devices; public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger, IFileSystem fileSystem) { @@ -46,12 +46,12 @@ namespace MediaBrowser.Server.Implementations.Devices public Task SaveDevice(DeviceInfo device) { var path = Path.Combine(GetDevicePath(device.Id), "device.json"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); lock (_syncLock) { _json.SerializeToFile(device, path); - _devices = null; + _devices[device.Id] = device; } return Task.FromResult(true); } @@ -95,9 +95,15 @@ namespace MediaBrowser.Server.Implementations.Devices { if (_devices == null) { - _devices = LoadDevices().ToList(); + _devices = new Dictionary<string, DeviceInfo>(StringComparer.OrdinalIgnoreCase); + + var devices = LoadDevices().ToList(); + foreach (var device in devices) + { + _devices[device.Id] = device; + } } - return _devices.ToList(); + return _devices.Values.ToList(); } } @@ -144,7 +150,7 @@ namespace MediaBrowser.Server.Implementations.Devices catch (DirectoryNotFoundException) { } - + _devices = null; } @@ -174,7 +180,7 @@ namespace MediaBrowser.Server.Implementations.Devices public void AddCameraUpload(string deviceId, LocalFileInfo file) { var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); lock (_syncLock) { |
