public GenericResult <IEnumerable <NewsModel> > GetNews(int pageSize, int pageNumber, bool hideAdult) { var result = new GenericResult <IEnumerable <NewsModel> >(); try { if (pageSize > 0 && pageNumber > 0) { using (var db = new RssAggregatorModelContainer()) { result.SetDataResult(db.GetDBSet <News>(el => el.IsActive) .OrderBy(el => el.Id) .Skip(pageSize * (pageNumber - 1)) .Take(pageSize) .ToList() .Select(el => el.GetModel()) .ToList()); } } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.BAL); result.SetErrorResultCode(SettingService.GetUserFriendlyExceptionMessage()); } return(result); }
public GenericResult <IEnumerable <KeyValuePair <string, int> > > GetAllNewsTags() { var result = new GenericResult <IEnumerable <KeyValuePair <string, int> > >(); try { using (var db = new RssAggregatorModelContainer()) { result.SetDataResult(db.GetDBSet <News>(el => el.IsActive) .Select(el => el.PostTags) .ToList() .AsParallel() .SelectMany(el => el.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) .GroupBy(el => el) .ToDictionary(el => el.Key, el => el.Count())); } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.BAL); result.SetErrorResultCode(SettingService.GetUserFriendlyExceptionMessage()); } return(result); }
public GenericResult <IDictionary <string, string> > GetAllUISettings() { var result = new GenericResult <IDictionary <string, string> >(); try { using (var db = new RssAggregatorModelContainer()) { result.SetDataResult(db.GetDBSet <Settings>(el => el.ForUI).ToDictionary(el => el.Key, el => el.Value)); } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.BAL); } return(result); }
public GenericResult <IEnumerable <TemplateModel> > GetAllUserTemplates() { var result = new GenericResult <IEnumerable <TemplateModel> >(); try { using (var db = new RssAggregatorModelContainer()) { result.SetDataResult(db.GetDBSet <Template>(el => el.Type == TemplateTypeEnum.Header || el.Type == TemplateTypeEnum.Post) .ToList() .Select(el => el.GetModel())); } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.BAL); result.SetErrorResultCode(SettingService.GetUserFriendlyExceptionMessage()); } return(result); }
static ParcerProviderFactory() { using (var db = new RssAggregatorModelContainer()) { foreach (var dataSource in db.GetDBSet <DataSources>()) { if (!string.IsNullOrEmpty(dataSource.XMLGuide)) { try { var xmlGuide = XDocument.Parse(dataSource.XMLGuide); switch (dataSource.Type) { case DataSourceEnum.VK: AddFactory(dataSource.Type, typeof(VKResourceParcer), new object [] { xmlGuide, dataSource.BaseUri }); break; case DataSourceEnum.Pikabu: AddFactory(dataSource.Type, typeof(PikabuResourceParcer), new object [] { xmlGuide, dataSource.BaseUri }); break; case DataSourceEnum.Mainfun: AddFactory(dataSource.Type, typeof(MainfunResourceParcer), new object [] { xmlGuide, dataSource.BaseUri }); break; case DataSourceEnum.OnlineRadio: AddFactory(dataSource.Type, typeof(ZaycevResourceParcer), new object [] { xmlGuide, dataSource.BaseUri }); break; } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.CORE, "ParcerProviderFactory initialization failed"); } } } } }
public GenericResult <IEnumerable <NavigationModel> > GetNavigationData() { var result = new GenericResult <IEnumerable <NavigationModel> >(); try { using (var db = new RssAggregatorModelContainer()) { result.SetDataResult(db.GetDBSet <Navigation>(el => el.IsActive) .OrderBy(el => el.OrderNo) .ToList() .Select(el => el.GetModel()) .ToList()); } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.BAL); result.SetErrorResultCode(SettingService.GetUserFriendlyExceptionMessage()); } return(result); }
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); }
public void ProcessAllActiveDataSources() { using (var db = new RssAggregatorModelContainer(true)) { if (_systemTemplates == null) { _systemTemplates = db.GetDBSet <Template>(el => el.Type == TemplateTypeEnum.System && el.Version == null).ToList(); } var user = db.GetSystemUser; var systemDataSource = db.GetEntity <DataSources>(el => el.Type == DataSourceEnum.System); foreach (var dataSource in db.GetDBSet <DataSources>(el => el.IsActive && el.IsNewsSource)) { try { var expectedFactory = ParcerProviderFactory.GetFactory(dataSource.Type); var contetn = expectedFactory.GetContent(new Uri(dataSource.Uri)); contetn.Wait(); foreach (var post in contetn.Result) { if (post.PostContent.Any()) { try { var postStringContetnt = new List <string>(); var postId = db.GetPostTransliteratedName(db.GetTransliteration(post.PostId), user.Name); var newPost = new News() { PostId = postId, AuthorName = post.AuthorName, AuthorId = post.AuthorId, AuthorLink = string.Format("{0}/{1}", dataSource.BaseUri.TrimEnd(new[] { '/' }), post.AuthorLink.TrimStart(new[] { '/' })), PostLikes = post.PostLikes, PostName = post.PostName, PostLink = null,//postId, PostTags = post.PostTags.Aggregate(string.Empty, (agg, el) => agg + ", " + el).TrimStart(new[] { ',', ' ' }), External = true, IsActive = true, AdultContent = false, DataSource = dataSource, CreationDateTime = DateTime.UtcNow, ModificationDateTime = DateTime.UtcNow, User = user, Location = dataSource.Location }; foreach (var postContent in post.PostContent.OrderBy(el => el.PostOrder)) { switch (postContent.PostContentType) { case PostContentTypeEnum.Text: var textPostContainer = _systemTemplates.First(el => el.Name.ToLower() == TEXT_TEMPLATE_NAME.ToLower()); foreach (var el in postContent.PostContent) { postStringContetnt.Add(textPostContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, el)); } break; case PostContentTypeEnum.Img: if (postContent.PostContent.Any()) { var imgPostContainer = _systemTemplates.First(el => el.Name.ToLower() == IMG_TEMPLATE_NAME.ToLower()); var imgGalleryContainer = _systemTemplates.First(el => el.Name.ToLower() == IMG_GALLERY_TEMPLATE_NAME.ToLower()); var imgPostContainers = string.Empty; foreach (var el in postContent.PostContent) { imgPostContainers += imgPostContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, el); } postStringContetnt.Add(imgGalleryContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, imgPostContainers)); } break; case PostContentTypeEnum.Audio: var audioPostContainer = _systemTemplates.First(el => el.Name.ToLower() == AUDIO_TEMPLATE_NAME.ToLower()); foreach (var el in ((BasePostContentModel <AudioPostContentContainerModel>)postContent).PostSpecificContent) { postStringContetnt.Add(audioPostContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, el.Link) .Replace(CONTENT_MEDIA_NAME_PLACEHOLDER, el.Name) .Replace(CONTENT_MEDIA_AUTHOR_PLACEHOLDER, el.Artist)); } break; case PostContentTypeEnum.Video: if (postContent.PostContent.Any()) { var videoPostContainer = _systemTemplates.First(el => el.Name.ToLower() == VIDEO_TEMPLATE_NAME.ToLower()); var videoGalleryContainer = _systemTemplates.First(el => el.Name.ToLower() == VIDEO_GALLERY_TEMPLATE_NAME.ToLower()); var videoPostContainers = string.Empty; foreach (var el in ((BasePostContentModel <VideoPostContentContainerModel>)postContent).PostSpecificContent) { videoPostContainers += videoPostContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, el.Data) .Replace(CONTENT_MEDIA_NAME_PLACEHOLDER, el.Name) .Replace(CONTENT_MEDIA_PREVIEW_PLACEHOLDER, el.ImagePreviewLink); } postStringContetnt.Add(videoGalleryContainer.View.Replace(CONTENT_VALUE_PLACEHOLDER, videoPostContainers)); } break; } newPost.PostTags += string.Format(", {0}", db.GetTagName((TagTypeEnum)postContent.PostContentType, newPost.Location)); } newPost.PostContent = postStringContetnt.Aggregate(string.Empty, (agg, el) => agg + '\n' + el); db.AddEntity(newPost); } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.CORE, string.Format("DataSourceProcessing for {0} factory failed to process post: {1}", dataSource.Type, post.PostId)); } } else { Logger.LogException(string.Format("DataSourceProcessing for {0} factory has empty content for the post: {1}", dataSource.Type, post.PostId), LogTypeEnum.CORE); } } if (dataSource.PostAmountPerIteration.HasValue) { if (contetn.Result.Count() != dataSource.PostAmountPerIteration.Value) { Logger.LogException(string.Format("DataSourceProcessing for {0} factory returned incorrect expected amount of post, expected {1}, got {2}", dataSource.Type, dataSource.PostAmountPerIteration.Value, contetn.Result.Count()), LogTypeEnum.CORE); } } } catch (Exception ex) { Logger.LogException(ex, LogTypeEnum.CORE, string.Format("DataSourceProcessing for {0} factory failed", dataSource.Type)); } } } }