Example #1
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            IComparable valueA = parameters.GetParameter <IComparable>("ValueA");
            IComparable valueB = parameters.GetParameter <IComparable>("ValueB");

            return(valueA.CompareTo(valueB));
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            bool isAndQuery = parameters.GetParameter <bool>("IsAndQuery");
            Expression <Func <T, bool> > left  = parameters.GetParameter <Expression <Func <T, bool> > >("Left");
            Expression <Func <T, bool> > right = parameters.GetParameter <Expression <Func <T, bool> > >("Right");

            Expression compound;

            if (isAndQuery)
            {
                Expression leftFilter  = Expression.Invoke(left, _dataItem);
                Expression rightFilter = Expression.Invoke(right, _dataItem);
                compound = Expression.And(leftFilter, rightFilter);
            }
            else
            {
                Expression leftFilter  = Expression.Invoke(left, _dataItem);
                Expression rightFilter = Expression.Invoke(right, _dataItem);
                compound = Expression.Or(leftFilter, rightFilter);
            }

            Expression <Func <T, bool> > lambdaExpression = Expression.Lambda <Func <T, bool> >(compound, new ParameterExpression[] { _dataItem });

            return(lambdaExpression);
        }
Example #3
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            SitemapScope SitemapScope;

            if (parameters.TryGetParameter <SitemapScope>("SitemapScope", out SitemapScope) == false)
            {
                SitemapScope = SitemapScope.Current;
            }

            Guid pageId = Guid.Empty;

            switch (SitemapScope)
            {
            case SitemapScope.Current:
                pageId = PageRenderer.CurrentPageId;
                break;

            case SitemapScope.Parent:
            case SitemapScope.Level1:
            case SitemapScope.Level2:
            case SitemapScope.Level3:
            case SitemapScope.Level4:
                IEnumerable <Guid> pageIds = PageStructureInfo.GetAssociatedPageIds(PageRenderer.CurrentPageId, SitemapScope);
                pageId = pageIds.FirstOrDefault();
                break;

            default:
                throw new NotImplementedException("Unhandled SitemapScope type: " + SitemapScope.ToString());
            }

            return(pageId);
        }
Example #4
0
        /// <exclude />
        public static Control Render(XDocument document, FunctionContextContainer contextContainer, IXElementToControlMapper mapper, IPage page)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                ExecuteEmbeddedFunctions(document.Root, contextContainer);

                ResolvePageFields(document, page);

                NormalizeAspNetForms(document);

                if (document.Root.Name != Namespaces.Xhtml + "html")
                {
                    return(new LiteralControl(document.ToString()));
                }

                XhtmlDocument xhtmlDocument = new XhtmlDocument(document);
                NormalizeXhtmlDocument(xhtmlDocument);

                ResolveRelativePaths(xhtmlDocument);

                PrioritizeHeadNodex(xhtmlDocument);

                AppendC1MetaTags(page, xhtmlDocument);

                LocalizationParser.Parse(xhtmlDocument);

                return(xhtmlDocument.AsAspNetControl(mapper));
            }
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            string commaSeparatedSearchTerms = parameters.GetParameter <string>("CommaSeparatedGuids");

            if (!commaSeparatedSearchTerms.IsNullOrEmpty())
            {
                ParameterExpression parameter = Expression.Parameter(typeof(Guid), "g");

                IEnumerable <string> guidStrings = commaSeparatedSearchTerms.Split(',');

                Expression body = null;

                foreach (string guidString in guidStrings)
                {
                    Guid temp = new Guid(guidString.Trim());

                    Expression part = Expression.Equal(parameter, Expression.Constant(temp));

                    body = body.NestedOr(part);
                }

                if (body != null)
                {
                    return(Expression.Lambda <Func <Guid, bool> >(body, parameter));
                }
            }

            return((Expression <Func <Guid, bool> >)(f => false));
        }
Example #6
0
        private IDictionary <string, object> parseParameters(FunctionContextContainer functionContextContainer)
        {
            var result = new Dictionary <string, object>();

            foreach (Param param in Parameters)
            {
                param.DataBind();

                object value;

                if (param.Controls.Count == 1 && param.Controls[0] is Function)
                {
                    var nestedFunction = param.Controls[0] as Function;

                    Type returnType;
                    value = nestedFunction.GetValue(functionContextContainer, out returnType);
                }
                else
                {
                    value = param.Value;
                }

                result.Add(param.Name, value);
            }

            return(result);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var httpContext = HttpContext.Current;

            if (httpContext?.Response == null)
            {
                return(null);
            }
            var cache = httpContext.Response.Cache;

            int maxSeconds = parameters.GetParameter <int>(ParameterName_MaxSeconds);

            if (maxSeconds <= 0)
            {
                cache.SetCacheability(HttpCacheability.NoCache);
                cache.SetNoServerCaching();
                cache.SetNoStore();
            }
            else
            {
                cache.SetExpires(DateTime.Now.AddSeconds(maxSeconds));
                cache.SetMaxAge(TimeSpan.FromSeconds(maxSeconds));
            }

            return(null);
        }
