示例#1
0
        public override void Download()
        {
            // NOTE ultimate guitar service prohibits unauthorized users to download raw gp files
            // By now, we are do not force users to create any accounts as there is another way to get gp-files
            // unfortunately, these files are json-serialized representation of gp, so we need to perform additional manipulations
            if (Entry.Type == "guitar pro")
            {
                GetGuitarProDownloadUrl(Entry.Id).ContinueWith(task =>
                {
                    var link = task.Result;
                    if (link != string.Empty)
                    {
                        GZipWebClient client = new GZipWebClient();

                        client.DownloadStringAsync(new Uri(link));
                        client.DownloadStringCompleted += (o, e) =>
                        {
                            // convert from json to guitar pro format
                            var songReader = new JsonSongReader(e.Result);
                            var song       = songReader.ReadSong();

                            var songWriter = new FifthGuitarProSongWriter(new BinaryWriter(GetOutputStream()));
                            songWriter.WriteSong(song);

                            InvokeDownloadComplete(new DownloadCompletedEventArgs(false));
                        };
                    }
                });
            }
            else
            {
                Download(WebRequest.Create(Entry.Url));
            }
        }
        public void CanParseDefault()
        {
            using (var stream = Application.GetResourceStream(new Uri("/PhoneGuitarTab.UnitTests;component/Resources/opeth_requiem.json",
                                                                      UriKind.Relative)).Stream)
            {
                using (var reader = new StreamReader(stream))
                {
                    var            tabContent = reader.ReadToEnd();
                    JsonSongReader jsonReader = new JsonSongReader(tabContent);

                    var song = jsonReader.ReadSong();

                    Assert.AreEqual(song.Artist, "Opeth");
                    Assert.AreEqual(song.Name, "Requiem");
                    Assert.AreEqual(song.Tracks.Count, 3);
                    Assert.AreEqual(song.Tracks.First().Name, "Acoustic Guitar I");
                    Assert.AreEqual(song.Tracks.First().Measures.Count, 32);
                }
            }
        }