public GetLibraryItemResultData Transform(string input) { JObject rootNode = JObject.Parse(input); JObject libraryItemNode = rootNode["libraryItem"] as JObject; long id = libraryItemNode["id"].ToObject <long>(); LibraryItemType type = LibraryItemTypeParser.Parse(libraryItemNode["type"].ToObject <string>()); string name = libraryItemNode["name"].ToObject <string>(); ILibraryItem libraryItem; switch (type) { case LibraryItemType.Directory: libraryItem = CreateDirectory(id, name, libraryItemNode); break; case LibraryItemType.Multimedia: libraryItem = CreateMultimedia(id, name, libraryItemNode); break; default: throw new ArgumentException("Invalid library item type received from server."); } return(new GetLibraryItemResultData(libraryItem)); }
public AddLibraryItemToPlaylistResultData Transform(string input) { JObject rootNode = JObject.Parse(input); bool result = rootNode["result"].ToObject <bool>(); if (!result) { return(new AddLibraryItemToPlaylistResultData(result, null)); } else { JObject libraryItemNode = rootNode["multimedia"] as JObject; long id = libraryItemNode["id"].ToObject <long>(); LibraryItemType type = LibraryItemTypeParser.Parse(libraryItemNode["type"].ToObject <string>()); if (type != LibraryItemType.Multimedia) { throw new ArgumentException("Only MULTIMEDIA type is supported for now."); } string name = libraryItemNode["name"].ToObject <string>(); int length = libraryItemNode["length"].ToObject <int>(); MultimediaItem multimedia = new MultimediaItem(id, name, length); return(new AddLibraryItemToPlaylistResultData(result, multimedia)); } }
private ILibraryItem CreateDirectory(long id, String name, JObject rootNode) { DirectoryItem directory = new DirectoryItem(id, name); foreach (JObject node in (rootNode["items"] as JArray)) { long itemId = node["id"].ToObject <long>(); LibraryItemType itemType = LibraryItemTypeParser.Parse(node["type"].ToObject <string>()); string itemName = node["name"].ToObject <string>(); GenericLibraryItem libraryItem = new GenericLibraryItem(itemId, itemType, itemName); directory.AddItem(libraryItem); } return(directory); }
public static ILibraryItem GetLibraryItem(LibraryItemType ItemType, string ItemName) { ILibraryItem libraryItem; switch (ItemType) { case LibraryItemType.Book: return(libraryItem = new Book(new Guid(), ItemName, DateTime.Now)); case LibraryItemType.Magzine: return(libraryItem = new Magzine(new Guid(), ItemName, DateTime.Now)); default: return(null); } }
public GenericLibraryItem(long id, LibraryItemType type, string name) { this.id = id; this.type = type; this.name = name; }