using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Web; using AutoMapper; using DR.AcCommonUI.Models; using DR.FV2016.Service.Helpers; using DR.FV2016.Service.Models; using DR.FV2016.Service.Models.Results; using DR.FV2016.Web.Models; using DR.FV2016.Web.Models.Candidate; using DR.FV2016.Web.Models.CandidateList; using DR.FV2016.Web.Models.Match; using DR.Redesign.Configuration.Service; using DR.Redesign.Configuration.Service.Contract; using DR.Redesign.Configuration.Service.Model; using DR.Redesign.Data.Services.Share.Repository.Contract; using DR.Redesign.Data.Services.Share.Repository.Model; using DR.Redesign.PsdbService.Service.Contract; using DR.Redesign.PsdbService.Service.Model; using DR.WCMS.Web.Mvc.IO.Contract; using DR.WCMS.Web.UIBindings.Extensions; using DR.Web.UI.Model; using DR.Web.UI.Model.ArticleComponents; using DR.Web.UI.Model.Navigation; using DRCMSRedesign.Contracts; using StructureMap; namespace DR.FV2016.Web { public static class AutoMapperInit { private static ArticleWrapper agentContent; //private static readonly string priorityAndLatestAgent = "index.htm";// ConfigurationManager.AppSettings["PriorityAndLatestAgentUrl"]; //private static readonly string priorityAndLatestAgentOverview = "index.htm";//ConfigurationManager.AppSettings["PriorityAndLatestAgentUrlOverview"]; //private static readonly string mostReadAgent = "index.htm";//ConfigurationManager.AppSettings["MostReadAgentUrl"]; //private static readonly string focusBands = "index.htm";//ConfigurationManager.AppSettings["FocusBandsUrl"]; //private static readonly string mediaBands = "index.htm";//ConfigurationManager.AppSettings["MediaBandsUrl"]; private static readonly string TvBaseUrl = GetPsdbBaseUrl("TvSpotBaseUrl"); private static readonly string RadioBaseUrl = GetPsdbBaseUrl("RadioSpotBaseUrl"); public static void Start() { var navigationBarService = ObjectFactory.GetInstance(); Mapper.CreateMap(); Mapper.CreateMap() .ForMember(a => a.PartyId, b => b.MapFrom(c => c.Id)) .ForMember(a => a.PartyLetter, b => b.MapFrom(c => c.Letter)) .ForMember(a => a.PartyName, b => b.MapFrom(c => c.Name)) ; Mapper.CreateMap() .ForMember(a => a.id, b => b.MapFrom(c => c.Id)) .ForMember(a => a.n, b => b.MapFrom(c => c.Name)) .ForMember(a => a.s, b => b.MapFrom(c => c.Name.UrlFriendly())) .ForMember(a => a.img, b => b.MapFrom(c => c.ImageFileName)) .ForMember(a => a.l, b => b.MapFrom(c => c.Party.Letter)) ; Mapper.CreateMap() .ForMember(a => a.id, b => b.MapFrom(c => c.Id)) .ForMember(a => a.n, b => b.MapFrom(c => c.Name)) .ForMember(a => a.u, b => b.MapFrom(c => c.CandidatePageUrl)) .ForMember(a => a.img, b => b.MapFrom(c => NotSoTinyCandidateImageUrl(c))) .ForMember(a => a.l, b => b.MapFrom(c => c.Party.Letter)) ; Mapper.CreateMap() .ForMember(a => a.Headline, b => b.MapFrom(c => c.Name)) .ForMember(a => a.Url, b => b.MapFrom(c => c.CandidatePageUrl)) .ForMember(a => a.CandidateId, b => b.MapFrom(c => c.Id)) .ForMember(a => a.CandidateName, b => b.MapFrom(c => c.Name)) .ForMember(a => a.CandidateImageUrl, b => b.MapFrom(c => c.ImageUrl)) .ForMember(a => a.CandidatePageUrl, b => b.MapFrom(c => c.CandidatePageUrl)) .ForMember(a => a.CandidateIsRerun, b => b.MapFrom(c => c.IsRerun)) .ForMember(a => a.PartyLetterUrlFriendly, b => b.MapFrom(c => c.Party.Letter.UrlFriendly())) .ForMember(a => a.PartyLetter, b => b.MapFrom(c => c.Party.Letter)) .ForMember(a => a.PartyName, b => b.MapFrom(c => c.Party.Name)) .ForMember(a => a.Votes, b => b.MapFrom(c => c.Votes)) .ForMember(a => a.MatchResult, b => b.MapFrom(c => c.MatchResult)) .ForMember(a => a.HasAnswered, b => b.MapFrom(c => c.AnswerString != null)); Mapper.CreateMap() .ForMember(a => a.Id, b => b.MapFrom(c => c.Id)) .ForMember(a => a.Type, b => b.Ignore()) .ForMember(a => a.Word, b => b.MapFrom(c => c.Name)); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() ; Mapper.CreateMap() .ForMember(a => a.Video, b => b.Ignore()) .ForMember(a => a.Fullname, b => b.MapFrom(c => c.Name)) .ForMember(a => a.Name, b => b.MapFrom(c => c.Name)) .ForMember(a => a.NameSlug, b => b.MapFrom(c => c.Name.UrlFriendly())) .ForMember(a => a.PageTitle, b => b.MapFrom(c => string.Format("{0} - {1}", c.Name, c.Party.Name))) .ForMember(a => a.ProfileViewModel, b => b.MapFrom(c => MapProfileViewModel(c))) .ForMember(a => a.SocialMediaSitesViewModel, b => b.MapFrom(c => MapSocialMediaSitesViewModel(c))) .ForMember(a => a.FactViewModel, b => b.MapFrom(c => MapFactViewModel(c))) .ForMember(a => a.PartyArticleViewModel, b => b.MapFrom(c => MapPartyArticleViewModel(c))) .ForMember(a => a.MainPointsViewModel, b => b.MapFrom(c => MapMainPointsViewModel(c))) ; Mapper.CreateMap(); Mapper.CreateMap() .ForMember(a => a.RenderMandateView, b => b.MapFrom(c => c.AreaType <= AreaType.Storkreds)) ; Mapper.CreateMap(); Mapper.CreateMap(); Mapper.CreateMap() .InheritMappingFromDestinationBaseType(); Mapper.CreateMap() .InheritMappingFromDestinationBaseType(); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.PageTitle, b => b.UseValue("Kandidat-testen")); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.PageTitle, b => b.UseValue("Resultat")); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.PageTitle, b => b.UseValue("Se din stemmeseddel")); Mapper.CreateMap(); Mapper.CreateMap() .ForMember(a => a.Constituency, b => b.Ignore()); Mapper.CreateMap() .ForMember(a => a.Constituency, b => b.Ignore()); Mapper.CreateMap() .ForMember(a => a.Match, b => b.Ignore()); Mapper.CreateMap() .BeforeMap((articleWrapper, viewBase) => SEOfyArticleWrapper(articleWrapper)) .ForMember(a => a.IsFrontPage, b => b.UseValue(false)) .ForMember(a => a.OverwrittenTitleSiteName, b => b.UseValue("Valg 2016")) .ForMember(a => a.SiteName, b => b.UseValue("Valg 2016")) .ForMember(a => a.IsResponsive, b => b.UseValue(true)) .ForMember(a => a.NavigationBarItems, b => b.TryMapFrom(a => navigationBarService.GetNavigationBarItems("fv2016").SetActive(SetCurrentPath(a)))) .ForMember(a => a.SiteRootRelativeUrl, b => b.UseValue("/nyheder/politik/valg2016")); Mapper.CreateMap() .InheritMappingFromDestinationBaseType(); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.IsResponsive, b => b.UseValue(false)) .ForMember(a => a.PrioritizedNews, b => b.MapFrom(c => c.Agents.GetAgent("fv_prioritized_news"))) .ForMember(a => a.RightColumnLatestNews, b => b.MapFrom(c => c.Agents.GetAgent("fv_latest_news").Limit(25))) .ForMember(a => a.RightColumnPrioritized, b => b.MapFrom(c => c.Agents.GetAgent("fv_prioritized_news"))) .ForMember(a => a.LatestNews, b => b.MapFrom(c => c.Agents.GetAgent("fv_latest_news").Limit(15))) //.ForMember(a => a.MostReadLastWeek, b => b.MapFrom(c => AgentHelper.GetAgentFromCms("fv_mest_laeste_uge", mostReadAgent).Limit(5))) //.ForMember(a => a.MostRead24Hour, b => b.MapFrom(c => AgentHelper.GetAgentFromCms("fv_mest_laeste_24t", mostReadAgent).Limit(5))) //.ForMember(a => a.TopShared, b => b.MapFrom(c => GetSharedItems(5))) .ForMember(a => a.OverviewRecentNews, b => b.MapFrom(c => c.Agents.GetAgent("2012nytdesign_seneste").Limit(14))) .ForMember(a => a.OverviewPrioritizedNews, b => b.MapFrom(c => c.Agents.GetAgent("2012nytdesign_prioriterede"))) .ForMember(a => a.CurrentTopics, b => b.MapFrom(c => c.Agents.GetAgent("2012nytdesign_vi_foelger"))) ; Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.MediaBands, b => b.MapFrom(c => c.Agents.GetAgent(("media_band")))) .ForMember(a => a.SlideShow, b => b.MapFrom(c => c.SlideShow)) .ForMember(a => a.Focusbands, b => b.MapFrom(c => c.Agents.GetAgent("fv_focusbands"))) ; Mapper.CreateMap() .InheritMappingFromDestinationBaseType() ; Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.PageTitle, b => b.UseValue("Kandidat")); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.RightColumnLatestNews, b => b.MapFrom(c => c.Agents.GetAgent("fv_latest_news").Limit(10))) .ForMember(a => a.RightColumnPrioritized, b => b.MapFrom(c => c.Agents.GetAgent("fv_prioritized_news"))) .ForMember(a => a.SpecialContent, b => b.MapFrom(c => GetFullWidthUrl(c))) .ForMember(a => a.Video, b => b.TryMapFrom(c => PsdbItems(MediaType.Tv))) .ForMember(a => a.Audio, b => b.TryMapFrom(c => PsdbItems(MediaType.Radio))) .ForMember(a => a.StaticFactBox, b => b.MapFrom(c => GetStaticFactBox(c.Agents.GetAgent("facta_analytiker")))) .ForMember(a => a.ProfileUrl, b => b.MapFrom(c => GetProfileUrl(c.Agents.GetAgent("analytiker_profil")))) .ForMember(a => a.FactBoxRelatedContent, b => b.MapFrom(c => c.Agents.GetAgent("seneste_analytiker"))); Mapper.CreateMap() .InheritMappingFromDestinationBaseType() .ForMember(a => a.RelatedVideoArticleList1, b => b.MapFrom(c => c.Agents.GetAgent("video_liste1"))) .ForMember(a => a.RelatedVideoArticleList2, b => b.MapFrom(c => c.Agents.GetAgent("video_liste2"))) // .AutoMapAgents() ; Mapper.CreateMap() .ForMember(a => a.DisplayName, b => b.MapFrom(c => c.DisplayName)) .ForMember(a => a.Path, b => b.MapFrom(c => c.Path)); Mapper.CreateMap() .ForMember(a => a.Headline, b => b.MapFrom(c => c.Title)) .ForMember(a => a.WideAspectImage, b => b.MapFrom(c => new ImageInfo { ImageUrl = c.ImageUrl })) .ForMember(a => a.Published, b => b.MapFrom(c => c.BroadcastTime)) .ForMember(a => a.Url, b => b.MapFrom(c => c.MediaType == MediaType.Tv ? TvBaseUrl + string.Format("{0}/{1}", c.ProgramSeriesSlug, c.Slug) : RadioBaseUrl + c.Slug)) .ForMember(a => a.MediaLinks, b => b.MapFrom(c => new List { new DR.Web.UI.Model.MediaLink { Url = c.ResourceHandlerUri } })) .ForMember(a => a.BroadcastTime, b => b.MapFrom(c => c.BroadcastTime)); Mapper.CreateMap() .ForMember(a => a.Headline, b => b.MapFrom(c => HttpUtility.HtmlDecode(c.Title))) .ForMember(a => a.Published, b => b.MapFrom(c => c.Published)) .ForMember(a => a.WideAspectImage, b => b.MapFrom(c => new ImageInfo { ImageUrl = c.TeaserImageUrl })) .ForMember(a => a.Url, b => b.MapFrom(c => c.Url)); Mapper.CreateMap() .InheritMappingFromDestinationBaseType(); Mapper.CreateMap() .InheritMappingFromDestinationBaseType(); Mapper.CreateMap() .ForMember(a => a.ReadMoreLink, b => b.UseValue(new Link { LinkText = "Seneste billedserier", AltText = "Seneste billedserier", Url = "/Nyheder/Billedserier" })); } private static readonly string ImageScaler = ConfigurationManager.AppSettings["NewImageScaler"]; private static string GetProfileUrl(Agent agent) { var posting = agent.Postings.FirstOrDefault(); if (posting == null || string.IsNullOrEmpty((posting.Url))) return string.Empty; return "http://www.dr.dk" + posting.Url; } private static FactBox GetStaticFactBox(Agent agent) { var firstPosting = agent.Postings.FirstOrDefault(); if (firstPosting == null || string.IsNullOrEmpty(firstPosting.Url)) return null; //get webcms base url var webcmsBaseUrl = ConfigurationManager.AppSettings["WebCmsBaseUrl"]; if (string.IsNullOrEmpty(webcmsBaseUrl)) throw new ConfigurationErrorsException("Web.Config doesn't contain the key WebCmsUrl, please fix."); var factBoxUrl = webcmsBaseUrl + firstPosting.Url + "?getdata=json&noagents=true"; var articleWrapperService = ObjectFactory.GetInstance(); var articleWrapper = articleWrapperService.GetArticleWrapper(factBoxUrl); var viewBase = Mapper.Map(articleWrapper); var factBox = viewBase.Article.ArticleBodyComponents.FirstOrDefault(x => x is FactBox); return factBox as FactBox; } private static ArticleList PsdbItems(MediaType type) { try { var psdbService = ObjectFactory.GetInstance(); var psdbItems = Enumerable.Empty(); var tvSpotListSlug = ConfigurationManager.AppSettings["TvSpotListSlug"]; if (string.IsNullOrEmpty(tvSpotListSlug)) throw new ConfigurationErrorsException("The key TvSpotListSlug is now set in web.config!"); var radioSpotListSlug = ConfigurationManager.AppSettings["RadioSpotListSlug"]; if (string.IsNullOrEmpty(radioSpotListSlug)) throw new ConfigurationErrorsException("The key RadioSpotListSlug is now set in web.config!"); psdbItems = type == MediaType.Tv ? psdbService.GetTvSpots(tvSpotListSlug) : psdbService.GetRadioSpots(radioSpotListSlug); return new ArticleList { Headline = type == MediaType.Tv ? "Politik i tv" : "Politik i radio", Items = Mapper.Map>(psdbItems) }; } catch { return new ArticleList { Headline = type == MediaType.Tv ? "Politik i tv" : "Politik i radio" }; } } private static SpecialContent GetFullWidthUrl(ArticleWrapper articleWrapper) { var configurationService = ObjectFactory.GetInstance(); var content = new SpecialContent(); if (configurationService == null) throw new KeyNotFoundException("Couldn't retrieve an instance of IConfigurationService, check your structuremap config! Or something."); if (articleWrapper == null) throw new ArgumentNullException("articleWrapper"); try { var fullwidthItems = configurationService.GetFullWidthUrls("politik").ToList(); if (!fullwidthItems.Any()) throw new KeyNotFoundException("Couldn't find any fullwidthItems"); var currentUrlArray = (!string.IsNullOrEmpty(articleWrapper.Path) ? articleWrapper.Path : string.Empty).ToLowerInvariant().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var fullWidthItem = fullwidthItems.FirstOrDefault(item => item.Url.ToLowerInvariant().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).SequenceEqual(currentUrlArray)); if (fullWidthItem != null) { content.ShowFullWidth = !string.IsNullOrEmpty(fullWidthItem.Content); content.Url = fullWidthItem.Content; content.IsIframe = fullWidthItem.IsIFrame; return content; } fullWidthItem = fullwidthItems.FirstOrDefault(item => item.Url.ToLowerInvariant().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Take(item.Url.ToLowerInvariant().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Count() - 1).SequenceEqual(currentUrlArray)); if (fullWidthItem != null) { content.ShowFullWidth = !string.IsNullOrEmpty(fullWidthItem.Content); content.Url = fullWidthItem.Content; content.IsIframe = fullWidthItem.IsIFrame; } } catch { return content; } return content; } private static string NotSoTinyCandidateImageUrl(BasicCandidate basicCandidate) { if (Service.App_Start.AutoMapperInit.Topcandidates.ContainsKey(basicCandidate.Id)) { if (!basicCandidate.ImageUrl.StartsWith(ImageScaler)) { return basicCandidate.ImageUrl= ImageScaler + "www.dr.dk"+basicCandidate.ImageUrl; } else return basicCandidate.ImageUrl; } return basicCandidate.ImageUrl.Replace("http://www.altinget.dk", ImageScaler + "www.altinget.dk"); } private static ArticleWrapper SetCurrentPath(ArticleWrapper articleWrapper) { if (articleWrapper.Path == "DefaultWrapper") articleWrapper.Path = UrlHelpers.GetCurrentRelativePath(); return articleWrapper; } private static CandidateArticleList MapProfileViewModel(Candidate candidate) { var profileViewModel = new CandidateArticleListItem(); profileViewModel.CandidatePageUrl = string.Format("/nyheder/politik/valg2016/kandidater/{0}/{1}", candidate.Name.UrlFriendly(), candidate.Id); profileViewModel.Headline = candidate.Name; profileViewModel.CandidateImageUrl = candidate.ImageUrl; profileViewModel.CandidateName = candidate.Name; profileViewModel.CandidateIsRerun = false; //TODO: map with correct data profileViewModel.PartyLetter = candidate.Party.Letter; profileViewModel.PartyLetterUrlFriendly = candidate.Party.Letter.UrlFriendly(); profileViewModel.CandidateId = candidate.Id; //TODO: Do we need ID? profileViewModel.PartyName = candidate.Party.Name; profileViewModel.PersonalVotesAvailable = candidate.PersonalVotesAvailable; profileViewModel.Votes = candidate.Votes; profileViewModel.PreviousVotes = candidate.PreviousVotes; profileViewModel.IsElected = candidate.IsElected; profileViewModel.IsElectedConfirmed = candidate.IsElectedConfirmed; return new CandidateArticleList() {Items = new List() {profileViewModel}}; } private static SocialMediaSitesViewModel MapSocialMediaSitesViewModel(Candidate candidate) { var viewModel = new SocialMediaSitesViewModel(); viewModel.Name = candidate.Name; if (!string.IsNullOrWhiteSpace(candidate.Facebook)) { viewModel.FacebookUrl = "http://www.facebook.com/" + candidate.Facebook; } if (!string.IsNullOrWhiteSpace(candidate.Twitter)) { viewModel.TwitterUrl = "https://twitter.com/intent/user?user_id=" + candidate.Twitter; } return viewModel; } private static FactViewModel MapFactViewModel(Candidate candidate) { var viewModel = new FactViewModel { Name = candidate.Name, ContentText = WebUtility.HtmlDecode(candidate.Cv), DateOfBirth = candidate.Birthdate, Occupation = candidate.Occupation, CivilStatus = candidate.MaritalStatus, Education = candidate.Education, Homepage = candidate.Url.CleanUrl(), Blog = candidate.Blog.CleanUrl(), Video = candidate.Video.CleanUrl() }; return viewModel; } private static PartyArticleViewModel MapPartyArticleViewModel(Candidate candidate) { var viewModel = new PartyArticleViewModel { PartyLetter = candidate.Party.Letter, PartyName = candidate.Party.Name }; return viewModel; } private static MainPointsViewModel MapMainPointsViewModel(Candidate candidate) { var viewModel = new MainPointsViewModel(); viewModel.Name = candidate.Name; viewModel.Video = candidate.Video.CleanUrl().YoutubeEmbedify(); if (!string.IsNullOrWhiteSpace(candidate.FirstIssueTitle) || !string.IsNullOrWhiteSpace(candidate.FirstIssue)) { viewModel.Points.Add(new Point() { Title = WebUtility.HtmlDecode(candidate.FirstIssueTitle), ContentText = WebUtility.HtmlDecode(candidate.FirstIssue) }); } if (!string.IsNullOrWhiteSpace(candidate.SecondIssueTitle) || !string.IsNullOrWhiteSpace(candidate.SecondIssue)) { viewModel.Points.Add(new Point() { Title = WebUtility.HtmlDecode(candidate.SecondIssueTitle), ContentText = WebUtility.HtmlDecode(candidate.SecondIssue) }); } if (!string.IsNullOrWhiteSpace(candidate.ThirdIssueTitle) || !string.IsNullOrWhiteSpace(candidate.ThirdIssue)) { viewModel.Points.Add(new Point() { Title = WebUtility.HtmlDecode(candidate.ThirdIssueTitle), ContentText = WebUtility.HtmlDecode(candidate.ThirdIssue) }); } return viewModel; } private static void SEOfyArticleWrapper(ArticleWrapper c) { if (c == null) return; if (c.MetaTags == null) return; var description = c.MetaTags.FirstOrDefault(x => x.Any(z => z.Key == "name" && z.Value == "description")); var keywords = c.MetaTags.FirstOrDefault(x => x.Any(z => z.Key == "name" && z.Value == "keywords")); var metaTags = setMetatags(c); if (description != null && metaTags.Count == 0) { description.Remove("content"); description.Add("content", "DR Nyheder dækker Folketingsvalget 2015 på tv, i radioen og på nettet. Læs nyheder, se resultater og følg valgkampen live i tekst og billeder."); } else if(description != null && keywords != null) { description.Remove("content"); keywords.Remove("content"); if (metaTags.Any()) { description.Add("content", metaTags[0].Description); keywords.Add("content", metaTags[0].Keywords); } } } public class PredefinedMetaTag { public string Description { get; set; } public string Keywords { get; set; } } private static List setMetatags(ArticleWrapper c) { if (c.Path == "DefaultWrapper") c.Path = UrlHelpers.GetCurrentRelativePath(); string path = c.Path; path = path.Contains("se-din-stemmeseddel") ? "se-din-stemmeseddel" : path; int position = path.LastIndexOf("/") + 1; string pageFileName = path.Substring(position, path.Length - position).ToLowerInvariant(); List metaTags = new List(); switch (pageFileName) { case "index": metaTags.Add(new PredefinedMetaTag() { Description = "Følg folketingsvalget på dr.dk med de seneste nyheder, meningsmålinger og live-dækning fra valget 2015.", Keywords = "Valg, folketingsvalg, meningsmåling, live, nyheder, 2015" }); break; case "live": metaTags.Add(new PredefinedMetaTag() { Description = "Følg folketingsvalget live med de seneste opdateringer fra valget samt live-tv hver dag hele valgkampen. Du kan også få svar på dine spørgsmål om valget fra vores eksperter.", Keywords = "Valg, folketingsvalg, live, opdateringer, nyheder, tv, spørgsmål, svar" }); break; case "resultat": metaTags.Add(new PredefinedMetaTag() { Description = "Følg folketingsvalget live med de seneste opdateringer fra valget samt live-tv hver dag hele valgkampen. Du kan også få svar på dine spørgsmål om valget fra vores eksperter.", Keywords = "Valg, folketingsvalg, live, opdateringer, nyheder, tv, spørgsmål, svar" }); break; case "kandidat-testen": metaTags.Add(new PredefinedMetaTag() { Description = "Tag kandidattesten, og se hvilke kandidater, du er mest eller mindst enige med til folketingsvalget 2015.", Keywords = "Kandidattest, kandidater, enig, stemme, folketingsvalg, valg, 2015" }); break; case "se-din-stemmeseddel": metaTags.Add(new PredefinedMetaTag() { Description = "Søg på din valgkreds, og se din stemmeseddel med de kandidater, du kan stemme på til folketingsvalget 2015.", Keywords = "Stemmeseddel, valgkreds, stemme, kandidat, valg, folketingsvalg, 2015" }); break; case "min-regering": metaTags.Add(new PredefinedMetaTag() { Description = "Prøv min regering, og se hvilke af dine Facebook-venner, der bliver en del af din regering og hvorfor.", Keywords = "Regering, Facebook, venner, Folketingsvalg, Valg, 2015" }); break; case "meningsmaalinger": metaTags.Add(new PredefinedMetaTag() { Description = "Se de seneste meningsmålinger fra folketingsvalget 2015, sammenlign resultater med tidligere valg, og se partiernes historiske udvikling.", Keywords = "Meningsmåling, stemmer, partier, resultater, udvikling, historisk, sammenlign, folketingsvalg, valg, 2015" }); break; case "plakat": metaTags.Add(new PredefinedMetaTag() { Description = "Lav din personlige valgplakat til folketingsvalget 2015 med dit eget billede og slogan, og del den med dine venner på Facebook og Twitter.", Keywords = "Valgplakat, plakat, del, venner, Facebook, Twitter, Folketingsvalg, valg, 2015" }); break; case "vaelgervandringer": metaTags.Add(new PredefinedMetaTag() { Description = "Se hvordan vælgerne har vandret mellem de forskellige partier fra folketingsvalget 2011 til 2015.", Keywords = "Vælgere, vandring, vælgervandring, partier, folketingsvalg 2011, folketingsvalg, valg, 2015" }); break; } return metaTags; } public static Agent ForcePriority(this Agent originAgent) { var priority = 1; var agent = new Agent() { AgentGuid = originAgent.AgentGuid, Headline = originAgent.Headline, Name = originAgent.Name, PriorityListGuid = originAgent.PriorityListGuid, Postings = originAgent.Postings.Select(a => new AgentPosting() { Images = a.Images, MediaLinks = a.MediaLinks, PostingGuid = a.PostingGuid, Priority = priority++, PublishTime = a.PublishTime, ReadMoreLinks = a.ReadMoreLinks, TeaserText = a.TeaserText, Title = a.Title, Url = a.Url }).ToList() }; return agent; } private static string GetPsdbBaseUrl(string key) { if (string.IsNullOrEmpty(key)) throw new ArgumentNullException("key", "type cannot be null or empty. Come on!"); var baseUrl = ConfigurationManager.AppSettings[key]; if (string.IsNullOrEmpty(baseUrl)) throw new ConfigurationErrorsException(string.Format("The key {0} is not set in web.config please fix!", key)); return baseUrl; } private static ArticleList GetSharedItems(int amount) { var baseUrl = ConfigurationManager.AppSettings["ShareBaseUrl"]; if (string.IsNullOrEmpty(baseUrl)) throw new ConfigurationErrorsException("Key ShareBaseUrl is not configured in web.config."); var shareServices = ConfigurationManager.AppSettings["ShareServices"]; if (string.IsNullOrEmpty(shareServices)) throw new ConfigurationErrorsException("Key ShareServices is not configured in web.config."); var maxHoursString = ConfigurationManager.AppSettings["ShareMaxHours"]; if (string.IsNullOrEmpty(maxHoursString)) throw new ConfigurationErrorsException("Key ShareMaxHours is not configured in web.config."); var maxHours = int.Parse(maxHoursString); var shareStatRepository = ObjectFactory.GetInstance(); if (shareStatRepository == null) throw new NullReferenceException("Instance not found : shareStatRepository is null"); List shares; try { shares = shareStatRepository.GetShareItems(baseUrl, shareServices.Split(new[] {','}), maxHours); } catch (Exception ex) { shares = null; } if (shares == null) return new ArticleList(); shares = shares.OrderByDescending(s => s.Shares).ToList(); var articleListItems = Mapper.Map>(shares); return new ArticleList() { Headline = "Mest delte seneste 24 timer", Items = articleListItems.Take(amount) }; } } }