Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            // Get the name of the function to execute by copying the current file name
            // (without the .ashx extension)
            string functionName = Path.GetFileNameWithoutExtension(context.Request.Path);
            // Locate the data culture to use - like en-US or nl-NL
            CultureInfo dataCulture = GetCurrentDataCulture(context);

            using (DataScope dataScope = new DataScope(DataScopeIdentifier.Public, dataCulture))
            {
                // Grab a function object to execute
                IFunction function = FunctionFacade.GetFunction(functionName);

                // Execute the function, passing all query string parameters as input parameters
                object functionResult = FunctionFacade.Execute <object>(function, context.Request.QueryString);

                // output result
                if (functionResult != null)
                {
                    context.Response.Write(functionResult.ToString());
                    if (functionResult is XNode && function.ReturnType != typeof(Composite.Core.Xml.XhtmlDocument))
                    {
                        context.Response.ContentType = "text/xml";
                    }
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            var functionName = (string)context.Request.RequestContext.RouteData.Values["function"];

            var dataCulture = GetCurrentDataCulture(context);

            using (var data = new DataConnection())
            {
                if (!data.Get <IFunctionRoute>().Any())
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                    return;
                }
            }

            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, functionName))
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                return;
            }

            using (var dataScope = new DataScope(DataScopeIdentifier.Public, dataCulture))
            {
                var functionResult = FunctionFacade.Execute <object>(function, context.Request.QueryString);
                if (functionResult == null)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return;
                }

                var xhtmlDocument = functionResult as XhtmlDocument;
                if (xhtmlDocument != null)
                {
                    PageRenderer.ExecuteEmbeddedFunctions(xhtmlDocument.Root, new FunctionContextContainer());
                    PageRenderer.NormalizeXhtmlDocument(xhtmlDocument);

                    var xhtml = xhtmlDocument.ToString();

                    xhtml = PageUrlHelper.ChangeRenderingPageUrlsToPublic(functionResult.ToString());
                    xhtml = MediaUrlHelper.ChangeInternalMediaUrlsToPublic(xhtml);

                    context.Response.Write(xhtml);
                }
                else
                {
                    context.Response.Write(functionResult.ToString());

                    if (functionResult is XNode && function.ReturnType != typeof(XhtmlDocument))
                    {
                        context.Response.ContentType = "text/xml";
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Executes the function.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="functionContextContainer">The function context container</param>
        /// <returns></returns>
        public static object ExecuteFunction(string name, IDictionary <string, object> parameters, FunctionContextContainer functionContextContainer)
        {
            IFunction function;

            if (!FunctionFacade.TryGetFunction(out function, name))
            {
                throw new InvalidOperationException("Failed to load function '{0}'".FormatWith(name));
            }

            functionContextContainer = functionContextContainer ?? new FunctionContextContainer();

            return(FunctionFacade.Execute <object>(function, parameters, functionContextContainer));
        }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var function = FunctionFacade.GetFunction(_c1FunctionName);

            if (function == null)
            {
                throw new InvalidOperationException("C1 function " + _c1FunctionName + " not recognized");
            }

            var parameters = new Dictionary <string, object>
            {
                { "Name", field.Name },
                { "HtmlAttributes", htmlAttributes },
                { "IsRequired", field.IsRequired },
                { "Label", field.Label },
                { "Placeholder", field.PlaceholderText }
            };

            var result = FunctionFacade.Execute <XhtmlDocument>(function, parameters);

            return(new HtmlString(result.ToString()));
        }
Пример #5
0
 public object Execute()
 {
     return(FunctionFacade.Execute <object>(FunctionFacade.GetFunction(this.Name)));
 }
Пример #6
0
        public override object GetData()
        {
            var function = FunctionFacade.GetFunction(_functioName);

            return(FunctionFacade.Execute <object>(function));
        }
Пример #7
0
        public virtual IHttpActionResult Body([FromBody] string body)
        {
            InitializeFullPageCaching(System.Web.HttpContext.Current);

            if (string.IsNullOrWhiteSpace(body))
            {
                NotFound();
            }

            var decrypted = LazyFunctionCallDataProvider.UnprotectFunctionCall(body);

            if (decrypted == null)
            {
                return(NotFound());
            }

            HttpContext.RewritePath(HttpContext.Request.FilePath, HttpContext.Request.PathInfo, decrypted.QueryString);

            using (var data = new DataConnection(PublicationScope.Published, ComposerContext.CultureInfo))
            {
                // Grab a function object to execute
                IFunction function = FunctionFacade.GetFunction(decrypted.FunctionName);

                PageRenderer.CurrentPage = PageManager.GetPageById(decrypted.PageId);;

                // Execute the function, passing all query string parameters as input parameters
                var functionResult = (XhtmlDocument)FunctionFacade.Execute <object>(function, decrypted.Parameters.ToDictionary(d => d.Key, d => (object)d.Value));


                // output result
                if (functionResult != null)
                {
                    var functionContext = new FunctionContextContainer();

                    PageRenderer.ExecuteEmbeddedFunctions(functionResult.Root, functionContext);

                    //PageRenderer.ProcessXhtmlDocument(functionResult, productPage);

                    using (Profiler.Measure("Normalizing XHTML document"))
                    {
                        PageRenderer.NormalizeXhtmlDocument(functionResult);
                    }

                    using (Profiler.Measure("Resolving relative paths"))
                    {
                        PageRenderer.ResolveRelativePaths(functionResult);
                    }


                    using (Profiler.Measure("Parsing localization strings"))
                    {
                        LocalizationParser.Parse(functionResult);
                    }

                    using (Profiler.Measure("Converting URLs from internal to public format (XhtmlDocument)"))
                    {
                        InternalUrls.ConvertInternalUrlsToPublic(functionResult);
                    }

                    //TODO: Update C1 Version
                    //PageRenderer.ProcessDocumentHead(functionResult);

                    StringBuilder sb = new StringBuilder();

                    foreach (var node in functionResult.Body.Nodes())
                    {
                        sb.Append(node.ToString());
                    }

                    return(Json(sb.ToString()));
                }
            }

            return(NotFound());
        }