public override void Load() { _hiddenFiledPagePersister.Load(); string viewStateStr = _hiddenFiledPagePersister.ViewState as string; // Page.Request.Form[STATE_KEY]; trace.WriteTrace(TraceSeverity.InformationEvent, TraceCategory.Content, "View state: " + viewStateStr); if (viewStateStr != null && viewStateStr.StartsWith(CacheKeyPrefix)) // state not inline check the cached state key { string state = LoadState(viewStateStr); if (state == null) { trace.WriteTrace(TraceSeverity.CriticalEvent, TraceCategory.Content, "View state lost. Probably cached item expired."); } else { try { Pair data = (Pair)StateFormatter.Deserialize(state); ViewState = data.First; ControlState = data.Second; } catch { trace.WriteTrace(TraceSeverity.Exception, TraceCategory.Content, String.Format("Could not deserialize view state. View state is invalid.")); } } } else { ViewState = _hiddenFiledPagePersister.ViewState; ControlState = _hiddenFiledPagePersister.ControlState; } }
public DictionaryObjectTreeItem(ObjectTreeItem parent, string propertyName, DictionaryData source, int depth) : base(parent, propertyName, source) { var builder = new List <ObjectTreeItem>(source.Dictionary.Count); foreach (var item in source.Dictionary) { builder.Add(StateFormatter.ToTreeHierarchy(this, item.Value, depth + 1, Convert.ToString(item.Key))); } Children = builder.ToArray(); }
public StateObjectTreeItem(ObjectTreeItem parent, string propertyName, StateObjectData source, int depth) : base(parent, propertyName, source) { var properties = new List <ObjectTreeItem>(source.Properties.Count); foreach (var item in source.Properties) { properties.Add(StateFormatter.ToTreeHierarchy(this, item.Value, depth + 1, item.Key)); } Children = properties.ToArray(); }
public ListObjectTreeItem(ObjectTreeItem parent, string propertyName, ListData source, int depth) : base(parent, propertyName, source) { var builder = new List <ObjectTreeItem>(source.List.Length); foreach (var item in source.List) { builder.Add(StateFormatter.ToTreeHierarchy(this, item, depth + 1, null)); } Children = builder.ToArray(); }
/// <summary> /// 保存ViewState。如果ViewState的尺寸小于配置信息中的值(缺省为10K),保存到隐藏域中,否则保存到数据库中 /// </summary> public override void Save() { if (ViewState != null || ControlState != null) { string hiddenFieldData = string.Empty; string serializedState = StateFormatter.Serialize(ViewState); if (serializedState.Length >= ViewStatePersistSettings.GetConfig().Threshold) { ViewState = SaveStateToDB(serializedState); } } }
/// <summary> /// Десериализация ViewState /// </summary> /// <param name="serializedViewState"></param> protected void Deserialize(string serializedViewState) { object vsPair = StateFormatter.Deserialize(serializedViewState); if (vsPair != null && (vsPair is Pair)) { var myPair = vsPair as Pair; ViewState = myPair.First; ControlState = myPair.Second; } else { ViewState = vsPair; } }
/// <summary> /// 加载ViewState。如果ViewState的尺寸小于配置信息中的值(缺省为10K),从隐藏域中加载,否则从数据库中加载 /// </summary> public override void Load() { string data = this.Page.Request.Form["__VIEWSTATE"]; if (string.IsNullOrEmpty(data) == false) { #region 注释掉原有的逻辑 //Pair statePair = (Pair)StateFormatter.Deserialize(data); //ControlState = statePair.Second; //ViewState = statePair.First; #endregion long id; if (long.TryParse(ViewState.ToString(), out id)) { string stateStr = LoadStateFromDB(id); ViewState = StateFormatter.Deserialize(stateStr); } } }
public override void Save() { if (cache.Loaded) { string cacheKey = CacheKeyPrefix + Guid.NewGuid().ToString("N"); // dynamic guid Pair data = new Pair(ViewState, ControlState); string state = StateFormatter.Serialize(data); bool cached = false; try { cached = cache.Insert(cacheKey, state); //insert without grouping } catch (Exception e) { if (!cached) { trace.WriteTrace(TraceSeverity.WarningEvent, TraceCategory.Content, "Could not cache view state." + e.Message); } } if (cached) { _hiddenFiledPagePersister.ViewState = cacheKey; // send dynamic guid to client ContentPerfCounters.Current.UpdateViewstateSize(state.Length); ContentPerfCounters.Current.IncrementViewstateAdditions(); trace.WriteTrace(TraceSeverity.InformationEvent, TraceCategory.Content, "view state cached: " + cacheKey); } } else { trace.WriteTrace(TraceSeverity.CriticalEvent, TraceCategory.Content, " Cache is not loaded. "); _hiddenFiledPagePersister.ViewState = ViewState; _hiddenFiledPagePersister.ControlState = ControlState; } _hiddenFiledPagePersister.Save(); }
protected override Object LoadPageStateFromPersistenceMedium() { Object state = null; String clientViewStateString = _requestValueCollection[ViewStateID]; if (clientViewStateString != null) { _privateViewState = StateFormatter.Deserialize(clientViewStateString) as Hashtable; if (_privateViewState != null) { String[] arr = _privateViewState[PageClientViewStateKey] as String[]; if (arr != null) { _activeFormID = arr[0]; String id = arr[1]; if (id != null) { _sessionViewState.Load(this, id); state = _sessionViewState.ViewState; if (state == null) { OnViewStateExpire(EventArgs.Empty); } else { Object[] arrState = state as Object[]; if (arrState != null) { _privateViewState = (Hashtable)arrState[1]; state = arrState[0]; } } } } _privateViewState.Remove(PageClientViewStateKey); // If the page had no view state, but had controls requiring postback, // this information was saved in client view state. Object controlsRequiringPostBack = _privateViewState[_controlsRequiringPostBackKey]; if (controlsRequiringPostBack != null) { state = new Triplet(GetTypeHashCode().ToString(), null, controlsRequiringPostBack); _privateViewState.Remove(_controlsRequiringPostBackKey); } // Apply whatever private view state can be applied now. foreach (DictionaryEntry entry in _privateViewState) { if (entry.Value != null) { MobileControl ctl = FindControl((String)entry.Key) as MobileControl; if (ctl != null) { ctl.LoadPrivateViewStateInternal(entry.Value); } } } } } _privateViewStateLoaded = true; if (state == null) { // Give framework back an empty page view state state = new Triplet(GetTypeHashCode().ToString(), null, null); } return(state); }
public static ObjectTreeItem ToTreeItem(object state) { var currentData = PropertiesCollector.Collect(state); return(StateFormatter.ToTreeHierarchy(currentData)); }
/// <summary> /// Сериализация ViewState /// </summary> /// <returns></returns> protected string Serialize() { var vsPair = new Pair(ViewState, ControlState); return(StateFormatter.Serialize(vsPair)); }
public async Task <RootState> ReduceAsync(RootState state, ReduxAction action, CancellationToken ct) { RootState result; switch (action) { case InsertNewAction insertNew: int key = state.Steps.Length; var actionDataTask = Task.Run(() => PropertiesCollector.Collect(insertNew.Action), ct); var stateDataTask = Task.Run(() => PropertiesCollector.Collect(insertNew.State), ct); await actionDataTask.ConfigureAwait(false); var actionTreeItem = await Task.Run(() => { string actionName = StateFormatter.GetActionName(insertNew.Action); return(StateFormatter.ToTreeHierarchy(actionDataTask.Result, actionName)); }).ConfigureAwait(false); await stateDataTask.ConfigureAwait(false); result = state.Clone(steps: state.Steps.Spread( new Step(key, insertNew.Action, insertNew.State, actionData: actionDataTask.Result, actionTreeItem: actionTreeItem, stateData: stateDataTask.Result, stateTreeItem: null, differenceItem: null, differenceCalculated: false))); break; case GenerateTreeHierarchyAction generateTreeHierarchy: { Step selectedStep = state.SelectedStep; result = state; if (selectedStep != null) { if (selectedStep.StateTreeItem is null) { var hierarchy = StateFormatter.ToTreeHierarchy(selectedStep.StateData); Step updated = selectedStep.Clone(stateTreeItem: hierarchy); result = result.Clone(steps: state.Steps.Replace(selectedStep, updated), selectedStep: updated); selectedStep = updated; } if (!selectedStep.DifferenceCalculated) { // first check if previous step has StateTree var selectedStepIndex = Array.IndexOf(result.Steps, selectedStep); var previousStep = selectedStepIndex > 0 ? result.Steps[selectedStepIndex - 1] : null; ObjectTreeItem previousHierarchy = null; if (previousStep != null) { if (previousStep.StateTreeItem == null) { previousHierarchy = StateFormatter.ToTreeHierarchy(previousStep.StateData); Step previousUpdated = previousStep.Clone(stateTreeItem: previousHierarchy); result = result.Clone(steps: result.Steps.Replace(previousStep, previousUpdated)); } else { previousHierarchy = previousStep.StateTreeItem; } } var difference = TreeComparer.CreateDifferenceTree(previousHierarchy, selectedStep.StateTreeItem); Step updated = selectedStep.Clone(differenceItem: difference, differenceCalculated: true); result = result.Clone(steps: result.Steps.Replace(selectedStep, updated), selectedStep: updated); } } } break; case SelectedStepChangedAction selectedStepChanged: { var selectedStep = selectedStepChanged.Key.HasValue ? state.Steps.Single(s => s.Key == selectedStepChanged.Key) : null; result = state.Clone(selectedStep: selectedStep); } break; default: result = state; break; } return(result); }