Example #1
0
        /// <summary>
        /// 加载嵌入的资源
        /// </summary>
        /// <param name="resourceHandler"></param>
        /// <param name="url"></param>
        internal virtual void LoadEmbeddedResource(CefSharpMe.ResourceHandler resourceHandler, Uri url)
        {
            Assembly assembly = this.ResolveResourceAssembly(url);

            string[] embeddedResourcePath = ResourceUrl.GetEmbeddedResourcePath(url);
            string   extension            = Path.GetExtension(embeddedResourcePath.Last <string>()).ToLower();
            Stream   stream = this.TryGetResourceWithFullPath(assembly, embeddedResourcePath);

            if (stream != null)
            {
                resourceHandler.RespondWith(stream, extension);
            }
        }
Example #2
0
        private void OnWebViewBeforeResourceLoad(CefSharpMe.ResourceHandler resourceHandler)
        {
            Func <string, Stream> customResourceRequested = this.CustomResourceRequested;

            if (customResourceRequested != null && resourceHandler.Url.StartsWith("custom" + Uri.SchemeDelimiter))
            {
                Task <Stream> task = Task.Run <Stream>(() => customResourceRequested(resourceHandler.Url));
                task.Wait(ReactViewRender.CustomRequestTimeout);
                if (!task.IsCompleted)
                {
                    throw new Exception(string.Format("Failed to fetch ({0}) within the alotted timeout", resourceHandler.Url));
                }
                resourceHandler.RespondWith(task.Result, "");
            }
        }