Exemple #1
0
 public async Task <JsonResult> GetSongs([FromUri] OnlineRadioServiceSearchModel inputParams)
 {
     return(new JsonResult
     {
         Data = await OnlineRadioService.Search(inputParams),
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
Exemple #2
0
 public async Task <JsonResult> GetTypeAhedResult([FromUri] OnlineRadioServiceSearchModel inputParams)
 {
     return(new JsonResult
     {
         Data = await OnlineRadioService.TypeAheadSearch(inputParams.Question),
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
        public async Task <GenericResult <IEnumerable <OnlineRadioServiceSongModel> > > Search(OnlineRadioServiceSearchModel searchModel)
        {
            var result = new GenericResult <IEnumerable <OnlineRadioServiceSongModel> >();

            try
            {
                var serverFactory = ParcerProviderFactory.GetFactory(DataSourceEnum.OnlineRadio);
                serverFactory.AddSearchCriteria(searchModel.Question);
                serverFactory.SetPageNumber(searchModel.PageNumber);

                var serverFactoryResult = await serverFactory.GetContent(new Uri(_onlineRadioSearchURl));

                if (serverFactoryResult != null && serverFactoryResult.Any())
                {
                    var allSong = new ConcurrentBag <OnlineRadioServiceSongModel>();
                    IEnumerable <SongsBlackList> songsBlackList;

                    using (var db = new RssAggregatorModelContainer())
                    {
                        songsBlackList = db.GetDBSet <SongsBlackList>(el => string.Compare(el.City, searchModel.City, true) == 0 && string.Compare(el.Country, searchModel.Country, true) == 0).ToList();
                    }

                    foreach (var postItem in serverFactoryResult)
                    {
                        foreach (var content in postItem.PostContent)
                        {
                            if (content.PostContentType == CORE.Models.Enums.PostContentTypeEnum.Audio)
                            {
                                Parallel.ForEach(((BasePostContentModel <AudioPostContentContainerModel>)content).PostSpecificContent, audioContent =>
                                {
                                    if (!string.IsNullOrEmpty(audioContent.Link))
                                    {
                                        using (var webClient = new WebClient())
                                        {
                                            var serverResult = webClient.DownloadString(string.Format("{0}/{1}", _onlineRadionBaseURL.TrimEnd(new[] { '/' }), audioContent.Link.TrimStart(new[] { '/' })));

                                            var serializedServerResult = JsonConvert.DeserializeObject <OnlineRadioServiceSongUrlJsonModel>(serverResult);
                                            if (serializedServerResult != null && !string.IsNullOrEmpty(serializedServerResult.url) && !songsBlackList.Any(el => el.SongURL == serializedServerResult.url))
                                            {
                                                allSong.Add(new OnlineRadioServiceSongModel
                                                {
                                                    Artist = audioContent.Artist,
                                                    Name   = audioContent.Name,
                                                    Link   = serializedServerResult.url
                                                });
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    }

                    result.SetDataResult(allSong);
                }
                else
                {
                    result.SetDataResult(Enumerable.Empty <OnlineRadioServiceSongModel>());
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, LogTypeEnum.BAL);
                result.SetErrorResultCode(SettingService.GetUserFriendlyExceptionMessage());
            }

            return(result);
        }