XmlSaverHelpers.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.Movies;
  3. using MediaBrowser.Controller.Entities.TV;
  4. using MediaBrowser.Controller.Persistence;
  5. using MediaBrowser.Model.Entities;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Globalization;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Security;
  12. using System.Text;
  13. using System.Xml;
  14. namespace MediaBrowser.Providers.Savers
  15. {
  16. /// <summary>
  17. /// Class XmlHelpers
  18. /// </summary>
  19. public static class XmlSaverHelpers
  20. {
  21. private static readonly Dictionary<string, string> CommonTags = new[] {
  22. "Added",
  23. "AspectRatio",
  24. "AudioDbAlbumId",
  25. "AudioDbArtistId",
  26. "AwardSummary",
  27. "BirthDate",
  28. "Budget",
  29. // Deprecated. No longer saving in this field.
  30. "certification",
  31. "Chapters",
  32. "ContentRating",
  33. "CustomRating",
  34. "CriticRating",
  35. "CriticRatingSummary",
  36. "DeathDate",
  37. "DisplayOrder",
  38. "EndDate",
  39. "Genres",
  40. "Genre",
  41. "GamesDbId",
  42. // Deprecated. No longer saving in this field.
  43. "IMDB_ID",
  44. "IMDB",
  45. // Deprecated. No longer saving in this field.
  46. "IMDbId",
  47. "Language",
  48. "LocalTitle",
  49. "LockData",
  50. "LockedFields",
  51. "Format3D",
  52. "Metascore",
  53. // Deprecated. No longer saving in this field.
  54. "MPAARating",
  55. "MusicBrainzArtistId",
  56. "MusicBrainzAlbumArtistId",
  57. "MusicBrainzAlbumId",
  58. "MusicBrainzReleaseGroupId",
  59. // Deprecated. No longer saving in this field.
  60. "MusicbrainzId",
  61. "Overview",
  62. "Persons",
  63. "PlotKeywords",
  64. "PremiereDate",
  65. "ProductionYear",
  66. "Rating",
  67. "Revenue",
  68. "RottenTomatoesId",
  69. "RunningTime",
  70. // Deprecated. No longer saving in this field.
  71. "Runtime",
  72. "SortTitle",
  73. "Studios",
  74. "Tags",
  75. // Deprecated. No longer saving in this field.
  76. "TagLine",
  77. "Taglines",
  78. "TMDbCollectionId",
  79. "TMDbId",
  80. // Deprecated. No longer saving in this field.
  81. "Trailer",
  82. "Trailers",
  83. "TVcomId",
  84. "TvDbId",
  85. "Type",
  86. "TVRageId",
  87. "VoteCount",
  88. "Website",
  89. "Zap2ItId",
  90. "CollectionItems"
  91. }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
  92. /// <summary>
  93. /// The us culture
  94. /// </summary>
  95. private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
  96. /// <summary>
  97. /// Saves the specified XML.
  98. /// </summary>
  99. /// <param name="xml">The XML.</param>
  100. /// <param name="path">The path.</param>
  101. /// <param name="xmlTagsUsed">The XML tags used.</param>
  102. public static void Save(StringBuilder xml, string path, List<string> xmlTagsUsed)
  103. {
  104. if (File.Exists(path))
  105. {
  106. var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
  107. xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
  108. }
  109. var xmlDocument = new XmlDocument();
  110. xmlDocument.LoadXml(xml.ToString());
  111. //Add the new node to the document.
  112. xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement);
  113. var parentPath = Path.GetDirectoryName(path);
  114. Directory.CreateDirectory(parentPath);
  115. var wasHidden = false;
  116. var file = new FileInfo(path);
  117. // This will fail if the file is hidden
  118. if (file.Exists)
  119. {
  120. if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  121. {
  122. file.Attributes &= ~FileAttributes.Hidden;
  123. wasHidden = true;
  124. }
  125. }
  126. using (var filestream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
  127. {
  128. using (var streamWriter = new StreamWriter(filestream, Encoding.UTF8))
  129. {
  130. xmlDocument.Save(streamWriter);
  131. }
  132. }
  133. if (wasHidden)
  134. {
  135. file.Refresh();
  136. // Add back the attribute
  137. file.Attributes |= FileAttributes.Hidden;
  138. }
  139. }
  140. /// <summary>
  141. /// Gets the custom tags.
  142. /// </summary>
  143. /// <param name="path">The path.</param>
  144. /// <param name="xmlTagsUsed">The XML tags used.</param>
  145. /// <returns>System.String.</returns>
  146. private static string GetCustomTags(string path, List<string> xmlTagsUsed)
  147. {
  148. var settings = new XmlReaderSettings
  149. {
  150. CheckCharacters = false,
  151. IgnoreProcessingInstructions = true,
  152. IgnoreComments = true,
  153. ValidationType = ValidationType.None
  154. };
  155. var builder = new StringBuilder();
  156. using (var streamReader = new StreamReader(path, Encoding.UTF8))
  157. {
  158. // Use XmlReader for best performance
  159. using (var reader = XmlReader.Create(streamReader, settings))
  160. {
  161. reader.MoveToContent();
  162. // Loop through each element
  163. while (reader.Read())
  164. {
  165. if (reader.NodeType == XmlNodeType.Element)
  166. {
  167. var name = reader.Name;
  168. if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
  169. {
  170. builder.AppendLine(reader.ReadOuterXml());
  171. }
  172. else
  173. {
  174. reader.Skip();
  175. }
  176. }
  177. }
  178. }
  179. }
  180. return builder.ToString();
  181. }
  182. /// <summary>
  183. /// Adds the common nodes.
  184. /// </summary>
  185. /// <param name="item">The item.</param>
  186. /// <param name="builder">The builder.</param>
  187. public static void AddCommonNodes(BaseItem item, StringBuilder builder)
  188. {
  189. if (!string.IsNullOrEmpty(item.OfficialRating))
  190. {
  191. builder.Append("<ContentRating>" + SecurityElement.Escape(item.OfficialRating) + "</ContentRating>");
  192. }
  193. builder.Append("<Added>" + SecurityElement.Escape(item.DateCreated.ToLocalTime().ToString("G")) + "</Added>");
  194. builder.Append("<LockData>" + item.IsLocked.ToString().ToLower() + "</LockData>");
  195. if (item.LockedFields.Count > 0)
  196. {
  197. builder.Append("<LockedFields>" + string.Join("|", item.LockedFields.Select(i => i.ToString()).ToArray()) + "</LockedFields>");
  198. }
  199. if (!string.IsNullOrEmpty(item.DisplayMediaType))
  200. {
  201. builder.Append("<Type>" + SecurityElement.Escape(item.DisplayMediaType) + "</Type>");
  202. }
  203. var hasCriticRating = item as IHasCriticRating;
  204. if (hasCriticRating != null)
  205. {
  206. if (hasCriticRating.CriticRating.HasValue)
  207. {
  208. builder.Append("<CriticRating>" + SecurityElement.Escape(hasCriticRating.CriticRating.Value.ToString(UsCulture)) + "</CriticRating>");
  209. }
  210. if (!string.IsNullOrEmpty(hasCriticRating.CriticRatingSummary))
  211. {
  212. builder.Append("<CriticRatingSummary><![CDATA[" + hasCriticRating.CriticRatingSummary + "]]></CriticRatingSummary>");
  213. }
  214. }
  215. if (!string.IsNullOrEmpty(item.Overview))
  216. {
  217. builder.Append("<Overview><![CDATA[" + item.Overview + "]]></Overview>");
  218. }
  219. if (!string.IsNullOrEmpty(item.CustomRating))
  220. {
  221. builder.Append("<CustomRating>" + SecurityElement.Escape(item.CustomRating) + "</CustomRating>");
  222. }
  223. if (!string.IsNullOrEmpty(item.Name) && !(item is Episode))
  224. {
  225. builder.Append("<LocalTitle>" + SecurityElement.Escape(item.Name) + "</LocalTitle>");
  226. }
  227. if (!string.IsNullOrEmpty(item.ForcedSortName))
  228. {
  229. builder.Append("<SortTitle>" + SecurityElement.Escape(item.ForcedSortName) + "</SortTitle>");
  230. }
  231. if (item.PremiereDate.HasValue)
  232. {
  233. if (item is Person)
  234. {
  235. builder.Append("<BirthDate>" + SecurityElement.Escape(item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd")) + "</BirthDate>");
  236. }
  237. else if (!(item is Episode))
  238. {
  239. builder.Append("<PremiereDate>" + SecurityElement.Escape(item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd")) + "</PremiereDate>");
  240. }
  241. }
  242. if (item.EndDate.HasValue)
  243. {
  244. if (item is Person)
  245. {
  246. builder.Append("<DeathDate>" + SecurityElement.Escape(item.EndDate.Value.ToString("yyyy-MM-dd")) + "</DeathDate>");
  247. }
  248. else if (!(item is Episode))
  249. {
  250. builder.Append("<EndDate>" + SecurityElement.Escape(item.EndDate.Value.ToString("yyyy-MM-dd")) + "</EndDate>");
  251. }
  252. }
  253. var hasTrailers = item as IHasTrailers;
  254. if (hasTrailers != null)
  255. {
  256. if (hasTrailers.RemoteTrailers.Count > 0)
  257. {
  258. builder.Append("<Trailers>");
  259. foreach (var trailer in hasTrailers.RemoteTrailers)
  260. {
  261. builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>");
  262. }
  263. builder.Append("</Trailers>");
  264. }
  265. }
  266. var hasDisplayOrder = item as IHasDisplayOrder;
  267. if (hasDisplayOrder != null && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
  268. {
  269. builder.Append("<DisplayOrder>" + SecurityElement.Escape(hasDisplayOrder.DisplayOrder) + "</DisplayOrder>");
  270. }
  271. var hasMetascore = item as IHasMetascore;
  272. if (hasMetascore != null && hasMetascore.Metascore.HasValue)
  273. {
  274. builder.Append("<Metascore>" + SecurityElement.Escape(hasMetascore.Metascore.Value.ToString(UsCulture)) + "</Metascore>");
  275. }
  276. var hasAwards = item as IHasAwards;
  277. if (hasAwards != null && !string.IsNullOrEmpty(hasAwards.AwardSummary))
  278. {
  279. builder.Append("<AwardSummary>" + SecurityElement.Escape(hasAwards.AwardSummary) + "</AwardSummary>");
  280. }
  281. var hasBudget = item as IHasBudget;
  282. if (hasBudget != null)
  283. {
  284. if (hasBudget.Budget.HasValue)
  285. {
  286. builder.Append("<Budget>" + SecurityElement.Escape(hasBudget.Budget.Value.ToString(UsCulture)) + "</Budget>");
  287. }
  288. if (hasBudget.Revenue.HasValue)
  289. {
  290. builder.Append("<Revenue>" + SecurityElement.Escape(hasBudget.Revenue.Value.ToString(UsCulture)) + "</Revenue>");
  291. }
  292. }
  293. if (item.CommunityRating.HasValue)
  294. {
  295. builder.Append("<Rating>" + SecurityElement.Escape(item.CommunityRating.Value.ToString(UsCulture)) + "</Rating>");
  296. }
  297. if (item.VoteCount.HasValue)
  298. {
  299. builder.Append("<VoteCount>" + SecurityElement.Escape(item.VoteCount.Value.ToString(UsCulture)) + "</VoteCount>");
  300. }
  301. if (item.ProductionYear.HasValue && !(item is Person))
  302. {
  303. builder.Append("<ProductionYear>" + SecurityElement.Escape(item.ProductionYear.Value.ToString(UsCulture)) + "</ProductionYear>");
  304. }
  305. if (!string.IsNullOrEmpty(item.HomePageUrl))
  306. {
  307. builder.Append("<Website>" + SecurityElement.Escape(item.HomePageUrl) + "</Website>");
  308. }
  309. var hasAspectRatio = item as IHasAspectRatio;
  310. if (hasAspectRatio != null)
  311. {
  312. if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
  313. {
  314. builder.Append("<AspectRatio>" + SecurityElement.Escape(hasAspectRatio.AspectRatio) + "</AspectRatio>");
  315. }
  316. }
  317. var hasLanguage = item as IHasPreferredMetadataLanguage;
  318. if (hasLanguage != null)
  319. {
  320. if (!string.IsNullOrEmpty(hasLanguage.PreferredMetadataLanguage))
  321. {
  322. builder.Append("<Language>" + SecurityElement.Escape(hasLanguage.PreferredMetadataLanguage) + "</Language>");
  323. }
  324. }
  325. // Use original runtime here, actual file runtime later in MediaInfo
  326. var runTimeTicks = item.RunTimeTicks;
  327. if (runTimeTicks.HasValue)
  328. {
  329. var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
  330. builder.Append("<RunningTime>" + Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture) + "</RunningTime>");
  331. }
  332. var imdb = item.GetProviderId(MetadataProviders.Imdb);
  333. if (!string.IsNullOrEmpty(imdb))
  334. {
  335. builder.Append("<IMDB>" + SecurityElement.Escape(imdb) + "</IMDB>");
  336. }
  337. var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
  338. if (!string.IsNullOrEmpty(tmdb))
  339. {
  340. builder.Append("<TMDbId>" + SecurityElement.Escape(tmdb) + "</TMDbId>");
  341. }
  342. if (!(item is Series))
  343. {
  344. var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
  345. if (!string.IsNullOrEmpty(tvdb))
  346. {
  347. builder.Append("<TvDbId>" + SecurityElement.Escape(tvdb) + "</TvDbId>");
  348. }
  349. }
  350. var externalId = item.GetProviderId(MetadataProviders.Tvcom);
  351. if (!string.IsNullOrEmpty(externalId))
  352. {
  353. builder.Append("<TVcomId>" + SecurityElement.Escape(externalId) + "</TVcomId>");
  354. }
  355. externalId = item.GetProviderId(MetadataProviders.RottenTomatoes);
  356. if (!string.IsNullOrEmpty(externalId))
  357. {
  358. builder.Append("<RottenTomatoesId>" + SecurityElement.Escape(externalId) + "</RottenTomatoesId>");
  359. }
  360. externalId = item.GetProviderId(MetadataProviders.Zap2It);
  361. if (!string.IsNullOrEmpty(externalId))
  362. {
  363. builder.Append("<Zap2ItId>" + SecurityElement.Escape(externalId) + "</Zap2ItId>");
  364. }
  365. externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum);
  366. if (!string.IsNullOrEmpty(externalId))
  367. {
  368. builder.Append("<MusicBrainzAlbumId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumId>");
  369. }
  370. externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist);
  371. if (!string.IsNullOrEmpty(externalId))
  372. {
  373. builder.Append("<MusicBrainzAlbumArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumArtistId>");
  374. }
  375. externalId = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
  376. if (!string.IsNullOrEmpty(externalId))
  377. {
  378. builder.Append("<MusicBrainzArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzArtistId>");
  379. }
  380. externalId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
  381. if (!string.IsNullOrEmpty(externalId))
  382. {
  383. builder.Append("<MusicBrainzReleaseGroupId>" + SecurityElement.Escape(externalId) + "</MusicBrainzReleaseGroupId>");
  384. }
  385. externalId = item.GetProviderId(MetadataProviders.Gamesdb);
  386. if (!string.IsNullOrEmpty(externalId))
  387. {
  388. builder.Append("<GamesDbId>" + SecurityElement.Escape(externalId) + "</GamesDbId>");
  389. }
  390. externalId = item.GetProviderId(MetadataProviders.TmdbCollection);
  391. if (!string.IsNullOrEmpty(externalId))
  392. {
  393. builder.Append("<TMDbCollectionId>" + SecurityElement.Escape(externalId) + "</TMDbCollectionId>");
  394. }
  395. externalId = item.GetProviderId(MetadataProviders.AudioDbArtist);
  396. if (!string.IsNullOrEmpty(externalId))
  397. {
  398. builder.Append("<AudioDbArtistId>" + SecurityElement.Escape(externalId) + "</AudioDbArtistId>");
  399. }
  400. externalId = item.GetProviderId(MetadataProviders.AudioDbAlbum);
  401. if (!string.IsNullOrEmpty(externalId))
  402. {
  403. builder.Append("<AudioDbAlbumId>" + SecurityElement.Escape(externalId) + "</AudioDbAlbumId>");
  404. }
  405. externalId = item.GetProviderId(MetadataProviders.TvRage);
  406. if (!string.IsNullOrEmpty(externalId))
  407. {
  408. builder.Append("<TVRageId>" + SecurityElement.Escape(externalId) + "</TVRageId>");
  409. }
  410. var hasTagline = item as IHasTaglines;
  411. if (hasTagline != null)
  412. {
  413. if (hasTagline.Taglines.Count > 0)
  414. {
  415. builder.Append("<Taglines>");
  416. foreach (var tagline in hasTagline.Taglines)
  417. {
  418. builder.Append("<Tagline>" + SecurityElement.Escape(tagline) + "</Tagline>");
  419. }
  420. builder.Append("</Taglines>");
  421. }
  422. }
  423. if (item.Genres.Count > 0)
  424. {
  425. builder.Append("<Genres>");
  426. foreach (var genre in item.Genres)
  427. {
  428. builder.Append("<Genre>" + SecurityElement.Escape(genre) + "</Genre>");
  429. }
  430. builder.Append("</Genres>");
  431. }
  432. if (item.Studios.Count > 0)
  433. {
  434. builder.Append("<Studios>");
  435. foreach (var studio in item.Studios)
  436. {
  437. builder.Append("<Studio>" + SecurityElement.Escape(studio) + "</Studio>");
  438. }
  439. builder.Append("</Studios>");
  440. }
  441. var hasTags = item as IHasTags;
  442. if (hasTags != null)
  443. {
  444. if (hasTags.Tags.Count > 0)
  445. {
  446. builder.Append("<Tags>");
  447. foreach (var tag in hasTags.Tags)
  448. {
  449. builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
  450. }
  451. builder.Append("</Tags>");
  452. }
  453. }
  454. var hasKeywords = item as IHasKeywords;
  455. if (hasKeywords != null)
  456. {
  457. if (hasKeywords.Keywords.Count > 0)
  458. {
  459. builder.Append("<PlotKeywords>");
  460. foreach (var tag in hasKeywords.Keywords)
  461. {
  462. builder.Append("<PlotKeyword>" + SecurityElement.Escape(tag) + "</PlotKeyword>");
  463. }
  464. builder.Append("</PlotKeywords>");
  465. }
  466. }
  467. if (item.People.Count > 0)
  468. {
  469. builder.Append("<Persons>");
  470. foreach (var person in item.People)
  471. {
  472. builder.Append("<Person>");
  473. builder.Append("<Name>" + SecurityElement.Escape(person.Name) + "</Name>");
  474. builder.Append("<Type>" + SecurityElement.Escape(person.Type) + "</Type>");
  475. builder.Append("<Role>" + SecurityElement.Escape(person.Role) + "</Role>");
  476. if (person.SortOrder.HasValue)
  477. {
  478. builder.Append("<SortOrder>" + SecurityElement.Escape(person.SortOrder.Value.ToString(UsCulture)) + "</SortOrder>");
  479. }
  480. builder.Append("</Person>");
  481. }
  482. builder.Append("</Persons>");
  483. }
  484. var folder = item as BoxSet;
  485. if (folder != null)
  486. {
  487. AddCollectionItems(folder, builder);
  488. }
  489. }
  490. public static void AddChapters(Video item, StringBuilder builder, IItemRepository repository)
  491. {
  492. var chapters = repository.GetChapters(item.Id);
  493. builder.Append("<Chapters>");
  494. foreach (var chapter in chapters)
  495. {
  496. builder.Append("<Chapter>");
  497. builder.Append("<Name>" + SecurityElement.Escape(chapter.Name) + "</Name>");
  498. var time = TimeSpan.FromTicks(chapter.StartPositionTicks);
  499. var ms = Convert.ToInt64(time.TotalMilliseconds);
  500. builder.Append("<StartPositionMs>" + SecurityElement.Escape(ms.ToString(UsCulture)) + "</StartPositionMs>");
  501. builder.Append("</Chapter>");
  502. }
  503. builder.Append("</Chapters>");
  504. }
  505. /// <summary>
  506. /// Appends the media info.
  507. /// </summary>
  508. /// <typeparam name="T"></typeparam>
  509. public static void AddMediaInfo<T>(T item, StringBuilder builder, IItemRepository itemRepository)
  510. where T : BaseItem, IHasMediaStreams
  511. {
  512. var video = item as Video;
  513. if (video != null && video.Video3DFormat.HasValue)
  514. {
  515. switch (video.Video3DFormat.Value)
  516. {
  517. case Video3DFormat.FullSideBySide:
  518. builder.Append("<Format3D>FSBS</Format3D>");
  519. break;
  520. case Video3DFormat.FullTopAndBottom:
  521. builder.Append("<Format3D>FTAB</Format3D>");
  522. break;
  523. case Video3DFormat.HalfSideBySide:
  524. builder.Append("<Format3D>HSBS</Format3D>");
  525. break;
  526. case Video3DFormat.HalfTopAndBottom:
  527. builder.Append("<Format3D>HTAB</Format3D>");
  528. break;
  529. }
  530. }
  531. }
  532. public static void AddCollectionItems(Folder item, StringBuilder builder)
  533. {
  534. var items = item.LinkedChildren
  535. .Where(i => i.Type == LinkedChildType.Manual && !string.IsNullOrWhiteSpace(i.ItemName))
  536. .ToList();
  537. if (items.Count == 0)
  538. {
  539. return;
  540. }
  541. builder.Append("<CollectionItems>");
  542. foreach (var link in items)
  543. {
  544. builder.Append("<CollectionItem>");
  545. builder.Append("<Name>" + SecurityElement.Escape(link.ItemName) + "</Name>");
  546. builder.Append("<Type>" + SecurityElement.Escape(link.ItemType) + "</Type>");
  547. if (link.ItemYear.HasValue)
  548. {
  549. builder.Append("<Year>" + SecurityElement.Escape(link.ItemYear.Value.ToString(UsCulture)) + "</Year>");
  550. }
  551. builder.Append("</CollectionItem>");
  552. }
  553. builder.Append("</CollectionItems>");
  554. }
  555. }
  556. }