diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-09-13 19:07:54 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-09-13 19:07:54 -0400 |
| commit | 8cf45a3e4a5345f704f8acef098b173ec1808251 (patch) | |
| tree | 06560c42256b91d02744369b8dc834ade8bc8ffb /MediaBrowser.Common.Implementations | |
| parent | 6cb184fcf8ea7803626e0f3e0a3c7f118e4328e9 (diff) | |
add more methods to IFileSystem
Diffstat (limited to 'MediaBrowser.Common.Implementations')
12 files changed, 84 insertions, 24 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 181f8e43d..af41635f3 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -321,7 +321,7 @@ namespace MediaBrowser.Common.Implementations protected virtual IJsonSerializer CreateJsonSerializer() { - return new JsonSerializer(); + return new JsonSerializer(FileSystemManager); } private void SetHttpLimit() @@ -450,7 +450,7 @@ namespace MediaBrowser.Common.Implementations RegisterSingleInstance<IApplicationPaths>(ApplicationPaths); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger, FileSystemManager); RegisterSingleInstance(JsonSerializer); RegisterSingleInstance(XmlSerializer); @@ -651,7 +651,7 @@ namespace MediaBrowser.Common.Implementations { try { - return Assembly.Load(FileSystemManager.ReadAllBytes((file))); + return Assembly.Load(File.ReadAllBytes((file))); } catch (Exception ex) { diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index f76359d30..9ba2effd3 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations { _dataDirectory = Path.Combine(ProgramDataPath, "data"); - FileSystem.CreateDirectory(_dataDirectory); + Directory.CreateDirectory(_dataDirectory); } return _dataDirectory; @@ -152,7 +152,7 @@ namespace MediaBrowser.Common.Implementations { _cachePath = Path.Combine(ProgramDataPath, "cache"); - FileSystem.CreateDirectory(_cachePath); + Directory.CreateDirectory(_cachePath); } return _cachePath; diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 1e9d4c97c..1b9146644 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.Configuration { var path = CommonApplicationPaths.SystemConfigurationFilePath; - FileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); lock (_configurationSyncLock) { @@ -276,7 +276,7 @@ namespace MediaBrowser.Common.Implementations.Configuration _configurations.AddOrUpdate(key, configuration, (k, v) => configuration); var path = GetConfigurationFile(key); - FileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); lock (_configurationSyncLock) { diff --git a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs index 6af59bb6b..276da58d4 100644 --- a/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs +++ b/MediaBrowser.Common.Implementations/Configuration/ConfigurationHelper.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Common.Implementations.Configuration /// <param name="path">The path.</param> /// <param name="xmlSerializer">The XML serializer.</param> /// <returns>System.Object.</returns> - public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer, IFileSystem fileSystem) + public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer) { object configuration; @@ -28,7 +28,7 @@ namespace MediaBrowser.Common.Implementations.Configuration // Use try/catch to avoid the extra file system lookup using File.Exists try { - buffer = fileSystem.ReadAllBytes(path); + buffer = File.ReadAllBytes(path); configuration = xmlSerializer.DeserializeFromBytes(type, buffer); } @@ -47,10 +47,10 @@ namespace MediaBrowser.Common.Implementations.Configuration // If the file didn't exist before, or if something has changed, re-save if (buffer == null || !buffer.SequenceEqual(newBytes)) { - fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); // Save it after load in case we got new items - fileSystem.WriteAllBytes(path, newBytes); + File.WriteAllBytes(path, newBytes); } return configuration; diff --git a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs b/MediaBrowser.Common.Implementations/Devices/DeviceId.cs index 02edc493a..39f11fabf 100644 --- a/MediaBrowser.Common.Implementations/Devices/DeviceId.cs +++ b/MediaBrowser.Common.Implementations/Devices/DeviceId.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Common.Implementations.Devices { lock (_syncLock) { - var value = _fileSystem.ReadAllText(CachePath, Encoding.UTF8); + var value = File.ReadAllText(CachePath, Encoding.UTF8); Guid guid; if (Guid.TryParse(value, out guid)) diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index 5951dbb31..2dd2575ad 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -107,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO throw new ArgumentNullException("target"); } - _fileSystem.WriteAllText(shortcutPath, target); + File.WriteAllText(shortcutPath, target); } /// <summary> @@ -449,5 +449,55 @@ namespace MediaBrowser.Common.Implementations.IO return directoryInfo.EnumerateDirectories("*", searchOption) .Concat<FileSystemInfo>(directoryInfo.EnumerateFiles("*", searchOption)); } + + public Stream OpenRead(string path) + { + return File.OpenRead(path); + } + + public void CopyFile(string source, string target, bool overwrite) + { + File.Copy(source, target, overwrite); + } + + public void MoveFile(string source, string target) + { + File.Move(source, target); + } + + public void MoveDirectory(string source, string target) + { + Directory.Move(source, target); + } + + public bool DirectoryExists(string path) + { + return Directory.Exists(path); + } + + public bool FileExists(string path) + { + return File.Exists(path); + } + + public string ReadAllText(string path) + { + return File.ReadAllText(path); + } + + public void WriteAllText(string path, string text, Encoding encoding) + { + File.WriteAllText(path, text, encoding); + } + + public void WriteAllText(string path, string text) + { + File.WriteAllText(path, text); + } + + public string ReadAllText(string path, Encoding encoding) + { + return File.ReadAllText(path, encoding); + } } } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index 239ea03cd..391e7c212 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Logging { LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(LogFilePath)); + Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); AddFileTarget(LogFilePath, level); diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 08c117220..906184c75 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -12,6 +12,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.ScheduledTasks { @@ -51,6 +52,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> /// <value>The task manager.</value> private ITaskManager TaskManager { get; set; } + private readonly IFileSystem _fileSystem; /// <summary> /// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class. @@ -71,7 +73,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// or /// logger /// </exception> - public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger) + public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { if (scheduledTask == null) { @@ -99,6 +101,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks TaskManager = taskManager; JsonSerializer = jsonSerializer; Logger = logger; + _fileSystem = fileSystem; ReloadTriggerEvents(true); } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index 7034113d7..9419bdf22 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -10,6 +10,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.ScheduledTasks { @@ -50,6 +51,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> /// <value>The logger.</value> private ILogger Logger { get; set; } + private readonly IFileSystem _fileSystem; /// <summary> /// Initializes a new instance of the <see cref="TaskManager" /> class. @@ -58,11 +60,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// <param name="jsonSerializer">The json serializer.</param> /// <param name="logger">The logger.</param> /// <exception cref="System.ArgumentException">kernel</exception> - public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger) + public TaskManager(IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { ApplicationPaths = applicationPaths; JsonSerializer = jsonSerializer; Logger = logger; + _fileSystem = fileSystem; ScheduledTasks = new IScheduledTaskWorker[] { }; } @@ -175,7 +178,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks var myTasks = ScheduledTasks.ToList(); var list = tasks.ToList(); - myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger))); + myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem))); ScheduledTasks = myTasks.ToArray(); } diff --git a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs index e5cf5856e..79e558794 100644 --- a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs +++ b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs @@ -99,15 +99,15 @@ namespace MediaBrowser.Common.Implementations.Security { try { - contents = _fileSystem.ReadAllLines(licenseFile); + contents = File.ReadAllLines(licenseFile); } catch (DirectoryNotFoundException) { - (_fileSystem.CreateFile(licenseFile)).Close(); + (File.Create(licenseFile)).Close(); } catch (FileNotFoundException) { - (_fileSystem.CreateFile(licenseFile)).Close(); + (File.Create(licenseFile)).Close(); } } if (contents != null && contents.Length > 0) @@ -150,8 +150,8 @@ namespace MediaBrowser.Common.Implementations.Security } var licenseFile = Filename; - _fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile)); - lock (_fileLock) _fileSystem.WriteAllLines(licenseFile, lines); + Directory.CreateDirectory(Path.GetDirectoryName(licenseFile)); + lock (_fileLock) File.WriteAllLines(licenseFile, lines); } } } diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 80ccd72f7..2c93f0549 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -1,6 +1,7 @@ using MediaBrowser.Model.Serialization; using System; using System.IO; +using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.Serialization { @@ -9,8 +10,11 @@ namespace MediaBrowser.Common.Implementations.Serialization /// </summary> public class JsonSerializer : IJsonSerializer { - public JsonSerializer() + private readonly IFileSystem _fileSystem; + + public JsonSerializer(IFileSystem fileSystem) { + _fileSystem = fileSystem; Configure(); } diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index fee23fd2e..12afdd8d7 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -573,7 +573,7 @@ namespace MediaBrowser.Common.Implementations.Updates //If it is an archive - write out a version file so we know what it is if (isArchive) { - _fileSystem.WriteAllText(target + ".ver", package.versionStr); + File.WriteAllText(target + ".ver", package.versionStr); } } catch (IOException e) |
