private void EmbeddedResourceHandler_ProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { readResponseStreamOffset = 0; var request = e.Request; var callback = e.Callback; //var uri = new Uri(request.Url); var refurl = request.ReferrerUrl; requestUrl = request.Url; Console.WriteLine("requrl: " + requestUrl); Console.WriteLine("reffer url : " + refurl); var uri = ResourceHelper.ResolveUri(requestUrl); string resourceMimeType; string resourceName; var ass = GetResourceInfo(uri, out resourceMimeType, out resourceName); if (!string.IsNullOrEmpty(resourceName) && ass.GetManifestResourceInfo(resourceName) != null) { webResource = GetWebResource(uri, ass, resourceName, resourceMimeType); browser.SetWebResource(uri.ToString(), webResource); Console.WriteLine($"[加载]:\t{requestUrl}"); callback.Continue(); e.SetReturnValue(true); } else { webResource = GetNonFoundWebResource(uri, resourceMimeType); browser.SetWebResource(uri.ToString(), webResource); Console.WriteLine($"[未找到]:\t{requestUrl}"); //callback.Continue(); //e.SetReturnValue(false); callback.Continue(); e.SetReturnValue(true); } }
private void EmbeddedResourceHandler_ProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { readResponseStreamOffset = 0; var request = e.Request; var callback = e.Callback; var uri = new Uri(request.Url); requestUrl = request.Url; var fileName = string.Format("{0}{1}", uri.Authority, uri.AbsolutePath); requestFile = uri.AbsolutePath; var ass = resourceAssembly; var resourcePath = string.Format("{0}.{1}", ass.GetName().Name, fileName.Replace('/', '.')); var resourceName = ass.GetManifestResourceNames().SingleOrDefault(p => p.Equals(resourcePath, StringComparison.CurrentCultureIgnoreCase)); if (!string.IsNullOrEmpty(resourceName) && ass.GetManifestResourceInfo(resourceName) != null) { using (var reader = new System.IO.BinaryReader(ass.GetManifestResourceStream(resourceName))) { var buff = reader.ReadBytes((int)reader.BaseStream.Length); webResource = new WebResource(buff, MimeHelper.GetMimeType(System.IO.Path.GetExtension(fileName))); reader.Close(); if (!browser.WebResource.ContainsKey(requestUrl)) { browser.SetWebResource(requestUrl, webResource); } } Console.WriteLine($"[加载]:\t{requestUrl}"); } else { Console.WriteLine($"[未找到]:\t{requestUrl}"); } callback.Continue(); e.SetReturnValue(true); }
private void OnProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { /* * System.Reflection.Assembly Asmb = System.Reflection.Assembly.GetExecutingAssembly(); * string strName = Asmb.GetName().Name + ".WebUI.logo512.png"; * System.IO.Stream ManifestStream = Asmb.GetManifestResourceStream(strName); * * byte[] StreamData = new byte[ManifestStream.Length]; * ManifestStream.Read(StreamData, 0, (int)ManifestStream.Length); */ var uri = new System.Uri(e.Request.Url); webResource = new WebResource(ImgMgr.Get().GetImg(uri.AbsolutePath.TrimStart('/'))); e.Callback.Continue(); e.SetReturnValue(true); }
private void LocalResourceHandler_ProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { readResponseStreamOffset = 0; var request = e.Request; var callback = e.Callback; var uri = new Uri(request.Url); requestUrl = request.Url; var localPath = uri.LocalPath; if (localPath.StartsWith("/")) { localPath = string.Format(".{0}", localPath); } var fileName = System.IO.Path.GetFullPath(localPath); requestFile = request.Url; if (System.IO.File.Exists(fileName)) { using (var stream = System.IO.File.OpenRead(fileName)) using (var reader = new System.IO.BinaryReader(stream)) { var buff = reader.ReadBytes((int)reader.BaseStream.Length); webResource = new WebResource(buff, MimeHelper.GetMimeType(System.IO.Path.GetExtension(fileName))); reader.Close(); stream.Close(); } Console.WriteLine(string.Format("[加载]:\t{0}\t->\t{1}", requestUrl, fileName)); } else { Console.WriteLine(string.Format("[未找到]:\t{0}", requestUrl)); } callback.Continue(); e.SetReturnValue(true); }
private void LocalResourceHandler_ProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { readResponseStreamOffset = 0; var request = e.Request; var callback = e.Callback; // var uri = new Uri(request.Url); requestUrl = request.Url; var uri = ResourceHelper.ResolveUri(requestUrl); var fileName = GetResourceFileName(uri); requestFile = request.Url; if (System.IO.File.Exists(fileName)) { webResource = GetWebResource(uri, fileName); browser.SetWebResource(uri.ToString(), webResource); Console.WriteLine($"[╪сть]:\t{requestUrl}\t->\t{fileName}"); } else { Console.WriteLine($"[н╢ур╣╫]:\t{requestUrl}"); //callback.Continue(); //e.SetReturnValue(false); webResource = GetNonFoundWebResource(uri, fileName); browser.SetWebResource(uri.ToString(), webResource); } callback.Continue(); e.SetReturnValue(true); }
private void OnProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { var request = e.Request; var callback = e.Callback; var uri = new Uri(request.Url); requestUrl = request.Url; var headers = request.GetHeaderMap().Select(x => new { Key = x[0], Value = x[1] }).ToList(); var contentRange = headers.FirstOrDefault(x => x.Key.ToLower() == "range"); if (contentRange != null) { var group = System.Text.RegularExpressions.Regex.Match(contentRange.Value, @"(?<start>\d+)-(?<end>\d*)")?.Groups; if (group != null) { if (!string.IsNullOrEmpty(group["start"].Value) && int.TryParse(group["start"].Value, out int startPos)) { buffStartPostition = startPos; } if (!string.IsNullOrEmpty(group["end"].Value) && int.TryParse(group["end"].Value, out int endPos)) { buffEndPostition = endPos; } } isPartContent = true; } readResponseStreamOffset = 0; readResponseStreamOffset = 0; if (buffStartPostition.HasValue) { readResponseStreamOffset = buffStartPostition.Value; } var fileName = string.IsNullOrEmpty(domain) ? string.Format("{0}{1}", uri.Authority, Uri.UnescapeDataString(uri.AbsolutePath)) : Uri.UnescapeDataString(uri.AbsolutePath); if (fileName.StartsWith("/") && fileName.Length > 1) { fileName = fileName.Substring(1); } var endTrimIndex = fileName.LastIndexOf('/'); if (endTrimIndex > -1) { var tmp = fileName.Substring(0, endTrimIndex); tmp = tmp.Replace("-", "_"); fileName = string.Format("{0}{1}", tmp, fileName.Substring(endTrimIndex)); } ZipArchiveEntry entry = archive.GetEntry(fileName); if (null != entry) { using (System.IO.Stream stream = entry.Open()) { byte[] buff = new byte[entry.Length]; stream.Read(buff, 0, (int)entry.Length); webResource = new WebResource(buff, CfxRuntime.GetMimeType(System.IO.Path.GetExtension(fileName).TrimStart('.'))); callback.Continue(); e.SetReturnValue(true); return; } } else { callback.Continue(); e.SetReturnValue(false); Console.WriteLine($"[找不到资源]:\t{requestUrl}"); } }
private void OnProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { var request = e.Request; var callback = e.Callback; var uri = new Uri(request.Url); requestUrl = request.Url; var headers = request.GetHeaderMap().Select(x => new { Key = x[0], Value = x[1] }).ToList(); var contentRange = headers.FirstOrDefault(x => x.Key.ToLower() == "range"); if (contentRange != null) { var group = System.Text.RegularExpressions.Regex.Match(contentRange.Value, @"(?<start>\d+)-(?<end>\d*)")?.Groups; if (group != null) { if (!string.IsNullOrEmpty(group["start"].Value) && int.TryParse(group["start"].Value, out int startPos)) { buffStartPostition = startPos; } if (!string.IsNullOrEmpty(group["end"].Value) && int.TryParse(group["end"].Value, out int endPos)) { buffEndPostition = endPos; } } isPartContent = true; } readResponseStreamOffset = 0; if (buffStartPostition.HasValue) { readResponseStreamOffset = buffStartPostition.Value; } if (browser.WebResources.ContainsKey(requestUrl)) { webResource = browser.WebResources[requestUrl]; callback.Continue(); e.SetReturnValue(true); return; } var fileName = string.IsNullOrEmpty(domain) ? string.Format("{0}{1}", uri.Authority, uri.AbsolutePath) : uri.AbsolutePath; if (fileName.StartsWith("/") && fileName.Length > 1) { fileName = fileName.Substring(1); } var mainAssembly = resourceAssembly; var endTrimIndex = fileName.LastIndexOf('/'); if (endTrimIndex > -1) { var tmp = fileName.Substring(0, endTrimIndex); tmp = tmp.Replace("-", "_"); fileName = string.Format("{0}{1}", tmp, fileName.Substring(endTrimIndex)); } var resourcePath = string.Format("{0}.{1}", mainAssembly.GetName().Name, fileName.Replace('/', '.')); Assembly satelliteAssembly = null; try { satelliteAssembly = mainAssembly.GetSatelliteAssembly(System.Threading.Thread.CurrentThread.CurrentCulture); } catch { } var resourceNames = mainAssembly.GetManifestResourceNames().Select(x => new { TargetAssembly = mainAssembly, Name = x, IsSatellite = false }); if (satelliteAssembly != null) { string HandleCultureName(string name) { var cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name; var fileInfo = new System.IO.FileInfo(name); return($"{System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name)}.{cultureName}{fileInfo.Extension}"); } resourceNames = resourceNames.Union(satelliteAssembly.GetManifestResourceNames().Select(x => new { TargetAssembly = satelliteAssembly, Name = HandleCultureName(x), IsSatellite = true })); } var resource = resourceNames.SingleOrDefault(p => p.Name.Equals(resourcePath, StringComparison.CurrentCultureIgnoreCase)); var manifestResourceName = resourcePath; if (resource != null && resource.IsSatellite) { var fileInfo = new System.IO.FileInfo(manifestResourceName); manifestResourceName = $"{System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name))}{fileInfo.Extension}"; } if (resource != null && resource.TargetAssembly.GetManifestResourceStream(manifestResourceName) != null) { using (var reader = new System.IO.BinaryReader(resource.TargetAssembly.GetManifestResourceStream(manifestResourceName))) { var buff = reader.ReadBytes((int)reader.BaseStream.Length); webResource = new WebResource(buff, CfxRuntime.GetMimeType(System.IO.Path.GetExtension(fileName).TrimStart('.'))); browser.SetWebResource(requestUrl, webResource); reader.Close(); } callback.Continue(); e.SetReturnValue(true); } else { Console.WriteLine($"[错误嵌入资源]:\t{requestUrl}"); callback.Continue(); e.SetReturnValue(false); } }
private void OnProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { readResponseStreamOffset = 0; var request = e.Request; var callback = e.Callback; var uri = new Uri(request.Url); requestUrl = request.Url; var fileName = string.IsNullOrEmpty(domain) ? string.Format("{0}{1}", uri.Authority, uri.AbsolutePath) : uri.AbsolutePath; if (fileName.StartsWith("/") && fileName.Length > 1) { fileName = fileName.Substring(1); } var mainAssembly = resourceAssembly; var endTrimIndex = fileName.LastIndexOf('/'); if (endTrimIndex > -1) { var tmp = fileName.Substring(0, endTrimIndex); tmp = tmp.Replace("-", "_"); fileName = string.Format("{0}{1}", tmp, fileName.Substring(endTrimIndex)); } var resourcePath = string.Format("{0}.{1}", mainAssembly.GetName().Name, fileName.Replace('/', '.')); Assembly satelliteAssembly = null; try { satelliteAssembly = mainAssembly.GetSatelliteAssembly(System.Threading.Thread.CurrentThread.CurrentCulture); } catch { } var resourceNames = mainAssembly.GetManifestResourceNames().Select(x => new { TargetAssembly = mainAssembly, Name = x, IsSatellite = false }); if (satelliteAssembly != null) { string HandleCultureName(string name) { var cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name; var fileInfo = new System.IO.FileInfo(name); return($"{System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name)}.{cultureName}{fileInfo.Extension}"); } resourceNames = resourceNames.Union(satelliteAssembly.GetManifestResourceNames().Select(x => new { TargetAssembly = satelliteAssembly, Name = HandleCultureName(x), IsSatellite = true })); } var resource = resourceNames.SingleOrDefault(p => p.Name.Equals(resourcePath, StringComparison.CurrentCultureIgnoreCase)); var manifestResourceName = resourcePath; if (resource != null && resource.IsSatellite) { var fileInfo = new System.IO.FileInfo(manifestResourceName); manifestResourceName = $"{System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name))}{fileInfo.Extension}"; } if (resource != null && resource.TargetAssembly.GetManifestResourceStream(manifestResourceName) != null) { using (var reader = new System.IO.BinaryReader(resource.TargetAssembly.GetManifestResourceStream(manifestResourceName))) { var buff = reader.ReadBytes((int)reader.BaseStream.Length); webResource = new WebResource(buff, CfxRuntime.GetMimeType(System.IO.Path.GetExtension(fileName).TrimStart('.'))); reader.Close(); if (!browser.webResources.ContainsKey(requestUrl)) { browser.SetWebResource(requestUrl, webResource); } } callback.Continue(); e.SetReturnValue(true); } else { Console.WriteLine($"[错误嵌入资源]:\t{requestUrl}"); callback.Continue(); e.SetReturnValue(false); } }
private void Handler_ProcessRequest(object sender, Chromium.Event.CfxProcessRequestEventArgs e) { e.Callback.Continue(); e.SetReturnValue(true); }