Ejemplo n.º 1
0
        public void OnPreRenderComplete()
        {
            WxeContext wxeContext = WxeContext.Current;

            _page.ClientScript.RegisterHiddenField(_page, WxeHandler.Parameters.WxeFunctionToken, wxeContext.FunctionToken);
            _page.ClientScript.RegisterHiddenField(_page, WxePageInfo.ReturningTokenID, null);
            int nextPostBackID = wxeContext.PostBackID + 1;

            _page.ClientScript.RegisterHiddenField(_page, WxePageInfo.PostBackSequenceNumberID, nextPostBackID.ToString());

            _page.ClientScript.RegisterClientScriptBlock(_page, typeof(WxePageInfo), "wxeDoSubmit",
                                                         "function wxeDoSubmit (button, pageToken) { \r\n"
                                                         + "  var theForm = document." + _wxeForm.ClientID + "; \r\n"
                                                         + "  theForm." + WxePageInfo.ReturningTokenID + ".value = pageToken; \r\n"
                                                         + "  document.getElementById(button).click(); \r\n"
                                                         + "}");

            _page.ClientScript.RegisterClientScriptBlock(_page, typeof(WxePageInfo), "wxeDoPostBack",
                                                         "function wxeDoPostBack (control, argument, returningToken) { \r\n"
                                                         + "  var theForm = document." + _wxeForm.ClientID + "; \r\n"
                                                         + "  theForm." + WxePageInfo.ReturningTokenID + ".value = returningToken; \r\n"
                                                         + "  __doPostBack (control, argument); \r\n"
                                                         + "}");

            HtmlHeadAppender.Current.RegisterUtilitiesJavaScriptInclude();

            RegisterWxeInitializationScript();
            SetCacheSettings();
        }
Ejemplo n.º 2
0
        /// <exception cref="WxePostbackOutOfSequenceException">
        ///   Thrown if a postback with an incorrect sequence number is handled.
        /// </exception>
        protected virtual void HandleLoadPostData(NameValueCollection postBackCollection)
        {
            ArgumentUtility.CheckNotNull("postBackCollection", postBackCollection);

            WxeContext wxeContext = WxeContext.Current;

            int postBackID = int.Parse(postBackCollection[WxePageInfo.PostBackSequenceNumberID]);

            if (postBackID != wxeContext.PostBackID)
            {
                CurrentPageStep.SetIsOutOfSequencePostBack(true);
            }

            string returningToken = postBackCollection[WxePageInfo.ReturningTokenID];

            if (!string.IsNullOrEmpty(returningToken))
            {
                WxeFunctionStateManager functionStates = WxeFunctionStateManager.Current;
                WxeFunctionState        functionState  = functionStates.GetItem(returningToken);
                if (functionState != null)
                {
                    CurrentPageStep.SetReturnState(functionState.Function, true, null);
                    _returningFunctionState = functionState;
                }
            }
        }
        public override void Execute(WxeContext context)
        {
            ArgumentUtility.CheckNotNull("context", context);

            if (_wxeHandler != null)
            {
                context.HttpContext.Handler = _wxeHandler;
                _wxeHandler = null;
            }

            if (!_isExecutionStarted)
            {
                _isExecutionStarted = true;
                _isPostBack         = false;
            }
            else
            {
                _isPostBack = true;
            }

            _userControlExecutor.Execute(context);

            try
            {
                PageStep.PageExecutor.ExecutePage(context, PageStep.Page, PageStep.IsPostBack);
            }
            finally
            {
                if (_userControlExecutor.IsReturningPostBack)
                {
                    _userControlExecutor = NullUserControlExecutor.Null;
                }
            }
        }
