Ejemplo n.º 1
0
        /// <summary>
        /// Gets the version of the running tor application.
        /// </summary>
        /// <returns>A <see cref="Version"/> object instance containing the version.</returns>
        private Version PropertyGetVersion()
        {
            GetInfoCommand  command  = new GetInfoCommand("version");
            GetInfoResponse response = command.Dispatch(client);

            if (!response.Success)
            {
                return(new Version());
            }

            Regex pattern = new Regex(@"(?<major>\d{1,})\.(?<minor>\d{1,})\.(?<build>\d{1,})\.(?<revision>\d{1,})(?:$|\s)");
            Match match   = pattern.Match(response.Values[0]);

            if (match.Success)
            {
                return(new Version(
                           Convert.ToInt32(match.Groups["major"].Value),
                           Convert.ToInt32(match.Groups["minor"].Value),
                           Convert.ToInt32(match.Groups["build"].Value),
                           Convert.ToInt32(match.Groups["revision"].Value)
                           ));
            }

            return(new Version());
        }
Ejemplo n.º 2
0
 public void Initialise()
 {
     _command = new GetInfoCommand(MAuth.Object)
     {
         ArtistName = "Frightened Rabbit"
     };
 }
Ejemplo n.º 3
0
        public async Task HandleSuccessResponse()
        {
            //Arrange
            const string tagName = "disco";
            const string tagUri  = "http://www.last.fm/tag/disco";

            var command     = new GetInfoCommand(MAuth.Object, tagName);
            var expectedTag = new LastTag(tagName, tagUri)
            {
                Reach      = 34671,
                Count      = 172224,
                Streamable = true
            };


            //Act
            var response     = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetInfoSuccess));
            var lastResponse = await command.HandleResponse(response);

            var tag = lastResponse.Content;

            //Assert
            Assert.IsTrue(lastResponse.Success);
            Assert.AreEqual(expectedTag.Reach, tag.Reach);
            Assert.AreEqual(expectedTag.Name, tag.Name);
            Assert.AreEqual(expectedTag.Count, tag.Count);
            Assert.AreEqual(expectedTag.Streamable, tag.Streamable);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a country code for a router within the tor network. This method will not work unless a <c>geoip</c> and/or <c>geoip6</c> file has been supplied.
        /// </summary>
        /// <param name="router">The router to retrieve the country code for.</param>
        /// <returns>A <see cref="System.String"/> containing the country code; otherwise, <c>null</c> if the country code could not be resolved.</returns>
        public string GetCountryCode(Router router)
        {
            if (router == null)
            {
                throw new ArgumentNullException("router");
            }

            string address = router.IPAddress.ToString();

            GetInfoCommand  command  = new GetInfoCommand(string.Format("ip-to-country/{0}", address));
            GetInfoResponse response = command.Dispatch(client);

            if (response.Success)
            {
                string[] values = response.Values[0].Split(new[] { '=' }, 2);

                if (values.Length == 2)
                {
                    return(values[1].Trim());
                }

                return(values[0].Trim().ToUpper());
            }

            return(null);
        }
Ejemplo n.º 5
0
        public async Task HandleSuccessResponse()
        {
            //Arrange
            const string tagName = "disco";
            const string tagUri = "http://www.last.fm/tag/disco";

            var command = new GetInfoCommand(MAuth.Object, tagName);
            var expectedTag=new LastTag(tagName,tagUri)
            {
                Reach = 34671,
                Count = 172224,
                Streamable = true
            };


            //Act
            var response = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetInfoSuccess));
            var lastResponse = await command.HandleResponse(response);
            var tag = lastResponse.Content;

            //Assert
            Assert.IsTrue(lastResponse.Success);
            Assert.AreEqual(expectedTag.Reach,tag.Reach);
            Assert.AreEqual(expectedTag.Name, tag.Name);
            Assert.AreEqual(expectedTag.Count, tag.Count);
            Assert.AreEqual(expectedTag.Streamable, tag.Streamable);
        }
Ejemplo n.º 6
0
 public void Initialise()
 {
     _command = new GetInfoCommand(MAuth.Object)
     {
         ArtistName = "Frightened Rabbit"
     };
 }
