Пример #1
0
        protected String PrepareModel(OutputViewModel data)
        {
            if (data == null) throw new ArgumentNullException("data");

            var output = this.PrepareView(data, data.Action.ToString());

            return output;
        }
Пример #2
0
 public void WriteFile(OutputViewModel model)
 {
     if (model == null) throw new ArgumentNullException("model");
     WriteFile(model, null);
 }
Пример #3
0
        public void WriteFile(OutputViewModel model, string pathOverride)
        {
            if (model == null) throw new ArgumentNullException("model");

            if (_historySitemap != null) _historySitemap.Add(model.SitemapItem);

            WritePage(model, pathOverride);
        }
Пример #4
0
        public static OutputViewModel CreateRegionOutputViewModel(Authority region,
            int count,
            IList<PageLinkModel> authorityLinks,
            PageLinkModel next,
            String descriptionPattern)
        {
            if (region == null) throw new ArgumentNullException("region");
            if (authorityLinks == null) throw new ArgumentNullException("authorityLinks");
            if (next == null) throw new ArgumentNullException("next");

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = region.CleanQualifiedName,
                    Id = region.Id,
                    Text = region.Name,
                    Title = region.Name,
                    Total = region.HauntedPubCount
                },
            };

            var pageLinks = authorityLinks.Select(link => link.Text != null
                ? new PageLinkModel
                {
                    Text = link.Text,
                    Title = link.Text,
                    Filename = link.Filename,
                    Total = link.Total
                }
                : null)
                .OrderBy(o => o.Text)
                .ToList();

            var articleDescription = string.Format(descriptionPattern, authorityLinks
                .Select(x => x.Text)
                .OxfordAnd());

            var metaDescription = articleDescription
                .SeoMetaDescriptionTruncate();

            var model = new OutputViewModel
            {
                Filename = region.CleanQualifiedName,
                PageTitle = region.Name,
                JumboTitle = region.Name,
                Action = PageTypeEnum.Region,
                Total = count,
                Priority = PageTypePriority.Region,
                Next = next,
                Lineage = lineage,
                PageLinks = pageLinks,
                MetaDescription = metaDescription,
                ArticleDescription = articleDescription,
                Summary = region.Summary,
                LocalGhostSpecialist = region.IsLocalGhostSpecialistValid
                    ? new PageLinkModel
                    {
                        Text = region.LocalGhostSpecialistName,
                        Title = region.LocalGhostSpecialistName,
                        ExternalUrl = region.LocalGhostSpecialistUrl
                    }
                    : null,
                LocalGhostHunter = region.IsLocalGhostHuntSpecialistValid
                    ? new PageLinkModel
                    {
                        Text = region.LocalGhostHuntSpecialistName,
                        Title = region.LocalGhostHuntSpecialistName,
                        ExternalUrl = region.LocalGhostHuntSpecialistUrl
                    }
                    : null
            };

            return model;
        }
Пример #5
0
        private void WritePage(OutputViewModel model, string pathOverride)
        {
            if (model == null) throw new ArgumentNullException("model");

            if (model.Filename == null) return;

            var toUse = !pathOverride.IsNullOrEmpty()
                ? pathOverride
                : _currentRoot.ToLower();

            if (toUse == null)
            {
                throw new ArgumentNullException("toUse");
            }

            var fullFilePath = String.Format("{0}{1}{2}",
                toUse,
                model.FriendlyFilename,
                ".html");

            if (model.FriendlyFilename == null) return;

            var contents = PrepareModel(model);

            if (contents == null) throw new ArgumentNullException("contents");

            model = null;

            FileSystemHelper.WriteFile(fullFilePath, contents);
        }