Example #8
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            /* viewContext is set by returning C1View... if this function is called without using a C1View
             * it will fallback to a normal route-based execution instead of a ChildAction */

            ViewContext viewContext = null;

            try
            {
                viewContext = (ViewContext)context.GetParameterValue("viewContext", typeof(ViewContext));
            }
            catch { }

            var routeValues = new Dictionary <string, object>();

            if (_modelType != null)
            {
                var model = Activator.CreateInstance(_modelType);

                foreach (var parameter in ParameterProfiles)
                {
                    var name  = parameter.Name;
                    var value = parameters.GetParameter(name);

                    _modelType.GetProperty(name).SetValue(model, value);
                }

                routeValues.Add("FunctionModel", model);
            }

            return(viewContext != null?ExecuteChildAction(routeValues, viewContext) : ExecuteDirectRoute(routeValues));
        }
Example #9
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            object valueA = parameters.GetParameter <object>("ValueA");
            object valueB = parameters.GetParameter <object>("ValueB");

            return(valueA.Equals(valueB));
        }
Example #10
0
 public override object Execute(ParameterList parameters, FunctionContextContainer context)
 {
     return(new TitleControl {
         PrefixToRemove = parameters.GetParameter <string>("PrefixToRemove"),
         PostfixToRemove = parameters.GetParameter <string>("PostfixToRemove")
     });
 }
        // IFunctionResultToXElementMapper
        public bool TryMakeXEmbedable(FunctionContextContainer contextContainer, object resultObject, out XNode resultElement)
        {
            var control = resultObject as Control;

            if (control == null)
            {
                resultElement = null;
                return(false);
            }

            string controlMarkerKey;

            lock (_controls)
            {
                controlMarkerKey = string.Format("[Composite.Function.Render.Asp.Net.Control.{0}]", _controls.Count);
                _controls.Add(controlMarkerKey, control);
            }

            resultElement =
                XElement.Parse(@"<c1marker:{0} xmlns:c1marker=""{1}"" key=""{2}"" />"
                               .FormatWith(_markerElementName.LocalName,
                                           _markerElementName.Namespace,
                                           controlMarkerKey));

            return(true);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            string valueToFind = parameters.GetParameter <string>("Value");
            Expression <Func <string, bool> > predicate = f => f.Contains(valueToFind);

            return(predicate);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            int value = parameters.GetParameter <int>("Value");
            Expression <Func <int, bool> > predicate = f => f == value;

            return(predicate);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            void SetParametersAction(WebPageBase webPageBase)
            {
                foreach (var param in parameters.AllParameterNames)
                {
                    var parameter = Parameters[param];

                    object parameterValue = parameters.GetParameter(param);

                    parameter.SetValue(webPageBase, parameterValue);
                }
            }

            try
            {
                return(RazorHelper.ExecuteRazorPage(VirtualPath, SetParametersAction, ReturnType, context));
            }
            catch (Exception ex)
            {
                EmbedExecutionExceptionSourceCode(ex);

                throw;
            }
        }
 public override object Execute(ParameterList parameters, FunctionContextContainer context)
 {
     return
         ($"{Constants.PageIdParamName}:\"{parameters.GetParameter<string>(Constants.PageIdParamName)}\";" +
          $"{Constants.TypeNameParamName}:\"{parameters.GetParameter<string>(Constants.TypeNameParamName)}\";" +
          $"{Constants.SitemapScopeIdParamName}:\"{parameters.GetParameter<int>(Constants.SitemapScopeIdParamName)}\";");
 }
