|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Collections.Generic;
|
| 6 | +using System.IO; |
6 | 7 | using System.Linq;
|
7 | 8 | using System.Threading.Tasks;
|
8 | 9 | using Microsoft.Performance.SDK.Options;
|
@@ -32,10 +33,46 @@ public sealed class PluginOptionsSystem
|
32 | 33 | /// <returns>
|
33 | 34 | /// A new instance of <see cref="PluginOptionsSystem"/> that persists options to a file.
|
34 | 35 | /// </returns>
|
| 36 | + /// <exception cref="T:System.ArgumentException"> |
| 37 | + /// The <paramref name="filePath" /> parameter contains invalid characters, is empty, is null, or contains only white spaces. |
| 38 | + /// |
| 39 | + /// -- or -- |
| 40 | + /// |
| 41 | + /// The <paramref name="filePath" /> parameter is prefixed with, or contains, only a colon character (:) |
| 42 | + /// |
| 43 | + /// -- or -- |
| 44 | + /// |
| 45 | + /// The <paramref name="filePath" /> parameter refers to the root directory of a volume. |
| 46 | + /// |
| 47 | + /// -- or -- |
| 48 | + /// |
| 49 | + /// The <paramref name="filePath" /> parameter does not contain directory information. |
| 50 | + /// </exception> |
| 51 | + /// <exception cref="T:System.IO.PathTooLongException"> |
| 52 | + /// The <paramref name="filePath" /> parameter is longer than the system-defined maximum length. |
| 53 | + /// </exception> |
| 54 | + /// <exception cref="T:System.IO.IOException"> |
| 55 | + /// The <paramref name="filePath"/> maps to a network whose name is not known. |
| 56 | + /// </exception> |
| 57 | + /// <exception cref="T:System.UnauthorizedAccessException"> |
| 58 | + /// The caller does not have the required permission to access <paramref name="filePath"/>. |
| 59 | + /// </exception> |
| 60 | + /// <exception cref="T:System.IO.DirectoryNotFoundException"> |
| 61 | + /// The specified <paramref name="filePath" /> is invalid (for example, it is on an unmapped drive). |
| 62 | + /// </exception> |
35 | 63 | public static PluginOptionsSystem CreateForFile(
|
36 | 64 | string filePath,
|
37 | 65 | Func<Type, ILogger> loggerFactory)
|
38 | 66 | {
|
| 67 | + var directory = Path.GetDirectoryName(filePath); |
| 68 | + |
| 69 | + if (string.IsNullOrEmpty(directory)) |
| 70 | + { |
| 71 | + throw new ArgumentException("Cannot get directory from file path.", nameof(filePath)); |
| 72 | + } |
| 73 | + |
| 74 | + Directory.CreateDirectory(directory); |
| 75 | + |
39 | 76 | var loader = new FilePluginOptionsLoader(filePath, loggerFactory(typeof(FilePluginOptionsLoader)));
|
40 | 77 | var saver = new FilePluginOptionsSaver(filePath, loggerFactory(typeof(FilePluginOptionsSaver)));
|
41 | 78 | var registry = new PluginOptionsRegistry(loggerFactory(typeof(PluginOptionsRegistry)));
|
|
0 commit comments