Exemple #1
0
        private void searchTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                ClearAutocomplete();
                Filter();
            }
            else
            {
                var search = GetSearch();
                if (search != lastSearch)
                {
                    lastSearch = search;
                    //ClearAutocomplete();
                    if (!string.IsNullOrEmpty(lastSearch) && lastSearch.Length > 1)
                    {
                        var suggestions = trackController.Search(lastSearch).Take(maxSuggestions);
                        if (suggestions != null && !suggestions.SequenceEqual(autocompleteTracks))
                        {
                            ClearAutocomplete();
                            foreach (var suggestion in suggestions)
                            {
                                autocompleteTracks.Add(suggestion);
                            }
                        }
                    }
                    else
                    {
                        ClearAutocomplete();
                    }

                    RefreshAutocomplete();
                }
            }
        }
Exemple #2
0
        public void LoadDirectories(ISource source)
        {
            if (source.Children.Count() == 1)
            {
                //var proxy = source.Children.FirstOrDefault() as ProxySource;
                //if (proxy != null)
                //    source.RemoveChild(proxy);

                if (Directory.Exists(source.Path))
                {
                    var directory = new DirectoryInfo(source.Path);
                    foreach (var subDirectory in directory.GetDirectories())
                    {
                        var child = source.Children.Where(x => x.Path == subDirectory.FullName).FirstOrDefault();
                        if (child == null)
                        {
                            child = new DirectorySource()
                            {
                                Name = subDirectory.Name, Path = subDirectory.FullName, Parent = source
                            };
                            source.AddChild(child);
                        }
                        //LoadDirectories(child);
                    }
                    foreach (var file in directory.GetFiles("*.mp3"))
                    {
                        try
                        {
                            var track = trackController.Search(new Dictionary <string, object> {
                                { "Path", file.FullName }
                            }).FirstOrDefault();
                            if (track == null)
                            {
                                track = trackController.ReadFromTag(file.FullName);
                                trackController.Save(track);
                            }

                            var item = GetPlaylistItem(source, track);
                            source.AddChild(item);
                        }
                        catch (Exception ex)
                        {
                            log.Error("SourceController.LoadDirectories: Could not load MP3 file. path=" + file.FullName, ex);
                        }
                    }
                    foreach (var file in directory.GetFiles("*.wav"))
                    {
                        try
                        {
                            var track = trackController.Search(new Dictionary <string, object> {
                                { "Path", file.FullName }
                            }).FirstOrDefault();
                            if (track == null)
                            {
                                track = new OldTrack {
                                    Path = file.FullName, Title = file.Name
                                };
                                trackController.Save(track);
                            }

                            var item = GetPlaylistItem(source, track);
                            source.AddChild(item);
                        }
                        catch (Exception ex)
                        {
                            log.Error("SourceController.LoadDirectories: Could not load WAV file. path=" + file.FullName, ex);
                        }
                    }
                }
            }
        }