public static RegionModel ValidRegionModel(PageRegion pageRegion) { return(new RegionModel { PageRegion = pageRegion, }); }
public void Prepare( PageRegion previousSection, PageMargin previousSectionMargin, DocumentVariables documentVariables) { var sectionBreak = _properties.StartOnNextPage ? SectionContentBreak.Page : SectionContentBreak.None; IPage contentPageRequest(PageNumber pageNumber) => this.OnPageRequest(pageNumber, previousSection.PagePosition.PageNumber, previousSectionMargin, documentVariables); var contentLastPosition = previousSection; foreach (var content in _contents) { content.Prepare(previousSection, contentLastPosition, sectionBreak, contentPageRequest); contentLastPosition = content.LastPageRegion; sectionBreak = content.SectionBreak; } var pr = _contents .SelectMany(c => c.PageRegions) .UnionThroughColumns() .ToArray(); this.ResetPageRegions(pr); }
public static LegacyRegionModel ValidLegacyRegionModel(string path, PageRegion pageRegion) { return(new LegacyRegionModel { Path = path, PageRegion = pageRegion, RegionEndpoint = "https://somewhere.com", }); }
public void MarkupMessagesReturnsRegionOfflineMessage(PageRegion pageRegion, string expected) { // arrange var model = new MarkupMessages(); // act var result = model.GetRegionOfflineHtml(pageRegion); // assert Assert.Equal(expected, result); }
private static HtmlString GetContent(PageViewModel pageViewModel, PageRegion pageRegionType) { var result = string.Empty; var pageRegionContentModel = pageViewModel.PageRegionContentModels.FirstOrDefault(x => x.PageRegionType == pageRegionType); if (pageRegionContentModel != null && pageRegionContentModel.Content != null) { result = pageRegionContentModel.Content.Value; } return(new HtmlString(result)); }
public async Task SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { var appRegistrationModel = await GetAppRegistrationModel(path); var regionModel = appRegistrationModel?.Regions?.FirstOrDefault(f => f.PageRegion == pageRegion); if (regionModel != null) { regionModel.IsHealthy = isHealthy; await appRegistryService.SetRegionHealthState(path, pageRegion, isHealthy); } }
public override void Prepare(IPage page) { var pagePosition = new PagePosition(page.PageNumber); var region = page .GetPageRegion() .Crop(page.Margin.Top, this.PageMargin.Right, this.PageMargin.Footer, this.PageMargin.Left); var context = new PageContext(pagePosition, region, page.DocumentVariables); PageContext childContextRequest(PagePosition pagePosition, PageContextElement child) => this.OutOfPageContextFactory(page); var absoluteHeight = page.Configuration.Height; var spaceAfterPrevious = 0.0; foreach (var child in _childs) { child.Prepare(context, childContextRequest); var lastRegion = child.LastPageRegion; spaceAfterPrevious = child.CalculateSpaceAfter(_childs); var cropFromTop = Math.Min(lastRegion.Region.Height + spaceAfterPrevious, absoluteHeight - 0.001); context = context.CropFromTop(cropFromTop); } var boundingRegion = _childs .SelectMany(c => c.PageRegions.Where(pr => pr.PagePosition.PageNumber == page.PageNumber)) .UnionPageRegions(Margin.None) .ToArray() .Single(); var offsetY = page.Configuration.Height - page.Margin.Top - Math.Max(boundingRegion.Region.Height, this.PageMargin.FooterHeight) - this.PageMargin.Footer; _pageOffset = new Point(0, offsetY); foreach (var child in _childs) { child.SetPageOffset(_pageOffset); } if (boundingRegion.Region.Height < this.PageMargin.FooterHeight) { var resized = new Rectangle(boundingRegion.Region.TopLeft, boundingRegion.Region.Width, this.PageMargin.FooterHeight); boundingRegion = new PageRegion(boundingRegion.PagePosition, resized); } this.ResetPageRegions(new[] { boundingRegion }); }
public async Task <bool> SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { var regionsUrl = $"{httpClient.BaseAddress}api/paths/{path}/regions/{(int)pageRegion}"; var regionPatchModel = new RegionPatchModel { IsHealthy = isHealthy }; var jsonRequest = JsonConvert.SerializeObject(regionPatchModel); using (var content = new StringContent(jsonRequest, Encoding.UTF8, MediaTypeNames.Application.Json)) { var response = await httpClient.PatchAsync(new Uri(regionsUrl), content).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return(response.IsSuccessStatusCode); } }
public async Task <bool> MarkRegionAsHealthy(string path, PageRegion pageRegion) { var url = $"appregistry/{path}/regions/{(int)pageRegion}"; try { var model = new JsonPatchDocument <PatchModel>().Add(x => x.IsHealthy, true); var response = await httpClientFactory.CreateClient(HttpClientName.AppRegistry).PatchAsJsonAsync(url, model).ConfigureAwait(false); return(response.IsSuccessStatusCode); } catch (Exception ex) { logger.LogError(ex, $"Error from Health checking url '{url}'"); return(false); } }
private Task <string> GetMarkup(List <Task <string> > tasks, PageRegion regionType, IEnumerable <RegionModel> regions, string article) { var pageRegionModel = regions.FirstOrDefault(x => x.PageRegion == regionType); if (pageRegionModel == null || string.IsNullOrWhiteSpace(pageRegionModel.RegionEndpoint)) { return(Task.FromResult <string>(null)); } if (!pageRegionModel.IsHealthy) { return(Task.FromResult(pageRegionModel.OfflineHTML)); } var url = FormatArticleUrl(pageRegionModel.RegionEndpoint, article, string.Empty); var task = contentRetriever.GetContent(url, pageRegionModel, true, RequestBaseUrl); tasks.Add(task); return(task); }
private Task <string> GetMarkup(List <Task <string> > tasks, string path, PageRegion regionType, IEnumerable <RegionModel> regions, string article, string queryString, IHeaderDictionary headers) { var pageRegionModel = regions.FirstOrDefault(x => x.PageRegion == regionType); if (pageRegionModel == null || string.IsNullOrWhiteSpace(pageRegionModel.RegionEndpoint)) { return(Task.FromResult <string>(null)); } if (!pageRegionModel.IsHealthy) { return(Task.FromResult(!string.IsNullOrWhiteSpace(pageRegionModel.OfflineHtml) ? pageRegionModel.OfflineHtml : markupMessages.GetRegionOfflineHtml(pageRegionModel.PageRegion))); } var url = FormatArticleUrl(pageRegionModel.RegionEndpoint, article, queryString); var task = contentRetriever.GetContent(url, path, pageRegionModel, true, RequestBaseUrl, headers); tasks.Add(task); return(task); }
public void Prepare( PageRegion previousSection, PageRegion previousContent, SectionContentBreak previousBreak, Func <PageNumber, IPage> pageFactory) { var context = this.CreateInitialPageContext(previousSection, previousContent, previousBreak, pageFactory); Func <PagePosition, PageContextElement, PageContext> childContextRequest = (pagePosition, child) => this.OnChildPageContextRequest(pagePosition, pageFactory); var spaceAfterPrevious = 0.0; foreach (var child in _childs) { child.Prepare(context, childContextRequest); var lastRegion = child.LastPageRegion; spaceAfterPrevious = child.CalculateSpaceAfter(_childs); context = this.CreateContextForPagePosition(lastRegion.PagePosition, lastRegion.Region, spaceAfterPrevious, pageFactory); } this.ResetPageRegionsFrom(_childs); }
public async Task <bool> SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { var patchUrl = new Uri($"{httpClient.BaseAddress}{path}/regions/{(int)pageRegion}", UriKind.Absolute); var regionPatchModel = new JsonPatchDocument <RegionModel>().Add(x => x.IsHealthy, isHealthy); var jsonRequest = JsonConvert.SerializeObject(regionPatchModel); using var content = new StringContent(jsonRequest, Encoding.UTF8, MediaTypeNames.Application.Json); try { var response = await httpClient.PatchAsync(patchUrl, content).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return(response.IsSuccessStatusCode); } catch (BrokenCircuitException ex) { logger.LogError(ex, $"{nameof(SetRegionHealthState)}: BrokenCircuit: {patchUrl} - {ex.Message}, marking AppRegistration: {path}.{pageRegion} IsHealthy = {isHealthy}"); return(false); } }
private PageContext CreateInitialPageContext( PageRegion previousSection, PageRegion previousContent, SectionContentBreak previousBreak, Func <PageNumber, IPage> pageFactory) { var spaceAfterPrevious = 0; switch (previousBreak) { case SectionContentBreak.None: { var pp = previousSection.PagePosition.SamePage(PageColumn.First, _columnsConfiguration.ColumnsCount); return(this.CreateContextForPagePosition(pp, previousSection.Region, spaceAfterPrevious, pageFactory)); } case SectionContentBreak.Column: { var pp = previousContent.PagePosition.Next(); var occupiedRegion = pp.PageNumber == previousSection.PagePosition.PageNumber ? previousSection.Region : Rectangle.Empty; return(this.CreateContextForPagePosition(pp, occupiedRegion, spaceAfterPrevious, pageFactory)); } case SectionContentBreak.Page: { var pp = previousContent.PagePosition.NextPage(PageColumn.First, _columnsConfiguration.ColumnsCount); return(this.CreateContextForPagePosition(pp, Rectangle.Empty, spaceAfterPrevious, pageFactory)); } default: throw new RendererException("unhandled section break;"); } }
public async Task <bool> SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { return(await Task.FromResult(true).ConfigureAwait(false)); }
private void PopulatePageRegionContent(ApplicationModel application, PageViewModel pageModel, PageRegion regionType, Task <string> task) { if (task == null) { return; } string outputHtmlMarkup = string.Empty; if (taskHelper.TaskCompletedSuccessfully(task)) { var taskResult = task.Result; var result = contentProcessorService.Process(taskResult, RequestBaseUrl, application.RootUrl); outputHtmlMarkup = result; } else { var pageRegionModel = application.AppRegistrationModel.Regions.FirstOrDefault(x => x.PageRegion == regionType); if (pageRegionModel != null) { outputHtmlMarkup = !string.IsNullOrWhiteSpace(pageRegionModel.OfflineHtml) ? pageRegionModel.OfflineHtml : markupMessages.GetRegionOfflineHtml(pageRegionModel.PageRegion); } } var pageRegionContentModel = pageModel.PageRegionContentModels.FirstOrDefault(x => x.PageRegionType == regionType); if (pageRegionContentModel != null) { pageRegionContentModel.Content = new HtmlString(outputHtmlMarkup); } }
public Task <bool> SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { throw new NotImplementedException(); }
public Task <bool> SetRegionHealthState(string path, PageRegion pageRegion, bool isHealthy) { return(Task.FromResult(true)); }
public string GetRegionOfflineHtml(PageRegion pageRegion) { return(RegionOfflineHtml.ContainsKey(pageRegion) ? RegionOfflineHtml[pageRegion] : null); }