Ejemplo n.º 4
0
        public override void Execute(WxeContext context)
        {
            ArgumentUtility.CheckNotNull("context", context);
            Assertion.IsNotNull(_executionListener);

            if (!IsExecutionStarted)
            {
                _variablesContainer.EnsureParametersInitialized(null);
                var wxeSecurityAdapter = GetWxeSecurityAdapter();
                _executionListener = new SecurityExecutionListener(this, _executionListener, wxeSecurityAdapter);

                _transactionStrategy = _transactionMode.CreateTransactionStrategy(this, context);
                Assertion.IsNotNull(_transactionStrategy);

                _executionListener = _transactionStrategy.CreateExecutionListener(_executionListener);
                Assertion.IsNotNull(_executionListener);
            }

            try
            {
                _executionListener.OnExecutionPlay(context);
                base.Execute(context);
                _executionListener.OnExecutionStop(context);
            }
            catch (WxeFatalExecutionException)
            {
                // bubble up
                throw;
            }
            catch (ThreadAbortException)
            {
                _executionListener.OnExecutionPause(context);
                throw;
            }
            catch (Exception stepException)
            {
                try
                {
                    _executionListener.OnExecutionFail(context, stepException);
                }
                catch (Exception listenerException)
                {
                    throw new WxeFatalExecutionException(stepException, listenerException);
                }

                var unwrappedException = WxeHttpExceptionPreservingException.GetUnwrappedException(stepException) ?? stepException;
                if (!_exceptionHandler.Catch(unwrappedException))
                {
                    throw new WxeUnhandledException(
                              string.Format("An exception ocured while executing WxeFunction '{0}'.", GetType().FullName),
                              stepException);
                }
            }

            if (_exceptionHandler.Exception == null && ParentStep != null)
            {
                _variablesContainer.ReturnParametersToCaller();
            }
        }
