/// <summary> Initializes a new <see cref="WxeFunction"/>, encapsulated in a <see cref="WxeFunctionState"/> object. </summary> /// <include file='..\doc\include\ExecutionEngine\WxeHandler.xml' path='WxeHandler/CreateNewFunctionState/*' /> protected WxeFunctionState CreateNewFunctionState(HttpContext context, Type type) { ArgumentUtility.CheckNotNull("context", context); ArgumentUtility.CheckNotNull("type", type); WxeFunctionStateManager functionStates = WxeFunctionStateManager.Current; functionStates.CleanUpExpired(); WxeFunction function = (WxeFunction)Activator.CreateInstance(type); WxeFunctionState functionState = new WxeFunctionState(function, true); functionStates.Add(functionState); function.VariablesContainer.InitializeParameters(context.Request.QueryString); string returnUrlArg = context.Request.QueryString[Parameters.ReturnUrl]; string returnToSelfArg = context.Request.QueryString[Parameters.WxeReturnToSelf]; if (!string.IsNullOrEmpty(returnUrlArg)) { function.ReturnUrl = returnUrlArg; } else if (!string.IsNullOrEmpty(returnToSelfArg)) { if (bool.Parse(returnToSelfArg)) { function.ReturnUrl = context.Request.RawUrl; } } return(functionState); }
/// <summary> Resumes an existing <see cref="WxeFunction"/>. </summary> /// <include file='..\doc\include\ExecutionEngine\WxeHandler.xml' path='WxeHandler/ResumeExistingFunctionState/*' /> protected WxeFunctionState ResumeExistingFunctionState(HttpContext context, string functionToken) { ArgumentUtility.CheckNotNull("context", context); ArgumentUtility.CheckNotNullOrEmpty("functionToken", functionToken); string action = context.Request.Params[Parameters.WxeAction]; bool isRefresh = StringUtility.AreEqual(action, Actions.Refresh, true); bool isAbort = StringUtility.AreEqual(action, Actions.Abort, true) || StringUtility.AreEqual(action, Actions.Cancel, true); bool isPostBackAction = isRefresh || isAbort; bool isPostRequest = string.Compare(context.Request.HttpMethod, "POST", true) == 0; if (!WxeFunctionStateManager.HasSession) { if (isPostRequest || isPostBackAction) { s_log.Error(string.Format("Error resuming WxeFunctionState {0}: The ASP.NET session has timed out.", functionToken)); throw new WxeTimeoutException("Session timeout.", functionToken); // TODO: display error message } try { return(CreateNewFunctionState(context, GetType(context))); } catch (WxeException e) { s_log.Error(string.Format("Error resuming WxeFunctionState {0}: The ASP.NET session has timed out.", functionToken)); throw new WxeTimeoutException("Session timeout.", functionToken, e); // TODO: display error message } } WxeFunctionStateManager functionStateManager = WxeFunctionStateManager.Current; if (functionStateManager.IsExpired(functionToken)) { if (isPostRequest || isPostBackAction) { s_log.Error(string.Format("Error resuming WxeFunctionState {0}: The function state has timed out or was aborted.", functionToken)); throw new WxeTimeoutException("Function Timeout.", functionToken); // TODO: display error message } try { return(CreateNewFunctionState(context, GetType(context))); } catch (WxeException e) { s_log.Error(string.Format("Error resuming WxeFunctionState {0}: The function state has timed out or was aborted.", functionToken)); throw new WxeTimeoutException("Function Timeout.", functionToken, e); // TODO: display error message } } WxeFunctionState functionState = functionStateManager.GetItem(functionToken); if (functionState.IsAborted) { s_log.Error(string.Format("Error resuming WxeFunctionState {0}: The function state has been aborted.", functionState.FunctionToken)); throw new InvalidOperationException(string.Format("WxeFunctionState {0} is aborted.", functionState.FunctionToken)); // TODO: display error message } if (isRefresh) { functionStateManager.Touch(functionToken); functionStateManager.CleanUpExpired(); return(null); } else if (isAbort) { functionStateManager.CleanUpExpired(); functionStateManager.Abort(functionState); return(null); } else { functionStateManager.Touch(functionToken); functionStateManager.CleanUpExpired(); if (functionState.Function == null) { throw new WxeException(string.Format("Function missing in WxeFunctionState {0}.", functionState.FunctionToken)); } return(functionState); } }