コード例 #1
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"));
        }
コード例 #2
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);
            }
        }
コード例 #3
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));
        }
コード例 #4
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));
        }
コード例 #5
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);
        }