DashboardService.cs 25 KB

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