示例#1
0
        /// <summary>
        /// Use to get the Token or renew it and return the TokenAccess
        /// </summary>
        /// <returns></returns>
        public async Task <string> GetTokenAccessAsync()
        {
            if (TokenLoaded == null || DateTime.Now >= DateExpireToken)
            {
                Debug.WriteLine(" ============================= On renouvelle le token ======================");
                this.TokenLoaded = await SpotifyConnection.GetToken_Async();
            }

            return(this.TokenLoaded.Access_token);
        }
    public static IEnumerable <Albums> GetAlbums()
    {
        int           CountPk      = 1;
        Random        random       = new Random(30);
        List <Albums> AlbumsEntity = new List <Albums>();

        SpotifyConnection sApi    = new SpotifyConnection();
        SpotifyEvents     sEvents = new SpotifyEvents(sApi.GetToken().Result);

        IDictionary <string, string> SpotifyAlbunsPOP = sEvents.GetAlbumsPerGenre("POP").Result;

        foreach (string key in SpotifyAlbunsPOP.Keys)
        {
            AlbumsEntity.Add(new Albums {
                AlbumsId = CountPk, Name = key, Artist = SpotifyAlbunsPOP[key], Genre = "POP", Price = (decimal)random.Next(15, 80)
            });
            CountPk++;
        }


        IDictionary <string, string> SpotifyAlbunsMPB = sEvents.GetAlbumsPerGenre("MPB").Result;

        foreach (string key in SpotifyAlbunsMPB.Keys)
        {
            AlbumsEntity.Add(new Albums {
                AlbumsId = CountPk, Name = key, Artist = SpotifyAlbunsMPB[key], Genre = "MPB", Price = (decimal)random.Next(15, 80)
            });
            CountPk++;
        }

        IDictionary <string, string> SpotifyAlbunsCLASSIC = sEvents.GetAlbumsPerGenre("CLASSIC").Result;

        foreach (string key in SpotifyAlbunsCLASSIC.Keys)
        {
            AlbumsEntity.Add(new Albums {
                AlbumsId = CountPk, Name = key, Artist = SpotifyAlbunsCLASSIC[key], Genre = "CLASSIC", Price = (decimal)random.Next(15, 80)
            });
            CountPk++;
        }

        IDictionary <string, string> SpotifyAlbunsROCK = sEvents.GetAlbumsPerGenre("ROCK").Result;

        foreach (string key in SpotifyAlbunsROCK.Keys)
        {
            AlbumsEntity.Add(new Albums {
                AlbumsId = CountPk, Name = key, Artist = SpotifyAlbunsROCK[key], Genre = "ROCK", Price = (decimal)random.Next(15, 80)
            });
            CountPk++;
        }

        return(AlbumsEntity);
    }
示例#3
0
        private ISpotify CreateConnection()
        {
            /* Check if username and password are set. */
            if (this.userName == null || this.password == null)
            {
                throw new Exception("Not logged in!");
            }

            /* Create a new connection. */
            SpotifyConnection connection = new SpotifyConnection();

            /* Try to login with given username and password. */
            connection.Login(this.userName, this.password);

            /* Add connection to pool. */
            this.connectionList.Add(connection);

            return(connection);
        }
示例#4
0
 public PlayerModule(SpotifyConnection spotifyConnection, PlayerStore playerStore, PlayerConnection playerConnection) : base("v1/player")
 {
     Get("token", _ => spotifyConnection.GetCurrentToken());
     Post("login", parameters =>
     {
         CredentialDto credentialDto = this.Bind <CredentialDto>();
         return(Response.AsJson(playerConnection.Login(credentialDto)));
     });
     Post("signup", parameters =>
     {
         SignUpDto signUpDto = this.Bind <SignUpDto>();
         return(Response.AsJson(playerConnection.SignUp(signUpDto)));
     });
     Get("info/{token}", parameters =>
     {
         Guid sessionToken = Guid.Parse(parameters.token);
         return(playerStore.GetProfilOf(sessionToken));
     });
 }
示例#5
0
 public HomeModule(SpotifyConnection spotifyConnection,
                   NapsterConnection napsterConnection,
                   YoutubeConnection youtubeConnection)
 {
     Get("/", _ => "Hello World!");
     Get("/ping", _ =>
     {
         if (spotifyConnection.Ping())
         {
             return(true);
         }
         return(false);
     });
     Post("/connect", async _ =>
     {
         SpotifySecrets spotifySecret  = this.Bind <SpotifySecrets>();
         NapsterSecrets napsterSecrets = this.Bind <NapsterSecrets>();
         YoutubeSecrets youtubeSecrets = this.Bind <YoutubeSecrets>();
         spotifyConnection.AddAndUseSecret(spotifySecret);
         youtubeConnection.AddAndUseSecret(youtubeSecrets);
         return(await spotifyConnection.Connect());
     });
 }
示例#6
0
 public void Test1()
 {
     SpotifyConnection connection = new SpotifyConnection();
 }