Ejemplo n.º 7
0
        public async Task <LastResponse <LastUser> > GetInfoAsync(string username)
        {
            var command = new GetInfoCommand(Auth, username)
            {
                HttpClient = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get the metadata for a tag.
        /// </summary>
        public Task<LastResponse<LastTag>> GetInfoAsync(string tagName)
        {
            var command = new GetInfoCommand(Auth, tagName)
            {
                HttpClient = HttpClient
            };

            return command.ExecuteAsync();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get the metadata for a tag.
        /// </summary>
        public Task <LastResponse <LastTag> > GetInfoAsync(string tagName)
        {
            var command = new GetInfoCommand(Auth, tagName)
            {
                HttpClient = HttpClient
            };

            return(command.ExecuteAsync());
        }
Ejemplo n.º 10
0
        public async Task <LastResponse <LastTrack> > GetInfoByMbidAsync(string mbid)
        {
            var command = new GetInfoCommand(Auth)
            {
                TrackMbid  = mbid,
                HttpClient = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 11
0
        public async Task<LastResponse<LastTrack>> GetInfoByMbidAsync(string mbid)
        {
            var command = new GetInfoCommand(Auth)
            {
                TrackMbid = mbid,
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 12
0
        public GetAlbumInfoCommandTests()
        {
            _command = new GetInfoCommand(MAuth.Object)
            {
                AlbumName  = "Ray of Light",
                ArtistName = "Madonna"
            };

            _command.SetParameters();
        }
Ejemplo n.º 13
0
        public async Task <LastResponse <LastAlbum> > GetInfoAsync(string artistname, string albumname, bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth, albumname, artistname)
            {
                Autocorrect = autocorrect,
                HttpClient  = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 14
0
        public async Task<LastResponse<LastAlbum>> GetInfoAsync(string artistname, string albumname, bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth, albumname, artistname)
                          {
                              Autocorrect = autocorrect,
                              HttpClient = HttpClient
                          };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 15
0
        public GetAlbumInfoCommandTests()
        {
            _command = new GetInfoCommand(MAuth.Object)
            {
                AlbumName = "Ray of Light",
                ArtistName = "Madonna"
            };

            _command.SetParameters();
        }
Ejemplo n.º 16
0
        public async Task <LastResponse <LastAlbum> > GetInfoByMbidAsync(string albumMbid, bool autocorrect = false, string username = null)
        {
            var command = new GetInfoCommand(Auth)
            {
                AlbumMbid   = albumMbid,
                Autocorrect = autocorrect,
                HttpClient  = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 17
0
        public async Task HandleErrorResponse()
        {
            var command = new GetInfoCommand(MAuth.Object, "errorTag");

            var response = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetInfoError));

            var parsed = await command.HandleResponse(response);

            Assert.IsFalse(parsed.Success);
            Assert.IsTrue(parsed.Status == LastResponseStatus.MissingParameters);
        }
Ejemplo n.º 18
0
        public async Task HandleErrorResponse()
        {
            var command = new GetInfoCommand(MAuth.Object, "errorTag");

            var response = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetInfoError));

            var parsed = await command.HandleResponse(response);

            Assert.IsFalse(parsed.Success);
            Assert.IsTrue(parsed.Status == LastResponseStatus.MissingParameters);
        }
Ejemplo n.º 19
0
        public async Task<LastResponse<LastAlbum>> GetInfoByMbidAsync(string albumMbid, bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth)
            {
                AlbumMbid = albumMbid,
                Autocorrect = autocorrect,
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 20
0
        public async Task <LastResponse <LastArtist> > GetInfoByMbidAsync(string mbid, string bioLang = LastFm.DefaultLanguageCode, bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth)
            {
                ArtistMbid  = mbid,
                BioLanguage = bioLang,
                Autocorrect = autocorrect,
                HttpClient  = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 21
0
        public async Task<LastResponse<LastTrack>> GetInfoAsync(string trackname, string artistname, string username = "")
        {
            var command = new GetInfoCommand(Auth)
            {
                TrackName = trackname,
                ArtistName = artistname,
                Username = username,
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 22
0
        public async Task<LastResponse<LastArtist>> GetInfoByMbidAsync(string mbid, string bioLang = LastFm.DefaultLanguageCode, bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth)
            {
                ArtistMbid = mbid,
                BioLanguage = bioLang,
                Autocorrect = autocorrect,
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 23
0
        public async Task HandleSuccessResponseForUser()
        {
            _command = new GetInfoCommand(MAuth.Object)
            {
                AlbumName  = "Ray of Light",
                ArtistName = "Madonna",
                UserName   = "******"
            };

            var expectedAlbum = new LastAlbum
            {
                ArtistName     = "Madonna",
                ListenerCount  = 509271,
                PlayCount      = 7341494,
                UserPlayCount  = 321,
                Mbid           = "ddb3168d-66a9-4b2d-af02-05278da8a23d",
                Url            = new Uri("http://www.last.fm/music/Madonna/Ray+of+Light", UriKind.Absolute),
                Name           = "Ray of Light",
                ReleaseDateUtc = new DateTime(2005, 09, 13, 0, 0, 0),
                Id             = "1934",
                Images         = new LastImageSet(
                    "http://userserve-ak.last.fm/serve/34s/37498173.png",
                    "http://userserve-ak.last.fm/serve/64s/37498173.png",
                    "http://userserve-ak.last.fm/serve/174s/37498173.png",
                    "http://userserve-ak.last.fm/serve/300x300/37498173.png",
                    "http://userserve-ak.last.fm/serve/_/37498173/Ray+of+Light.png"),
                TopTags = new List <LastTag>
                {
                    new LastTag("albums i own", "http://www.last.fm/tag/albums%20i%20own"),
                    new LastTag("pop", "http://www.last.fm/tag/pop"),
                    new LastTag("electronic", "http://www.last.fm/tag/electronic"),
                    new LastTag("dance", "http://www.last.fm/tag/dance"),
                    new LastTag("madonna", "http://www.last.fm/tag/madonna")
                }
            };

            var file     = GetFileContents("AlbumApi.AlbumGetInfoForUser.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(AlbumApiResponses.AlbumGetInfoForUser));
            var parsed = await _command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);

            var actual = parsed.Content;

            Assert.IsTrue(actual.Tracks.Count() == 13);
            actual.Tracks = null;

            var expectedJson = JsonConvert.SerializeObject(expectedAlbum, Formatting.Indented);
            var actualJson   = JsonConvert.SerializeObject(parsed.Content, Formatting.Indented);

            Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson));
        }
Ejemplo n.º 24
0
        public async Task <LastResponse <LastTrack> > GetInfoByMbidAsync(string mbid, string username = "", bool autocorrect = false)
        {
            var command = new GetInfoCommand(Auth)
            {
                TrackMbid   = mbid,
                Username    = username,
                Autocorrect = autocorrect,
                HttpClient  = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 25
0
        public async Task <LastResponse <LastTrack> > GetInfoAsync(string trackname, string artistname, string username = "")
        {
            var command = new GetInfoCommand(Auth)
            {
                TrackName  = trackname,
                ArtistName = artistname,
                Username   = username,
                HttpClient = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Ejemplo n.º 26
0
        private async Task InitDevice()
        {
            using (MarkBusy())
            {
                if (SelectedDevice != null)
                {
                    await _teensyBatDevice.Connect(SelectedDevice);

                    GetInfoCommand command = new GetInfoCommand();
                    DeviceInfo = await command.Execute(_teensyBatDevice);
                }
            }
        }
        public void GetInfoRequest_Can_Be_Sent()
        {
            //Arrange
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode  = commandContext.GetConnectedNode(null);
            var command        = new GetInfoCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1", "-i", "true");

            //Assert
            var requestSent = TestCommandHelpers.GetRequest <GetInfoRequest>(connectedNode);

            requestSent.Should().BeOfType(typeof(GetInfoRequest));
        }
Ejemplo n.º 28
0
 private async void Refresh()
 {
     using (MarkBusy())
     {
         if (_teensyBatDevice != null && _teensyBatDevice.IsConnected)
         {
             GetInfoCommand command = new GetInfoCommand();
             DeviceInfo = await command.Execute(_teensyBatDevice);
         }
         else
         {
             await CheckForDevice();
         }
     }
 }
Ejemplo n.º 29
0
        public void ArtistGetInfo_SetLangParam_Success()
        {
            GetInfoCommand _command2 = new GetInfoCommand(MAuth.Object)
            {
                ArtistName  = "Frightened Rabbit",
                BioLanguage = "fr"
            };

            //call the commands SetParameter method - this is ususally done in Command.ExecuteAsync
            _command2.SetParameters();

            string langValue;

            Assert.IsTrue(_command2.Parameters.TryGetValue("lang", out langValue));
            Assert.AreEqual("fr", langValue);
        }
Ejemplo n.º 30
0
        public void GetInfoResponse_Can_Get_Output()
        {
            //Arrange
            var getInfoResponse = new GetInfoResponse {
                Query = "Test"
            };
            var commandContext = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getInfoCommand = new GetInfoCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, getInfoResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(getInfoResponse.ToJsonString());
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Gets a value indicating whether the tor software service is dormant.
        /// </summary>
        /// <returns><c>true</c> if the tor software service is dormant; otherwise, <c>false</c>.</returns>
        private bool PropertyGetIsDormant()
        {
            GetInfoCommand  command  = new GetInfoCommand("dormant");
            GetInfoResponse response = command.Dispatch(client);

            if (!response.Success)
            {
                return(false);
            }

            int value;

            if (!int.TryParse(response.Values[0], out value))
            {
                return(false);
            }

            return(value != 0);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Gets an approximation of the total bytes uploaded by the tor software.
        /// </summary>
        /// <returns>A <see cref="Bytes"/> object instance containing the estimated number of bytes.</returns>
        private Bytes PropertyGetTotalBytesUploaded()
        {
            GetInfoCommand  command  = new GetInfoCommand("traffic/written");
            GetInfoResponse response = command.Dispatch(client);

            if (!response.Success)
            {
                return(Bytes.Empty);
            }

            double value;

            if (!double.TryParse(response.Values[0], out value))
            {
                return(Bytes.Empty);
            }

            return(new Bytes(value).Normalize());
        }
Ejemplo n.º 33
0
        public async Task<LastResponse<LastUser>> GetInfoAsync(string username)
        {
            var command = new GetInfoCommand(Auth, username)
            {
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Ejemplo n.º 34
0
 private static extern int GetRawInputDeviceInfoW(
     [In, Optional] IntPtr devHandle,
     [In] GetInfoCommand command,
     [In, Out, MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 3), Optional] string data,
     [In, Out] ref int dataSize
     );