예제 #1
0
        public async Task <IEnumerable <Tonie> > GetTonies()
        {
            if (tonies == null)
            {
                tonieCloudService.RefreshCreativeTonies();

                var cts = await tonieCloudService.GetCreativeTonies();

                var mappings = await repositoryService.GetMappings();

                tonies = cts
                         .Select(t => new Tonie
                {
                    Id               = t.Id,
                    ImageUrl         = t.ImageUrl,
                    Name             = t.Name,
                    CurrentMediaPath = mappings.FirstOrDefault(m => m.TonieId == t.Id)?.Path
                })
                         .ToArray();
            }

            return(tonies);
        }
        public async Task <IEnumerable <MediaItem> > GetItems(string path)
        {
            var fullpath = settings.LibraryRoot + path;
            var mappings = await repositoryService.GetMappings();

            var directoryTasks = Directory.GetDirectories(fullpath)
                                 .Where(p => !settings.IgnoreFolderNames.Contains(Path.GetFileName(p), StringComparer.OrdinalIgnoreCase))
                                 .Where(p => !File.Exists(Path.Combine(p, settings.MarkFolderAsHiddenFile)))
                                 .Select(async subfullpath =>
            {
                var subpath   = path + "/" + Path.GetFileName(subfullpath);
                var childs    = await GetItems(subpath);
                var hasChilds = childs.Any();

                return(new MediaItem
                {
                    Path = subpath,
                    Name = Path.GetFileName(subfullpath),
                    MappedTonieIds = hasChilds
                            ? Enumerable.Empty <string>()
                            : mappings.Where(m => m.Path == subpath).Select(m => m.TonieId).ToArray(),
                    HasBought = settings.EnableShop
                            ? hasChilds
                                ? childs.Any(sub => sub.HasBought)
                                : File.Exists(subfullpath + "/" + settings.MarkFolderAsBoughtFile)
                            : true,
                    Childs = childs
                });
            });

            var directory = (await Task.WhenAll(directoryTasks))
                            .OrderBy(p => p.Name)
                            .ToArray();

            return(directory);
        }