diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-08-16 02:43:41 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-08-16 02:43:41 -0400 |
| commit | bfcd1b520fd79b893e721ba916ae5e1656407d2f (patch) | |
| tree | 6a05119800484435fb384da25c6390054a27c3c3 /Emby.Common.Implementations/Devices | |
| parent | e3531534b85aeaaa3e4aaf462d5e77ea142dc762 (diff) | |
merge common implementations and server implementations
Diffstat (limited to 'Emby.Common.Implementations/Devices')
| -rw-r--r-- | Emby.Common.Implementations/Devices/DeviceId.cs | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/Emby.Common.Implementations/Devices/DeviceId.cs b/Emby.Common.Implementations/Devices/DeviceId.cs deleted file mode 100644 index 1de76456c..000000000 --- a/Emby.Common.Implementations/Devices/DeviceId.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.IO; -using System.Text; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; - -namespace Emby.Common.Implementations.Devices -{ - public class DeviceId - { - private readonly IApplicationPaths _appPaths; - private readonly ILogger _logger; - private readonly IFileSystem _fileSystem; - - private readonly object _syncLock = new object(); - - private string CachePath - { - get { return Path.Combine(_appPaths.DataPath, "device.txt"); } - } - - private string GetCachedId() - { - try - { - lock (_syncLock) - { - var value = File.ReadAllText(CachePath, Encoding.UTF8); - - Guid guid; - if (Guid.TryParse(value, out guid)) - { - return value; - } - - _logger.Error("Invalid value found in device id file"); - } - } - catch (DirectoryNotFoundException) - { - } - catch (FileNotFoundException) - { - } - catch (Exception ex) - { - _logger.ErrorException("Error reading file", ex); - } - - return null; - } - - private void SaveId(string id) - { - try - { - var path = CachePath; - - _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); - - lock (_syncLock) - { - _fileSystem.WriteAllText(path, id, Encoding.UTF8); - } - } - catch (Exception ex) - { - _logger.ErrorException("Error writing to file", ex); - } - } - - private string GetNewId() - { - return Guid.NewGuid().ToString("N"); - } - - private string GetDeviceId() - { - var id = GetCachedId(); - - if (string.IsNullOrWhiteSpace(id)) - { - id = GetNewId(); - SaveId(id); - } - - return id; - } - - private string _id; - - public DeviceId(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem) - { - if (fileSystem == null) { - throw new ArgumentNullException ("fileSystem"); - } - - _appPaths = appPaths; - _logger = logger; - _fileSystem = fileSystem; - } - - public string Value - { - get { return _id ?? (_id = GetDeviceId()); } - } - } -} |
