コード例 #1
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Preparing DOM

        // Load XML from a URI; this runs on caller thread of BeginQuery (Refresh/InitialLoad)
        private void LoadFromSource()
        {
            // convert the Source into an absolute URI
            Uri sourceUri = this.Source;

            if (sourceUri.IsAbsoluteUri == false)
            {
                Uri baseUri = (_baseUri != null) ? _baseUri : BindUriHelper.BaseUri;
                sourceUri = BindUriHelper.GetResolvedUri(baseUri, sourceUri);
            }

            // create a request to load the content
            // Ideally we would want to use RegisterPrefix and WebRequest.Create.
            // However, these two functions regress 700k working set in System.dll and System.xml.dll
            //  which is mostly for logging and config.
            // Call PackWebRequestFactory.CreateWebRequest to bypass the regression if possible
            //  by calling Create on PackWebRequest if uri is pack scheme
            WebRequest request = PackWebRequestFactory.CreateWebRequest(sourceUri);

            if (request == null)
            {
                throw new Exception(SR.Get(SRID.WebRequestCreationFailed));
            }

            // load it on a worker thread ?
            if (IsAsynchronous)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(CreateDocFromExternalSourceAsynch),
                                             request);
            }
            else
            {
                CreateDocFromExternalSource(request);
            }
        }
コード例 #2
0
ファイル: FontSource.cs プロジェクト: walterlv/wpf
        public Stream GetStream()
        {
            if (IsFile)
            {
                FileMapping fileMapping = new FileMapping();

                DemandFileIOPermission();

                fileMapping.OpenFile(_fontUri.LocalPath);
                return(fileMapping);
            }

            byte[] bits;

            // Try our cache first.
            lock (_resourceCache)
            {
                bits = _resourceCache.Get(_fontUri);
            }

            if (bits != null)
            {
                return(new MemoryStream(bits));
            }

            Stream fontStream;

            if (_isInternalCompositeFont)
            {
                // We should read this font from our framework resources
                fontStream = GetCompositeFontResourceStream();
            }
            else
            {
                WebRequest  request  = PackWebRequestFactory.CreateWebRequest(_fontUri);
                WebResponse response = request.GetResponse();

                fontStream = response.GetResponseStream();
                if (String.Equals(response.ContentType, ObfuscatedContentType, StringComparison.Ordinal))
                {
                    // The third parameter makes sure the original stream is closed
                    // when the deobfuscating stream is disposed.
                    fontStream = new DeobfuscatingStream(fontStream, _fontUri, false);
                }
            }

            return(fontStream);
        }
コード例 #3
0
        // Token: 0x06001CDD RID: 7389 RVA: 0x00086CD8 File Offset: 0x00084ED8
        private void LoadFromSource()
        {
            Uri uri = this.Source;

            if (!uri.IsAbsoluteUri)
            {
                Uri baseUri = (this._baseUri != null) ? this._baseUri : BindUriHelper.BaseUri;
                uri = BindUriHelper.GetResolvedUri(baseUri, uri);
            }
            WebRequest webRequest = PackWebRequestFactory.CreateWebRequest(uri);

            if (webRequest == null)
            {
                throw new Exception(SR.Get("WebRequestCreationFailed"));
            }
            if (this.IsAsynchronous)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.CreateDocFromExternalSourceAsynch), webRequest);
                return;
            }
            this.CreateDocFromExternalSource(webRequest);
        }
コード例 #4
0
        internal static WebRequest CreateRequest(Uri uri)
        {
            // Ideally we would want to use RegisterPrefix and WebRequest.Create.
            // However, these two functions regress 700k working set in System.dll and System.xml.dll
            //  which is mostly for logging and config.
            // Call PackWebRequestFactory.CreateWebRequest to bypass the regression if possible
            //  by calling Create on PackWebRequest if uri is pack scheme
            if (string.Compare(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.Ordinal) == 0)
            {
                return(PackWebRequestFactory.CreateWebRequest(uri));
                // The PackWebRequest may end up creating a "real" web request as its inner request.
                // It will then call this method again.
            }

            // Work around the issue with FileWebRequest not handling #.
            // FileWebRequest doesn't support the concept of query and fragment.
            if (uri.IsFile)
            {
                uri = new Uri(uri.GetLeftPart(UriPartial.Path));
            }

            WebRequest request = WebRequest.Create(uri);

            // It is not clear whether WebRequest.Create() can ever return null, but v1 code make this check in
            // a couple of places, so it is still done here, just in case.
            if (request == null)
            {
                // Unfortunately, there is no appropriate exception string in PresentationCore, and for v3.5
                // we have a total resource freeze. So just report WebExceptionStatus.RequestCanceled:
                // "The request was canceled, the WebRequest.Abort method was called, or an unclassifiable error
                // occurred. This is the default value for Status."
                Uri requestUri = BaseUriHelper.PackAppBaseUri.MakeRelativeUri(uri);
                throw new WebException(requestUri.ToString(), WebExceptionStatus.RequestCanceled);
                //throw new IOException(SR.Get(SRID.GetResponseFailed, requestUri.ToString()));
            }

            HttpWebRequest httpRequest = request as HttpWebRequest;

            if (httpRequest != null)
            {
                if (string.IsNullOrEmpty(httpRequest.UserAgent))
                {
                    httpRequest.UserAgent = DefaultUserAgent;
                }

                CookieHandler.HandleWebRequest(httpRequest);

                if (String.IsNullOrEmpty(httpRequest.Referer))
                {
                    httpRequest.Referer = BindUriHelper.GetReferer(uri);
                }

                CustomCredentialPolicy.EnsureCustomCredentialPolicy();

                // Enable NTLM authentication.
                // This is safe to do thanks to the CustomCredentialPolicy.
                httpRequest.UseDefaultCredentials = true;
            }

            return(request);
        }