public Core(Server server, HttpContext context, string viewstate = "", string type = "") { Server = server; Context = context; Request = context.Request; Response = context.Response; Session = context.Session; Sql = new Sql(this); Util = new Utility.Util(this); User = new User(); //load viewstate if (useViewState == true) { ViewStateId = viewstate; if(ViewStateId == "") { ViewStateId = Util.Str.CreateID(); } if (Session["viewstate-" + ViewStateId] != null) { ViewState vs = new ViewState(); vs = (ViewState)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstate-" + ViewStateId]), vs.GetType()); Page = vs.Page; Elements = new Elements(this, Page.themeFolder); }else { Page = new Page(); } }else { Page = new Page(); } if (Session["user"] != null) { User = (User)Util.Serializer.ReadObject(Util.Str.GetString(Session["user"]), User.GetType()); } //load references to Core R Sql.Load(); Page.Load(this); User.Load(this); //generate visitor id if (User.visitorId == "" || User.visitorId == null) { User.visitorId = Util.Str.CreateID(); } //detect request type & host type if (type == "service") { isWebService = true; } if (Request.Host.Value.IndexOf("localhost") >= 0 || Request.Host.Value.IndexOf("192.168.") >= 0) { isLocal = true; } }
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); }