internal static async Task <string> GetPreviewFunctionPreviewImageFile(HttpContext context) { string previewUrl = context.Request.Url.ToString().Replace("/FunctionBox?", "/FunctionPreview.ashx?"); var renderingResult = await BrowserRender.RenderUrlAsync(context, previewUrl, RenderingMode); if (renderingResult == null) { return(null); } if (renderingResult.Status == RenderingResultStatus.Success) { return(renderingResult.FilePath); } if (renderingResult.Status >= RenderingResultStatus.Error) { string functionTitle = context.Request.QueryString["title"] ?? "null"; Log.LogWarning("FunctionPreview", "Failed to build preview for function '{0}'. Reason: {1}; Output:\r\n{2}", functionTitle, renderingResult.Status, string.Join(Environment.NewLine, renderingResult.Output)); } return(null); }
private void context_AuthorizeRequest(object sender, EventArgs e) { var application = (HttpApplication)sender; HttpContext context = application.Context; string currentPath = context.Request.Path.ToLowerInvariant(); if (_adminRootPath == null || !currentPath.StartsWith(_adminRootPath)) { return; } if (!_allowC1ConsoleRequests) { context.Response.StatusCode = 403; context.Response.ContentType = "text/html"; string iePadding = new String('!', 512); context.Response.Write(string.Format(c1ConsoleRequestsNotAllowedHtmlTemplate, iePadding)); context.Response.End(); return; } var url = context.Request.Url; // https check if (_forceHttps && url.Scheme != "https") { if (!AlwaysAllowUnsecured(url.LocalPath) && !UserOptedOutOfHttps(context)) { context.Response.Redirect( $"{unsecureRedirectRelativePath}?fallback={_allowFallbackToHttp.ToString().ToLower()}&httpsport={_customHttpsPortNumber}"); } } // access check if (currentPath.Length > _adminRootPath.Length && !UserValidationFacade.IsLoggedIn() && !_allAllowedPaths.Any(p => currentPath.StartsWith(p, StringComparison.OrdinalIgnoreCase))) { if (currentPath.StartsWith(_servicesPath)) { context.Response.StatusCode = 403; context.Response.End(); return; } Log.LogWarning("Authorization", "DENIED {0} access to {1}", context.Request.UserHostAddress, currentPath); string redirectUrl = $"{_loginPagePath}?ReturnUrl={HttpUtility.UrlEncode(url.PathAndQuery, Encoding.UTF8)}"; context.Response.Redirect(redirectUrl, true); return; } // On authenticated request make sure these resources gets compiled / launched. if (IsConsoleOnline) { BrowserRender.EnsureReadiness(); BuildManagerHelper.InitializeControlPreLoading(); } }
/// <exclude /> public static int GetFunctionPreviewHash() { if (!GlobalSettingsFacade.FunctionPreviewEnabled) { return(0); } return(BrowserRender.GetLastCacheUpdateTime(RenderingMode).GetHashCode()); }
internal static async Task <string> GetPreviewFunctionPreviewImageFile(HttpContext context) { string previewUrl = context.Request.Url.ToString().Replace("/FunctionBox?", "/FunctionPreview.ashx?"); var renderingResult = await BrowserRender.RenderUrlAsync(context, previewUrl, RenderingMode); if (renderingResult == null) { return(null); } if (renderingResult.Status == BrowserRender.RenderingResultStatus.Success) { return(renderingResult.FilePath); } if (renderingResult.Status >= BrowserRender.RenderingResultStatus.Error) { Log.LogWarning("FunctionPreview", "Failed to build preview for function. Reason: {0}; Output:\r\n{1}", renderingResult.Status, renderingResult.Output); } return(null); }
/// <exclude /> public static bool GetPreviewInformation(HttpContext context, Guid pageId, Guid templateId, out string imageFilePath, out PlaceholderInformation[] placeholders) { int updateHash = BrowserRender.GetLastCacheUpdateTime(RenderingMode).GetHashCode(); string requestUrl = new UrlBuilder(context.Request.Url.ToString()).ServerUrl + ServiceUrl + $"?p={pageId}&t={templateId}&hash={updateHash}"; RenderingResult result = null; var renderTask = BrowserRender.RenderUrlAsync(context, requestUrl, RenderingMode); renderTask.Wait(10000); if (renderTask.Status == TaskStatus.RanToCompletion) { result = renderTask.Result; } if (result == null) { imageFilePath = null; placeholders = null; return(false); } if (result.Status != RenderingResultStatus.Success) { Log.LogWarning("PageTemplatePreview", "Failed to build preview for page template '{0}'. Reason: {1}; Output:\r\n{2}", templateId, result.Status, result.Output); imageFilePath = null; placeholders = null; return(false); } imageFilePath = result.FilePath; ICollection <string> output = result.Output; const string templateInfoPrefix = "templateInfo:"; var placeholderData = output.FirstOrDefault(l => l.StartsWith(templateInfoPrefix)); var pList = new List <PlaceholderInformation>(); // TODO: use JSON if (placeholderData != null) { foreach (var infoPart in placeholderData.Substring(templateInfoPrefix.Length).Split('|')) { string[] parts = infoPart.Split(','); double left, top, width, height; if (parts.Length != 5 || !double.TryParse(parts[1], out left) || !double.TryParse(parts[2], out top) || !double.TryParse(parts[3], out width) || !double.TryParse(parts[4], out height)) { throw new InvalidOperationException($"Incorrectly serialized template part info: {infoPart}"); } var zoom = 1.0; pList.Add(new PlaceholderInformation { PlaceholderId = parts[0], ClientRectangle = new Rectangle((int)left, (int)top, (int)width, (int)height), ClientRectangleWithZoom = new Rectangle( (int)Math.Round(zoom * left), (int)Math.Round(zoom * top), (int)Math.Round(zoom * width), (int)Math.Round(zoom * height)) }); } } placeholders = pList.ToArray(); return(true); }
/// <exclude /> public static void ClearCache() { BrowserRender.ClearCache(RenderingMode); }
/// <exclude /> public static bool GetPreviewInformation(HttpContext context, Guid pageId, Guid templateId, out string imageFilePath, out PlaceholderInformation[] placeholders) { int updateHash = BrowserRender.GetLastCacheUpdateTime(RenderingMode).GetHashCode(); string requestUrl = new UrlBuilder(context.Request.Url.ToString()).ServerUrl + ServiceUrl + "?p=" + pageId + "&t=" + templateId + "&hash=" + updateHash; BrowserRender.RenderingResult result = null; var renderTask = BrowserRender.RenderUrlAsync(context, requestUrl, RenderingMode); renderTask.Wait(10000); if (renderTask.Status == TaskStatus.RanToCompletion) { result = renderTask.Result; } if (result == null) { imageFilePath = null; placeholders = null; return(false); } if (result.Status != BrowserRender.RenderingResultStatus.Success) { Log.LogWarning("PageTemplatePreview", "Failed to build preview for page template '{0}'. Reason: {1}; Output:\r\n{2}", templateId, result.Status, result.Output); imageFilePath = null; placeholders = null; return(false); } imageFilePath = result.FilePath; string output = result.Output; var pList = new List <PlaceholderInformation>(); string templateInfoPrefix = "templateInfo:"; if (output.StartsWith(templateInfoPrefix)) { foreach (var infoPart in output.Substring(templateInfoPrefix.Length).Split('|')) { string[] parts = infoPart.Split(','); Verify.That(parts.Length == 5, "Incorrectly serialized template part info: " + infoPart); int left = Int32.Parse(parts[1]); int top = Int32.Parse(parts[2]); int width = Int32.Parse(parts[3]); int height = Int32.Parse(parts[4]); var zoom = 1.0; pList.Add(new PlaceholderInformation { PlaceholderId = parts[0], ClientRectangle = new Rectangle(left, top, width, height), ClientRectangleWithZoom = new Rectangle( (int)Math.Round(zoom * left), (int)Math.Round(zoom * top), (int)Math.Round(zoom * width), (int)Math.Round(zoom * height)) }); } } placeholders = pList.ToArray(); return(true); }
static FunctionPreview() { GlobalEventSystemFacade.OnDesignChange += () => BrowserRender.ClearCache(RenderingMode); }
/// <exclude /> public static int GetFunctionPreviewHash() { return(BrowserRender.GetLastCacheUpdateTime(RenderingMode).GetHashCode()); }