Ejemplo n.º 5
0
        /// <summary>  Invokes <see cref="WxeFunction.Execute(WxeContext)"/> on the <paramref name="function"/>. </summary>
        /// <include file='..\doc\include\ExecutionEngine\WxeHandler.xml' path='WxeHandler/ExecuteFunction/*' />
        protected virtual void ExecuteFunction(WxeFunction function, WxeContext context, bool isNew)
        {
            ArgumentUtility.CheckNotNull("function", function);
            ArgumentUtility.CheckNotNull("context", context);
            if (function.IsAborted)
            {
                throw new ArgumentException("The function " + function.GetType().FullName + " is aborted.");
            }

            function.ExceptionHandler.AppendCatchExceptionTypes(typeof(WxeUserCancelException));
            function.Execute(context);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///   Sets the current <see cref="WxeContext"/> and invokes <see cref="ExecuteFunction"/> on the
        ///   <paramref name="functionState"/>'s <see cref="WxeFunctionState.Function"/>.
        /// </summary>
        /// <include file='..\doc\include\ExecutionEngine\WxeHandler.xml' path='WxeHandler/ExecuteFunctionState/*' />
        protected void ExecuteFunctionState(HttpContext context, WxeFunctionState functionState, bool isNewFunction)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("functionState", functionState);
            if (functionState.IsAborted)
            {
                throw new ArgumentException("The function state " + functionState.FunctionToken + " is aborted.");
            }

            WxeContext wxeContext = new WxeContext(new HttpContextWrapper(context), WxeFunctionStateManager.Current, functionState, context.Request.QueryString);

            WxeContext.SetCurrent(wxeContext);

            functionState.PostBackID++;
            ExecuteFunction(functionState.Function, wxeContext, isNewFunction);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///   Displays the <see cref="WxePageStep"/>'s page or the sub-function that has been invoked by the
        ///   <see cref="ExecuteFunction(Infrastructure.WxePageStepExecutionStates.PreProcessingSubFunctionStateParameters,Infrastructure.WxeRepostOptions)"/> method.
        /// </summary>
        /// <include file='..\doc\include\ExecutionEngine\WxePageStep.xml' path='WxePageStep/Execute/*' />
        public override void Execute(WxeContext context)
        {
            ArgumentUtility.CheckNotNull("context", context);

            if (_wxeHandler != null)
            {
                context.HttpContext.Handler = _wxeHandler;
                _wxeHandler = null;
            }

            if (!_isExecutionStarted)
            {
                _isExecutionStarted = true;
                _isPostBack         = false;
            }
            else
            {
                _isPostBack = true;
            }

            ClearIsOutOfSequencePostBack();
            ClearReturnState();

            while (_executionState.IsExecuting)
            {
                _executionState.ExecuteSubFunction(context);
            }

            _userControlExecutor.Execute(context);

            try
            {
                _pageExecutor.ExecutePage(context, Page, _isPostBack);
            }
            finally
            {
                if (_userControlExecutor.IsReturningPostBack)
                {
                    _userControlExecutor = NullUserControlExecutor.Null;
                }

                ClearIsOutOfSequencePostBack();
                ClearReturnState();
            }
        }
Ejemplo n.º 8
0
        public override void Execute(WxeContext context)
        {
            if (!IsExecutionStarted)
            {
                _executingStep = 0;
            }

            while (_executingStep < _steps.Count)
            {
                var currentStep = _steps[_executingStep];
                if (currentStep.IsAborted)
                {
                    throw new InvalidOperationException("Step " + _executingStep + " of " + this.GetType().FullName + " is aborted.");
                }
                currentStep.Execute(context);
                _executingStep++;
            }
        }
Ejemplo n.º 9
0
        //  public WxeMethodStep (WxeMethod method)
        //    : this ((WxeStepList) method.Target, method.Method)
        //  {
        //    _method = method;
        //  }
        //
        //  public WxeMethodStep (WxeMethodWithContext method)
        //    : this ((WxeStepList) method.Target, method.Method)
        //  {
        //    _methodWithContext = method;
        //  }

        /// <summary> Executes the method provided during the initizalion of this <see cref="WxeMethodStep"/>. </summary>
        /// <param name="context"> The <see cref="WxeContext"/> containing the information about the execution. </param>
        public override void Execute(WxeContext context)
        {
            if (_hasContext)
            {
                if (_methodWithContext == null)
                {
                    _methodWithContext =
                        (WxeMethodWithContext)Delegate.CreateDelegate(typeof(WxeMethodWithContext), _target, _methodName, false);
                }
                _methodWithContext(context);
            }
            else
            {
                if (_method == null)
                {
                    _method = (WxeMethod)Delegate.CreateDelegate(typeof(WxeMethod), _target, _methodName, false);
                }
                _method();
            }
        }
Ejemplo n.º 10
0
        private NameValueCollection DeterminePostBackMode(HttpContext httpContext)
        {
            WxeContext wxeContext = WxeContext.Current;

            if (wxeContext == null)
            {
                return(null);
            }
            if (!CurrentPageStep.IsPostBack)
            {
                return(null);
            }
            if (CurrentPageStep.PostBackCollection != null)
            {
                return(CurrentPageStep.PostBackCollection);
            }
            if (httpContext.Request == null)
            {
                return(null);
            }

            NameValueCollection collection;

            if (StringUtility.AreEqual(httpContext.Request.HttpMethod, "POST", false))
            {
                collection = httpContext.Request.Form;
            }
            else
            {
                collection = httpContext.Request.QueryString;
            }

            if ((collection[ControlHelper.ViewStateFieldPrefixID] == null) && (collection[ControlHelper.PostEventSourceID] == null))
            {
                return(null);
            }
            else
            {
                return(collection);
            }
        }
Ejemplo n.º 11
0
        private static string GetExternalFunctionUrl(WxeFunction function, bool createPermaUrl, NameValueCollection urlParameters)
        {
            string functionToken = WxeContext.Current.GetFunctionTokenForExternalFunction(function, false);

            NameValueCollection internalUrlParameters;

            if (urlParameters == null)
            {
                if (createPermaUrl)
                {
                    internalUrlParameters = function.VariablesContainer.SerializeParametersForQueryString();
                }
                else
                {
                    internalUrlParameters = new NameValueCollection();
                }
            }
            else
            {
                internalUrlParameters = NameValueCollectionUtility.Clone(urlParameters);
            }
            internalUrlParameters.Set(WxeHandler.Parameters.WxeFunctionToken, functionToken);
            return(WxeContext.GetPermanentUrl(WxeContext.Current.HttpContext, function.GetType(), internalUrlParameters));
        }
Ejemplo n.º 12
0
 public static void SetCurrent(WxeContext value)
 {
     s_context.SetCurrent(value);
 }
Ejemplo n.º 13
0
 public abstract void Execute(WxeContext context);
Ejemplo n.º 14
0
        private void RegisterWxeInitializationScript()
        {
            IResourceManager resourceManager = GetResourceManager();

            string     temp;
            WxeContext wxeContext = WxeContext.Current;

            int    refreshInterval = 0;
            string refreshPath     = "null";
            string abortPath       = "null";

            if (WxeHandler.IsSessionManagementEnabled)
            {
                //  Ensure the registration of "__doPostBack" on the page.
                temp = _page.ClientScript.GetPostBackEventReference(_page, null);

                bool isAbortEnabled = _page.IsAbortEnabled;

                string resumePath = wxeContext.GetPath(wxeContext.FunctionToken, null);

                if (WxeHandler.IsSessionRefreshEnabled)
                {
                    refreshInterval = WxeHandler.RefreshInterval * 60000;
                    refreshPath     = "'" + resumePath + "&" + WxeHandler.Parameters.WxeAction + "=" + WxeHandler.Actions.Refresh + "'";
                }

                if (isAbortEnabled)
                {
                    abortPath = "'" + resumePath + "&" + WxeHandler.Parameters.WxeAction + "=" + WxeHandler.Actions.Abort + "'";
                }
            }

            string statusIsAbortingMessage = "null";
            string statusIsCachedMessage   = "null";

            if (_page.AreStatusMessagesEnabled)
            {
                if (string.IsNullOrEmpty(_page.StatusIsAbortingMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.StatusIsAbortingMessage);
                }
                else
                {
                    temp = _page.StatusIsAbortingMessage;
                }
                statusIsAbortingMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";

                if (string.IsNullOrEmpty(_page.StatusIsCachedMessage))
                {
                    temp = resourceManager.GetString(ResourceIdentifier.StatusIsCachedMessage);
                }
                else
                {
                    temp = _page.StatusIsCachedMessage;
                }
                statusIsCachedMessage = "'" + ScriptUtility.EscapeClientScript(temp) + "'";
            }

            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnLoad, "WxePage_OnLoad", "WxePage_OnLoad");
            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnAbort, "WxePage_OnAbort", "WxePage_OnAbort");
            _page.RegisterClientSidePageEventHandler(SmartPageEvents.OnUnload, "WxePage_OnUnload", "WxePage_OnUnload");
            _page.CheckFormStateFunction = "WxePage_CheckFormState";

            string isCacheDetectionEnabled = _page.AreOutOfSequencePostBacksEnabled ? "false" : "true";

            StringBuilder initScript = new StringBuilder(500);

            initScript.AppendLine("WxePage_Context.SetInstance (new WxePage_Context (");
            initScript.AppendLine("    ").Append(isCacheDetectionEnabled).AppendLine(",");
            initScript.AppendLine("    ").Append(refreshInterval).AppendLine(",");
            initScript.AppendLine("    ").Append(refreshPath).AppendLine(",");
            initScript.AppendLine("    ").Append(abortPath).AppendLine(",");
            initScript.AppendLine("    ").Append(statusIsAbortingMessage).AppendLine(",");
            initScript.AppendLine("    ").Append(statusIsCachedMessage).AppendLine("));");

            _page.ClientScript.RegisterClientScriptBlock(_page, typeof(WxePageInfo), "wxeInitialize", initScript.ToString());
        }