Пример #6
0
        public static OutputViewModel CreateOrgOutputViewModel(
            Org org,
            PageLinkModel next,
            String descriptionPattern
            )
        {
            if (org == null) throw new ArgumentNullException("org");
            if (next == null) throw new ArgumentNullException("next");

            //var notes = org.Notes.Select(note => new PageLinkModel
            //{
            //    Id = note.Id,
            //    Text = note.Text,
            //    Title = note.Text
            //}).ToList();

            const PageTypeEnum action = PageTypeEnum.Pub;

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = org.Authority.ParentAuthority.CleanQualifiedName,
                    Id = org.Id,
                    Text = org.Authority.ParentAuthority.Name,
                    Title = org.Authority.ParentAuthority.Name,
                    Total = org.Authority.ParentAuthority.HauntedPubCount
                },
                Authority = new PageLinkModel
                {
                    Filename = org.Authority.CleanQualifiedName,
                    Id = org.Id,
                    Text = org.Authority.Name,
                    Title = org.Authority.Name,
                    Total = org.Authority.HauntedPubCount
                },
                Locality = new PageLinkModel
                {
                    Filename = org.QualifiedLocalityDashified
                        .Clean(),
                    Id = org.Id,
                    Text = org.Locality,
                    Title = org.Locality
                },
                Organisation = new PageLinkModel
                {
                    Filename = org.Filename,
                    Id = org.Id,
                    Text = org.TradingName,
                    Title = org.TradingName
                }
            };

            var adjusted = new Breadcrumb();

            if (org.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var model = new OutputViewModel
            {
                IsMapAvailable = !org.IsOutsideUnitedKingdom,
                Filename = org.Filename,
                JumboTitle = org.JumboTitle,
                PageTitle = org.Title,
                Action = action,
                PageLinks = new List<PageLinkModel>(),
                MetaDescription = org.SeoDescription,
                Description = org.Description,
                ArticleDescription = string.Format(descriptionPattern, org.Address, org.PostcodePrimaryPart),
                Tags = org.Sections,
                Priority = PageTypePriority.Pub,
                Next = next,
                Lat = org.Lat.ToString(),
                Lon = org.Lon.ToString(),
                OtherNames = org.Authority.Orgs
                    .Where(o => o.Address == org.Address
                                && o.Postcode == org.Postcode
                                && o.Id != org.Id)
                    .Select(
                        o => new PageLinkModel
                        {
                            Id = o.Id,
                            Text = o.TradingName,
                            Title = o.TradingName,
                            Filename = o.Filename
                        }
                    ).ToList(),
                Lineage = lineage
            };

            return model;
        }
Пример #7
0
        public static OutputViewModel CreatePageTypeOutputViewModel(PageTypeEnum pageType, string priority,
            string description,
            List<PageLinkModel> links, string title)
        {
            if (priority == null) throw new ArgumentNullException("priority");
            if (description == null) throw new ArgumentNullException("description");
            if (title == null) throw new ArgumentNullException("title");

            var model = new OutputViewModel(true)
            {
                JumboTitle = title,
                PageTitle = title,
                Action = pageType,
                MetaDescription = description.SeoMetaDescriptionTruncate(),
                ArticleDescription = description,
                Filename = pageType.ToString(),
                Priority = priority,
                PageLinks = links,
                Total = links != null ? links.Count() : 0
            };

            return model;
        }
Пример #8
0
        public static OutputViewModel CreateAuthorityOutputViewModel(Authority authority, int count,
            IList<PageLinkModel> locations,
            PageLinkModel next,
            string descriptionPattern
            )
        {
            if (authority == null) throw new ArgumentNullException("authority");
            if (locations == null) throw new ArgumentNullException("locations");
            if (next == null) throw new ArgumentNullException("next");

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = authority.ParentAuthority.CleanQualifiedName,
                    Id = authority.ParentAuthority.Id,
                    Text = authority.ParentAuthority.Name,
                    Title = authority.ParentAuthority.Name,
                    Total = authority.ParentAuthority.HauntedPubCount,
                },
                Authority = new PageLinkModel
                {
                    Filename = authority.CleanQualifiedName,
                    Id = authority.Id,
                    Text = authority.Name,
                    Title = authority.Name,
                    Total = authority.HauntedPubCount,
                }
            };

            var adjusted = new Breadcrumb();

            if (authority.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var pageLinks = locations.OrderBy(x => x.Text).ToList();

            var articleDescription = string.Format(
                descriptionPattern,
                locations.Select(x => x.Text).OxfordAnd());

            var metaDescription = articleDescription
                .SeoMetaDescriptionTruncate();

            var model = new OutputViewModel
            {
                // this is for example: cheshire-west-and-chester-ua.html
                Filename = authority.CleanQualifiedName,
                JumboTitle = authority.Name,
                PageTitle = authority.Name,
                Action = PageTypeEnum.Authority,
                Total = count,
                Priority = PageTypePriority.Authority,
                Next = next,
                Lineage = lineage,
                MetaDescription = metaDescription,
                ArticleDescription = articleDescription,
                PageLinks = pageLinks,
                Summary = authority.Summary,
                LocalGhostSpecialist = authority.IsLocalGhostSpecialistValid
                    ? new PageLinkModel
                    {
                        Text = authority.LocalGhostSpecialistName,
                        Title = authority.LocalGhostSpecialistName,
                        ExternalUrl = authority.LocalGhostSpecialistUrl
                    }
                    : null,
                LocalGhostHunter = authority.IsLocalGhostHuntSpecialistValid
                    ? new PageLinkModel
                    {
                        Text = authority.LocalGhostHuntSpecialistName,
                        Title = authority.LocalGhostHuntSpecialistName,
                        ExternalUrl = authority.LocalGhostHuntSpecialistUrl
                    }
                    : null
            };

            return model;
        }
