Ejemplo n.º 1
0
        /// <summary> Gets the URL to be used for transfering to the external function. </summary>
        internal string GetDestinationUrlForExternalFunction(WxeFunction function, string functionToken, WxePermaUrlOptions permaUrlOptions)
        {
            string href;

            if (permaUrlOptions.UsePermaUrl)
            {
                NameValueCollection internalUrlParameters;
                if (permaUrlOptions.UrlParameters == null)
                {
                    internalUrlParameters = function.VariablesContainer.SerializeParametersForQueryString();
                }
                else
                {
                    internalUrlParameters = permaUrlOptions.UrlParameters.Clone();
                }
                internalUrlParameters.Set(WxeHandler.Parameters.WxeFunctionToken, functionToken);

                href = GetPermanentUrl(function.GetType(), internalUrlParameters, permaUrlOptions.UseParentPermaUrl);
            }
            else
            {
                UrlMappingEntry mappingEntry = UrlMappingConfiguration.Current.Mappings[function.GetType()];
                string          path         = (mappingEntry != null) ? mappingEntry.Resource : _httpContext.Request.Url.AbsolutePath;
                href = GetPath(path, functionToken, permaUrlOptions.UrlParameters);
            }

            return(href);
        }
Ejemplo n.º 2
0
        public void FindByID()
        {
            WebConfigurationMock.Current = WebConfigurationFactory.GetExecutionEngineUrlMapping();
            UrlMappingCollection mappings = UrlMappingConfiguration.Current.Mappings;

            UrlMappingEntry entry = mappings[0];

            Assert.AreSame(mappings[0], mappings.FindByID(entry.ID), "Could not find {0}.", entry.ID);

            entry = mappings[1];
            Assert.AreSame(mappings[1], mappings.FindByID(entry.ID), "Could not find {0}.", entry.Resource);

            Assert.IsNull(mappings.FindByID("unknown"), "Found mapping for unknown id.");
        }
Ejemplo n.º 3
0
        public void FindByResource()
        {
            WebConfigurationMock.Current = WebConfigurationFactory.GetExecutionEngineUrlMapping();
            UrlMappingCollection mappings = UrlMappingConfiguration.Current.Mappings;

            UrlMappingEntry entry = mappings[0];

            Assert.AreSame(mappings[0], mappings.Find(entry.Resource), "Could not find {0}.", entry.Resource);

            entry = mappings[1];
            Assert.AreSame(mappings[1], mappings.Find(entry.Resource), "Could not find {0}.", entry.Resource);

            entry = mappings[2];
            Assert.AreSame(mappings[2], mappings.Find(entry.Resource), "Could not find {0}.", entry.Resource);

            Assert.IsNull(mappings.Find("~/unmapped.wxe"), "Found mapping for unmapped resource.");
        }
Ejemplo n.º 4
0
        public void FindByFunctionType()
        {
            WebConfigurationMock.Current = WebConfigurationFactory.GetExecutionEngineUrlMapping();
            UrlMappingCollection mappings = UrlMappingConfiguration.Current.Mappings;

            UrlMappingEntry entry = mappings[0];

            Assert.AreSame(mappings[0], mappings.Find(entry.FunctionType), "Could not find {0}.", entry.FunctionType.FullName);

            entry = mappings[1];
            Assert.AreSame(mappings[1], mappings.Find(entry.FunctionType), "Could not find {0}.", entry.FunctionType.FullName);

            entry = mappings[2];
            Assert.AreSame(mappings[0], mappings.Find(entry.FunctionType), "Could not find {0}.", entry.FunctionType.FullName);

            Assert.IsNull(mappings.Find(typeof(UnmappedFunction)), "Found mapping for unmapped function.");
        }
Ejemplo n.º 5
0
            public virtual Type ResolveFunctionType()
            {
                UrlMappingEntry mapping = UrlMappingConfiguration.Current.Mappings.FindByID(_mappingID);

                bool hasMapping  = mapping != null;
                bool hasTypeName = !string.IsNullOrEmpty(_typeName);

                Type functionType = null;

                if (hasTypeName)
                {
                    functionType = WebTypeUtility.GetType(_typeName, true);
                }

                if (hasMapping)
                {
                    if (functionType == null)
                    {
                        functionType = mapping.FunctionType;
                    }
                    else if (mapping.FunctionType != functionType)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "The WxeFunctionCommand in has both a MappingID ('{0}') and a TypeName ('{1}') defined, but they resolve to different WxeFunctions.",
                                      _mappingID,
                                      _typeName));
                    }
                }
                else if (!hasTypeName)
                {
                    throw new InvalidOperationException("The WxeFunctionCommand has no valid MappingID or FunctionTypeName specified.");
                }

                return(functionType);
            }