CreateHtmlTextWriterFromType() публичный статический Метод

public static CreateHtmlTextWriterFromType ( TextWriter tw, Type writerType ) : System.Web.UI.HtmlTextWriter
tw System.IO.TextWriter
writerType System.Type
Результат System.Web.UI.HtmlTextWriter
Пример #1
0
        private string GetCssStyleRenderString(Type htmlTextWriterType)
        {
            // Nothing to do if no styles are registered.
            if (_registeredStyleInfo == null)
            {
                return(null);
            }

            // Create an empty cssStringWriter
            StringWriter cssStringWriter = new StringWriter(CultureInfo.CurrentCulture);

            // Create a new HtmlTextWriter, with the same type as the current one
            HtmlTextWriter cssHtmlTextWriter =
                Page.CreateHtmlTextWriterFromType(cssStringWriter, htmlTextWriterType);

            CssTextWriter cssWriter = new CssTextWriter(cssHtmlTextWriter);

            foreach (SelectorStyleInfo si in _registeredStyleInfo)
            {
                HtmlHead.RenderCssRule(cssWriter, si.selector, si.style, si.urlResolver);
            }

            // Return the css style rendered string
            return(cssStringWriter.ToString());
        }
Пример #2
0
        /// <include file='doc\PartialCachingControl.uex' path='docs/doc[@for="PartialCachingControl.Render"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override void Render(HtmlTextWriter output)
        {
            // If the output is cached, use it and do nothing else
            if (_outputString != null)
            {
                output.Write(_outputString);
                return;
            }

            // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922)
            StringWriter   tmpWriter     = new StringWriter();
            HtmlTextWriter tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType());

            TextWriter savedWriter = Context.Response.SwitchWriter(tmpWriter);

            try {
                _cachedCtrl.RenderControl(tmpHtmlWriter);
            }
            finally {
                Context.Response.SwitchWriter(savedWriter);
            }

            string outputString = tmpWriter.ToString();

            // Send the output to the response
            output.Write(outputString);

            // Cache the output
            // Compute the expiration time
            DateTime utcExpires = DateTime.UtcNow.AddSeconds(_duration);

            HttpRuntime.CacheInternal.UtcInsert(_cacheKey, outputString, _cacheDependency /*dependencies*/, utcExpires,
                                                Cache.NoSlidingExpiration);
        }
        private string GetCssStyleRenderString(Type htmlTextWriterType)
        {
            if (this._registeredStyleInfo == null)
            {
                return(null);
            }
            StringWriter  tw        = new StringWriter(CultureInfo.CurrentCulture);
            CssTextWriter cssWriter = new CssTextWriter(Page.CreateHtmlTextWriterFromType(tw, htmlTextWriterType));

            foreach (SelectorStyleInfo info in this._registeredStyleInfo)
            {
                HtmlHead.RenderCssRule(cssWriter, info.selector, info.style, info.urlResolver);
            }
            return(tw.ToString());
        }
