/// <summary> /// Renders the resource in the specified <see cref="IHtmlWriter" />. /// </summary> public override void Render(IHtmlWriter writer, IDotvvmRequestContext context) { if (CdnUrl != null) { writer.AddAttribute("src", CdnUrl); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); if (Url != null && GlobalObjectName != null) { writer.RenderBeginTag("script"); var url = context.TranslateVirtualPath(GetUrl()); writer.WriteUnencodedText(string.Format(CdnFallbackScript, GlobalObjectName, url)); writer.RenderEndTag(); } } else if (Url != null) { writer.AddAttribute("src", GetUrl()); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.RenderEndTag(); } }
public static string EvaluateRouteUrl(string routeName, RouteLink control, IDotvvmRequestContext context) { var urlSuffix = GenerateUrlSuffixCore(control.GetValue(RouteLink.UrlSuffixProperty) as string, control); var coreUrl = GenerateRouteUrlCore(routeName, control, context) + urlSuffix; return(context.TranslateVirtualPath(coreUrl)); }
public void RenderHtmlAttribute(IHtmlWriter writer, IDotvvmRequestContext requestContext, string attributeName, object attributeValue) { if (attributeValue != null) { attributeValue = requestContext.TranslateVirtualPath((string)attributeValue); } writer.WriteHtmlAttribute(attributeName, (string)attributeValue); }
public static string GenerateKnockoutHrefExpression(string routeName, RouteLink control, IDotvvmRequestContext context) { var link = GenerateRouteLinkCore(routeName, control, context); var urlSuffix = GetUrlSuffixExpression(control); return($"'{context.TranslateVirtualPath("~/")}' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"); }
public static string BuildUrl(IDotvvmRequestContext context, string routeName, object routeParams = null, object queryStringParams = null, string urlSuffix = null, bool keepCurrentRouteParams = true) { var baseUrl = keepCurrentRouteParams ? context.Configuration.RouteTable[routeName].BuildUrl(context.Parameters, routeParams) : context.Configuration.RouteTable[routeName].BuildUrl(routeParams); var suffix = UrlHelper.BuildUrlSuffix(urlSuffix, queryStringParams); return(context.TranslateVirtualPath(baseUrl + suffix)); }
public override void Render(IHtmlWriter writer, IDotvvmRequestContext context, string resourceName) { var resource = (ScriptResource)context.ResourceManager.FindResource(ResourceConstants.PolyfillBundleResourceName); var resourceUrl = context.TranslateVirtualPath( resource.Location.GetUrl(context, ResourceConstants.PolyfillBundleResourceName)); writer.AddAttribute("type", "text/javascript"); writer.RenderBeginTag("script"); writer.WriteUnencodedText($"dotvvm__polyfillUrl = '{resourceUrl}';"); writer.RenderEndTag(); }
private static async Task <string> GetRemoteResource(UrlResourceLocation resource, IDotvvmRequestContext context) { using (var web = new WebClient()) { string address = context.TranslateVirtualPath(resource.Url); if (!Uri.TryCreate(address, UriKind.Absolute, out var result)) { var baseUrl = new Uri(context.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority)); address = context.TranslateVirtualPath($"~/{resource.Url}"); result = new Uri(baseUrl, address); } ; using (Stream stream = web.OpenRead(result)) using (var reader = new StreamReader(stream ?? throw new ArgumentException($"Unable to load resource at {resource}"))) { var readToEnd = reader.ReadToEnd(); return(await Task.FromResult(readToEnd)); } } }
public static string EvaluateRouteUrl(string routeName, HtmlGenericControl control, DotvvmProperty urlSuffixProperty, IDotvvmRequestContext context) { var coreUrl = GenerateRouteUrlCore(routeName, control, context) + (control.GetValue(urlSuffixProperty) as string ?? ""); if ((bool)control.GetValue(Internal.IsSpaPageProperty)) { return "#!/" + coreUrl; } else { return context.TranslateVirtualPath(coreUrl); } }
public static string EvaluateRouteUrl(string routeName, HtmlGenericControl control, DotvvmProperty urlSuffixProperty, IDotvvmRequestContext context) { var coreUrl = GenerateRouteUrlCore(routeName, control, context) + (control.GetValue(urlSuffixProperty) as string ?? ""); if ((bool)control.GetValue(Internal.IsSpaPageProperty)) { return("#!/" + coreUrl); } else { return(context.TranslateVirtualPath(coreUrl)); } }
public static string EvaluateRouteUrl(string routeName, RouteLink control, IDotvvmRequestContext context) { var urlSuffix = GenerateUrlSuffixCore(control.GetValue(RouteLink.UrlSuffixProperty) as string, control); var coreUrl = GenerateRouteUrlCore(routeName, control, context) + urlSuffix; if ((bool)control.GetValue(Internal.IsSpaPageProperty) && !(bool)control.GetValue(Internal.UseHistoryApiSpaNavigationProperty)) { return("#!/" + (coreUrl.StartsWith("~/", StringComparison.Ordinal) ? coreUrl.Substring(2) : coreUrl)); } else { return(context.TranslateVirtualPath(coreUrl)); } }
public static string EvaluateRouteUrl(string routeName, RouteLink control, IDotvvmRequestContext context) { var urlSuffix = GenerateUrlSuffixCore(control.GetValue(RouteLink.UrlSuffixProperty) as string, control); var coreUrl = GenerateRouteUrlCore(routeName, control, context) + urlSuffix; if ((bool)control.GetValue(Internal.IsSpaPageProperty)) { return("#!/" + coreUrl); } else { return(context.TranslateVirtualPath(coreUrl)); } }
public static string GenerateKnockoutHrefExpression(string routeName, HtmlGenericControl control, DotvvmProperty urlSuffixProperty, IDotvvmRequestContext context) { var link = GenerateRouteLinkCore(routeName, control, context); var urlSuffix = GetUrlSuffixExpression(control, urlSuffixProperty); if ((bool)control.GetValue(Internal.IsSpaPageProperty)) { return $"'#!/' + {link} + {urlSuffix}"; } else { return $"'{context.TranslateVirtualPath("~/")}' + {link} + {urlSuffix}"; } }
public static string GenerateKnockoutHrefExpression(string routeName, HtmlGenericControl control, DotvvmProperty urlSuffixProperty, IDotvvmRequestContext context) { var link = GenerateRouteLinkCore(routeName, control, context); var urlSuffix = GetUrlSuffixExpression(control, urlSuffixProperty); if ((bool)control.GetValue(Internal.IsSpaPageProperty)) { return($"'#!/' + {link} + {urlSuffix}"); } else { return($"'{context.TranslateVirtualPath("~/")}' + {link} + {urlSuffix}"); } }
/// <summary> /// Redirects the client to the specified file. /// </summary> public static void ReturnFile(this IDotvvmRequestContext context, Stream stream, string fileName, string mimeType, IEnumerable <KeyValuePair <string, string> > additionalHeaders = null) { var returnedFileStorage = context.Services.GetService <IReturnedFileStorage>(); var metadata = new ReturnedFileMetadata() { FileName = fileName, MimeType = mimeType, AdditionalHeaders = additionalHeaders?.GroupBy(k => k.Key, k => k.Value)?.ToDictionary(k => k.Key, k => k.ToArray()) }; var generatedFileId = returnedFileStorage.StoreFile(stream, metadata).Result; context.SetRedirectResponse(context.TranslateVirtualPath("~/dotvvmReturnedFile?id=" + generatedFileId)); throw new DotvvmInterruptRequestExecutionException(InterruptReason.ReturnFile, fileName); }
public static string GenerateKnockoutHrefExpression(string routeName, RouteLink control, IDotvvmRequestContext context) { var link = GenerateRouteLinkCore(routeName, control, context); var urlSuffix = GetUrlSuffixExpression(control); if ((bool)control.GetValue(Internal.IsSpaPageProperty) && !context.Configuration.UseHistoryApiSpaNavigation) { return($"'#!/' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"); } else { return($"'{context.TranslateVirtualPath("~/")}' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"); } }
/// <summary> /// Redirects the client to the specified file. /// </summary> public static void ReturnFile(this IDotvvmRequestContext context, Stream stream, string fileName, string mimeType, IEnumerable <KeyValuePair <string, string> > additionalHeaders = null) { var returnedFileStorage = context.Services.GetService <IReturnedFileStorage>(); if (returnedFileStorage == null) { throw new DotvvmFileStorageMissingException($"Unable to resolve service for type '{typeof(IReturnedFileStorage).Name}'. " + $"Visit https://www.dotvvm.com/docs/tutorials/advanced-returning-files for more details!"); } var metadata = new ReturnedFileMetadata() { FileName = fileName, MimeType = mimeType, AdditionalHeaders = additionalHeaders?.GroupBy(k => k.Key, k => k.Value)?.ToDictionary(k => k.Key, k => k.ToArray()) }; var generatedFileId = returnedFileStorage.StoreFile(stream, metadata).Result; context.SetRedirectResponse(context.TranslateVirtualPath("~/dotvvmReturnedFile?id=" + generatedFileId)); throw new DotvvmInterruptRequestExecutionException(InterruptReason.ReturnFile, fileName); }
/// <summary> /// Returns the redirect response and interrupts the execution of current request. /// </summary> public static void RedirectToUrl(this IDotvvmRequestContext context, string url, bool replaceInHistory = false, bool allowSpaRedirect = false) { context.SetRedirectResponse(context.TranslateVirtualPath(url), (int)HttpStatusCode.Redirect, replaceInHistory, allowSpaRedirect); throw new DotvvmInterruptRequestExecutionException(InterruptReason.Redirect, url); }
public string GetUrl(IDotvvmRequestContext context, string name) { return(context.TranslateVirtualPath(Url)); }
public void RenderHtmlAttribute(IHtmlWriter writer, IDotvvmRequestContext requestContext, string attributeName, object attributeValue) { if (attributeValue != null) attributeValue = requestContext.TranslateVirtualPath((string)attributeValue); writer.WriteHtmlAttribute(attributeName, (string)attributeValue); }