private void DownloadTabByType(TabulatureType type)
        {
            var destination = Guid.NewGuid().ToString();

            var searcher = new UltimateGuitarTabSearcher();
            var mre      = new ManualResetEvent(false);

            searcher.SearchComplete += (sender, args) =>
            {
                var entry = searcher.Entries.First();

                var downloader = new UltimateGuitarFileDownloader(entry, destination);
                downloader.DownloadComplete += (o, eventArgs) => mre.Set();
                downloader.Download();
            };

            searcher.Run(SearchContext.DefaulGroupName, SearchContext.DefaultSongName, 0, type, ResultsSortOrder.Alphabetical);

            mre.WaitOne(SearchContext.SearchTimeout);

            using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var file = storage.OpenFile(destination, FileMode.Open))
                {
                    Assert.AreNotEqual(0, file.Length);
                }
            }
        }
        private void DoDownloadTab(string arg)
        {
            downloadButtonClicked = true;

            if (IsDownloading)
            {
                Dialog.Show(AppResources.Search_DownloadFailed);
                return;
            }
            TabEntity tab;

            if (_sortOrder == ResultsSortOrder.Alphabetical)
            {
                tab = SearchGroupTabs.Tabs.FirstOrDefault(t => t.SearchId == arg);
            }
            else
            {
                tab = SearchPopularTabs.FirstOrDefault(t => t.SearchId == arg);
            }
            //TODO create converter
            var entry = new SearchTabResultEntry
            {
                Id   = tab.SearchId,
                Url  = tab.SearchUrl,
                Type = tab.Type
            };

            var filePath = TabFileStorage.CreateTabFilePath();

            // TODO Do not depend on implementation!
            // TODO examine IO errors
            var downloader = new UltimateGuitarFileDownloader(entry, filePath);

            downloader.DownloadComplete += delegate(object sender, DownloadCompletedEventArgs args)
            {
                if (args.HasErrors)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(
                        () => { IsDownloading = false; });
                }
                else
                {
                    DownloadTabComplete(tab, filePath);
                }
            };
            SearchInfoTextBlock = String.Format(AppResources.Search_Downloading, tab.Name);
            IsDownloading       = true;
            try
            {
                downloader.Download();
            }
            catch (Exception ex)
            {
                Dialog.Show(String.Format(AppResources.Search_Error, ex));
                IsDownloading = false;
            }
        }