Пример #9
0
        public static OutputViewModel CreateLocalityOutputViewModel(string locality,
            Authority authority,
            IList<PageLinkModel> orgLinks,
            PageLinkModel next,
            String descriptionPattern)
        {
            if (locality == null) throw new ArgumentNullException("locality");
            if (authority == null) throw new ArgumentNullException("authority");
            if (orgLinks == null) throw new ArgumentNullException("orgLinks");
            if (next == null) throw new ArgumentNullException("next");

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = authority.ParentAuthority.CleanQualifiedName,
                    Id = authority.ParentAuthority.Id,
                    Text = authority.ParentAuthority.Name,
                    Title = authority.ParentAuthority.Name,
                    Total = authority.ParentAuthority.HauntedPubCount
                },
                Authority = new PageLinkModel
                {
                    Filename = authority.CleanQualifiedName,
                    Id = authority.Id,
                    Text = authority.Name,
                    Title = authority.Name,
                    Total = authority.HauntedPubCount
                },
                Locality = new PageLinkModel
                {
                    Filename = locality.In(authority.CleanQualifiedName, true),
                    Id = authority.Id,
                    Text = locality,
                    Title = locality
                }
            };

            var adjusted = new Breadcrumb();

            if (authority.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var articleDescription = string.Format(descriptionPattern, locality, authority.Name,
                authority.ParentAuthority.Name);

            var metaDescription = articleDescription
                .SeoMetaDescriptionTruncate();

            var pageLinks = orgLinks.Select(link => link.Text != null
                ? new PageLinkModel
                {
                    Text = link.Text,
                    Title = link.Title,
                    // dpc - example: 10930-the-headless-woman-duddon.html
                    Filename = link.Filename
                }
                : null)
                .OrderBy(o => o.Text)
                .ToList();

            var model = new OutputViewModel
            {
                // dpc - example: duddon-in-cheshire-west-and-chester-ua.html
                Filename = locality.In(authority.CleanQualifiedName, true),
                JumboTitle = locality.In(authority.QualifiedName),
                PageTitle = locality.In(authority.QualifiedName),
                Action = PageTypeEnum.Locality,
                Total = orgLinks.Count(),
                Priority = PageTypePriority.Locality,
                Next = next,
                Lineage = lineage,
                MetaDescription = metaDescription,
                ArticleDescription = articleDescription,
                PageLinks = pageLinks
            };

            return model;
        }
Пример #10
0
        public static OutputViewModel CreateAllUkRegionsOutputViewModel(string currentRoot,
            List<PageLinkModel> pageLinks, string metaDescription, string articleDescription)
        {
            if (currentRoot == null) throw new ArgumentNullException("currentRoot");
            if (pageLinks == null) throw new ArgumentNullException("pageLinks");
            if (metaDescription == null) throw new ArgumentNullException("metaDescription");
            if (articleDescription == null) throw new ArgumentNullException("articleDescription");

            var viewModel = new OutputViewModel
            {
                Filename = "UK",
                PageTitle = "Haunted pubs in UK by region",
                JumboTitle = "Haunted pubs in UK by region",
                Action = PageTypeEnum.Country,
                PageLinks = pageLinks,
                MetaDescription = metaDescription,
                ArticleDescription = articleDescription,
                Priority = PageTypePriority.Country
            };

            return viewModel;
        }
Пример #11
0
        public static OutputViewModel CreateRegionOutputViewModel(Authority region,
                                                                  int count,
                                                                  IList <PageLinkModel> authorityLinks,
                                                                  PageLinkModel next,
                                                                  String descriptionPattern)
        {
            if (region == null)
            {
                throw new ArgumentNullException("region");
            }
            if (authorityLinks == null)
            {
                throw new ArgumentNullException("authorityLinks");
            }
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = region.CleanQualifiedName,
                    Id       = region.Id,
                    Text     = region.Name,
                    Title    = region.Name,
                    Total    = region.HauntedPubCount
                },
            };

            var pageLinks = authorityLinks.Select(link => link.Text != null
                ? new PageLinkModel
            {
                Text     = link.Text,
                Title    = link.Text,
                Filename = link.Filename,
                Total    = link.Total
            }
                : null)
                            .OrderBy(o => o.Text)
                            .ToList();

            var articleDescription = string.Format(descriptionPattern, authorityLinks
                                                   .Select(x => x.Text)
                                                   .OxfordAnd());

            var metaDescription = articleDescription
                                  .SeoMetaDescriptionTruncate();

            var model = new OutputViewModel
            {
                Filename             = region.CleanQualifiedName,
                PageTitle            = region.Name,
                JumboTitle           = region.Name,
                Action               = PageTypeEnum.Region,
                Total                = count,
                Priority             = PageTypePriority.Region,
                Next                 = next,
                Lineage              = lineage,
                PageLinks            = pageLinks,
                MetaDescription      = metaDescription,
                ArticleDescription   = articleDescription,
                Summary              = region.Summary,
                LocalGhostSpecialist = region.IsLocalGhostSpecialistValid
                    ? new PageLinkModel
                {
                    Text        = region.LocalGhostSpecialistName,
                    Title       = region.LocalGhostSpecialistName,
                    ExternalUrl = region.LocalGhostSpecialistUrl
                }
                    : null,
                LocalGhostHunter = region.IsLocalGhostHuntSpecialistValid
                    ? new PageLinkModel
                {
                    Text        = region.LocalGhostHuntSpecialistName,
                    Title       = region.LocalGhostHuntSpecialistName,
                    ExternalUrl = region.LocalGhostHuntSpecialistUrl
                }
                    : null
            };

            return(model);
        }
Пример #12
0
        public static OutputViewModel CreateOrgOutputViewModel(
            Org org,
            PageLinkModel next,
            String descriptionPattern
            )
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            //var notes = org.Notes.Select(note => new PageLinkModel
            //{
            //    Id = note.Id,
            //    Text = note.Text,
            //    Title = note.Text
            //}).ToList();

            const PageTypeEnum action = PageTypeEnum.Pub;

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = org.Authority.ParentAuthority.CleanQualifiedName,
                    Id       = org.Id,
                    Text     = org.Authority.ParentAuthority.Name,
                    Title    = org.Authority.ParentAuthority.Name,
                    Total    = org.Authority.ParentAuthority.HauntedPubCount
                },
                Authority = new PageLinkModel
                {
                    Filename = org.Authority.CleanQualifiedName,
                    Id       = org.Id,
                    Text     = org.Authority.Name,
                    Title    = org.Authority.Name,
                    Total    = org.Authority.HauntedPubCount
                },
                Locality = new PageLinkModel
                {
                    Filename = org.QualifiedLocalityDashified
                               .Clean(),
                    Id    = org.Id,
                    Text  = org.Locality,
                    Title = org.Locality
                },
                Organisation = new PageLinkModel
                {
                    Filename = org.Filename,
                    Id       = org.Id,
                    Text     = org.TradingName,
                    Title    = org.TradingName
                }
            };

            var adjusted = new Breadcrumb();

            if (org.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var model = new OutputViewModel
            {
                IsMapAvailable     = !org.IsOutsideUnitedKingdom,
                Filename           = org.Filename,
                JumboTitle         = org.JumboTitle,
                PageTitle          = org.Title,
                Action             = action,
                PageLinks          = new List <PageLinkModel>(),
                MetaDescription    = org.SeoDescription,
                Description        = org.Description,
                ArticleDescription = string.Format(descriptionPattern, org.Address, org.PostcodePrimaryPart),
                Tags       = org.Sections,
                Priority   = PageTypePriority.Pub,
                Next       = next,
                Lat        = org.Lat.ToString(),
                Lon        = org.Lon.ToString(),
                OtherNames = org.Authority.Orgs
                             .Where(o => o.Address == org.Address &&
                                    o.Postcode == org.Postcode &&
                                    o.Id != org.Id)
                             .Select(
                    o => new PageLinkModel
                {
                    Id       = o.Id,
                    Text     = o.TradingName,
                    Title    = o.TradingName,
                    Filename = o.Filename
                }
                    ).ToList(),
                Lineage = lineage
            };

            return(model);
        }
