diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-29 16:02:21 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-29 16:02:21 -0400 |
| commit | da20e8dcd2867df0a9a6ebc1081edb2db2eebdef (patch) | |
| tree | 0c00e59c5def4263126353e63bd79b9464b60b10 /MediaBrowser.Common.Implementations/Devices/DeviceId.cs | |
| parent | e5d71c1014cc2d78e5004d0736e321b350b7bb64 (diff) | |
continue with .net core targeting
Diffstat (limited to 'MediaBrowser.Common.Implementations/Devices/DeviceId.cs')
| -rw-r--r-- | MediaBrowser.Common.Implementations/Devices/DeviceId.cs | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs b/MediaBrowser.Common.Implementations/Devices/DeviceId.cs deleted file mode 100644 index 40bbe8713..000000000 --- a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs +++ /dev/null @@ -1,109 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Logging; -using System; -using System.IO; -using System.Text; -using MediaBrowser.Model.IO; - -namespace MediaBrowser.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(Path.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()); } - } - } -} |
