DashboardService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Common.ScheduledTasks;
  5. using MediaBrowser.Controller;
  6. using MediaBrowser.Controller.Configuration;
  7. using MediaBrowser.Controller.Dto;
  8. using MediaBrowser.Controller.Plugins;
  9. using MediaBrowser.Controller.Session;
  10. using MediaBrowser.Model.Logging;
  11. using MediaBrowser.Model.Tasks;
  12. using ServiceStack.ServiceHost;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Reflection;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.WebDashboard.Api
  21. {
  22. /// <summary>
  23. /// Class GetDashboardConfigurationPages
  24. /// </summary>
  25. [Route("/dashboard/ConfigurationPages", "GET")]
  26. [Restrict(VisibilityTo = EndpointAttributes.None)]
  27. public class GetDashboardConfigurationPages : IReturn<List<ConfigurationPageInfo>>
  28. {
  29. /// <summary>
  30. /// Gets or sets the type of the page.
  31. /// </summary>
  32. /// <value>The type of the page.</value>
  33. public ConfigurationPageType? PageType { get; set; }
  34. }
  35. /// <summary>
  36. /// Class GetDashboardConfigurationPage
  37. /// </summary>
  38. [Route("/dashboard/ConfigurationPage", "GET")]
  39. [Restrict(VisibilityTo = EndpointAttributes.None)]
  40. public class GetDashboardConfigurationPage
  41. {
  42. /// <summary>
  43. /// Gets or sets the name.
  44. /// </summary>
  45. /// <value>The name.</value>
  46. public string Name { get; set; }
  47. }
  48. /// <summary>
  49. /// Class GetDashboardResource
  50. /// </summary>
  51. [Route("/dashboard/{ResourceName*}", "GET")]
  52. [Restrict(VisibilityTo = EndpointAttributes.None)]
  53. public class GetDashboardResource
  54. {
  55. /// <summary>
  56. /// Gets or sets the name.
  57. /// </summary>
  58. /// <value>The name.</value>
  59. public string ResourceName { get; set; }
  60. /// <summary>
  61. /// Gets or sets the V.
  62. /// </summary>
  63. /// <value>The V.</value>
  64. public string V { get; set; }
  65. }
  66. /// <summary>
  67. /// Class GetDashboardInfo
  68. /// </summary>
  69. [Route("/dashboard/dashboardInfo", "GET")]
  70. [Restrict(VisibilityTo = EndpointAttributes.None)]
  71. public class GetDashboardInfo : IReturn<DashboardInfo>
  72. {
  73. }
  74. /// <summary>
  75. /// Class DashboardService
  76. /// </summary>
  77. public class DashboardService : IRestfulService, IHasResultFactory
  78. {
  79. /// <summary>
  80. /// Gets or sets the logger.
  81. /// </summary>
  82. /// <value>The logger.</value>
  83. public ILogger Logger { get; set; }
  84. /// <summary>
  85. /// Gets or sets the HTTP result factory.
  86. /// </summary>
  87. /// <value>The HTTP result factory.</value>
  88. public IHttpResultFactory ResultFactory { get; set; }
  89. /// <summary>
  90. /// Gets or sets the request context.
  91. /// </summary>
  92. /// <value>The request context.</value>
  93. public IRequestContext RequestContext { get; set; }
  94. /// <summary>
  95. /// Gets or sets the task manager.
  96. /// </summary>
  97. /// <value>The task manager.</value>
  98. private readonly ITaskManager _taskManager;
  99. /// <summary>
  100. /// The _app host
  101. /// </summary>
  102. private readonly IServerApplicationHost _appHost;
  103. /// <summary>
  104. /// The _server configuration manager
  105. /// </summary>
  106. private readonly IServerConfigurationManager _serverConfigurationManager;
  107. private readonly ISessionManager _sessionManager;
  108. private readonly IDtoService _dtoService;
  109. private readonly IFileSystem _fileSystem;
  110. /// <summary>
  111. /// Initializes a new instance of the <see cref="DashboardService" /> class.
  112. /// </summary>
  113. /// <param name="taskManager">The task manager.</param>
  114. /// <param name="appHost">The app host.</param>
  115. /// <param name="serverConfigurationManager">The server configuration manager.</param>
  116. /// <param name="sessionManager">The session manager.</param>
  117. public DashboardService(ITaskManager taskManager, IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, ISessionManager sessionManager, IDtoService dtoService, IFileSystem fileSystem)
  118. {
  119. _taskManager = taskManager;
  120. _appHost = appHost;
  121. _serverConfigurationManager = serverConfigurationManager;
  122. _sessionManager = sessionManager;
  123. _dtoService = dtoService;
  124. _fileSystem = fileSystem;
  125. }
  126. /// <summary>
  127. /// Gets the dashboard UI path.
  128. /// </summary>
  129. /// <value>The dashboard UI path.</value>
  130. public string DashboardUIPath
  131. {
  132. get
  133. {
  134. if (!string.IsNullOrEmpty(_serverConfigurationManager.Configuration.DashboardSourcePath))
  135. {
  136. return _serverConfigurationManager.Configuration.DashboardSourcePath;
  137. }
  138. var runningDirectory = Path.GetDirectoryName(_serverConfigurationManager.ApplicationPaths.ApplicationPath);
  139. return Path.Combine(runningDirectory, "dashboard-ui");
  140. }
  141. }
  142. /// <summary>
  143. /// Gets the dashboard resource path.
  144. /// </summary>
  145. /// <param name="virtualPath">The virtual path.</param>
  146. /// <returns>System.String.</returns>
  147. private string GetDashboardResourcePath(string virtualPath)
  148. {
  149. return Path.Combine(DashboardUIPath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
  150. }
  151. /// <summary>
  152. /// Gets the specified request.
  153. /// </summary>
  154. /// <param name="request">The request.</param>
  155. /// <returns>System.Object.</returns>
  156. public object Get(GetDashboardInfo request)
  157. {
  158. var result = GetDashboardInfo(_appHost, _taskManager, _sessionManager, _dtoService);
  159. return ResultFactory.GetOptimizedResult(RequestContext, result);
  160. }
  161. /// <summary>
  162. /// Gets the dashboard info.
  163. /// </summary>
  164. /// <param name="appHost">The app host.</param>
  165. /// <param name="taskManager">The task manager.</param>
  166. /// <param name="connectionManager">The connection manager.</param>
  167. /// <returns>DashboardInfo.</returns>
  168. public static DashboardInfo GetDashboardInfo(IServerApplicationHost appHost,
  169. ITaskManager taskManager,
  170. ISessionManager connectionManager, IDtoService dtoService)
  171. {
  172. var connections = connectionManager.Sessions.Where(i => i.IsActive).ToList();
  173. return new DashboardInfo
  174. {
  175. SystemInfo = appHost.GetSystemInfo(),
  176. RunningTasks = taskManager.ScheduledTasks.Where(i => i.State == TaskState.Running || i.State == TaskState.Cancelling)
  177. .Select(ScheduledTaskHelpers.GetTaskInfo)
  178. .ToList(),
  179. ApplicationUpdateTaskId = taskManager.ScheduledTasks.First(t => t.ScheduledTask.GetType().Name.Equals("SystemUpdateTask", StringComparison.OrdinalIgnoreCase)).Id,
  180. ActiveConnections = connections.Select(dtoService.GetSessionInfoDto).ToList()
  181. };
  182. }
  183. /// <summary>
  184. /// Gets the specified request.
  185. /// </summary>
  186. /// <param name="request">The request.</param>
  187. /// <returns>System.Object.</returns>
  188. public object Get(GetDashboardConfigurationPage request)
  189. {
  190. var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
  191. return ResultFactory.GetStaticResult(RequestContext, page.Plugin.Version.ToString().GetMD5(), page.Plugin.AssemblyDateLastModified, null, MimeTypes.GetMimeType("page.html"), () => ModifyHtml(page.GetHtmlStream()));
  192. }
  193. /// <summary>
  194. /// Gets the specified request.
  195. /// </summary>
  196. /// <param name="request">The request.</param>
  197. /// <returns>System.Object.</returns>
  198. public object Get(GetDashboardConfigurationPages request)
  199. {
  200. const string unavilableMessage = "The server is still loading. Please try again momentarily.";
  201. var instance = ServerEntryPoint.Instance;
  202. if (instance == null)
  203. {
  204. throw new InvalidOperationException(unavilableMessage);
  205. }
  206. var pages = instance.PluginConfigurationPages;
  207. if (pages == null)
  208. {
  209. throw new InvalidOperationException(unavilableMessage);
  210. }
  211. if (request.PageType.HasValue)
  212. {
  213. pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value);
  214. }
  215. return ResultFactory.GetOptimizedResult(RequestContext, pages.Select(p => new ConfigurationPageInfo(p)).ToList());
  216. }
  217. /// <summary>
  218. /// Gets the specified request.
  219. /// </summary>
  220. /// <param name="request">The request.</param>
  221. /// <returns>System.Object.</returns>
  222. public object Get(GetDashboardResource request)
  223. {
  224. var path = request.ResourceName;
  225. var contentType = MimeTypes.GetMimeType(path);
  226. // Don't cache if not configured to do so
  227. // But always cache images to simulate production
  228. if (!_serverConfigurationManager.Configuration.EnableDashboardResponseCaching && !contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
  229. {
  230. return ResultFactory.GetResult(GetResourceStream(path).Result, contentType);
  231. }
  232. TimeSpan? cacheDuration = null;
  233. // Cache images unconditionally - updates to image files will require new filename
  234. // If there's a version number in the query string we can cache this unconditionally
  235. if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || !string.IsNullOrEmpty(request.V))
  236. {
  237. cacheDuration = TimeSpan.FromDays(365);
  238. }
  239. var assembly = GetType().Assembly.GetName();
  240. var cacheKey = (assembly.Version + path).GetMD5();
  241. return ResultFactory.GetStaticResult(RequestContext, cacheKey, null, cacheDuration, contentType, () => GetResourceStream(path));
  242. }
  243. /// <summary>
  244. /// Gets the resource stream.
  245. /// </summary>
  246. /// <param name="path">The path.</param>
  247. /// <returns>Task{Stream}.</returns>
  248. private async Task<Stream> GetResourceStream(string path)
  249. {
  250. Stream resourceStream;
  251. if (path.Equals("scripts/all.js", StringComparison.OrdinalIgnoreCase))
  252. {
  253. resourceStream = await GetAllJavascript().ConfigureAwait(false);
  254. }
  255. else if (path.Equals("css/all.css", StringComparison.OrdinalIgnoreCase))
  256. {
  257. resourceStream = await GetAllCss().ConfigureAwait(false);
  258. }
  259. else
  260. {
  261. resourceStream = GetRawResourceStream(path);
  262. }
  263. if (resourceStream != null)
  264. {
  265. var isHtml = IsHtml(path);
  266. // Don't apply any caching for html pages
  267. // jQuery ajax doesn't seem to handle if-modified-since correctly
  268. if (isHtml)
  269. {
  270. resourceStream = await ModifyHtml(resourceStream).ConfigureAwait(false);
  271. }
  272. }
  273. return resourceStream;
  274. }
  275. /// <summary>
  276. /// Gets the raw resource stream.
  277. /// </summary>
  278. /// <param name="path">The path.</param>
  279. /// <returns>Task{Stream}.</returns>
  280. private Stream GetRawResourceStream(string path)
  281. {
  282. return _fileSystem.GetFileStream(GetDashboardResourcePath(path), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true);
  283. }
  284. /// <summary>
  285. /// Determines whether the specified path is HTML.
  286. /// </summary>
  287. /// <param name="path">The path.</param>
  288. /// <returns><c>true</c> if the specified path is HTML; otherwise, <c>false</c>.</returns>
  289. private bool IsHtml(string path)
  290. {
  291. return Path.GetExtension(path).EndsWith("html", StringComparison.OrdinalIgnoreCase);
  292. }
  293. /// <summary>
  294. /// Modifies the HTML by adding common meta tags, css and js.
  295. /// </summary>
  296. /// <param name="sourceStream">The source stream.</param>
  297. /// <returns>Task{Stream}.</returns>
  298. internal async Task<Stream> ModifyHtml(Stream sourceStream)
  299. {
  300. string html;
  301. using (var memoryStream = new MemoryStream())
  302. {
  303. await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);
  304. html = Encoding.UTF8.GetString(memoryStream.ToArray());
  305. }
  306. var version = GetType().Assembly.GetName().Version;
  307. html = html.Replace("<head>", "<head>" + GetMetaTags() + GetCommonCss(version) + GetCommonJavascript(version));
  308. var bytes = Encoding.UTF8.GetBytes(html);
  309. sourceStream.Dispose();
  310. return new MemoryStream(bytes);
  311. }
  312. /// <summary>
  313. /// Gets the meta tags.
  314. /// </summary>
  315. /// <returns>System.String.</returns>
  316. private static string GetMetaTags()
  317. {
  318. var sb = new StringBuilder();
  319. sb.Append("<meta http-equiv=\"X-UA-Compatibility\" content=\"IE=Edge\">");
  320. sb.Append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">");
  321. sb.Append("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");
  322. //sb.Append("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">");
  323. // http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
  324. sb.Append("<link rel=\"apple-touch-icon\" href=\"css/images/touchicon.png\" />");
  325. sb.Append("<link rel=\"apple-touch-icon\" sizes=\"72x72\" href=\"css/images/touchicon72.png\" />");
  326. sb.Append("<link rel=\"apple-touch-icon\" sizes=\"114x114\" href=\"css/images/touchicon114.png\" />");
  327. sb.Append("<link rel=\"apple-touch-startup-image\" href=\"css/images/iossplash.png\" />");
  328. sb.Append("<link rel=\"shortcut icon\" href=\"favicon.ico\" />");
  329. return sb.ToString();
  330. }
  331. /// <summary>
  332. /// Gets the common CSS.
  333. /// </summary>
  334. /// <param name="version">The version.</param>
  335. /// <returns>System.String.</returns>
  336. private static string GetCommonCss(Version version)
  337. {
  338. var versionString = "?v=" + version;
  339. var files = new[]
  340. {
  341. "http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css",
  342. "thirdparty/jqm-icon-pack-3.0/font-awesome/jqm-icon-pack-3.0.0-fa.css" + versionString,
  343. "css/all.css" + versionString
  344. };
  345. var tags = files.Select(s => string.Format("<link rel=\"stylesheet\" href=\"{0}\" />", s)).ToArray();
  346. return string.Join(string.Empty, tags);
  347. }
  348. /// <summary>
  349. /// Gets the common javascript.
  350. /// </summary>
  351. /// <param name="version">The version.</param>
  352. /// <returns>System.String.</returns>
  353. private static string GetCommonJavascript(Version version)
  354. {
  355. var builder = new StringBuilder();
  356. builder.Append("<script type=\"text/javascript\">if (navigator.userAgent.toLowerCase().indexOf('compatible; msie 7')!=-1){alert(\"Please ensure you're running at least IE10 and that compatibility mode is disabled.\");}");
  357. builder.Append("</script>");
  358. var versionString = "?v=" + version;
  359. var files = new[]
  360. {
  361. "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js",
  362. "http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js",
  363. "scripts/all.js" + versionString,
  364. "thirdparty/jstree1.0/jquery.jstree.js"
  365. };
  366. var tags = files.Select(s => string.Format("<script src=\"{0}\"></script>", s)).ToArray();
  367. builder.Append(string.Join(string.Empty, tags));
  368. return builder.ToString();
  369. }
  370. /// <summary>
  371. /// Gets a stream containing all concatenated javascript
  372. /// </summary>
  373. /// <returns>Task{Stream}.</returns>
  374. private async Task<Stream> GetAllJavascript()
  375. {
  376. var assembly = GetType().Assembly;
  377. var scriptFiles = new[]
  378. {
  379. "extensions.js",
  380. "site.js",
  381. "librarybrowser.js",
  382. "ratingdialog.js",
  383. "aboutpage.js",
  384. "allusersettings.js",
  385. "alphapicker.js",
  386. "addpluginpage.js",
  387. "advancedconfigurationpage.js",
  388. "advancedmetadataconfigurationpage.js",
  389. "boxsets.js",
  390. "clientsettings.js",
  391. "dashboardpage.js",
  392. "directorybrowser.js",
  393. "edititemmetadata.js",
  394. "edititempeople.js",
  395. "edititemimages.js",
  396. "edituserpage.js",
  397. "gamesrecommendedpage.js",
  398. "gamesystemspage.js",
  399. "gamespage.js",
  400. "gamegenrepage.js",
  401. "gamestudiospage.js",
  402. "indexpage.js",
  403. "itembynamedetailpage.js",
  404. "itemdetailpage.js",
  405. "itemgallery.js",
  406. "itemlistpage.js",
  407. "librarysettings.js",
  408. "livetvchannel.js",
  409. "livetvchannels.js",
  410. "livetvguide.js",
  411. "livetvrecording.js",
  412. "livetvrecordings.js",
  413. "livetvtimer.js",
  414. "livetvtimers.js",
  415. "loginpage.js",
  416. "logpage.js",
  417. "medialibrarypage.js",
  418. "mediaplayer.js",
  419. "metadataconfigurationpage.js",
  420. "metadataimagespage.js",
  421. "moviegenres.js",
  422. "movies.js",
  423. "moviepeople.js",
  424. "moviesrecommended.js",
  425. "moviestudios.js",
  426. "movietrailers.js",
  427. "musicalbums.js",
  428. "musicalbumartists.js",
  429. "musicartists.js",
  430. "musicgenres.js",
  431. "musicrecommended.js",
  432. "musicvideos.js",
  433. "notifications.js",
  434. "playlist.js",
  435. "plugincatalogpage.js",
  436. "pluginspage.js",
  437. "pluginupdatespage.js",
  438. "remotecontrol.js",
  439. "scheduledtaskpage.js",
  440. "scheduledtaskspage.js",
  441. "search.js",
  442. "songs.js",
  443. "supporterkeypage.js",
  444. "supporterpage.js",
  445. "episodes.js",
  446. "tvgenres.js",
  447. "tvnextup.js",
  448. "tvpeople.js",
  449. "tvrecommended.js",
  450. "tvshows.js",
  451. "tvstudios.js",
  452. "tvupcoming.js",
  453. "updatepasswordpage.js",
  454. "userimagepage.js",
  455. "userprofilespage.js",
  456. "usersettings.js",
  457. "wizardfinishpage.js",
  458. "wizardservice.js",
  459. "wizardstartpage.js",
  460. "wizardsettings.js",
  461. "wizarduserpage.js"
  462. };
  463. var memoryStream = new MemoryStream();
  464. var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
  465. var versionString = string.Format("window.dashboardVersion='{0}';", _appHost.ApplicationVersion);
  466. var versionBytes = Encoding.UTF8.GetBytes(versionString);
  467. await memoryStream.WriteAsync(versionBytes, 0, versionBytes.Length).ConfigureAwait(false);
  468. await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  469. await AppendResource(memoryStream, "thirdparty/autoNumeric.js", newLineBytes).ConfigureAwait(false);
  470. await AppendResource(memoryStream, "thirdparty/html5slider.js", newLineBytes).ConfigureAwait(false);
  471. await AppendResource(assembly, memoryStream, "MediaBrowser.WebDashboard.ApiClient.js", newLineBytes).ConfigureAwait(false);
  472. foreach (var file in scriptFiles)
  473. {
  474. await AppendResource(memoryStream, "scripts/" + file, newLineBytes).ConfigureAwait(false);
  475. }
  476. memoryStream.Position = 0;
  477. return memoryStream;
  478. }
  479. /// <summary>
  480. /// Gets all CSS.
  481. /// </summary>
  482. /// <returns>Task{Stream}.</returns>
  483. private async Task<Stream> GetAllCss()
  484. {
  485. var files = new[]
  486. {
  487. "site.css",
  488. "librarybrowser.css",
  489. "detailtable.css",
  490. "posteritem.css",
  491. "tileitem.css",
  492. "metadataeditor.css",
  493. "notifications.css",
  494. "search.css",
  495. "pluginupdates.css",
  496. "remotecontrol.css",
  497. "userimage.css"
  498. };
  499. var memoryStream = new MemoryStream();
  500. var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
  501. foreach (var file in files)
  502. {
  503. await AppendResource(memoryStream, "css/" + file, newLineBytes).ConfigureAwait(false);
  504. }
  505. memoryStream.Position = 0;
  506. return memoryStream;
  507. }
  508. /// <summary>
  509. /// Appends the resource.
  510. /// </summary>
  511. /// <param name="assembly">The assembly.</param>
  512. /// <param name="outputStream">The output stream.</param>
  513. /// <param name="path">The path.</param>
  514. /// <param name="newLineBytes">The new line bytes.</param>
  515. /// <returns>Task.</returns>
  516. private async Task AppendResource(Assembly assembly, Stream outputStream, string path, byte[] newLineBytes)
  517. {
  518. using (var stream = assembly.GetManifestResourceStream(path))
  519. {
  520. await stream.CopyToAsync(outputStream).ConfigureAwait(false);
  521. await outputStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  522. }
  523. }
  524. /// <summary>
  525. /// Appends the resource.
  526. /// </summary>
  527. /// <param name="outputStream">The output stream.</param>
  528. /// <param name="path">The path.</param>
  529. /// <param name="newLineBytes">The new line bytes.</param>
  530. /// <returns>Task.</returns>
  531. private async Task AppendResource(Stream outputStream, string path, byte[] newLineBytes)
  532. {
  533. path = GetDashboardResourcePath(path);
  534. using (var fs = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true))
  535. {
  536. using (var streamReader = new StreamReader(fs))
  537. {
  538. var text = await streamReader.ReadToEndAsync().ConfigureAwait(false);
  539. var bytes = Encoding.UTF8.GetBytes(text);
  540. await outputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
  541. }
  542. }
  543. await outputStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  544. }
  545. }
  546. }