DashboardService.cs 26 KB

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