예제 #1
0
파일: BasePage.cs 프로젝트: jesumarquez/lt
        protected override void SavePageStateToPersistenceMedium(Object pViewState)
        {
            Pair pair1;

            System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
            Object ViewState;

            if (pViewState is Pair)
            {
                pair1 = ((Pair)pViewState);
                pageStatePersister1.ControlState = pair1.First;
                ViewState = pair1.Second;
            }
            else
            {
                ViewState = pViewState;
            }
            LosFormatter mFormat = new LosFormatter();
            StringWriter mWriter = new StringWriter();

            mFormat.Serialize(mWriter, ViewState);
            String mViewStateStr = mWriter.ToString();

            byte[] pBytes = System.Convert.FromBase64String(mViewStateStr);
            pBytes = Compress(pBytes);
            String vStateStr = System.Convert.ToBase64String(pBytes);

            pageStatePersister1.ViewState = vStateStr;
            pageStatePersister1.Save();
        }
        protected override void SavePageStateToPersistenceMedium(object pViewState)
        {
            //############
            //Uma outra opção é se usar um Provider, envia o ViewState direto, sem compactação.
            //Bastaria apenas fazer uma condição ( if (ViewStateProviderService.UseProvider) ) e chamar a linha abaixo.
            //base.SavePageStateToPersistenceMedium(pViewState);

            if (ViewStateProviderService.UseProvider)
            {
                base.SavePageStateToPersistenceMedium(pViewState);
            }
            else
            {
                Pair pair1;
                System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
                Object ViewState;
                if (pViewState is Pair)
                {
                    pair1 = ((Pair)pViewState);
                    pageStatePersister1.ControlState = pair1.First;
                    ViewState = pair1.Second;
                }
                else
                {
                    ViewState = pViewState;
                }

                LosFormatter mFormat = new LosFormatter();
                StringWriter mWriter = new StringWriter();
                mFormat.Serialize(mWriter, ViewState);
                String mViewStateStr = mWriter.ToString();
                byte[] pBytes        = System.Convert.FromBase64String(mViewStateStr);
                pBytes = Compressor.Compress(pBytes);
                String vStateStr = System.Convert.ToBase64String(pBytes);
                //pageStatePersister1.ViewState = vStateStr;
                pageStatePersister1.Save();

                //##### - Precisa averiguar se há uma forma compactar o pair1.First que é uma HybridDictionary.
                //##### Do jeito que está, está compactando apenas o ViewState Pair e não o ViewState do Controle.

                //Este irá salvar no hidden viewstate padrão ou no custom hidden viewstate_key.
                //Ao salvar no hidden viewstate padrão o campo "pageStatePersister1.ViewState" acima, será preenchido.
                base.SavePageStateToPersistenceMedium(vStateStr);
            }
        }