private string ApplyReplacePatterns(string html, Services.DTO.ProxyModel model) { foreach (var pattern in model.ReplacePatterns) { html = new Regex(pattern.Key, RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(html, pattern.Value); } return(html); }
// GET: /<controller>/ public async Task <IActionResult> IndexAsync(string query) { var model = new Services.DTO.ProxyModel() { FullOriginal = new Uri("https://habr.com/" + query), AddString = "™" }; model.ReplacePatterns.Add($"//{ model.FullOriginal.Host }", $"//{ HttpContext.Request.Host }"); model.ReplacePatterns.Add(@"\\/\\/" + model.FullOriginal.Host, @"\/\/" + HttpContext.Request.Host); var result = await _proxyConverter.GetProxyAsync(model).ConfigureAwait(false); return(View("Index", result)); }
private async System.Threading.Tasks.Task <string> ReadToEndAsync(Services.DTO.ProxyModel model) { if (string.IsNullOrWhiteSpace(model?.FullOriginal.ToString())) { return(String.Empty); } string result = String.Empty; try { var config = Configuration.Default.WithDefaultLoader(); var context = BrowsingContext.New(config); var document = await context.OpenAsync(model?.FullOriginal.ToString()).ConfigureAwait(false); result = AddString(model.AddString, document); } catch (Exception e) { _logger.LogDebug(1, e.Message); } return(result.Trim()); }
public async System.Threading.Tasks.Task <string> GetProxyAsync(Services.DTO.ProxyModel model) { return(ApplyReplacePatterns(await ReadToEndAsync(model).ConfigureAwait(false), model)); }