Exemple #1
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _auth = new ApiClientConfig(configuration);
     _host = new HostConfig(configuration);
     _fh   = new ForwardedHeadersConfig(configuration);
 }
        public async Task <ActionResult> PauseCurrentTrack()
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser"));
                }

                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var tryPauseTrack = await _playerRepo.PauseCurrentPlayBack(client);

                var modelValues = await GetPrivateUserDefaultModel(client);

                _model = modelValues;

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH)); throw;
            }
        }
        public async Task <List <Deployment> > GetAsync(DeployOptions options)
        {
            var config      = new ApiClientConfig(options.ApiKey);
            var deployments = await _client.GetAsync <List <Deployment> >(config, ROUTE);

            deployments = deployments
                          .Filter(d => d.App, options.App)
                          .Filter(d => d.Environment, options.Environment)
                          .Filter(d => d.Version, options.Version);

            return(deployments);
        }
        public async Task CancelAsync(DeployOptions options)
        {
            var config  = new ApiClientConfig(options.ApiKey);
            var payload = new
            {
                version         = options.Version,
                appName         = options.App,
                environmentName = options.Environment
            };

            await _client.PostAsync(config, ROUTE + "/cancel", payload);
        }
        public async Task <ActionResult> Index(string playListId)
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser", "SpotifyUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser", "SpotifyUser"));
                }

                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var playList = await _playListRepo.GetPlayList(playListId, client);

                var playListModel = _mapper.Map <FullPlayListModel>(playList);


                foreach (var pList in playList.Tracks.Items.ToList())
                {
                    if (pList?.Track?.Type == ItemType.Track)
                    {
                        var trackModel = new PlayListTrackModel <FullTrackModel>
                        {
                            AddedAt = pList.AddedAt,
                            AddedBy = _mapper.Map <PublicUserModel>(pList.AddedBy),
                            IsLocal = pList.IsLocal,
                            Track   = _mapper.Map <FullTrackModel>(pList.Track)
                        };

                        playListModel.Tracks.Add(trackModel);
                    }
                }

                _model.PlayList = playListModel;

                return(View(_model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
        public async Task <ActionResult> Details(string artistId)
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser", "SpotifyUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser", "SpotifyUser"));
                }

                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var artistRes       = _artistRepo.GetArtist(artistId, client);
                var artistAlbums    = _artistRepo.GetArtistAlbums(artistId, client);
                var artistTopTracks = _artistRepo.GetArtistTopTracks(artistId, client);

                await Task.WhenAll(artistRes, artistAlbums, artistTopTracks);

                var artistmodel          = _mapper.Map <FullArtistModel>(artistRes.Result);
                var artistAlbumsModel    = _mapper.Map <List <SimpleAlbumModel> >(artistAlbums.Result);
                var artistTopTracksModel = _mapper.Map <List <FullTrackModel> >(artistTopTracks.Result);



                _model.ArtistModel =
                    artistmodel ?? new FullArtistModel();

                _model.ArtistAlbums =
                    artistAlbumsModel ?? new List <SimpleAlbumModel>();

                _model.ArtistTopTracks =
                    artistTopTracksModel ?? new List <FullTrackModel>();


                return(View(_model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
        public ActionResult LoginUser()
        {
            try
            {
                var urlRedirection = ApiClientConfig.GetRedirectionUriPath();

                return(Redirect(urlRedirection.ToString()));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
Exemple #8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            SimpleLogSettings.DefaultPrefix = "DemoLogApi";
            services.AddSingleton <ILogApi, LogApi>();

            #region only for test proxy client call!

            //todo with di
            var apiClientConfig = new ApiClientConfig()
            {
                FailTimeoutMilliseconds = 200,
                BaseUri = "http://localhost:10005/api/log"
            };
            var webApiHelper = WebApiHelper.Resolve();
            webApiHelper.LogMessage = true;

            var webApiHelperWrapper = WebApiHelperWrapper.Resolve();
            webApiHelperWrapper.TestConnectionGetApiUri = "http://localhost:10005/api/log/getDate";
            webApiHelperWrapper.TestTimeoutMilliseconds = apiClientConfig.FailTimeoutMilliseconds;

            services.AddSingleton(apiClientConfig);
            services.AddSingleton(webApiHelper);
            services.AddSingleton(webApiHelperWrapper);

            var logApiProxy = new LogApiProxy(webApiHelperWrapper, apiClientConfig);
            LogApiProxy.Resolve = () => logApiProxy;
            services.AddSingleton(logApiProxy);
            services.AddSingleton <ILogApiProxy>(logApiProxy);

            //var apiClientConfig = new ApiClientConfig()
            //{
            //    FailTimeoutMilliseconds = 200,
            //    BaseUri = "http://localhost:10005/api/log"
            //};
            //var webApiHelper = WebApiHelper.Resolve();
            //webApiHelper.LogMessage = true;
            //var simpleApiClient = new SimpleApiClient(webApiHelper, apiClientConfig);

            //var webApiProxySmartWrapper = SimpleApiClientSmartWrapper.Resolve();
            //webApiProxySmartWrapper.TestConnectionGetApiUri = "http://localhost:10005/api/log/getDate";
            //webApiProxySmartWrapper.TestTimeoutMilliseconds = apiClientConfig.FailTimeoutMilliseconds;
            //webApiProxySmartWrapper.Reset(simpleApiClient);

            //services.AddSingleton<ISimpleApiClient>(webApiProxySmartWrapper);

            #endregion
        }
 public async Task CompleteAsync(DeployOptions options)
 {
     var config  = new ApiClientConfig(options.ApiKey);
     var payload = new
     {
         name            = options.Name,
         uri             = options.Uri,
         branch          = options.Branch,
         commit          = options.Commit,
         version         = options.Version,
         appName         = options.App,
         environmentName = options.Environment
     };
     await _client.PostAsync(config, ROUTE + "/complete", payload);
 }
Exemple #10
0
        public async Task <ActionResult> CategoryPlayList
            (string categoryId)
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser", "SpotifyUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser", "SpotifyUser"));
                }


                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var categoryPlayLists = await _browseRepo
                                        .GetCategoryPlayLists(categoryId, client);

                var categoryPlayListsModel = _mapper
                                             .Map <List <SimplePlayListModel> >(categoryPlayLists);



                if (categoryPlayListsModel != null)
                {
                    _model.CategoryPlayLists = categoryPlayListsModel;
                }



                return(View(_model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
Exemple #11
0
        public async Task <ActionResult> GetSearchedValues
            (BrowseViewModel inputModel)
        {
            var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
            var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

            if (tokenGiven != null && tokenTimes != null)
            {
                if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                {
                    return(RedirectToAction("LoginUser", "SpotifyUser"));
                }
            }
            else
            {
                return(RedirectToAction("LoginUser", "SpotifyUser"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var searchRequestSpotify = _mapper.Map <SearchRequest>(inputModel.SearchModel);

                    client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                    var searchRes = await _browseRepo.GetSearchResult(searchRequestSpotify, client);

                    var searchResModel = _mapper.Map <SearchResponseModel>(searchRes);


                    _model.SearchResponseModel = searchResModel;



                    return(View(_model));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View(ERROR_MESSAGE_PATH));
                }
            }

            return(View(_model));
        }
        public async Task <ActionResult> GetPublicUserProfile(string userid)
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser"));
                }


                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var userProfile  = _userRepo.GetPublicUser(userid, client);
                var userPlayList = _userRepo.GetPublicUserPlayLists(userid, client);

                await Task.WhenAll(userProfile, userPlayList);

                var userProfileModel   = _mapper.Map <PublicUserModel>(userProfile.Result);
                var userPlayListsModel = _mapper.Map <List <SimplePlayListModel> >(userPlayList.Result);

                _userModel.UserModel           = userProfileModel;
                _userModel.UserPublicPlayLists = userPlayListsModel;


                return(View(_userModel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
        public async Task <ActionResult> Callback(string code)
        {
            try
            {
                var responseConfig = await ApiClientConfig.GetClientReponse(code);

                var tokenCookie = new HttpCookie("TokenGiven", responseConfig.AccessToken);
                var tokentime   = new HttpCookie("TokenTime", DateTime.Now.ToString());

                _cookiesManager.AddCookie(tokenCookie, Response);
                _cookiesManager.AddCookie(tokentime, Response);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
Exemple #14
0
        public async Task <ActionResult> Details(string trackId)
        {
            try
            {
                var tokenGiven = _cookiesManager.GetCookie("TokenGiven", Request);
                var tokenTimes = _cookiesManager.GetCookie("TokenTime", Request);

                if (tokenGiven != null && tokenTimes != null)
                {
                    if (ApiClientConfig.IsIfTokenExpired(Convert.ToDateTime(tokenTimes.Value), tokenGiven.Value))
                    {
                        return(RedirectToAction("LoginUser", "SpotifyUser"));
                    }
                }
                else
                {
                    return(RedirectToAction("LoginUser", "SpotifyUser"));
                }

                client = ApiClientConfig.GetClientInstance(tokenGiven.Value);

                var trackRes = await _trackrepo.GetTrack(trackId, client);

                var albumRes = await _trackrepo.GetTrackAlbum(trackRes.Album.Id, client);

                var trackmodel = _mapper.Map <FullTrackModel>(trackRes);
                var albumModel = _mapper.Map <FullAlbumModel>(albumRes);



                _model.AlbumModel = albumModel;
                _model.TrackModel = trackmodel;

                return(View(_model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(ERROR_MESSAGE_PATH));
            }
        }
Exemple #15
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _auth = new ApiClientConfig(configuration);
 }