public ArticleModel(DocumentationPage page, TableOfContents tableOfContents) { Key = page.Key; //TableOfContents = tableOfContents; Title = page.Title; HtmlContent = page.HtmlContent; }
public void Process_ExistingPage() { // Arrange var dataStorePage = Models.CreateDocumentationPage(id: 84926); var clientPage = new DocumentationPage { Id = dataStorePage.Id, // Same id as data store page because this is an existing page. Title = dataStorePage.Title, Content = dataStorePage.Content, Order = dataStorePage.Order, ParentPageId = dataStorePage.ParentPageId, }; var documentationPageRepository = Mocks.Create <IDocumentationPageRepository>(); documentationPageRepository.Setup(r => r.Read(clientPage.Id)).Returns(dataStorePage); documentationPageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == clientPage.Id))); var serializer = new JavaScriptSerializer(); var requestData = serializer.Serialize(clientPage); var processor = new SaveDocumentationPageRequestProcessor(documentationPageRepository.Object); // Act var result = processor.Process(requestData); // Assert Assert.That(result, Is.Not.Null, "A response state instance should be returned."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "The response content should contain JSON."); var resultPage = serializer.Deserialize <DocumentationPage>(result.Content); Assert.That(resultPage.Id, Is.EqualTo(clientPage.Id), "The page id should not change."); Mocks.VerifyAll(); }
public IEnumerable <DocumentationPage> AllPages(DocumentationPage parentPage = null) { if (parentPage == null) { foreach (var page in Pages) { yield return(page); foreach (var item in AllPages(page)) { yield return(item); } } } else { foreach (var childPage in parentPage.ChildPages) { yield return(childPage); foreach (var item in AllPages(childPage)) { yield return(item); } } } }
private static void AddParameters(DocumentationPage page, SqlCommand command) { command.Parameters.AddRange(new SqlParameter[] { new SqlParameter("@parentPageId", (object)page.ParentPageId ?? DBNull.Value), new SqlParameter("@order", (object)page.Order ?? DBNull.Value), new SqlParameter("@title", page.Title), new SqlParameter("@content", page.Content), new SqlParameter("@isHidden", page.IsHidden), }); }
public void OutputPage(DocumentationPage page) { Output.AppendFormat("<div id='page-{0}' class='page' >", page.Name.Replace(" ", "")); page.GetContent(this); Output.Append("</div>"); foreach (var child in page.ChildPages) { OutputPage(child); } }
public static void ShowWindow(DocumentationPage page) { var window = GetWindow <uFrameHelp>(); window.title = "uFrame Help"; window.minSize = new Vector2(1100, 806); if (page != null) { window.ShowPage(page); } window.ShowUtility(); }
private void PageLink(DocumentationPage page, StringBuilder builder) { if (PageLinkHandler != null) { builder.Append(PageLinkHandler(page)); } else { builder.AppendFormat("<a href='{0}.html' target='content-frame'>{1}</a>", page.Name.Replace(" ", ""), page.Name).AppendLine(); } //onclick=\"$('.page').hide(); $('#page-{0}').show();\" }
public void Create(DocumentationPage page) { using (var connection = SqlConnectionFactory.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = SqlScripts.DocumentationPage_Create; AddParameters(page, command); connection.Open(); page.Id = (int)command.ExecuteScalar(); } }
public void Update(DocumentationPage page) { using (var connection = SqlConnectionFactory.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = SqlScripts.DocumentationPage_Update; AddParameters(page, command); command.Parameters.Add(new SqlParameter("@id", page.Id)); connection.Open(); command.ExecuteNonQuery(); } }
private PageLinksValidationResult ValidatePageLinks(HttpClient client, DocumentationPage page, IList <DocumentationPage> pages) { var result = new PageLinksValidationResult(page.Key, page.Language == Language.All ? _currentLanguage : page.Language, page.Version); var htmlDocument = HtmlHelper.ParseHtml(page.HtmlContent); var links = htmlDocument.DocumentNode.SelectNodes("//a[@href]"); if (links == null) { return(result); } var currentUri = new Uri(_options.RootUrl + page.Key + "/../"); foreach (var link in links) { var hrefAttribute = link.Attributes["href"]; var href = hrefAttribute.Value.Trim(); try { var isValid = false; Uri uri = null; if (string.IsNullOrEmpty(href) == false) { uri = href.StartsWith("http") ? new Uri(href, UriKind.Absolute) : new Uri(currentUri + href, UriKind.Absolute); var indexOfHash = uri.AbsoluteUri.IndexOf("#", StringComparison.InvariantCultureIgnoreCase); if (indexOfHash != -1) { var potentialGuid = uri.AbsoluteUri.Substring(indexOfHash + 1); Guid guid; if (Guid.TryParse(potentialGuid, out guid)) { continue; } } isValid = ValidatePageLink(client, uri); } result.Links[string.Format("[{0}][{1}]", link.InnerText, uri)] = isValid; } catch (Exception) { result.Links[href] = false; } } return(result); }
public void OutputTOC(DocumentationPage page, StringBuilder builder, int indent = 1) { if (!page.ShowInNavigation) { return; } builder.AppendFormat("<div class='page-toc page-{0}'>", page.Name.Replace(" ", "").ToLower()); PageLink(page, builder); builder.AppendFormat("<div class='page-toc-margin' style='margin-left: {0}px'>", indent * 10); foreach (var child in page.ChildPages.OrderBy(p => p.Order)) { OutputTOC(child, builder, indent + 1); } builder.AppendLine("</div>"); builder.AppendLine("</div>"); }
private static void GetValue(DocumentationPage[] allPages, List<DocumentationPage> pages, DocumentationPage parentPage) { foreach (var page in allPages) { // foreach (var page in allPages // .Where(p => p.ParentPage == (parentPage == null ? null : parentPage.GetType()))) if (parentPage != null && page.ParentPage != null && page.ParentPage.IsAssignableFrom(parentPage.GetType())) { pages.Add(page); GetValue(allPages, page.ChildPages, page); } else if (parentPage == null && page.ParentPage == null) { pages.Add(page); GetValue(allPages, page.ChildPages, page); } } }
public DocumentationPage Read(int id) { DocumentationPage result = null; using (var connection = SqlConnectionFactory.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = SqlScripts.DocumentationPage_ReadById; command.Parameters.Add(new SqlParameter("@id", id)); connection.Open(); using (var reader = command.ExecuteReader()) { result = HydratePages(reader).FirstOrDefault(); } } return(result); }
public DocumentationPage CreateDocumentationPage( int id = 0, int?parentPageId = null, string title = null, int order = 1, bool isHidden = false) { title = title ?? string.Format("Unit Test Help {0}", _documentationPageCount.ToString("00#")); var result = new DocumentationPage { Id = id, Content = "Test content for documentation page.", Order = order, ParentPageId = parentPageId, Title = title, IsHidden = isHidden, }; _documentationPageCount++; return(result); }
private IEnumerable <DocumentationPage> HydratePages(SqlDataReader reader) { var idOrdinal = reader.GetOrdinal("Id"); var parentPageIdOrdinal = reader.GetOrdinal("ParentPageId"); var orderOrdinal = reader.GetOrdinal("Order"); var titleOrdinal = reader.GetOrdinal("Title"); var contentOrdinal = reader.GetOrdinal("Content"); var isHiddenOrdinal = reader.GetOrdinal("IsHidden"); while (reader.Read()) { var result = new DocumentationPage { Id = reader.GetInt32(idOrdinal), ParentPageId = reader.IsDBNull(parentPageIdOrdinal) ? (int?)null : reader.GetInt32(parentPageIdOrdinal), Order = reader.GetInt32(orderOrdinal), Title = reader.GetString(titleOrdinal), Content = reader.GetString(contentOrdinal), IsHidden = reader.GetBoolean(isHiddenOrdinal) }; yield return(result); } }
private PageLinksValidationResult ValidatePageLinks(HttpClient client, DocumentationPage page) { void ValidateLinks(HttpClient httpClient, List <HtmlNode> toValidate, Uri baseUri, PageLinksValidationResult results) { foreach (var link in toValidate) { var hrefAttribute = link.Attributes["href"]; var href = hrefAttribute.Value.Trim(); try { var isValid = false; Uri uri = null; if (string.IsNullOrEmpty(href) == false) { uri = href.StartsWith("http") ? new Uri(href, UriKind.Absolute) : new Uri(baseUri + href, UriKind.Absolute); var indexOfHash = uri.AbsoluteUri.IndexOf("#", StringComparison.InvariantCultureIgnoreCase); if (indexOfHash != -1) { var potentialGuid = uri.AbsoluteUri.Substring(indexOfHash + 1); if (Guid.TryParse(potentialGuid, out Guid _)) { continue; } } isValid = ValidatePageLink(httpClient, uri); } results.Links[$"[{link.InnerText}][{uri}]"] = isValid; } catch (Exception) { results.Links[href] = false; } } } var result = new PageLinksValidationResult(page.Key, page.Language == Language.All ? _currentLanguage : page.Language, page.Version); var htmlDocument = HtmlHelper.ParseHtml(page.HtmlContent); var linksToValidate = new List <HtmlNode>(); var links = htmlDocument.DocumentNode.SelectNodes("//a[@href]"); if (links != null) { linksToValidate.AddRange(links); } if (string.IsNullOrWhiteSpace(page.RelatedArticlesContent) == false) { htmlDocument = HtmlHelper.ParseHtml(page.RelatedArticlesContent); links = htmlDocument.DocumentNode.SelectNodes("//a[@href]"); if (links != null) { linksToValidate.AddRange(links); } } if (linksToValidate.Count == 0) { return(result); } var currentUri = new Uri(_options.RootUrl + page.Key + "/../"); ValidateLinks(client, linksToValidate, currentUri, result); return(result); }
private void ShowPage(DocumentationPage page) { LastPage = page.Name; PageStack.Push(page); }