Ejemplo n.º 1
0
        public async Task PerformAutoImport()
        {
            if (App.Config.AutoImportPaths.Count <= 0)
            {
                return;                                        // not really needed but prevents going through unneeded
            }
            // effort (and showing the notification)
            var notification = new Notification {
                ContentText = Properties.Resources.NOTIFICATION_SCANNING
            };

            NotificationHandler.Add(notification);
            var filesToImport = new List <string>();
            var library       = Library.Read();
            await Task.Run(() =>
            {
                foreach (var folder in App.Config.AutoImportPaths)
                {
                    var files = Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories)
                                .Where(name => name.EndsWith(".mp3") ||
                                       name.EndsWith(".wav") || name.EndsWith(".m4a") || name.EndsWith(".ogg") ||
                                       name.EndsWith(".flac") || name.EndsWith(".aiff") ||
                                       name.EndsWith(".wma") ||
                                       name.EndsWith(".aac")).ToArray();
                    foreach (var file in files)
                    {
                        if (!library.Select(x => x.Path).Contains(file))
                        {
                            filesToImport.Add(file);
                        }
                    }
                }
                Library.Import(filesToImport);
            });

            NotificationHandler.Remove(notification);
        }