DashboardService.cs 27 KB

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