2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
2012-07-15 20:27:07 +00:00
|
|
|
|
using System.Runtime.Serialization;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Entities
|
|
|
|
|
{
|
|
|
|
|
public class Folder : BaseItem
|
|
|
|
|
{
|
|
|
|
|
public bool IsRoot { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IsVirtualFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Parent != null && Parent.IsRoot;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-15 20:27:07 +00:00
|
|
|
|
[IgnoreDataMember]
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public BaseItem[] Children { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds an item by ID, recursively
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BaseItem FindById(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (Id == id)
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (BaseItem item in Children)
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
var folder = item as Folder;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
var foundItem = folder.FindById(id);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (foundItem != null)
|
|
|
|
|
{
|
|
|
|
|
return foundItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (item.Id == id)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds an item by path, recursively
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BaseItem FindByPath(string path)
|
|
|
|
|
{
|
|
|
|
|
if (Path.Equals(path, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (BaseItem item in Children)
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
var folder = item as Folder;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
var foundItem = folder.FindByPath(path);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (foundItem != null)
|
|
|
|
|
{
|
|
|
|
|
return foundItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (item.Path.Equals(path, StringComparison.OrdinalIgnoreCase))
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|