Пример #4
0
        /// <internalonly/>
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Render(HtmlTextWriter output)
        {
            CacheDependency sqlCacheDep = null;

            // If the output is cached, use it and do nothing else
            if (_outputString != null)
            {
                output.Write(_outputString);
                RegisterValidationEvents();
                return;
            }

            // If caching was turned off, just render the control
            if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
            {
                _cachedCtrl.RenderControl(output);
                return;
            }

            // Create SQL cache dependency before we render the page
            if (_sqlDependency != null)
            {
                sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency);
            }

            _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType());

            // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922)
            StringWriter    tmpWriter     = new StringWriter();
            HtmlTextWriter  tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType());
            CacheDependency cacheDep;
            TextWriter      savedWriter = Context.Response.SwitchWriter(tmpWriter);

            try {
                // Make sure the Page knows about us while the control's OnPreRender is called
                Page.PushCachingControl(this);
                _cachedCtrl.RenderControl(tmpHtmlWriter);
                Page.PopCachingControl();
            }
            finally {
                Context.Response.SwitchWriter(savedWriter);
            }

            _cacheEntry.OutputString = tmpWriter.ToString();

            // Send the output to the response
            output.Write(_cacheEntry.OutputString);

            // Cache the output

            cacheDep = _cacheDependency;

            if (sqlCacheDep != null)
            {
                if (cacheDep == null)
                {
                    cacheDep = sqlCacheDep;
                }
                else
                {
                    AggregateCacheDependency aggr = new AggregateCacheDependency();

                    aggr.Add(cacheDep);
                    aggr.Add(sqlCacheDep);
                    cacheDep = aggr;
                }
            }

            ControlCachedVary cachedVary = null;
            string            realItemCacheKey;

            // If there are no varies, use the non-varying key
            if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null)
            {
                realItemCacheKey = _cacheKey;
            }
            else
            {
                string[] varyByParams = null;
                if (_varyByParamsCollection != null)
                {
                    varyByParams = _varyByParamsCollection.GetParams();
                }

                cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom);

                HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode);
                realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary);
            }

            // Compute the correct expiration, sliding or absolute
            DateTime utcExpirationTime;
            TimeSpan slidingExpiration;

            if (_useSlidingExpiration)
            {
                utcExpirationTime = Cache.NoAbsoluteExpiration;
                slidingExpiration = _utcExpirationTime - DateTime.UtcNow;
            }
            else
            {
                utcExpirationTime = _utcExpirationTime;
                slidingExpiration = Cache.NoSlidingExpiration;
            }

            try {
                OutputCache.InsertFragment(_cacheKey, cachedVary,
                                           realItemCacheKey, _cacheEntry,
                                           cacheDep /*dependencies*/,
                                           utcExpirationTime, slidingExpiration,
                                           _provider);
            }
            catch {
                if (cacheDep != null)
                {
                    cacheDep.Dispose();
                }
                throw;
            }
        }
        protected internal override void Render(HtmlTextWriter output)
        {
            CacheDependency dependency = null;

            if (this._outputString != null)
            {
                output.Write(this._outputString);
                this.RegisterValidationEvents();
            }
            else if (this._cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
            {
                this._cachedCtrl.RenderControl(output);
            }
            else
            {
                string   str;
                DateTime noAbsoluteExpiration;
                TimeSpan noSlidingExpiration;
                if (this._sqlDependency != null)
                {
                    dependency = SqlCacheDependency.CreateOutputCacheDependency(this._sqlDependency);
                }
                this._cacheEntry.CssStyleString = this.GetCssStyleRenderString(output.GetType());
                StringWriter   tw      = new StringWriter();
                HtmlTextWriter writer  = Page.CreateHtmlTextWriterFromType(tw, output.GetType());
                TextWriter     writer3 = this.Context.Response.SwitchWriter(tw);
                try
                {
                    this.Page.PushCachingControl(this);
                    this._cachedCtrl.RenderControl(writer);
                    this.Page.PopCachingControl();
                }
                finally
                {
                    this.Context.Response.SwitchWriter(writer3);
                }
                this._cacheEntry.OutputString = tw.ToString();
                output.Write(this._cacheEntry.OutputString);
                CacheDependency dependencies = this._cacheDependency;
                if (dependency != null)
                {
                    if (dependencies == null)
                    {
                        dependencies = dependency;
                    }
                    else
                    {
                        AggregateCacheDependency dependency3 = new AggregateCacheDependency();
                        dependency3.Add(new CacheDependency[] { dependencies });
                        dependency3.Add(new CacheDependency[] { dependency });
                        dependencies = dependency3;
                    }
                }
                ControlCachedVary cachedVary = null;
                if (((this._varyByParamsCollection == null) && (this._varyByControlsCollection == null)) && (this._varyByCustom == null))
                {
                    str = this._cacheKey;
                }
                else
                {
                    string[] varyByParams = null;
                    if (this._varyByParamsCollection != null)
                    {
                        varyByParams = this._varyByParamsCollection.GetParams();
                    }
                    cachedVary = new ControlCachedVary(varyByParams, this._varyByControlsCollection, this._varyByCustom);
                    HashCodeCombiner combinedHashCode = new HashCodeCombiner(this._nonVaryHashCode);
                    str = this.ComputeVaryCacheKey(combinedHashCode, cachedVary);
                }
                if (this._useSlidingExpiration)
                {
                    noAbsoluteExpiration = Cache.NoAbsoluteExpiration;
                    noSlidingExpiration  = (TimeSpan)(this._utcExpirationTime - DateTime.UtcNow);
                }
                else
                {
                    noAbsoluteExpiration = this._utcExpirationTime;
                    noSlidingExpiration  = Cache.NoSlidingExpiration;
                }
                try
                {
                    OutputCache.InsertFragment(this._cacheKey, cachedVary, str, this._cacheEntry, dependencies, noAbsoluteExpiration, noSlidingExpiration, this._provider);
                }
                catch
                {
                    if (dependencies != null)
                    {
                        dependencies.Dispose();
                    }
                    throw;
                }
            }
        }