public ResourceLoadingAction ResourceLoading(IResourceLoadingArgs args)
        {
            if (args.OriginalUri.EndsWith(".jpg"))
            {
                try // load substitute image
                {
                    byte[] imageBytes = File.ReadAllBytes(Path.Combine(dataDir, "aspose-logo.jpg"));
                    args.SetData(imageBytes);
                    return(ResourceLoadingAction.UserProvided);
                }
                catch (Exception)
                {
                    return(ResourceLoadingAction.Skip);
                }
            }
            else if (args.OriginalUri.EndsWith(".png"))
            {
                // set substitute url
                args.Uri = "http://www.google.com/images/logos/ps_logo2.png";
                return(ResourceLoadingAction.Default);
            }

            // skip all other images
            return(ResourceLoadingAction.Skip);
        }
Esempio n. 2
0
        public ResourceLoadingAction ResourceLoading(IResourceLoadingArgs args)
        {
            string workbookPath = args.OriginalUri;

            if (workbookPath.IndexOf(':') > 1 && !workbookPath.StartsWith("file:///")) // schemed path
            {
                try
                {
                    WebRequest request = WebRequest.Create(workbookPath);
                    request.Credentials = new System.Net.NetworkCredential("testuser", "testuser");
                    using (WebResponse response = request.GetResponse())
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            //byte[] buffer = BlobDownloadManager.Download(responseStream);
                            // args.SetData(buffer);
                            return(ResourceLoadingAction.UserProvided);
                        }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(ex.ToString());
                }
            }
            else
            {
                return(ResourceLoadingAction.Default);
            }
        }