2
0

Folder.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  1. using MediaBrowser.Common.Progress;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.Querying;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Runtime.Serialization;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using CommonIO;
  15. using MediaBrowser.Controller.Channels;
  16. using MediaBrowser.Controller.Entities.Audio;
  17. using MediaBrowser.Controller.Entities.TV;
  18. using MediaBrowser.Model.Channels;
  19. namespace MediaBrowser.Controller.Entities
  20. {
  21. /// <summary>
  22. /// Class Folder
  23. /// </summary>
  24. public class Folder : BaseItem
  25. {
  26. public static IUserManager UserManager { get; set; }
  27. public static IUserViewManager UserViewManager { get; set; }
  28. /// <summary>
  29. /// Gets or sets a value indicating whether this instance is root.
  30. /// </summary>
  31. /// <value><c>true</c> if this instance is root; otherwise, <c>false</c>.</value>
  32. public bool IsRoot { get; set; }
  33. public virtual List<LinkedChild> LinkedChildren { get; set; }
  34. [IgnoreDataMember]
  35. public DateTime? DateLastMediaAdded { get; set; }
  36. public Folder()
  37. {
  38. LinkedChildren = new List<LinkedChild>();
  39. }
  40. [IgnoreDataMember]
  41. public override bool SupportsThemeMedia
  42. {
  43. get { return true; }
  44. }
  45. [IgnoreDataMember]
  46. public virtual bool IsPreSorted
  47. {
  48. get { return false; }
  49. }
  50. [IgnoreDataMember]
  51. public virtual bool IsPhysicalRoot
  52. {
  53. get { return false; }
  54. }
  55. /// <summary>
  56. /// Gets a value indicating whether this instance is folder.
  57. /// </summary>
  58. /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value>
  59. [IgnoreDataMember]
  60. public override bool IsFolder
  61. {
  62. get
  63. {
  64. return true;
  65. }
  66. }
  67. [IgnoreDataMember]
  68. public virtual bool SupportsCumulativeRunTimeTicks
  69. {
  70. get
  71. {
  72. return false;
  73. }
  74. }
  75. [IgnoreDataMember]
  76. public virtual bool SupportsDateLastMediaAdded
  77. {
  78. get
  79. {
  80. return false;
  81. }
  82. }
  83. public override bool RequiresRefresh()
  84. {
  85. var baseResult = base.RequiresRefresh();
  86. if (SupportsCumulativeRunTimeTicks && !RunTimeTicks.HasValue)
  87. {
  88. baseResult = true;
  89. }
  90. return baseResult;
  91. }
  92. [IgnoreDataMember]
  93. public override string FileNameWithoutExtension
  94. {
  95. get
  96. {
  97. if (LocationType == LocationType.FileSystem)
  98. {
  99. return System.IO.Path.GetFileName(Path);
  100. }
  101. return null;
  102. }
  103. }
  104. protected override bool IsAllowTagFilterEnforced()
  105. {
  106. if (this is ICollectionFolder)
  107. {
  108. return false;
  109. }
  110. if (this is UserView)
  111. {
  112. return false;
  113. }
  114. return true;
  115. }
  116. [IgnoreDataMember]
  117. protected virtual bool SupportsShortcutChildren
  118. {
  119. get { return false; }
  120. }
  121. /// <summary>
  122. /// Adds the child.
  123. /// </summary>
  124. /// <param name="item">The item.</param>
  125. /// <param name="cancellationToken">The cancellation token.</param>
  126. /// <returns>Task.</returns>
  127. /// <exception cref="System.InvalidOperationException">Unable to add + item.Name</exception>
  128. public async Task AddChild(BaseItem item, CancellationToken cancellationToken)
  129. {
  130. item.SetParent(this);
  131. if (item.Id == Guid.Empty)
  132. {
  133. item.Id = LibraryManager.GetNewItemId(item.Path, item.GetType());
  134. }
  135. if (ActualChildren.Any(i => i.Id == item.Id))
  136. {
  137. throw new ArgumentException(string.Format("A child with the Id {0} already exists.", item.Id));
  138. }
  139. if (item.DateCreated == DateTime.MinValue)
  140. {
  141. item.DateCreated = DateTime.UtcNow;
  142. }
  143. if (item.DateModified == DateTime.MinValue)
  144. {
  145. item.DateModified = DateTime.UtcNow;
  146. }
  147. await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
  148. }
  149. /// <summary>
  150. /// Removes the child.
  151. /// </summary>
  152. /// <param name="item">The item.</param>
  153. public void RemoveChild(BaseItem item)
  154. {
  155. item.SetParent(null);
  156. }
  157. /// <summary>
  158. /// Returns the valid set of index by options for this folder type.
  159. /// Override or extend to modify.
  160. /// </summary>
  161. /// <returns>Dictionary{System.StringFunc{UserIEnumerable{BaseItem}}}.</returns>
  162. protected virtual IEnumerable<string> GetIndexByOptions()
  163. {
  164. return new List<string> {
  165. {"None"},
  166. {"Performer"},
  167. {"Genre"},
  168. {"Director"},
  169. {"Year"},
  170. {"Studio"}
  171. };
  172. }
  173. /// <summary>
  174. /// Get the list of indexy by choices for this folder (localized).
  175. /// </summary>
  176. /// <value>The index by option strings.</value>
  177. [IgnoreDataMember]
  178. public IEnumerable<string> IndexByOptionStrings
  179. {
  180. get { return GetIndexByOptions(); }
  181. }
  182. /// <summary>
  183. /// Gets the actual children.
  184. /// </summary>
  185. /// <value>The actual children.</value>
  186. [IgnoreDataMember]
  187. protected virtual IEnumerable<BaseItem> ActualChildren
  188. {
  189. get
  190. {
  191. return LoadChildren();
  192. }
  193. }
  194. /// <summary>
  195. /// thread-safe access to the actual children of this folder - without regard to user
  196. /// </summary>
  197. /// <value>The children.</value>
  198. [IgnoreDataMember]
  199. public IEnumerable<BaseItem> Children
  200. {
  201. get { return ActualChildren.ToList(); }
  202. }
  203. /// <summary>
  204. /// thread-safe access to all recursive children of this folder - without regard to user
  205. /// </summary>
  206. /// <value>The recursive children.</value>
  207. [IgnoreDataMember]
  208. public IEnumerable<BaseItem> RecursiveChildren
  209. {
  210. get { return GetRecursiveChildren(); }
  211. }
  212. public override bool IsVisible(User user)
  213. {
  214. if (this is ICollectionFolder && !(this is BasePluginFolder))
  215. {
  216. if (user.Policy.BlockedMediaFolders != null)
  217. {
  218. if (user.Policy.BlockedMediaFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase) ||
  219. // Backwards compatibility
  220. user.Policy.BlockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
  221. {
  222. return false;
  223. }
  224. }
  225. else
  226. {
  227. if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase))
  228. {
  229. return false;
  230. }
  231. }
  232. }
  233. return base.IsVisible(user);
  234. }
  235. /// <summary>
  236. /// Loads our children. Validation will occur externally.
  237. /// We want this sychronous.
  238. /// </summary>
  239. protected virtual IEnumerable<BaseItem> LoadChildren()
  240. {
  241. //Logger.Debug("Loading children from {0} {1} {2}", GetType().Name, Id, Path);
  242. //just load our children from the repo - the library will be validated and maintained in other processes
  243. return GetCachedChildren();
  244. }
  245. public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
  246. {
  247. return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)));
  248. }
  249. /// <summary>
  250. /// Validates that the children of the folder still exist
  251. /// </summary>
  252. /// <param name="progress">The progress.</param>
  253. /// <param name="cancellationToken">The cancellation token.</param>
  254. /// <param name="metadataRefreshOptions">The metadata refresh options.</param>
  255. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  256. /// <returns>Task.</returns>
  257. public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true)
  258. {
  259. return ValidateChildrenInternal(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService);
  260. }
  261. private Dictionary<Guid, BaseItem> GetActualChildrenDictionary()
  262. {
  263. var dictionary = new Dictionary<Guid, BaseItem>();
  264. foreach (var child in ActualChildren)
  265. {
  266. var id = child.Id;
  267. if (dictionary.ContainsKey(id))
  268. {
  269. Logger.Error("Found folder containing items with duplicate id. Path: {0}, Child Name: {1}",
  270. Path ?? Name,
  271. child.Path ?? child.Name);
  272. }
  273. else
  274. {
  275. dictionary[id] = child;
  276. }
  277. }
  278. return dictionary;
  279. }
  280. private bool IsValidFromResolver(BaseItem current, BaseItem newItem)
  281. {
  282. return current.IsValidFromResolver(newItem);
  283. }
  284. /// <summary>
  285. /// Validates the children internal.
  286. /// </summary>
  287. /// <param name="progress">The progress.</param>
  288. /// <param name="cancellationToken">The cancellation token.</param>
  289. /// <param name="recursive">if set to <c>true</c> [recursive].</param>
  290. /// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
  291. /// <param name="refreshOptions">The refresh options.</param>
  292. /// <param name="directoryService">The directory service.</param>
  293. /// <returns>Task.</returns>
  294. protected async virtual Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  295. {
  296. var locationType = LocationType;
  297. cancellationToken.ThrowIfCancellationRequested();
  298. var validChildren = new List<BaseItem>();
  299. if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
  300. {
  301. IEnumerable<BaseItem> nonCachedChildren;
  302. try
  303. {
  304. nonCachedChildren = GetNonCachedChildren(directoryService);
  305. }
  306. catch (IOException ex)
  307. {
  308. nonCachedChildren = new BaseItem[] { };
  309. Logger.ErrorException("Error getting file system entries for {0}", ex, Path);
  310. }
  311. if (nonCachedChildren == null) return; //nothing to validate
  312. progress.Report(5);
  313. //build a dictionary of the current children we have now by Id so we can compare quickly and easily
  314. var currentChildren = GetActualChildrenDictionary();
  315. //create a list for our validated children
  316. var newItems = new List<BaseItem>();
  317. cancellationToken.ThrowIfCancellationRequested();
  318. foreach (var child in nonCachedChildren)
  319. {
  320. BaseItem currentChild;
  321. if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child))
  322. {
  323. await currentChild.UpdateIsOffline(false).ConfigureAwait(false);
  324. validChildren.Add(currentChild);
  325. continue;
  326. }
  327. // Brand new item - needs to be added
  328. child.SetParent(this);
  329. newItems.Add(child);
  330. validChildren.Add(child);
  331. }
  332. // If any items were added or removed....
  333. if (newItems.Count > 0 || currentChildren.Count != validChildren.Count)
  334. {
  335. // That's all the new and changed ones - now see if there are any that are missing
  336. var itemsRemoved = currentChildren.Values.Except(validChildren).ToList();
  337. var actualRemovals = new List<BaseItem>();
  338. foreach (var item in itemsRemoved)
  339. {
  340. var itemLocationType = item.LocationType;
  341. if (itemLocationType == LocationType.Virtual ||
  342. itemLocationType == LocationType.Remote)
  343. {
  344. }
  345. else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path))
  346. {
  347. await item.UpdateIsOffline(true).ConfigureAwait(false);
  348. }
  349. else
  350. {
  351. actualRemovals.Add(item);
  352. }
  353. }
  354. if (actualRemovals.Count > 0)
  355. {
  356. foreach (var item in actualRemovals)
  357. {
  358. Logger.Debug("Removed item: " + item.Path);
  359. item.SetParent(null);
  360. item.IsOffline = false;
  361. await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
  362. LibraryManager.ReportItemRemoved(item);
  363. }
  364. }
  365. await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false);
  366. }
  367. }
  368. progress.Report(10);
  369. cancellationToken.ThrowIfCancellationRequested();
  370. if (recursive)
  371. {
  372. await ValidateSubFolders(ActualChildren.OfType<Folder>().ToList(), directoryService, progress, cancellationToken).ConfigureAwait(false);
  373. }
  374. progress.Report(20);
  375. if (refreshChildMetadata)
  376. {
  377. var container = this as IMetadataContainer;
  378. var innerProgress = new ActionableProgress<double>();
  379. innerProgress.RegisterAction(p => progress.Report(.80 * p + 20));
  380. if (container != null)
  381. {
  382. await container.RefreshAllMetadata(refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false);
  383. }
  384. else
  385. {
  386. await RefreshMetadataRecursive(refreshOptions, recursive, innerProgress, cancellationToken);
  387. }
  388. }
  389. progress.Report(100);
  390. }
  391. private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
  392. {
  393. var children = ActualChildren.ToList();
  394. var percentages = new Dictionary<Guid, double>(children.Count);
  395. var numComplete = 0;
  396. var count = children.Count;
  397. foreach (var child in children)
  398. {
  399. cancellationToken.ThrowIfCancellationRequested();
  400. if (child.IsFolder)
  401. {
  402. var innerProgress = new ActionableProgress<double>();
  403. // Avoid implicitly captured closure
  404. var currentChild = child;
  405. innerProgress.RegisterAction(p =>
  406. {
  407. lock (percentages)
  408. {
  409. percentages[currentChild.Id] = p / 100;
  410. var innerPercent = percentages.Values.Sum();
  411. innerPercent /= count;
  412. innerPercent *= 100;
  413. progress.Report(innerPercent);
  414. }
  415. });
  416. await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
  417. .ConfigureAwait(false);
  418. }
  419. else
  420. {
  421. await RefreshChildMetadata(child, refreshOptions, false, new Progress<double>(), cancellationToken)
  422. .ConfigureAwait(false);
  423. }
  424. numComplete++;
  425. double percent = numComplete;
  426. percent /= count;
  427. percent *= 100;
  428. progress.Report(percent);
  429. }
  430. progress.Report(100);
  431. }
  432. private async Task RefreshChildMetadata(BaseItem child, MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
  433. {
  434. var container = child as IMetadataContainer;
  435. if (container != null)
  436. {
  437. await container.RefreshAllMetadata(refreshOptions, progress, cancellationToken).ConfigureAwait(false);
  438. }
  439. else
  440. {
  441. await child.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
  442. if (recursive)
  443. {
  444. var folder = child as Folder;
  445. if (folder != null)
  446. {
  447. await folder.RefreshMetadataRecursive(refreshOptions, true, progress, cancellationToken);
  448. }
  449. }
  450. }
  451. progress.Report(100);
  452. }
  453. /// <summary>
  454. /// Refreshes the children.
  455. /// </summary>
  456. /// <param name="children">The children.</param>
  457. /// <param name="directoryService">The directory service.</param>
  458. /// <param name="progress">The progress.</param>
  459. /// <param name="cancellationToken">The cancellation token.</param>
  460. /// <returns>Task.</returns>
  461. private async Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
  462. {
  463. var list = children;
  464. var childCount = list.Count;
  465. var percentages = new Dictionary<Guid, double>(list.Count);
  466. foreach (var item in list)
  467. {
  468. cancellationToken.ThrowIfCancellationRequested();
  469. var child = item;
  470. var innerProgress = new ActionableProgress<double>();
  471. innerProgress.RegisterAction(p =>
  472. {
  473. lock (percentages)
  474. {
  475. percentages[child.Id] = p / 100;
  476. var percent = percentages.Values.Sum();
  477. percent /= childCount;
  478. progress.Report(10 * percent + 10);
  479. }
  480. });
  481. await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService)
  482. .ConfigureAwait(false);
  483. }
  484. }
  485. /// <summary>
  486. /// Determines whether the specified path is offline.
  487. /// </summary>
  488. /// <param name="path">The path.</param>
  489. /// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
  490. public static bool IsPathOffline(string path)
  491. {
  492. if (FileSystem.FileExists(path))
  493. {
  494. return false;
  495. }
  496. var originalPath = path;
  497. // Depending on whether the path is local or unc, it may return either null or '\' at the top
  498. while (!string.IsNullOrEmpty(path) && path.Length > 1)
  499. {
  500. if (FileSystem.DirectoryExists(path))
  501. {
  502. return false;
  503. }
  504. path = System.IO.Path.GetDirectoryName(path);
  505. }
  506. if (ContainsPath(LibraryManager.GetVirtualFolders(), originalPath))
  507. {
  508. return true;
  509. }
  510. return false;
  511. }
  512. /// <summary>
  513. /// Determines whether the specified folders contains path.
  514. /// </summary>
  515. /// <param name="folders">The folders.</param>
  516. /// <param name="path">The path.</param>
  517. /// <returns><c>true</c> if the specified folders contains path; otherwise, <c>false</c>.</returns>
  518. private static bool ContainsPath(IEnumerable<VirtualFolderInfo> folders, string path)
  519. {
  520. return folders.SelectMany(i => i.Locations).Any(i => ContainsPath(i, path));
  521. }
  522. private static bool ContainsPath(string parent, string path)
  523. {
  524. return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || FileSystem.ContainsSubPath(parent, path);
  525. }
  526. /// <summary>
  527. /// Get the children of this folder from the actual file system
  528. /// </summary>
  529. /// <returns>IEnumerable{BaseItem}.</returns>
  530. protected virtual IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
  531. {
  532. var collectionType = LibraryManager.GetContentType(this);
  533. var libraryOptions = LibraryManager.GetLibraryOptions(this);
  534. return LibraryManager.ResolvePaths(GetFileSystemChildren(directoryService), directoryService, this, libraryOptions, collectionType);
  535. }
  536. /// <summary>
  537. /// Get our children from the repo - stubbed for now
  538. /// </summary>
  539. /// <returns>IEnumerable{BaseItem}.</returns>
  540. protected IEnumerable<BaseItem> GetCachedChildren()
  541. {
  542. return ItemRepository.GetItemList(new InternalItemsQuery
  543. {
  544. ParentId = Id,
  545. GroupByPresentationUniqueKey = false
  546. });
  547. }
  548. public virtual int GetChildCount(User user)
  549. {
  550. if (LinkedChildren.Count > 0)
  551. {
  552. if (!(this is ICollectionFolder))
  553. {
  554. return GetChildren(user, true).Count();
  555. }
  556. }
  557. var result = GetItems(new InternalItemsQuery(user)
  558. {
  559. Recursive = false,
  560. Limit = 0,
  561. ParentId = Id
  562. }).Result;
  563. return result.TotalRecordCount;
  564. }
  565. public QueryResult<BaseItem> QueryRecursive(InternalItemsQuery query)
  566. {
  567. var user = query.User;
  568. if (!query.ForceDirect && RequiresPostFiltering(query))
  569. {
  570. IEnumerable<BaseItem> items;
  571. Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
  572. if (query.User == null)
  573. {
  574. items = GetRecursiveChildren(filter);
  575. }
  576. else
  577. {
  578. items = GetRecursiveChildren(user, query);
  579. }
  580. return PostFilterAndSort(items, query, true, true);
  581. }
  582. if (!(this is UserRootFolder) && !(this is AggregateFolder))
  583. {
  584. query.ParentId = query.ParentId ?? Id;
  585. }
  586. return LibraryManager.GetItemsResult(query);
  587. }
  588. private bool RequiresPostFiltering(InternalItemsQuery query)
  589. {
  590. if (LinkedChildren.Count > 0)
  591. {
  592. if (!(this is ICollectionFolder))
  593. {
  594. Logger.Debug("Query requires post-filtering due to LinkedChildren. Type: " + GetType().Name);
  595. return true;
  596. }
  597. }
  598. if (query.SortBy != null && query.SortBy.Length > 0)
  599. {
  600. if (query.SortBy.Contains(ItemSortBy.AiredEpisodeOrder, StringComparer.OrdinalIgnoreCase))
  601. {
  602. Logger.Debug("Query requires post-filtering due to ItemSortBy.AiredEpisodeOrder");
  603. return true;
  604. }
  605. if (query.SortBy.Contains(ItemSortBy.Budget, StringComparer.OrdinalIgnoreCase))
  606. {
  607. Logger.Debug("Query requires post-filtering due to ItemSortBy.Budget");
  608. return true;
  609. }
  610. if (query.SortBy.Contains(ItemSortBy.GameSystem, StringComparer.OrdinalIgnoreCase))
  611. {
  612. Logger.Debug("Query requires post-filtering due to ItemSortBy.GameSystem");
  613. return true;
  614. }
  615. if (query.SortBy.Contains(ItemSortBy.Metascore, StringComparer.OrdinalIgnoreCase))
  616. {
  617. Logger.Debug("Query requires post-filtering due to ItemSortBy.Metascore");
  618. return true;
  619. }
  620. if (query.SortBy.Contains(ItemSortBy.Players, StringComparer.OrdinalIgnoreCase))
  621. {
  622. Logger.Debug("Query requires post-filtering due to ItemSortBy.Players");
  623. return true;
  624. }
  625. if (query.SortBy.Contains(ItemSortBy.Revenue, StringComparer.OrdinalIgnoreCase))
  626. {
  627. Logger.Debug("Query requires post-filtering due to ItemSortBy.Revenue");
  628. return true;
  629. }
  630. if (query.SortBy.Contains(ItemSortBy.VideoBitRate, StringComparer.OrdinalIgnoreCase))
  631. {
  632. Logger.Debug("Query requires post-filtering due to ItemSortBy.VideoBitRate");
  633. return true;
  634. }
  635. }
  636. if (query.ItemIds.Length > 0)
  637. {
  638. Logger.Debug("Query requires post-filtering due to ItemIds");
  639. return true;
  640. }
  641. if (query.IsInBoxSet.HasValue)
  642. {
  643. Logger.Debug("Query requires post-filtering due to IsInBoxSet");
  644. return true;
  645. }
  646. // Filter by Video3DFormat
  647. if (query.Is3D.HasValue)
  648. {
  649. Logger.Debug("Query requires post-filtering due to Is3D");
  650. return true;
  651. }
  652. if (query.HasOfficialRating.HasValue)
  653. {
  654. Logger.Debug("Query requires post-filtering due to HasOfficialRating");
  655. return true;
  656. }
  657. if (query.IsPlaceHolder.HasValue)
  658. {
  659. Logger.Debug("Query requires post-filtering due to IsPlaceHolder");
  660. return true;
  661. }
  662. if (query.HasSpecialFeature.HasValue)
  663. {
  664. Logger.Debug("Query requires post-filtering due to HasSpecialFeature");
  665. return true;
  666. }
  667. if (query.HasSubtitles.HasValue)
  668. {
  669. Logger.Debug("Query requires post-filtering due to HasSubtitles");
  670. return true;
  671. }
  672. if (query.HasTrailer.HasValue)
  673. {
  674. Logger.Debug("Query requires post-filtering due to HasTrailer");
  675. return true;
  676. }
  677. if (query.HasThemeSong.HasValue)
  678. {
  679. Logger.Debug("Query requires post-filtering due to HasThemeSong");
  680. return true;
  681. }
  682. if (query.HasThemeVideo.HasValue)
  683. {
  684. Logger.Debug("Query requires post-filtering due to HasThemeVideo");
  685. return true;
  686. }
  687. // Filter by VideoType
  688. if (query.VideoTypes.Length > 0)
  689. {
  690. Logger.Debug("Query requires post-filtering due to VideoTypes");
  691. return true;
  692. }
  693. // Apply person filter
  694. if (query.ItemIdsFromPersonFilters != null)
  695. {
  696. Logger.Debug("Query requires post-filtering due to ItemIdsFromPersonFilters");
  697. return true;
  698. }
  699. if (query.MinPlayers.HasValue)
  700. {
  701. Logger.Debug("Query requires post-filtering due to MinPlayers");
  702. return true;
  703. }
  704. if (query.MaxPlayers.HasValue)
  705. {
  706. Logger.Debug("Query requires post-filtering due to MaxPlayers");
  707. return true;
  708. }
  709. if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager))
  710. {
  711. Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems");
  712. return true;
  713. }
  714. if (!string.IsNullOrWhiteSpace(query.AdjacentTo))
  715. {
  716. Logger.Debug("Query requires post-filtering due to AdjacentTo");
  717. return true;
  718. }
  719. if (query.AirDays.Length > 0)
  720. {
  721. Logger.Debug("Query requires post-filtering due to AirDays");
  722. return true;
  723. }
  724. if (query.SeriesStatuses.Length > 0)
  725. {
  726. Logger.Debug("Query requires post-filtering due to SeriesStatuses");
  727. return true;
  728. }
  729. if (query.AiredDuringSeason.HasValue)
  730. {
  731. Logger.Debug("Query requires post-filtering due to AiredDuringSeason");
  732. return true;
  733. }
  734. if (!string.IsNullOrWhiteSpace(query.AlbumArtistStartsWithOrGreater))
  735. {
  736. Logger.Debug("Query requires post-filtering due to AlbumArtistStartsWithOrGreater");
  737. return true;
  738. }
  739. if (query.IsPlayed.HasValue)
  740. {
  741. if (query.IncludeItemTypes.Length == 1 && query.IncludeItemTypes.Contains(typeof(Series).Name))
  742. {
  743. Logger.Debug("Query requires post-filtering due to IsPlayed");
  744. return true;
  745. }
  746. }
  747. return false;
  748. }
  749. public Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
  750. {
  751. if (query.ItemIds.Length > 0)
  752. {
  753. var result = LibraryManager.GetItemsResult(query);
  754. if (query.SortBy.Length == 0)
  755. {
  756. var ids = query.ItemIds.ToList();
  757. // Try to preserve order
  758. result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray();
  759. }
  760. return Task.FromResult(result);
  761. }
  762. return GetItemsInternal(query);
  763. }
  764. protected virtual async Task<QueryResult<BaseItem>> GetItemsInternal(InternalItemsQuery query)
  765. {
  766. if (SourceType == SourceType.Channel)
  767. {
  768. try
  769. {
  770. // Don't blow up here because it could cause parent screens with other content to fail
  771. return await ChannelManager.GetChannelItemsInternal(new ChannelItemQuery
  772. {
  773. ChannelId = ChannelId,
  774. FolderId = Id.ToString("N"),
  775. Limit = query.Limit,
  776. StartIndex = query.StartIndex,
  777. UserId = query.User.Id.ToString("N"),
  778. SortBy = query.SortBy,
  779. SortOrder = query.SortOrder
  780. }, new Progress<double>(), CancellationToken.None);
  781. }
  782. catch
  783. {
  784. // Already logged at lower levels
  785. return new QueryResult<BaseItem>();
  786. }
  787. }
  788. if (query.Recursive)
  789. {
  790. return QueryRecursive(query);
  791. }
  792. var user = query.User;
  793. Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
  794. IEnumerable<BaseItem> items;
  795. if (query.User == null)
  796. {
  797. items = query.Recursive
  798. ? GetRecursiveChildren(filter)
  799. : Children.Where(filter);
  800. }
  801. else
  802. {
  803. items = query.Recursive
  804. ? GetRecursiveChildren(user, query)
  805. : GetChildren(user, true).Where(filter);
  806. }
  807. return PostFilterAndSort(items, query, true, true);
  808. }
  809. protected QueryResult<BaseItem> PostFilterAndSort(IEnumerable<BaseItem> items, InternalItemsQuery query, bool collapseBoxSetItems, bool enableSorting)
  810. {
  811. return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager, ConfigurationManager, collapseBoxSetItems, enableSorting);
  812. }
  813. public virtual IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
  814. {
  815. if (user == null)
  816. {
  817. throw new ArgumentNullException();
  818. }
  819. //the true root should return our users root folder children
  820. if (IsPhysicalRoot) return user.RootFolder.GetChildren(user, includeLinkedChildren);
  821. var result = new Dictionary<Guid, BaseItem>();
  822. AddChildren(user, includeLinkedChildren, result, false, null);
  823. return result.Values;
  824. }
  825. protected virtual IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  826. {
  827. return Children;
  828. }
  829. /// <summary>
  830. /// Adds the children to list.
  831. /// </summary>
  832. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  833. private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query)
  834. {
  835. foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
  836. {
  837. if (child.IsVisible(user))
  838. {
  839. if (query == null || UserViewBuilder.FilterItem(child, query))
  840. {
  841. result[child.Id] = child;
  842. }
  843. if (recursive && child.IsFolder)
  844. {
  845. var folder = (Folder)child;
  846. folder.AddChildren(user, includeLinkedChildren, result, true, query);
  847. }
  848. }
  849. }
  850. if (includeLinkedChildren)
  851. {
  852. foreach (var child in GetLinkedChildren(user))
  853. {
  854. if (child.IsVisible(user))
  855. {
  856. if (query == null || UserViewBuilder.FilterItem(child, query))
  857. {
  858. result[child.Id] = child;
  859. }
  860. }
  861. }
  862. }
  863. }
  864. /// <summary>
  865. /// Gets allowed recursive children of an item
  866. /// </summary>
  867. /// <param name="user">The user.</param>
  868. /// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
  869. /// <returns>IEnumerable{BaseItem}.</returns>
  870. /// <exception cref="System.ArgumentNullException"></exception>
  871. public IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true)
  872. {
  873. return GetRecursiveChildren(user, null);
  874. }
  875. public virtual IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
  876. {
  877. if (user == null)
  878. {
  879. throw new ArgumentNullException("user");
  880. }
  881. var result = new Dictionary<Guid, BaseItem>();
  882. AddChildren(user, true, result, true, query);
  883. return result.Values;
  884. }
  885. /// <summary>
  886. /// Gets the recursive children.
  887. /// </summary>
  888. /// <returns>IList{BaseItem}.</returns>
  889. public IList<BaseItem> GetRecursiveChildren()
  890. {
  891. return GetRecursiveChildren(true);
  892. }
  893. public IList<BaseItem> GetRecursiveChildren(bool includeLinkedChildren)
  894. {
  895. return GetRecursiveChildren(i => true, includeLinkedChildren);
  896. }
  897. public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter)
  898. {
  899. return GetRecursiveChildren(filter, true);
  900. }
  901. public IList<BaseItem> GetRecursiveChildren(Func<BaseItem, bool> filter, bool includeLinkedChildren)
  902. {
  903. var result = new Dictionary<Guid, BaseItem>();
  904. AddChildrenToList(result, true, true, filter);
  905. return result.Values.ToList();
  906. }
  907. /// <summary>
  908. /// Adds the children to list.
  909. /// </summary>
  910. private void AddChildrenToList(Dictionary<Guid, BaseItem> result, bool includeLinkedChildren, bool recursive, Func<BaseItem, bool> filter)
  911. {
  912. foreach (var child in Children)
  913. {
  914. if (filter == null || filter(child))
  915. {
  916. result[child.Id] = child;
  917. }
  918. if (recursive && child.IsFolder)
  919. {
  920. var folder = (Folder)child;
  921. // We can only support includeLinkedChildren for the first folder, or we might end up stuck in a loop of linked items
  922. folder.AddChildrenToList(result, false, true, filter);
  923. }
  924. }
  925. if (includeLinkedChildren)
  926. {
  927. foreach (var child in GetLinkedChildren())
  928. {
  929. if (filter == null || filter(child))
  930. {
  931. result[child.Id] = child;
  932. }
  933. }
  934. }
  935. }
  936. /// <summary>
  937. /// Gets the linked children.
  938. /// </summary>
  939. /// <returns>IEnumerable{BaseItem}.</returns>
  940. public IEnumerable<BaseItem> GetLinkedChildren()
  941. {
  942. return LinkedChildren
  943. .Select(GetLinkedChild)
  944. .Where(i => i != null);
  945. }
  946. protected virtual bool FilterLinkedChildrenPerUser
  947. {
  948. get
  949. {
  950. return false;
  951. }
  952. }
  953. public IEnumerable<BaseItem> GetLinkedChildren(User user)
  954. {
  955. if (!FilterLinkedChildrenPerUser || user == null)
  956. {
  957. return GetLinkedChildren();
  958. }
  959. var locations = user.RootFolder
  960. .Children
  961. .OfType<CollectionFolder>()
  962. .Where(i => i.IsVisible(user))
  963. .SelectMany(i => i.PhysicalLocations)
  964. .ToList();
  965. return LinkedChildren
  966. .Select(i =>
  967. {
  968. var child = GetLinkedChild(i);
  969. if (child != null)
  970. {
  971. var childLocationType = child.LocationType;
  972. if (childLocationType == LocationType.Remote || childLocationType == LocationType.Virtual)
  973. {
  974. if (!child.IsVisibleStandalone(user))
  975. {
  976. return null;
  977. }
  978. }
  979. else if (childLocationType == LocationType.FileSystem && !locations.Any(l => FileSystem.ContainsSubPath(l, child.Path)))
  980. {
  981. return null;
  982. }
  983. }
  984. return child;
  985. })
  986. .Where(i => i != null);
  987. }
  988. /// <summary>
  989. /// Gets the linked children.
  990. /// </summary>
  991. /// <returns>IEnumerable{BaseItem}.</returns>
  992. public IEnumerable<Tuple<LinkedChild, BaseItem>> GetLinkedChildrenInfos()
  993. {
  994. return LinkedChildren
  995. .Select(i => new Tuple<LinkedChild, BaseItem>(i, GetLinkedChild(i)))
  996. .Where(i => i.Item2 != null);
  997. }
  998. [IgnoreDataMember]
  999. protected override bool SupportsOwnedItems
  1000. {
  1001. get
  1002. {
  1003. return base.SupportsOwnedItems || SupportsShortcutChildren;
  1004. }
  1005. }
  1006. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  1007. {
  1008. var changesFound = false;
  1009. if (LocationType == LocationType.FileSystem)
  1010. {
  1011. if (RefreshLinkedChildren(fileSystemChildren))
  1012. {
  1013. changesFound = true;
  1014. }
  1015. }
  1016. var baseHasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  1017. return baseHasChanges || changesFound;
  1018. }
  1019. /// <summary>
  1020. /// Refreshes the linked children.
  1021. /// </summary>
  1022. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  1023. private bool RefreshLinkedChildren(IEnumerable<FileSystemMetadata> fileSystemChildren)
  1024. {
  1025. var currentManualLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Manual).ToList();
  1026. var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList();
  1027. List<LinkedChild> newShortcutLinks;
  1028. if (SupportsShortcutChildren)
  1029. {
  1030. newShortcutLinks = fileSystemChildren
  1031. .Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory && FileSystem.IsShortcut(i.FullName))
  1032. .Select(i =>
  1033. {
  1034. try
  1035. {
  1036. Logger.Debug("Found shortcut at {0}", i.FullName);
  1037. var resolvedPath = FileSystem.ResolveShortcut(i.FullName);
  1038. if (!string.IsNullOrEmpty(resolvedPath))
  1039. {
  1040. return new LinkedChild
  1041. {
  1042. Path = resolvedPath,
  1043. Type = LinkedChildType.Shortcut
  1044. };
  1045. }
  1046. Logger.Error("Error resolving shortcut {0}", i.FullName);
  1047. return null;
  1048. }
  1049. catch (IOException ex)
  1050. {
  1051. Logger.ErrorException("Error resolving shortcut {0}", ex, i.FullName);
  1052. return null;
  1053. }
  1054. })
  1055. .Where(i => i != null)
  1056. .ToList();
  1057. }
  1058. else { newShortcutLinks = new List<LinkedChild>(); }
  1059. if (!newShortcutLinks.SequenceEqual(currentShortcutLinks, new LinkedChildComparer()))
  1060. {
  1061. Logger.Info("Shortcut links have changed for {0}", Path);
  1062. newShortcutLinks.AddRange(currentManualLinks);
  1063. LinkedChildren = newShortcutLinks;
  1064. return true;
  1065. }
  1066. foreach (var child in LinkedChildren)
  1067. {
  1068. // Reset the cached value
  1069. child.ItemId = null;
  1070. }
  1071. return false;
  1072. }
  1073. /// <summary>
  1074. /// Folders need to validate and refresh
  1075. /// </summary>
  1076. /// <returns>Task.</returns>
  1077. public override async Task ChangedExternally()
  1078. {
  1079. var progress = new Progress<double>();
  1080. await ValidateChildren(progress, CancellationToken.None).ConfigureAwait(false);
  1081. await base.ChangedExternally().ConfigureAwait(false);
  1082. }
  1083. /// <summary>
  1084. /// Marks the played.
  1085. /// </summary>
  1086. /// <param name="user">The user.</param>
  1087. /// <param name="datePlayed">The date played.</param>
  1088. /// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
  1089. /// <returns>Task.</returns>
  1090. public override async Task MarkPlayed(User user,
  1091. DateTime? datePlayed,
  1092. bool resetPosition)
  1093. {
  1094. var query = new InternalItemsQuery
  1095. {
  1096. User = user,
  1097. Recursive = true,
  1098. IsFolder = false,
  1099. EnableTotalRecordCount = false
  1100. };
  1101. if (!user.Configuration.DisplayMissingEpisodes || !user.Configuration.DisplayUnairedEpisodes)
  1102. {
  1103. query.ExcludeLocationTypes = new[] { LocationType.Virtual };
  1104. }
  1105. var itemsResult = await GetItems(query).ConfigureAwait(false);
  1106. // Sweep through recursively and update status
  1107. var tasks = itemsResult.Items.Select(c => c.MarkPlayed(user, datePlayed, resetPosition));
  1108. await Task.WhenAll(tasks).ConfigureAwait(false);
  1109. }
  1110. /// <summary>
  1111. /// Marks the unplayed.
  1112. /// </summary>
  1113. /// <param name="user">The user.</param>
  1114. /// <returns>Task.</returns>
  1115. public override async Task MarkUnplayed(User user)
  1116. {
  1117. var itemsResult = await GetItems(new InternalItemsQuery
  1118. {
  1119. User = user,
  1120. Recursive = true,
  1121. IsFolder = false,
  1122. EnableTotalRecordCount = false
  1123. }).ConfigureAwait(false);
  1124. // Sweep through recursively and update status
  1125. var tasks = itemsResult.Items.Select(c => c.MarkUnplayed(user));
  1126. await Task.WhenAll(tasks).ConfigureAwait(false);
  1127. }
  1128. public override bool IsPlayed(User user)
  1129. {
  1130. var itemsResult = GetItems(new InternalItemsQuery(user)
  1131. {
  1132. Recursive = true,
  1133. IsFolder = false,
  1134. ExcludeLocationTypes = new[] { LocationType.Virtual },
  1135. EnableTotalRecordCount = false
  1136. }).Result;
  1137. return itemsResult.Items
  1138. .All(i => i.IsPlayed(user));
  1139. }
  1140. public override bool IsUnplayed(User user)
  1141. {
  1142. return !IsPlayed(user);
  1143. }
  1144. [IgnoreDataMember]
  1145. public virtual bool SupportsUserDataFromChildren
  1146. {
  1147. get
  1148. {
  1149. // These are just far too slow.
  1150. if (this is ICollectionFolder)
  1151. {
  1152. return false;
  1153. }
  1154. if (this is UserView)
  1155. {
  1156. return false;
  1157. }
  1158. if (this is UserRootFolder)
  1159. {
  1160. return false;
  1161. }
  1162. if (this is Channel)
  1163. {
  1164. return false;
  1165. }
  1166. if (SourceType != SourceType.Library)
  1167. {
  1168. return false;
  1169. }
  1170. return true;
  1171. }
  1172. }
  1173. public override async Task FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user)
  1174. {
  1175. if (!SupportsUserDataFromChildren)
  1176. {
  1177. return;
  1178. }
  1179. var unplayedQueryResult = await GetItems(new InternalItemsQuery(user)
  1180. {
  1181. Recursive = true,
  1182. IsFolder = false,
  1183. IsVirtualItem = false,
  1184. EnableTotalRecordCount = true,
  1185. Limit = 0,
  1186. IsPlayed = false
  1187. }).ConfigureAwait(false);
  1188. var allItemsQueryResult = await GetItems(new InternalItemsQuery(user)
  1189. {
  1190. Recursive = true,
  1191. IsFolder = false,
  1192. IsVirtualItem = false,
  1193. EnableTotalRecordCount = true,
  1194. Limit = 0
  1195. }).ConfigureAwait(false);
  1196. if (itemDto != null)
  1197. {
  1198. itemDto.RecursiveItemCount = allItemsQueryResult.TotalRecordCount;
  1199. }
  1200. var recursiveItemCount = allItemsQueryResult.TotalRecordCount;
  1201. double unplayedCount = unplayedQueryResult.TotalRecordCount;
  1202. if (recursiveItemCount > 0)
  1203. {
  1204. var unplayedPercentage = (unplayedCount / recursiveItemCount) * 100;
  1205. dto.PlayedPercentage = 100 - unplayedPercentage;
  1206. dto.Played = dto.PlayedPercentage.Value >= 100;
  1207. dto.UnplayedItemCount = unplayedQueryResult.TotalRecordCount;
  1208. }
  1209. if (itemDto != null)
  1210. {
  1211. if (this is Season || this is MusicAlbum)
  1212. {
  1213. itemDto.ChildCount = recursiveItemCount;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }