private static bool PageIsDynamic(Uri pageUrl, out PageInformation pageInformation) { pageInformation = new PageInformation(); if (pageUrl.Segments.Length <= 1 || pageUrl.ToString().EndsWith("default.ashx", StringComparison.OrdinalIgnoreCase)) return false; string superCollection = string.Empty; if (pageUrl.Segments.Length >= 2) superCollection = pageUrl.Segments[1].Split('/')[0]; string collection = superCollection; if (pageUrl.Segments.Length >= 3) collection = pageUrl.Segments[2].Split('/')[0]; Timeline timeline = ChronozoomSVC.Instance.GetTimelines(superCollection, collection, null, null, null, null, null, "1"); if (timeline != null) { pageInformation.Title = timeline.Title; foreach (Exhibit exhibit in timeline.Exhibits) { foreach (ContentItem contentItem in exhibit.ContentItems) { if (contentItem.Uri.ToString().EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)) { pageInformation.Images.Add(contentItem.Uri); } } } return true; } return false; }
internal static string GenerateDefaultPage(PageInformation pageInformation, string pageName = _mainPageName) { try { using (StreamReader streamReader = new StreamReader(_baseDirectory.Value + pageName)) { XmlReader xmlReader = new XmlTextReader(streamReader); XDocument pageRoot = XDocument.Load(xmlReader); // Remove DOCTYPE extra [] pageRoot.DocumentType.InternalSubset = null; XNamespace ns = "http://www.w3.org/1999/xhtml"; XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlReader.NameTable); xmlNamespaceManager.AddNamespace("xhtml", ns.ToString()); ComposePage(pageRoot, xmlNamespaceManager, pageInformation); return(pageRoot.ToString()); } } catch (Exception e) { if (e is OutOfMemoryException) { throw; } // Not critical since the generated page only contains additional metadata used in SEO/Embedding return(_mainPage.Value); } }
private static string GenerateDefaultPage(PageInformation pageInformation) { using (StreamReader streamReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + _mainPageName)) { XmlReader xmlReader = new XmlTextReader(streamReader); XDocument pageRoot = XDocument.Load(xmlReader); XNamespace ns = "http://www.w3.org/1999/xhtml"; XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlReader.NameTable); xmlNamespaceManager.AddNamespace("xhtml", ns.ToString()); ComposePage(pageRoot, xmlNamespaceManager, pageInformation); return(pageRoot.ToString()); } }
private static bool PageIsDynamic(Uri pageUrl, out PageInformation pageInformation) { pageInformation = new PageInformation(); if (pageUrl.Segments.Length <= 1 || pageUrl.ToString().EndsWith("default.ashx", StringComparison.OrdinalIgnoreCase)) { return(false); } string superCollection = string.Empty; if (pageUrl.Segments.Length >= 2) { superCollection = pageUrl.Segments[1].Split('/')[0]; } string collection = superCollection; if (pageUrl.Segments.Length >= 3) { collection = pageUrl.Segments[2].Split('/')[0]; } if (IsSuperCollectionPresent(superCollection)) { Timeline timeline = ChronozoomSVC.Instance.GetTimelines(superCollection, collection, null, null, null, null, null, "1"); if (timeline != null) { pageInformation.Title = timeline.Title; foreach (Exhibit exhibit in timeline.Exhibits) { foreach (ContentItem contentItem in exhibit.ContentItems) { if (contentItem.Uri.ToString().EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)) { pageInformation.Images.Add(contentItem.Uri); } } } return(true); } } return(false); }
public void TestUI_DefaultHttpHandler_GeneratesDefaultPage() { PageInformation pageInformation = new PageInformation(); PrivateType privateDefaultHttpHandler = new PrivateType(typeof(DefaultHttpHandler)); privateDefaultHttpHandler.SetStaticField("_hostPath", new Lazy<string>(() => { return ""; })); try { string page = DefaultHttpHandler.GenerateDefaultPage(pageInformation); Assert.IsNotNull(page, "Page is expected to generate correctly"); Assert.IsTrue(page.Length > 0, "Page is expected to contain content"); } catch (Exception) { Assert.Fail("GenerateDefaultPage should not throw exceptions"); } }
private static void ComposePage(XDocument pageRoot, XmlNamespaceManager xmlNamespaceManager, PageInformation pageInformation) { XElement scriptNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:script[@id='constants']", xmlNamespaceManager); scriptNode.Value = "var constants = { " + "analyticsId: \"" + pageInformation.AnalyticsServiceId + "\", " + "airbrakeTrackClient: " + pageInformation.AirbrakeTrackClient.ToString().ToLower() + ", " + "airbrakeProjectId: \"" + pageInformation.AirbrakeProjectId + "\", " + "airbrakeProjectKey: \"" + pageInformation.AirbrakeProjectKey + "\", " + "airbrakeEnvironment: \"" + pageInformation.AirbrakeEnvironment + "\", " + "featuredContentList: \"" + pageInformation.FeaturedContentList + "\", " + "onedriveClientId: \"" + pageInformation.OneDriveClientID + "\", " + "useMergedJSFiles: " + pageInformation.UseMergedJSFiles.ToString( ).ToLower() + ", " + "useMinifiedJSFiles: " + pageInformation.UseMinifiedJSFiles.ToString().ToLower() + ", " + "cssFileVersion: \"" + pageInformation.CSSFileVersion + "\", " + "jsFileVersion: \"" + pageInformation.JSFileVersion + "\", " + "schemaVersion: \"" + pageInformation.SchemaVersion + "\", " + "environment: \"" + CurrentEnvironment.ToString() + "\" " + "};"; if (!string.IsNullOrEmpty(pageInformation.Title)) { XElement titleNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:title", xmlNamespaceManager); titleNode.Value = string.Format(CultureInfo.InvariantCulture, "{0} - ChronoZoom", pageInformation.Title); } if (!string.IsNullOrEmpty(pageInformation.Description)) { XElement metaDescription = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='Description']", xmlNamespaceManager); XName contentAttribute = "content"; metaDescription.SetAttributeValue(contentAttribute, pageInformation.Description); } XElement lastMetaTag = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", xmlNamespaceManager); int imageCount = 0; foreach (string image in pageInformation.Images) { if (++imageCount > 3) break; XName metaNode = "meta"; XName linkNode = "link"; lastMetaTag.AddAfterSelf( new XElement( linkNode, new XAttribute("rel", "image_src"), new XAttribute("href", image) ), new XElement( metaNode, new XAttribute("property", "og:image"), new XAttribute("content", image) ) ); } }
internal static string GenerateDefaultPage(PageInformation pageInformation, string pageName = _mainPageName) { try { using (StreamReader streamReader = new StreamReader(_baseDirectory.Value + pageName)) { XmlReader xmlReader = new XmlTextReader(streamReader); XDocument pageRoot = XDocument.Load(xmlReader); // Remove DOCTYPE extra [] pageRoot.DocumentType.InternalSubset = null; XNamespace ns = "http://www.w3.org/1999/xhtml"; XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlReader.NameTable); xmlNamespaceManager.AddNamespace("xhtml", ns.ToString()); ComposePage(pageRoot, xmlNamespaceManager, pageInformation); return pageRoot.ToString(); } } catch (Exception e) { if (e is OutOfMemoryException) throw; // Not critical since the generated page only contains additional metadata used in SEO/Embedding return _mainPage.Value; } }
private static bool PageIsDynamic(Uri pageUrl, out PageInformation pageInformation, bool isMinimized = false) { pageInformation = new PageInformation(); // if the home page was specified if ( pageUrl.Segments.Length == 1 || pageUrl.ToString().EndsWith("default.ashx", StringComparison.OrdinalIgnoreCase) ) { // then exit reporting page is not dynamic return false; } // home page was not specified so ascertain the superCollection title and collection Path from the URL string superCollectionSegment = Regex.Replace(pageUrl.Segments[1].Trim(), @"[^A-Za-z0-9\-]+", "").ToLower(); string collectionSegment = pageUrl.Segments.Length < 3 ? "" : Regex.Replace(pageUrl.Segments[2].Trim(), @"[^A-Za-z0-9\-]+", "").ToLower(); // try to look up collection id Guid collectionId = ChronozoomSVC.Instance.CollectionIdOrDefault(_storage, superCollectionSegment, collectionSegment); // if collection id could not be found if (collectionId == Guid.Empty) { // if collection segment was specified (and also the supercollection segment) if (collectionSegment != "") { // redirect to the default collection for the specified supercollection if (isMinimized) HttpContext.Current.Response.Redirect("/czmin/" + superCollectionSegment + "#"); else HttpContext.Current.Response.Redirect("/" + superCollectionSegment + "#"); return false; } // otherwise redirect to the default supercollection's default collection if(isMinimized) HttpContext.Current.Response.Redirect("/czmin/#"); else HttpContext.Current.Response.Redirect("/#"); return false; } // set page title to collection title (must be server-side and not through JS for SEO purposes) pageInformation.Title = (ChronozoomSVC.Instance.GetCollection(superCollectionSegment, collectionSegment)).Title; // collection id was found so try to get root timeline and its accoutriments Timeline timeline = ChronozoomSVC.Instance.GetTimelines(superCollectionSegment, collectionSegment, null, null, null, null, null, "1"); if (timeline == null) { // a timeline for this collection could not be found so exit reporting page is not dynamic return false; } // timeline was found so populate rest of page contents and report page is dynamic foreach (Exhibit exhibit in timeline.Exhibits) { foreach (ContentItem contentItem in exhibit.ContentItems) { if (contentItem.Uri.ToString().EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)) { pageInformation.Images.Add(contentItem.Uri); } } } return true; }
private static void ComposePage(XDocument pageRoot, XmlNamespaceManager xmlNamespaceManager, PageInformation pageInformation) { XElement scriptNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:script[@id='constants']", xmlNamespaceManager); scriptNode.Value = "var constants = { " + "analyticsId: \"" + pageInformation.AnalyticsServiceId + "\", " + "exceptionsId: \"" + pageInformation.ExceptionsServiceId + "\", " + "environment: \"" + CurrentEnvironment.ToString() + "\" " + "};"; if (!string.IsNullOrEmpty(pageInformation.Title)) { XElement titleNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:title", xmlNamespaceManager); titleNode.Value = string.Format(CultureInfo.InvariantCulture, "{0} - ChronoZoom", pageInformation.Title); } if (!string.IsNullOrEmpty(pageInformation.Description)) { XElement metaDescription = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='Description']", xmlNamespaceManager); XName contentAttribute = "content"; metaDescription.SetAttributeValue(contentAttribute, pageInformation.Description); } XElement lastMetaTag = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", xmlNamespaceManager); int imageCount = 0; foreach (string image in pageInformation.Images) { if (++imageCount > 3) break; XName metaNode = "meta"; XName linkNode = "link"; lastMetaTag.AddAfterSelf( new XElement( linkNode, new XAttribute("rel", "image_src"), new XAttribute("href", image) ), new XElement( metaNode, new XAttribute("property", "og:image"), new XAttribute("content", image) ) ); } }
private static string GenerateDefaultPage(PageInformation pageInformation) { using (StreamReader streamReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + _mainPageName)) { XmlReader xmlReader = new XmlTextReader(streamReader); XDocument pageRoot = XDocument.Load(xmlReader); XNamespace ns = "http://www.w3.org/1999/xhtml"; XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlReader.NameTable); xmlNamespaceManager.AddNamespace("xhtml", ns.ToString()); ComposePage(pageRoot, xmlNamespaceManager, pageInformation); return pageRoot.ToString(); } }
private static void ComposePage(XDocument pageRoot, XmlNamespaceManager xmlNamespaceManager, PageInformation pageInformation) { XElement scriptNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:script[@id='constants']", xmlNamespaceManager); scriptNode.Value = "var constants = { " + "analyticsId: \"" + pageInformation.AnalyticsServiceId + "\", " + "airbrakeProjectId: \"" + pageInformation.AirbrakeProjectId + "\", " + "airbrakeProjectKey: \"" + pageInformation.AirbrakeProjectKey + "\", " + "airbrakeEnvironmentName: \"" + pageInformation.AirbrakeEnvironmentName + "\", " + "onedriveClientId: \"" + pageInformation.OneDriveClientID + "\", " + "cssFileVersion: \"" + pageInformation.CSSFileVersion + "\", " + "jsFileVersion: \"" + pageInformation.JSFileVersion + "\", " + "schemaVersion: \"" + pageInformation.SchemaVersion + "\", " + "environment: \"" + CurrentEnvironment.ToString() + "\" " + "};"; if (!string.IsNullOrEmpty(pageInformation.Title)) { XElement titleNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:title", xmlNamespaceManager); titleNode.Value = string.Format(CultureInfo.InvariantCulture, "{0} - ChronoZoom", pageInformation.Title); } if (!string.IsNullOrEmpty(pageInformation.Description)) { XElement metaDescription = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='Description']", xmlNamespaceManager); XName contentAttribute = "content"; metaDescription.SetAttributeValue(contentAttribute, pageInformation.Description); } XElement lastMetaTag = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", xmlNamespaceManager); int imageCount = 0; foreach (string image in pageInformation.Images) { if (++imageCount > 3) { break; } XName metaNode = "meta"; XName linkNode = "link"; lastMetaTag.AddAfterSelf( new XElement( linkNode, new XAttribute("rel", "image_src"), new XAttribute("href", image) ), new XElement( metaNode, new XAttribute("property", "og:image"), new XAttribute("content", image) ) ); } }
private static void ComposePage(XDocument pageRoot, XmlNamespaceManager xmlNamespaceManager, PageInformation pageInformation) { XElement scriptNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:script[@id='constants']", xmlNamespaceManager); scriptNode.Value = "var constants = { " + "analyticsId: \"" + pageInformation.AnalyticsServiceId + "\", " + "exceptionsId: \"" + pageInformation.ExceptionsServiceId + "\", " + "environment: \"" + CurrentEnvironment.ToString() + "\" " + "};"; if (!string.IsNullOrEmpty(pageInformation.Title)) { XElement titleNode = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:title", xmlNamespaceManager); titleNode.Value = string.Format(CultureInfo.InvariantCulture, "{0} - ChronoZoom", pageInformation.Title); } if (!string.IsNullOrEmpty(pageInformation.Description)) { XElement metaDescription = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='Description']", xmlNamespaceManager); XName contentAttribute = "content"; metaDescription.SetAttributeValue(contentAttribute, pageInformation.Description); } XElement metaIECompatibile = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@http-equiv='X-UA-Compatible']", xmlNamespaceManager); XName contentIEAttribute = "content"; metaIECompatibile.SetAttributeValue(contentIEAttribute, "IE=edge"); XElement lastMetaTag = pageRoot.XPathSelectElement("/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", xmlNamespaceManager); int imageCount = 0; foreach (string image in pageInformation.Images) { if (++imageCount > 3) { break; } XName metaNode = "meta"; XName linkNode = "link"; lastMetaTag.AddAfterSelf( new XElement( linkNode, new XAttribute("rel", "image_src"), new XAttribute("href", image) ), new XElement( metaNode, new XAttribute("property", "og:image"), new XAttribute("content", image) ) ); } }
private static bool PageIsDynamic(Uri pageUrl, out PageInformation pageInformation) { pageInformation = new PageInformation(); // if the home page was specified if ( pageUrl.Segments.Length == 1 || pageUrl.ToString().EndsWith("default.ashx", StringComparison.OrdinalIgnoreCase) ) { // then exit reporting page is not dynamic return(false); } // home page was not specified so ascertain the superCollection title and collection Path from the URL string superCollectionSegment = Regex.Replace(pageUrl.Segments[1].Trim(), @"[^A-Za-z0-9]+", "").ToLower(); string collectionSegment = pageUrl.Segments.Length < 3 ? "" : Regex.Replace(pageUrl.Segments[2].Trim(), @"[^A-Za-z0-9]+", "").ToLower(); // try to look up collection id Guid collectionId = ChronozoomSVC.Instance.CollectionIdOrDefault(_storage, superCollectionSegment, collectionSegment); // if collection id could not be found if (collectionId == Guid.Empty) { // if collection segment was specified (and also the supercollection segment) if (collectionSegment != "") { // redirect to the default collection for the specified supercollection HttpContext.Current.Response.Redirect("/" + superCollectionSegment + "#"); return(false); } // otherwise redirect to the default supercollection's default collection HttpContext.Current.Response.Redirect("/#"); return(false); } // set page title to collection title (must be server-side and not through JS for SEO purposes) pageInformation.Title = (ChronozoomSVC.Instance.GetCollection(superCollectionSegment, collectionSegment)).Title; // collection id was found so try to get root timeline and its accoutriments Timeline timeline = ChronozoomSVC.Instance.GetTimelines(superCollectionSegment, collectionSegment, null, null, null, null, null, "1"); if (timeline == null) { // a timeline for this collection could not be found so exit reporting page is not dynamic return(false); } // timeline was found so populate rest of page contents and report page is dynamic foreach (Exhibit exhibit in timeline.Exhibits) { foreach (ContentItem contentItem in exhibit.ContentItems) { if (contentItem.Uri.ToString().EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)) { pageInformation.Images.Add(contentItem.Uri); } } } return(true); }