Example #16
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            IEnumerable <string> strings = parameters.GetParameter <IEnumerable <string> >("Strings");
            string separator             = parameters.GetParameter <string>("Separator");

            return(string.Join(separator, strings.ToArray()));
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            if (!parameters.TryGetParameter <SitemapScope>(nameof(SitemapScope), out var sitemapScope))
            {
                sitemapScope = SitemapScope.Current;
            }

            var pageId = GetCurrentPageId();

            switch (sitemapScope)
            {
            case SitemapScope.Current:
                return(pageId);

            case SitemapScope.Parent:
            case SitemapScope.Level1:
            case SitemapScope.Level2:
            case SitemapScope.Level3:
            case SitemapScope.Level4:
                var pageIds = PageStructureInfo.GetAssociatedPageIds(pageId, sitemapScope);
                return(pageIds.FirstOrDefault());

            default:
                throw new NotImplementedException("Unhandled SitemapScope type: " + sitemapScope.ToString());
            }
        }
        /// <exclude />
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            EnsureUpdated();

            Dictionary <string, object> sqlParameters = new Dictionary <string, object>();

            foreach (ParameterProfile profile in ParameterProfiles)
            {
                object value = parameters.GetParameter(profile.Name);
                sqlParameters.Add(profile.Name, value);
            }

            ISqlConnection sqlConnection = GetConnection();

            string connectionString = sqlConnection.EncryptedConnectionString.Decrypt();

            Verify.That(!connectionString.IsNullOrEmpty(), "Connection string is empty");

            string result = null;

            if (sqlConnection.IsMsSql)
            {
                result = RunSequel(connectionString, sqlParameters);
            }
            else
            {
                result = RunOleDbSequel(connectionString, sqlParameters);
            }

            return(BuidlXElement(result));
        }
Example #19
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            decimal value = parameters.GetParameter <decimal>("Value");
            Expression <Func <decimal, bool> > predicate = f => f < value;

            return(predicate);
        }
 /// <summary>
 /// Executes the razor page.
 /// </summary>
 /// <typeparam name="ResultType">The result type.</typeparam>
 /// <param name="virtualPath">The virtual path.</param>
 /// <param name="setParameters">Delegate to set the parameters.</param>
 /// <param name="functionContextContainer">The function context container.</param>
 /// <returns></returns>
 public static ResultType ExecuteRazorPage<ResultType>(
     string virtualPath, 
     Action<WebPageBase> setParameters, 
     FunctionContextContainer functionContextContainer = null) where ResultType: class
 {
     return (ResultType) ExecuteRazorPage(virtualPath, setParameters, typeof(ResultType), functionContextContainer);
 }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var metaTags = new List <XElement>();

            string contentType   = parameters.GetParameter <string>("ContentType");
            string designer      = parameters.GetParameter <string>("Designer");
            bool   showGenerator = parameters.GetParameter <bool>("ShowGenerator");

            if (!string.IsNullOrWhiteSpace(contentType))
            {
                metaTags.Add(new XElement(Namespaces.Xhtml + "meta",
                                          new XAttribute("http-equiv", "Content-Type"),
                                          new XAttribute("content", contentType)));
            }

            if (!string.IsNullOrWhiteSpace(designer))
            {
                metaTags.Add(new XElement(Namespaces.Xhtml + "meta",
                                          new XAttribute("name", "Designer"),
                                          new XAttribute("content", designer)));
            }

            if (showGenerator)
            {
                metaTags.Add(new XElement(Namespaces.Xhtml + "meta",
                                          new XAttribute("name", "Generator"),
                                          new XAttribute("content", "C1 CMS Foundation - Free Open Source from Orckestra and https://github.com/Orckestra/CMS-Foundation")));
            }

            return(metaTags);
        }
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                string result = HttpContext.Current.Request.QueryString[parameters.GetParameter <string>("ParameterName")];

                if (result != null)
                {
                    switch (result.ToLowerInvariant())
                    {
                    case "0":
                    case "false":
                        return(false);

                    case "1":
                    case "true":
                        return(true);

                    default:
                        return(bool.Parse(result));
                    }
                }
            }

            return(parameters.GetParameter <bool>("FallbackValue"));
        }
Example #23
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            bool value = parameters.GetParameter <bool>("Value");
            Expression <Func <bool?, bool> > predicate = f => f.HasValue && f.Value == value;

            return(predicate);
        }
Example #24
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            DateTime value = parameters.GetParameter <DateTime>("Value");
            Expression <Func <DateTime, bool> > predicate = f => f > value;

            return(predicate);
        }
Example #25
0
        /// <exclude />
        public static Control Render(XDocument document, FunctionContextContainer contextContainer, IXElementToControlMapper mapper, IPage page)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                using (Profiler.Measure("Executing embedded functions"))
                {
                    ExecuteEmbeddedFunctions(document.Root, contextContainer);
                }

                using (Profiler.Measure("Resolving page fields"))
                {
                    ResolvePageFields(document, page);
                }

                using (Profiler.Measure("Normalizing ASP.NET forms"))
                {
                    NormalizeAspNetForms(document);
                }

                if (document.Root.Name != RenderingElementNames.Html)
                {
                    return(new LiteralControl(document.ToString()));
                }

                var xhtmlDocument = new XhtmlDocument(document);

                ProcessXhtmlDocument(xhtmlDocument, page);

                using (Profiler.Measure("Converting XHTML document into an ASP.NET control"))
                {
                    return(xhtmlDocument.AsAspNetControl(mapper));
                }
            }
        }
