using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Web;
using System.Xml.Linq;
using Composite.Core;
using Composite.Data;
using Composite.Functions;
using Composite.Core.Xml;
using Composite.Core.WebClient.Renderings.Page;
using Composite.Core.WebClient;
///
/// Executes a C1 Function. The name of the function is copied from the name of this .ashx file,
/// i.e. if this file is named "Composite.Pages.QuickSitemap.ashx" the function "Composite.Pages.QuickSitemap" will be called
/// Parameters specified in the URL will be passed on to the function.
///
/// You control the data culture through the URL parameter "cultureScope", like "cultureScope=en-US".
///
/// To use this class - create a .ashx file which inherit from this class (ExecuteC1FunctionHttpHandler) and name it
/// (full function name).ashx
///
public abstract class ExecuteC1FunctionHttpHandler : IHttpHandler
{
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