DashboardService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. #if __MonoCS__
  149. return Path.Combine(DashboardUIPath, virtualPath);
  150. #else
  151. return Path.Combine(DashboardUIPath, virtualPath.Replace('/', '\\'));
  152. #endif
  153. }
  154. /// <summary>
  155. /// Gets the specified request.
  156. /// </summary>
  157. /// <param name="request">The request.</param>
  158. /// <returns>System.Object.</returns>
  159. public object Get(GetDashboardInfo request)
  160. {
  161. var result = GetDashboardInfo(_appHost, _taskManager, _sessionManager, _dtoService);
  162. return ResultFactory.GetOptimizedResult(RequestContext, result);
  163. }
  164. /// <summary>
  165. /// Gets the dashboard info.
  166. /// </summary>
  167. /// <param name="appHost">The app host.</param>
  168. /// <param name="taskManager">The task manager.</param>
  169. /// <param name="connectionManager">The connection manager.</param>
  170. /// <returns>DashboardInfo.</returns>
  171. public static DashboardInfo GetDashboardInfo(IServerApplicationHost appHost,
  172. ITaskManager taskManager,
  173. ISessionManager connectionManager, IDtoService dtoService)
  174. {
  175. var connections = connectionManager.Sessions.Where(i => i.IsActive).ToList();
  176. return new DashboardInfo
  177. {
  178. SystemInfo = appHost.GetSystemInfo(),
  179. RunningTasks = taskManager.ScheduledTasks.Where(i => i.State == TaskState.Running || i.State == TaskState.Cancelling)
  180. .Select(ScheduledTaskHelpers.GetTaskInfo)
  181. .ToList(),
  182. ApplicationUpdateTaskId = taskManager.ScheduledTasks.First(t => t.ScheduledTask.GetType().Name.Equals("SystemUpdateTask", StringComparison.OrdinalIgnoreCase)).Id,
  183. ActiveConnections = connections.Select(dtoService.GetSessionInfoDto).ToList()
  184. };
  185. }
  186. /// <summary>
  187. /// Gets the specified request.
  188. /// </summary>
  189. /// <param name="request">The request.</param>
  190. /// <returns>System.Object.</returns>
  191. public object Get(GetDashboardConfigurationPage request)
  192. {
  193. var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
  194. return ResultFactory.GetStaticResult(RequestContext, page.Plugin.Version.ToString().GetMD5(), page.Plugin.AssemblyDateLastModified, null, MimeTypes.GetMimeType("page.html"), () => ModifyHtml(page.GetHtmlStream()));
  195. }
  196. /// <summary>
  197. /// Gets the specified request.
  198. /// </summary>
  199. /// <param name="request">The request.</param>
  200. /// <returns>System.Object.</returns>
  201. public object Get(GetDashboardConfigurationPages request)
  202. {
  203. const string unavilableMessage = "The server is still loading. Please try again momentarily.";
  204. var instance = ServerEntryPoint.Instance;
  205. if (instance == null)
  206. {
  207. throw new InvalidOperationException(unavilableMessage);
  208. }
  209. var pages = instance.PluginConfigurationPages;
  210. if (pages == null)
  211. {
  212. throw new InvalidOperationException(unavilableMessage);
  213. }
  214. if (request.PageType.HasValue)
  215. {
  216. pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value);
  217. }
  218. return ResultFactory.GetOptimizedResult(RequestContext, pages.Select(p => new ConfigurationPageInfo(p)).ToList());
  219. }
  220. /// <summary>
  221. /// Gets the specified request.
  222. /// </summary>
  223. /// <param name="request">The request.</param>
  224. /// <returns>System.Object.</returns>
  225. public object Get(GetDashboardResource request)
  226. {
  227. var path = request.ResourceName;
  228. var contentType = MimeTypes.GetMimeType(path);
  229. // Don't cache if not configured to do so
  230. // But always cache images to simulate production
  231. if (!_serverConfigurationManager.Configuration.EnableDashboardResponseCaching && !contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
  232. {
  233. return ResultFactory.GetResult(GetResourceStream(path).Result, contentType);
  234. }
  235. TimeSpan? cacheDuration = null;
  236. // Cache images unconditionally - updates to image files will require new filename
  237. // If there's a version number in the query string we can cache this unconditionally
  238. if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || !string.IsNullOrEmpty(request.V))
  239. {
  240. cacheDuration = TimeSpan.FromDays(365);
  241. }
  242. var assembly = GetType().Assembly.GetName();
  243. var cacheKey = (assembly.Version + path).GetMD5();
  244. return ResultFactory.GetStaticResult(RequestContext, cacheKey, null, cacheDuration, contentType, () => GetResourceStream(path));
  245. }
  246. /// <summary>
  247. /// Gets the resource stream.
  248. /// </summary>
  249. /// <param name="path">The path.</param>
  250. /// <returns>Task{Stream}.</returns>
  251. private async Task<Stream> GetResourceStream(string path)
  252. {
  253. Stream resourceStream;
  254. if (path.Equals("scripts/all.js", StringComparison.OrdinalIgnoreCase))
  255. {
  256. resourceStream = await GetAllJavascript().ConfigureAwait(false);
  257. }
  258. else if (path.Equals("css/all.css", StringComparison.OrdinalIgnoreCase))
  259. {
  260. resourceStream = await GetAllCss().ConfigureAwait(false);
  261. }
  262. else
  263. {
  264. resourceStream = GetRawResourceStream(path);
  265. }
  266. if (resourceStream != null)
  267. {
  268. var isHtml = IsHtml(path);
  269. // Don't apply any caching for html pages
  270. // jQuery ajax doesn't seem to handle if-modified-since correctly
  271. if (isHtml)
  272. {
  273. resourceStream = await ModifyHtml(resourceStream).ConfigureAwait(false);
  274. }
  275. }
  276. return resourceStream;
  277. }
  278. /// <summary>
  279. /// Gets the raw resource stream.
  280. /// </summary>
  281. /// <param name="path">The path.</param>
  282. /// <returns>Task{Stream}.</returns>
  283. private Stream GetRawResourceStream(string path)
  284. {
  285. return new FileStream(GetDashboardResourcePath(path), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, StreamDefaults.DefaultFileStreamBufferSize, true);
  286. }
  287. /// <summary>
  288. /// Determines whether the specified path is HTML.
  289. /// </summary>
  290. /// <param name="path">The path.</param>
  291. /// <returns><c>true</c> if the specified path is HTML; otherwise, <c>false</c>.</returns>
  292. private bool IsHtml(string path)
  293. {
  294. return Path.GetExtension(path).EndsWith("html", StringComparison.OrdinalIgnoreCase);
  295. }
  296. /// <summary>
  297. /// Modifies the HTML by adding common meta tags, css and js.
  298. /// </summary>
  299. /// <param name="sourceStream">The source stream.</param>
  300. /// <returns>Task{Stream}.</returns>
  301. internal async Task<Stream> ModifyHtml(Stream sourceStream)
  302. {
  303. string html;
  304. using (var memoryStream = new MemoryStream())
  305. {
  306. await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);
  307. html = Encoding.UTF8.GetString(memoryStream.ToArray());
  308. }
  309. var version = GetType().Assembly.GetName().Version;
  310. html = html.Replace("<head>", "<head>" + GetMetaTags() + GetCommonCss(version) + GetCommonJavascript(version));
  311. var bytes = Encoding.UTF8.GetBytes(html);
  312. sourceStream.Dispose();
  313. return new MemoryStream(bytes);
  314. }
  315. /// <summary>
  316. /// Gets the meta tags.
  317. /// </summary>
  318. /// <returns>System.String.</returns>
  319. private static string GetMetaTags()
  320. {
  321. var sb = new StringBuilder();
  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. "aboutpage.js",
  385. "allusersettings.js",
  386. "alphapicker.js",
  387. "addpluginpage.js",
  388. "advancedconfigurationpage.js",
  389. "advancedmetadataconfigurationpage.js",
  390. "boxsets.js",
  391. "clientsettings.js",
  392. "dashboardpage.js",
  393. "directorybrowser.js",
  394. "edititemmetadata.js",
  395. "edititempeople.js",
  396. "edititemimages.js",
  397. "edituserpage.js",
  398. "gamesrecommendedpage.js",
  399. "gamesystemspage.js",
  400. "gamespage.js",
  401. "gamegenrepage.js",
  402. "gamestudiospage.js",
  403. "indexpage.js",
  404. "itembynamedetailpage.js",
  405. "itemdetailpage.js",
  406. "itemgallery.js",
  407. "itemlistpage.js",
  408. "librarysettings.js",
  409. "loginpage.js",
  410. "logpage.js",
  411. "medialibrarypage.js",
  412. "mediaplayer.js",
  413. "metadataconfigurationpage.js",
  414. "metadataimagespage.js",
  415. "moviegenres.js",
  416. "movies.js",
  417. "moviepeople.js",
  418. "moviesrecommended.js",
  419. "moviestudios.js",
  420. "movietrailers.js",
  421. "musicalbums.js",
  422. "musicartists.js",
  423. "musicgenres.js",
  424. "musicrecommended.js",
  425. "musicvideos.js",
  426. "notifications.js",
  427. "playlist.js",
  428. "plugincatalogpage.js",
  429. "pluginspage.js",
  430. "pluginupdatespage.js",
  431. "remotecontrol.js",
  432. "scheduledtaskpage.js",
  433. "scheduledtaskspage.js",
  434. "search.js",
  435. "songs.js",
  436. "supporterkeypage.js",
  437. "supporterpage.js",
  438. "episodes.js",
  439. "tvgenres.js",
  440. "tvnextup.js",
  441. "tvpeople.js",
  442. "tvrecommended.js",
  443. "tvshows.js",
  444. "tvstudios.js",
  445. "updatepasswordpage.js",
  446. "userimagepage.js",
  447. "userprofilespage.js",
  448. "wizardfinishpage.js",
  449. "wizardservice.js",
  450. "wizardstartpage.js",
  451. "wizardsettings.js",
  452. "wizarduserpage.js"
  453. };
  454. var memoryStream = new MemoryStream();
  455. var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
  456. var versionString = string.Format("window.dashboardVersion='{0}';", _appHost.ApplicationVersion);
  457. var versionBytes = Encoding.UTF8.GetBytes(versionString);
  458. await memoryStream.WriteAsync(versionBytes, 0, versionBytes.Length).ConfigureAwait(false);
  459. await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  460. await AppendResource(memoryStream, "thirdparty/autoNumeric.js", newLineBytes).ConfigureAwait(false);
  461. await AppendResource(memoryStream, "thirdparty/html5slider.js", newLineBytes).ConfigureAwait(false);
  462. await AppendResource(assembly, memoryStream, "MediaBrowser.WebDashboard.ApiClient.js", newLineBytes).ConfigureAwait(false);
  463. foreach (var file in scriptFiles)
  464. {
  465. await AppendResource(memoryStream, "scripts/" + file, newLineBytes).ConfigureAwait(false);
  466. }
  467. memoryStream.Position = 0;
  468. return memoryStream;
  469. }
  470. /// <summary>
  471. /// Gets all CSS.
  472. /// </summary>
  473. /// <returns>Task{Stream}.</returns>
  474. private async Task<Stream> GetAllCss()
  475. {
  476. var files = new[]
  477. {
  478. "site.css",
  479. "librarybrowser.css",
  480. "detailtable.css",
  481. "posteritem.css",
  482. "tileitem.css",
  483. "metadataeditor.css",
  484. "notifications.css",
  485. "search.css",
  486. "pluginupdates.css",
  487. "remotecontrol.css",
  488. "userimage.css"
  489. };
  490. var memoryStream = new MemoryStream();
  491. var newLineBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
  492. foreach (var file in files)
  493. {
  494. await AppendResource(memoryStream, "css/" + file, newLineBytes).ConfigureAwait(false);
  495. }
  496. memoryStream.Position = 0;
  497. return memoryStream;
  498. }
  499. /// <summary>
  500. /// Appends the resource.
  501. /// </summary>
  502. /// <param name="assembly">The assembly.</param>
  503. /// <param name="outputStream">The output stream.</param>
  504. /// <param name="path">The path.</param>
  505. /// <param name="newLineBytes">The new line bytes.</param>
  506. /// <returns>Task.</returns>
  507. private async Task AppendResource(Assembly assembly, Stream outputStream, string path, byte[] newLineBytes)
  508. {
  509. using (var stream = assembly.GetManifestResourceStream(path))
  510. {
  511. await stream.CopyToAsync(outputStream).ConfigureAwait(false);
  512. await outputStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  513. }
  514. }
  515. /// <summary>
  516. /// Appends the resource.
  517. /// </summary>
  518. /// <param name="outputStream">The output stream.</param>
  519. /// <param name="path">The path.</param>
  520. /// <param name="newLineBytes">The new line bytes.</param>
  521. /// <returns>Task.</returns>
  522. private async Task AppendResource(Stream outputStream, string path, byte[] newLineBytes)
  523. {
  524. path = GetDashboardResourcePath(path);
  525. using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, StreamDefaults.DefaultFileStreamBufferSize, true))
  526. {
  527. using (var streamReader = new StreamReader(fs))
  528. {
  529. var text = await streamReader.ReadToEndAsync().ConfigureAwait(false);
  530. var bytes = Encoding.UTF8.GetBytes(text);
  531. await outputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
  532. }
  533. }
  534. await outputStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);
  535. }
  536. }
  537. }