private static void GetSessionKey() { // try get the session key from the registry string sessionKey = GetRegistrySetting(sessionKeyRegistryKeyName, null); if (string.IsNullOrEmpty(sessionKey)) { // instantiate a new scrobbler int tried = 0; bool error = false; error = false; // Try get session key from Last.fm try { sessionKey = scrobbler.GetSession(); var user = scrobbler.GetSessionUser(); // successfully got a key. Save it to the registry for next time SetRegistrySetting(sessionKeyRegistryKeyName, sessionKey); SetRegistrySetting("ScrobblerUser", user); SetRegistrySetting("ScrobblerRealName", Services.User.GetRealName(user)); RaiseMySessionChangedEvent(); } catch (LastFmApiException exception) { error = true; } App.Current.Dispatcher.BeginInvoke(new Action(() => errormessage(!error))); } _scrobbler = new QueuingScrobbler(ApiKey, ApiSecret, sessionKey); }
private string GetSessionKey() { const string sessionKeyRegistryKeyName = "LastFmSessionKey"; // try get the session key from the registry string sessionKey = GetRegistrySetting(sessionKeyRegistryKeyName, null); if (string.IsNullOrEmpty(sessionKey)) { // instantiate a new scrobbler var scrobbler = new Scrobbler(apiKey, apiSecret); //NOTE: This is demo code. You would not normally do this in a production application while (string.IsNullOrEmpty(sessionKey)) { // Try get session key from Last.fm try { sessionKey = scrobbler.GetSession(); // successfully got a key. Save it to the registry for next time SetRegistrySetting(sessionKeyRegistryKeyName, sessionKey); } catch (LastFmApiException exception) { // get a url to authenticate this application string url = scrobbler.GetAuthorisationUri(); // open the URL in the default browser Process.Start(url); //Console.ReadKey(); } } } return(sessionKey); }
private string GetSessionKey() { const string sessionKeyRegistryKeyName = "LastFmSessionKey"; // try get the session key from the registry string sessionKey = GetRegistrySetting(sessionKeyRegistryKeyName, null); if (string.IsNullOrEmpty(sessionKey)) { // Try get session key from Last.fm try { sessionKey = scrobbler.GetSession(); // successfully got a key. Save it to the registry for next time SetRegistrySetting(sessionKeyRegistryKeyName, sessionKey); } catch (LastFmApiException exception) { // Wahrscheinlich nicht authorisiert. } } return(sessionKey); }
private Session GetSession() { // try get the session key from the registry Session session = new Session(); Properties.Settings.Default.Upgrade(); session.Key = Properties.Settings.Default.SessionKey; session.Username = Properties.Settings.Default.UserName; if (string.IsNullOrEmpty(session.Key) || string.IsNullOrEmpty(session.Username)) { // instantiate a new scrobbler var scrobbler = new Scrobbler(ApiKey, ApiSecret, new Session() { Key = session.Key }); //NOTE: This is demo code. You would not normally do this in a production application while (string.IsNullOrEmpty(session.Key) || string.IsNullOrEmpty(session.Username)) { // Try get session key from Last.fm try { session = scrobbler.GetSession(); // successfully got a key. Save it to the registry for next time Properties.Settings.Default.SessionKey = session.Key; Properties.Settings.Default.UserName = session.Username; Properties.Settings.Default.Save(); } catch (LastFmApiException) { // get session key from Last.fm failed //MessageBox.Show(exception.Message); if (MessageBox.Show( "Linear Audio Playerはlast.fmに対応しています。last.fmを使用しますか?\nはいを選択した場合はlast.fmのアカウントへの認証設定のページを開きます。", "use last.fm?", MessageBoxButtons.YesNo) == DialogResult.No) { return(null); } // get a url to authenticate this application string url = scrobbler.GetAuthorisationUri(); // open the URL in the default browser Process.Start(url); // Block this application while the user authenticates MessageBox.Show("ブラウザで許可したあとOKボタンをクリックしてください。"); } } } return(session); }
public void GetSession_UnAuthorisedToken_ThrowsException() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret); // Act string session = scrobbler.GetSession(); // Assert Assert.IsNotNull(session); }
public void GetSession_UnAuthorisedToken_ThrowsException() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret); // Act string session = scrobbler.GetSession(); // Assert Assert.IsNotNull(session); }
public void GetSession_AuthorisedToken_ReturnsSessionKey() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret); // break here and authorise via a browser string uri = scrobbler.GetAuthorisationUri(); // Act string session = scrobbler.GetSession(); // Assert Assert.IsNotNull(session); }
public void GetSession_AuthorisedToken_ReturnsSessionKey() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret); // break here and authorise via a browser string uri = scrobbler.GetAuthorisationUri(); // Act string session = scrobbler.GetSession(); // Assert Assert.IsNotNull(session); }
private string GetSessionKey() { LoadSettings(); // try get the session key from the registry string sessionKey = appSettings.Key; if (string.IsNullOrEmpty(sessionKey)) { // instantiate a new scrobbler var scrobbler = new Scrobbler(ApiKey, ApiSecret); //NOTE: This is demo code. You would not normally do this in a production application while (string.IsNullOrEmpty(sessionKey)) { // Try get session key from Last.fm try { sessionKey = scrobbler.GetSession(); // successfully got a key. Save it to the registry for next time appSettings.Key = sessionKey; SaveSettings(); //SetRegistrySetting(sessionKeyRegistryKeyName, sessionKey); } catch (LastFmApiException exception) { // get session key from Last.fm failed // Console.WriteLine(exception.Message); // get a url to authenticate this application string url = scrobbler.GetAuthorisationUri(); // open the URL in the default browser Process.Start(url); // To enable easy authorisation controlled by other application, this must be the first response. // An external application can check whether authentication is needed by checking first responce to the message below Console.WriteLine("[Authenticates] Press RETURN when application authenticated."); Console.ReadLine(); } } } return(sessionKey); }