Ejemplo n.º 1
0
        public void SaveViewState()
        {
            if (useViewState == false)
            {
                return;
            }
            ViewState vs = new ViewState();

            vs.Load(this);
            Session["viewstate-" + ViewStateId] = Util.Serializer.WriteObject(vs);

            //get list of viewstates to update details
            structViewStateInfo vsd = new structViewStateInfo();
            ViewStates          vss = new ViewStates();
            bool isfound            = false;

            vsd.dateCreated  = DateTime.Now;
            vsd.dateModified = DateTime.Now;
            vsd.id           = ViewStateId;

            if (Util.IsEmpty(Session["viewstates"]) == false)
            {
                vss = (ViewStates)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstates"]), vss.GetType());
                if (vss.Views.Count >= 0)
                {
                    List <int> removes = new List <int>();
                    for (int x = 0; x <= vss.Views.Count - 1; x++)
                    {
                        if ((vss.Views[x].id == ViewStateId))
                        {
                            //update current vewstate modified date
                            vsd = vss.Views[x];
                            vsd.dateModified = DateTime.Now;
                            vss.Views[x]     = vsd;
                            isfound          = true;
                        }
                        else
                        {
                            //clean up expired viewstates
                            TimeSpan ts = DateTime.Now - vss.Views[x].dateModified;
                            if (ts.Minutes > 4)
                            {
                                removes.Add(x);
                                Session.Remove("viewstate-" + vss.Views[x].id);
                            }
                        }
                    }

                    if (removes.Count > 0)
                    {
                        //remove expired viewstates from list
                        int offset = 0;
                        foreach (int x in removes)
                        {
                            vss.Views.Remove(vss.Views[x - offset]);
                            offset += 1;
                        }
                    }
                }
            }

            if (isfound == false)
            {
                vss.Views.Add(vsd);
            }
            Session["viewstates"] = Util.Serializer.WriteObject(vss);
        }
Ejemplo n.º 2
0
Archivo: Core.cs Proyecto: nhtera/Home
        public void SaveViewState()
        {
            if(useViewState == false) { return; }
            ViewState vs = new ViewState();
            vs.Load(this);
            Session["viewstate-" + ViewStateId] = Util.Serializer.WriteObject(vs);

            //get list of viewstates to update details
            structViewStateInfo vsd = new structViewStateInfo();
            ViewStates vss = new ViewStates();
            bool isfound = false;

            vsd.dateCreated = DateTime.Now;
            vsd.dateModified = DateTime.Now;
            vsd.id = ViewStateId;

            if (Util.IsEmpty(Session["viewstates"]) == false)
            {
                vss = (ViewStates)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstates"]), vss.GetType());
                if (vss.Views.Count >= 0)
                {
                    List<int> removes = new List<int>();
                    for (int x = 0; x <= vss.Views.Count - 1; x++)
                    {
                        if ((vss.Views[x].id == ViewStateId))
                        {
                            //update current vewstate modified date
                            vsd = vss.Views[x];
                            vsd.dateModified = DateTime.Now;
                            vss.Views[x] = vsd;
                            isfound = true;
                        }
                        else
                        {
                            //clean up expired viewstates
                            TimeSpan ts = DateTime.Now - vss.Views[x].dateModified;
                            if (ts.Minutes > 4)
                            {
                                removes.Add(x);
                                Session.Remove("viewstate-" + vss.Views[x].id);
                            }
                        }
                    }

                    if (removes.Count > 0)
                    {
                        //remove expired viewstates from list
                        int offset = 0;
                        foreach (int x in removes)
                        {
                            vss.Views.Remove(vss.Views[x - offset]);
                            offset += 1;
                        }
                    }
                }
            }

            if (isfound == false)
            {
                vss.Views.Add(vsd);
            }
            Session["viewstates"] = Util.Serializer.WriteObject(vss);
        }