Example #26
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            IEnumerable elements          = parameters.GetParameter <IEnumerable>("Elements");
            string      keyPropertyName   = parameters.GetParameter <string>("KeyPropertyName");
            string      valuePropertyName = parameters.GetParameter <string>("ValuePropertyName");

            Dictionary <string, string> resultDictionary = new Dictionary <string, string>();

            PropertyInfo keyPropertyInfo   = null;
            PropertyInfo valuePropertyInfo = null;

            foreach (object element in elements)
            {
                if (keyPropertyInfo == null)
                {
                    keyPropertyInfo = element.GetType().GetProperty(keyPropertyName);
                }

                if (valuePropertyInfo == null)
                {
                    valuePropertyInfo = element.GetType().GetProperty(valuePropertyName);
                }

                string keyValue   = keyPropertyInfo.GetValue(element, null).ToString();
                string valueValue = valuePropertyInfo.GetValue(element, null).ToString();

                resultDictionary.Add(keyValue, valueValue);
            }

            return(resultDictionary);
        }
Example #27
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            string stringA   = parameters.GetParameter <string>("StringA");
            string stringB   = parameters.GetParameter <string>("StringB");
            string separator = parameters.GetParameter <string>("Separator");

            return(stringA + separator + stringB);
        }
 public override object Execute(ParameterList parameters, FunctionContextContainer context)
 {
     return(new XsltExtensionDefinition <MarkupParserXsltExtensions>
     {
         EntensionObject = new MarkupParserXsltExtensions(),
         ExtensionNamespace = "#MarkupParserExtensions"
     });
 }
Example #29
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            var result = new List <FormEmail>();

            result.AddRange(parameters.GetParameter <IEnumerable <FormEmail> >("EmailA"));
            result.AddRange(parameters.GetParameter <IEnumerable <FormEmail> >("EmailB"));
            return(result);
        }
Example #30
0
 /// <summary>
 /// Executes all cacheable (not dynamic) functions and returns <value>True</value>
 /// if all of the functions were cacheable.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="functionContext"></param>
 /// <returns></returns>
 internal static bool ExecuteCacheableFunctions(XElement element, FunctionContextContainer functionContext)
 {
     return(ExecuteFunctionsRec(element, functionContext, name =>
     {
         var function = FunctionFacade.GetFunction(name);
         return !(function is IDynamicFunction df && df.PreventFunctionOutputCaching);
     }));
 }
Example #31
0
        public virtual object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            IList<object> arguments = new List<object>();
            foreach (ParameterProfile paramProfile in ParameterProfiles)
            {
                arguments.Add(parameters.GetParameter(paramProfile.Name, paramProfile.Type));
            }

            return this.MethodInfo.Invoke(null, arguments.ToArray());
        }
Example #32
0
        public override object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            if (_notLoadedInlineFunction != null)
            {
                return (_notLoadedInlineFunction as IFunction).Execute(parameters, context);
            }

            return base.Execute(parameters, context);
        }
        object IFunction.Execute(ParameterList parameters, FunctionContextContainer context)
        {
            if (_errors.CompileErrors.Count > 0)
            {
                var error = _errors.CompileErrors[0];
                var exception = new InvalidOperationException("{1} Line {0}: {2}".FormatWith(error.Item1, error.Item2, error.Item3));

                if (_sourceCode == null)
                {
                    string filepath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory), _function.CodePath);

                    if (C1File.Exists(filepath))
                    {
                        _sourceCode = C1File.ReadAllLines(filepath);
                    }
                    else
                    {
                        _sourceCode = new string[0];
                    }
                }

                if (_sourceCode.Length > 0)
                {
                    XhtmlErrorFormatter.EmbedSourceCodeInformation(exception, _sourceCode, error.Item1);
                }

                throw exception;
            }

            if (_errors.LoadingException != null)
            {
                throw _errors.LoadingException;
            }

            throw new InvalidOperationException("Function wasn't loaded due to compilation errors");
        }
Example #34
0
        public object Execute(ParameterList parameters, FunctionContextContainer context)
        {
            try
            {
                var dynamicMethod = DynamicMethodHelper.GetDynamicMethod("<C1 function> " + _functionToWrap.CompositeName());

                return dynamicMethod(() => _functionToWrap.Execute(parameters, context));
            }
            catch (Exception ex)
            {
                if (_functionToWrap.ReturnType == typeof(XhtmlDocument))
                {
                    XElement errorBoxHtml;
                    if (context.ProcessException(_functionToWrap.CompositeName(), ex, LogTitle, out errorBoxHtml))
                    {
                        XhtmlDocument errorInfoDocument = new XhtmlDocument();
                        errorInfoDocument.Body.Add(errorBoxHtml);
                        return errorInfoDocument;
                    }
                }

                throw;
            }
        }