Пример #13
0
        public static OutputViewModel CreateLocalityOutputViewModel(string locality,
                                                                    Authority authority,
                                                                    IList <PageLinkModel> orgLinks,
                                                                    PageLinkModel next,
                                                                    String descriptionPattern)
        {
            if (locality == null)
            {
                throw new ArgumentNullException("locality");
            }
            if (authority == null)
            {
                throw new ArgumentNullException("authority");
            }
            if (orgLinks == null)
            {
                throw new ArgumentNullException("orgLinks");
            }
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = authority.ParentAuthority.CleanQualifiedName,
                    Id       = authority.ParentAuthority.Id,
                    Text     = authority.ParentAuthority.Name,
                    Title    = authority.ParentAuthority.Name,
                    Total    = authority.ParentAuthority.HauntedPubCount
                },
                Authority = new PageLinkModel
                {
                    Filename = authority.CleanQualifiedName,
                    Id       = authority.Id,
                    Text     = authority.Name,
                    Title    = authority.Name,
                    Total    = authority.HauntedPubCount
                },
                Locality = new PageLinkModel
                {
                    Filename = locality.In(authority.CleanQualifiedName, true),
                    Id       = authority.Id,
                    Text     = locality,
                    Title    = locality
                }
            };


            var adjusted = new Breadcrumb();

            if (authority.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var articleDescription = string.Format(descriptionPattern, locality, authority.Name,
                                                   authority.ParentAuthority.Name);

            var metaDescription = articleDescription
                                  .SeoMetaDescriptionTruncate();

            var pageLinks = orgLinks.Select(link => link.Text != null
                ? new PageLinkModel
            {
                Text  = link.Text,
                Title = link.Title,
                // dpc - example: 10930-the-headless-woman-duddon.html
                Filename = link.Filename
            }
                : null)
                            .OrderBy(o => o.Text)
                            .ToList();

            var model = new OutputViewModel
            {
                // dpc - example: duddon-in-cheshire-west-and-chester-ua.html
                Filename           = locality.In(authority.CleanQualifiedName, true),
                JumboTitle         = locality.In(authority.QualifiedName),
                PageTitle          = locality.In(authority.QualifiedName),
                Action             = PageTypeEnum.Locality,
                Total              = orgLinks.Count(),
                Priority           = PageTypePriority.Locality,
                Next               = next,
                Lineage            = lineage,
                MetaDescription    = metaDescription,
                ArticleDescription = articleDescription,
                PageLinks          = pageLinks
            };

            return(model);
        }
Пример #14
0
        public static OutputViewModel CreateAuthorityOutputViewModel(Authority authority, int count,
                                                                     IList <PageLinkModel> locations,
                                                                     PageLinkModel next,
                                                                     string descriptionPattern
                                                                     )
        {
            if (authority == null)
            {
                throw new ArgumentNullException("authority");
            }
            if (locations == null)
            {
                throw new ArgumentNullException("locations");
            }
            if (next == null)
            {
                throw new ArgumentNullException("next");
            }

            var lineage = new Breadcrumb
            {
                Region = new PageLinkModel
                {
                    Filename = authority.ParentAuthority.CleanQualifiedName,
                    Id       = authority.ParentAuthority.Id,
                    Text     = authority.ParentAuthority.Name,
                    Title    = authority.ParentAuthority.Name,
                    Total    = authority.ParentAuthority.HauntedPubCount,
                },
                Authority = new PageLinkModel
                {
                    Filename = authority.CleanQualifiedName,
                    Id       = authority.Id,
                    Text     = authority.Name,
                    Title    = authority.Name,
                    Total    = authority.HauntedPubCount,
                }
            };

            var adjusted = new Breadcrumb();

            if (authority.IsOutsideUnitedKingdom)
            {
                lineage = adjusted.Swap(lineage);
            }

            var pageLinks = locations.OrderBy(x => x.Text).ToList();

            var articleDescription = string.Format(
                descriptionPattern,
                locations.Select(x => x.Text).OxfordAnd());

            var metaDescription = articleDescription
                                  .SeoMetaDescriptionTruncate();

            var model = new OutputViewModel
            {
                // this is for example: cheshire-west-and-chester-ua.html
                Filename             = authority.CleanQualifiedName,
                JumboTitle           = authority.Name,
                PageTitle            = authority.Name,
                Action               = PageTypeEnum.Authority,
                Total                = count,
                Priority             = PageTypePriority.Authority,
                Next                 = next,
                Lineage              = lineage,
                MetaDescription      = metaDescription,
                ArticleDescription   = articleDescription,
                PageLinks            = pageLinks,
                Summary              = authority.Summary,
                LocalGhostSpecialist = authority.IsLocalGhostSpecialistValid
                    ? new PageLinkModel
                {
                    Text        = authority.LocalGhostSpecialistName,
                    Title       = authority.LocalGhostSpecialistName,
                    ExternalUrl = authority.LocalGhostSpecialistUrl
                }
                    : null,
                LocalGhostHunter = authority.IsLocalGhostHuntSpecialistValid
                    ? new PageLinkModel
                {
                    Text        = authority.LocalGhostHuntSpecialistName,
                    Title       = authority.LocalGhostHuntSpecialistName,
                    ExternalUrl = authority.LocalGhostHuntSpecialistUrl
                }
                    : null
            };

            return(model);
        }