Ejemplo n.º 1
0
        /// <summary>
        ///   Implements <see cref="Remotion.Web.UI.ISmartNavigablePage.GetNavigationUrlParameters">ISmartNavigablePage.GetNavigationUrlParameters</see>.
        /// </summary>
        public NameValueCollection GetNavigationUrlParameters()
        {
            NameValueCollection urlParameters = new NameValueCollection();

            foreach (INavigationControl control in _navigationControls.Values)
            {
                NameValueCollectionUtility.Append(urlParameters, control.GetNavigationUrlParameters());
            }

            return(urlParameters);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Implements <see cref="IWxePage.GetPermanentUrlParameters">IWxePage.GetPermanentUrlParameters()</see>.
        /// </summary>
        public NameValueCollection GetPermanentUrlParameters()
        {
            NameValueCollection urlParameters = CurrentPageFunction.VariablesContainer.SerializeParametersForQueryString();

            ISmartNavigablePage smartNavigablePage = _page as ISmartNavigablePage;

            if (smartNavigablePage != null)
            {
                NameValueCollectionUtility.Append(urlParameters, smartNavigablePage.GetNavigationUrlParameters());
            }

            return(urlParameters);
        }
Ejemplo n.º 3
0
        public void AppendWithEmptyCollection()
        {
            NameValueCollectionUtility.Append(_collection, new NameValueCollection());

            Assert.That(_collection.Count, Is.EqualTo(3));

            Assert.That(_collection.GetKey(0), Is.EqualTo("FirstKey"));
            Assert.That(_collection.GetKey(1), Is.EqualTo("SecondKey"));
            Assert.That(_collection.GetKey(2), Is.EqualTo("ThirdKey"));

            Assert.That(_collection["FirstKey"], Is.EqualTo("FirstValue"));
            Assert.That(_collection["SecondKey"], Is.EqualTo("SecondValue"));
            Assert.That(_collection["ThirdKey"], Is.EqualTo("ThirdValue,Other ThirdValue"));
        }
Ejemplo n.º 4
0
        public void Clone()
        {
            NameValueCollection actual = NameValueCollectionUtility.Clone(_collection);

            Assert.That(actual, Is.Not.Null);
            Assert.That(ReferenceEquals(_collection, actual), Is.False);
            Assert.That(actual.Count, Is.EqualTo(3));

            Assert.That(actual.GetKey(0), Is.EqualTo("FirstKey"));
            Assert.That(actual.GetKey(1), Is.EqualTo("SecondKey"));
            Assert.That(actual.GetKey(2), Is.EqualTo("ThirdKey"));

            Assert.That(actual["FirstKey"], Is.EqualTo("FirstValue"));
            Assert.That(actual["SecondKey"], Is.EqualTo("SecondValue"));
            Assert.That(actual["ThirdKey"], Is.EqualTo("ThirdValue,Other ThirdValue"));
        }
Ejemplo n.º 5
0
        public void AppendWithOtherCollection()
        {
            NameValueCollectionUtility.Append(_collection, _otherCollection);

            Assert.That(_collection.Count, Is.EqualTo(5));

            Assert.That(_collection.GetKey(0), Is.EqualTo("FirstKey"));
            Assert.That(_collection.GetKey(1), Is.EqualTo("SecondKey"));
            Assert.That(_collection.GetKey(2), Is.EqualTo("ThirdKey"));
            Assert.That(_collection.GetKey(3), Is.EqualTo("FourthKey"));
            Assert.That(_collection.GetKey(4), Is.EqualTo("FifthKey"));

            Assert.That(_collection["FirstKey"], Is.EqualTo("FirstValue"));
            Assert.That(_collection["SecondKey"], Is.EqualTo("Other SecondValue"));
            Assert.That(_collection["ThirdKey"], Is.EqualTo("ThirdValue,Other ThirdValue"));
            Assert.That(_collection["FourthKey"], Is.EqualTo("FourthValue"));
            Assert.That(_collection["FifthKey"], Is.EqualTo("FifthValue"));
        }
Ejemplo n.º 6
0
        /// <summary> Creates a <see cref="CommandInfo"/> for the <see cref="HrefCommand"/>. </summary>
        /// <param name="parameters">
        ///   The strings inserted into the href attribute using <c>string.Format</c>.
        /// </param>
        /// <param name="onClick">
        ///   The string always rendered in the <c>onClick</c> tag of the anchor element.
        /// </param>
        /// <param name="additionalUrlParameters">
        ///   The <see cref="NameValueCollection"/> containing additional url parameters.
        ///   Must not be <see langword="null"/>.
        /// </param>
        /// <param name="includeNavigationUrlParameters">
        ///   <see langword="true"/> to include URL parameters provided by <see cref="ISmartNavigablePage"/>.
        ///   Defaults to <see langword="true"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   If called while the <see cref="Type"/> is not set to <see cref="CommandType.Href"/>.
        /// </exception>
        protected virtual CommandInfo GetCommandInfoForHrefCommand(
            string[] parameters,
            string onClick,
            NameValueCollection additionalUrlParameters,
            bool includeNavigationUrlParameters)
        {
            ArgumentUtility.CheckNotNull("parameters", parameters);
            ArgumentUtility.CheckNotNull("additionalUrlParameters", additionalUrlParameters);
            if (Type != CommandType.Href)
            {
                throw new InvalidOperationException("Call to GetCommandInfoForHrefCommand not allowed unless Type is set to CommandType.Href.");
            }

            string href = HrefCommand.FormatHref(parameters);

            if (includeNavigationUrlParameters)
            {
                ISmartNavigablePage page = null;
                if (OwnerControl != null)
                {
                    page = OwnerControl.Page as ISmartNavigablePage;
                }

                if (page != null)
                {
                    additionalUrlParameters = additionalUrlParameters.Clone();
                    NameValueCollectionUtility.Append(additionalUrlParameters, page.GetNavigationUrlParameters());
                }
            }
            href = UrlUtility.AddParameters(href, additionalUrlParameters);
            if (OwnerControl != null)
            {
                href = OwnerControl.ResolveClientUrl(href);
            }

            return(CommandInfo.CreateForLink(
                       StringUtility.EmptyToNull(_toolTip),
                       StringUtility.EmptyToNull(_accessKey),
                       href,
                       StringUtility.EmptyToNull(HrefCommand.Target),
                       StringUtility.EmptyToNull(onClick)));
        }
Ejemplo n.º 7
0
        public void MergeWithFirstValueAndSecondValue()
        {
            NameValueCollection actual = NameValueCollectionUtility.Merge(_collection, _otherCollection);

            Assert.That(actual, Is.Not.Null);
            Assert.That(ReferenceEquals(_collection, actual), Is.False);
            Assert.That(actual.Count, Is.EqualTo(5));

            Assert.That(actual.GetKey(0), Is.EqualTo("FirstKey"));
            Assert.That(actual.GetKey(1), Is.EqualTo("SecondKey"));
            Assert.That(actual.GetKey(2), Is.EqualTo("ThirdKey"));
            Assert.That(actual.GetKey(3), Is.EqualTo("FourthKey"));
            Assert.That(actual.GetKey(4), Is.EqualTo("FifthKey"));

            Assert.That(actual["FirstKey"], Is.EqualTo("FirstValue"));
            Assert.That(actual["SecondKey"], Is.EqualTo("Other SecondValue"));
            Assert.That(actual["ThirdKey"], Is.EqualTo("ThirdValue,Other ThirdValue"));
            Assert.That(actual["FourthKey"], Is.EqualTo("FourthValue"));
            Assert.That(actual["FifthKey"], Is.EqualTo("FifthValue"));
        }
Ejemplo n.º 8
0
        public WxeContext(HttpContextBase context, WxeFunctionStateManager functionStateManager, WxeFunctionState functionState, NameValueCollection queryString)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("functionStateManager", functionStateManager);
            ArgumentUtility.CheckNotNull("functionState", functionState);

            _httpContext          = context;
            _functionStateManager = functionStateManager;

            _functionState = functionState;

            if (queryString == null)
            {
                _queryString = new NameValueCollection();
            }
            else
            {
                _queryString = NameValueCollectionUtility.Clone(queryString);
                _queryString.Remove(WxeHandler.Parameters.WxeFunctionToken);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///   Gets the permanent URL for the <see cref="WxeFunction"/> defined by the
        ///   <see cref="Command.WxeFunctionCommandInfo"/>.
        /// </summary>
        /// <param name="additionalUrlParameters">
        ///   The <see cref="NameValueCollection"/> containing additional url parameters.
        ///   Must not be <see langword="null"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   <para>
        ///     Thrown if called while the <see cref="Type"/> is not set to <see cref="CommandType.WxeFunction"/>.
        ///   </para><para>
        ///     Thrown if neither the <see cref="Command.WxeFunctionCommandInfo.MappingID"/> nor the
        ///     <see cref="Command.WxeFunctionCommandInfo.TypeName"/> are set.
        ///   </para><para>
        ///     Thrown if the <see cref="Command.WxeFunctionCommandInfo.MappingID"/> and
        ///     <see cref="Command.WxeFunctionCommandInfo.TypeName"/> specify different functions.
        ///   </para>
        /// </exception>
        public virtual string GetWxeFunctionPermanentUrl(NameValueCollection additionalUrlParameters)
        {
            ArgumentUtility.CheckNotNull("additionalUrlParameters", additionalUrlParameters);

            if (Type != CommandType.WxeFunction)
            {
                throw new InvalidOperationException("Call to ExecuteWxeFunction not allowed unless Type is set to CommandType.WxeFunction.");
            }

            Type functionType = WxeFunctionCommand.ResolveFunctionType();

            WxeParameterDeclaration[] parameterDeclarations = WxeVariablesContainer.GetParameterDeclarations(functionType);
            object[] parameterValues = WxeVariablesContainer.ParseActualParameters(
                parameterDeclarations, WxeFunctionCommand.Parameters, CultureInfo.InvariantCulture);

            NameValueCollection queryString = WxeVariablesContainer.SerializeParametersForQueryString(parameterDeclarations, parameterValues);

            queryString.Set(WxeHandler.Parameters.WxeReturnToSelf, true.ToString());
            NameValueCollectionUtility.Append(queryString, additionalUrlParameters);

            return(WxeContext.GetPermanentUrl(new HttpContextWrapper(HttpContext.Current), functionType, queryString));
        }
Ejemplo n.º 10
0
        /// <summary> Gets the absolute path that resumes the function with specified token. </summary>
        /// <param name="path"> The path to the <see cref="WxeHandler"/>. Must not be <see langword="null"/> or emtpy. </param>
        /// <param name="functionToken">
        ///   The function token of the function to resume. Must not be <see langword="null"/> or emtpy.
        /// </param>
        /// <param name="queryString"> An optional list of URL parameters to be appended to the <paramref name="path"/>. </param>
        private string GetPath(string path, string functionToken, NameValueCollection queryString)
        {
            ArgumentUtility.CheckNotNullOrEmpty("path", path);
            ArgumentUtility.CheckNotNullOrEmpty("functionToken", functionToken);

            if (path.IndexOf("?") != -1)
            {
                throw new ArgumentException("The path must be provided without a query string. Use the query string parameter instead.", "path");
            }

            if (queryString == null)
            {
                queryString = new NameValueCollection();
            }
            else
            {
                queryString = NameValueCollectionUtility.Clone(queryString);
            }

            queryString.Set(WxeHandler.Parameters.WxeFunctionToken, functionToken);

            path = UrlUtility.GetAbsoluteUrl(_httpContext, path);
            return(UrlUtility.AddParameters(path, queryString, _httpContext.Response.ContentEncoding));
        }
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
        /// <summary>
        ///   Gets the permanent URL for the <see cref="WxeFunction"/> of the specified <paramref name="functionType"/>
        ///   and using the <paramref name="urlParameters"/>.
        /// </summary>
        /// <include file='..\doc\include\ExecutionEngine\WxeContext.xml' path='WxeContext/GetPermanentUrl/param[@name="httpContext" or @name="functionType" or @name="urlParameters" or @name="fallbackOnCurrentUrl"]' />
        protected static string GetPermanentUrl(HttpContextBase httpContext, Type functionType, NameValueCollection urlParameters, bool fallbackOnCurrentUrl)
        {
            ArgumentUtility.CheckNotNull("httpContext", httpContext);
            ArgumentUtility.CheckNotNull("functionType", functionType);
            if (!typeof(WxeFunction).IsAssignableFrom(functionType))
            {
                throw new ArgumentException(string.Format("The functionType '{0}' must be derived from WxeFunction.", functionType), "functionType");
            }
            ArgumentUtility.CheckNotNull("urlParameters", urlParameters);

            NameValueCollection internalUrlParameters = NameValueCollectionUtility.Clone(urlParameters);

            UrlMapping.UrlMappingEntry mappingEntry = UrlMapping.UrlMappingConfiguration.Current.Mappings[functionType];
            if (mappingEntry == null)
            {
                string functionTypeName = WebTypeUtility.GetQualifiedName(functionType);
                internalUrlParameters.Set(WxeHandler.Parameters.WxeFunctionType, functionTypeName);
            }

            string path;

            if (mappingEntry == null)
            {
                string defaultWxeHandler = Configuration.WebConfiguration.Current.ExecutionEngine.DefaultWxeHandler;
                if (string.IsNullOrEmpty(defaultWxeHandler))
                {
                    if (fallbackOnCurrentUrl)
                    {
                        path = httpContext.Request.Url.AbsolutePath;
                    }
                    else
                    {
                        throw new WxeException(
                                  string.Format(
                                      "No URL mapping has been defined for WXE Function '{0}', nor has a default WxeHandler URL been specified in the application configuration (web.config).",
                                      functionType.FullName));
                    }
                }
                else
                {
                    path = defaultWxeHandler;
                }
            }
            else
            {
                path = mappingEntry.Resource;
            }

            string permanentUrl = UrlUtility.GetAbsoluteUrl(httpContext, path)
                                  + UrlUtility.FormatQueryString(internalUrlParameters, httpContext.Response.ContentEncoding);

            int maxLength = Configuration.WebConfiguration.Current.ExecutionEngine.MaximumUrlLength;

            if (permanentUrl.Length > maxLength)
            {
                throw new WxePermanentUrlTooLongException(
                          string.Format(
                              "Error while creating the permanent URL for WXE function '{0}'. "
                              + "The URL exceeds the maximum length of {1} bytes. Generated URL: {2}",
                              functionType.Name,
                              maxLength,
                              permanentUrl));
            }

            return(permanentUrl);
        }
Ejemplo n.º 13
0
 public void MergeWithFirstNullAndSecondNull()
 {
     Assert.That(NameValueCollectionUtility.Merge(null, null), Is.Null);
 }