Example #1
2
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || (parameters.Length < 2 || parameters.Length > 3))
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 2 or 3 parameters.", markup);

            // text field to bind to
            // selected value

            // text field to bind to
            // value field to bind to
            // selected value

            if (obj == null)
                return null;

            if (obj.GetType().GetInterface("IEnumerable") != null) {

                IReflector reflector = new Reflector();

                bool textOnly = parameters.Length == 2;
                string textField = parameters[0];
                string selectedField = textOnly ? parameters[1] : parameters[2];

                StringBuilder optionBuilder = new StringBuilder();
                IEnumerator en = ((IEnumerable) obj).GetEnumerator();

                // &#34; for quotes
                // &#39; for apostrophes

                // lookup the selected value
                object selectedObject = bag == null ? null : reflector.Eval(bag, selectedField);
                string selectedValue = selectedObject != null ? selectedObject.ToString() : null;

                if (textOnly) {
                    while (en.MoveNext()) {
                        object current = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null ? textObject.ToString() : null;
                        string selected = (textString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option{1}>{0}</option>", textString, selected);
                    }
                } else {
                    string valueField = parameters[1];

                    while(en.MoveNext()) {
                        object current = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null ? textObject.ToString() : null;
                        object valueObject = reflector.Eval(current, valueField);
                        string valueString = valueObject != null ? valueObject.ToString() : null;

                        string selected = (valueString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option value=\"{0}\"{2}>{1}</option>", valueString, textString, selected);
                    }
                }
                return optionBuilder.ToString();
            }

            return null;
        }
        protected ImpressionExceptionBase(string message, IMarkupBase markupBase)
            : this(message,
				markupBase != null ? markupBase.Markup : null,
				markupBase != null ? markupBase.LineNumber : -1,
			markupBase != null ? markupBase.CharPos : -1)
        {
        }
Example #3
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            string dateFormat = null;

            if (parameters != null && parameters.Length > 1)
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept more than one parameter.");

            if (parameters == null || parameters.Length == 0)
                dateFormat = ImpressionEngine.DateFormat;
            else
                dateFormat = IsLiteral(parameters[0])
                    ? GetLiteral(parameters[0])
                    : bag[parameters[0]].ToString();

            if (obj != null) {
                if (obj is DateTime) {
                    obj = ((DateTime)obj).ToString(dateFormat);
                }
                else {
                    DateTime val;
                    if (DateTime.TryParse(obj.ToString(), out val)) {
                        obj = val.ToString(dateFormat);
                    }
                }
            }
            return obj;
        }
Example #4
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");

            if (obj == null)
            {
                obj = 0.0;
            }

            double val = 0;
            string valString = obj.ToString();
            if (Double.TryParse(valString, out val))
            {
                int pointIndex = valString.IndexOf('.');
                if (pointIndex >= 0)
                {
                    string subs = valString.Substring(pointIndex + 1, valString.Length - (pointIndex + 1));
                    if (subs.Length > 2)
                    {
                        obj = subs.Substring(0, 2);
                    } else
                    {
                        obj = subs.PadRight(2, '0');
                    }
                } else
                {
                    obj = "00";
                }
            }

            return obj;
        }
Example #5
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Formatter " + Keyword + " cannot be used with parameters.", markup);

            return (obj != null ? obj.ToString().Trim() : obj);
        }
Example #6
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");
            }

            if (obj == null)
            {
                obj = 0.0;
            }

            double val = 0;

            if (Double.TryParse(obj.ToString(), out val))
            {
                string moneyFormat = ImpressionEngine.MoneyFormat;

                string symbol   = bag != null ? bag["Money.Symbol"] as string : null;
                string currency = bag != null ? bag["Money.Currency"] as string: null;
                obj = (symbol ?? "") + val.ToString(moneyFormat) + (!string.IsNullOrEmpty(currency) ? " " + currency : "");
            }

            return(obj);
        }
Example #7
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);

            return !AsBoolean(obj);
        }
 protected ImpressionExceptionBase(string message, IMarkupBase markupBase)
     : this(
         message,
         markupBase != null ? markupBase.Markup : null,
         markupBase != null ? markupBase.LineNumber : -1,
         markupBase != null ? markupBase.CharPos : -1)
 {
 }
Example #9
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            return(Count(obj));
        }
Example #10
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Formatter " + Keyword + " cannot be used with parameters.", markup);
            }

            return(obj != null ? obj.ToString().ToLower() : obj);
        }
Example #11
0
 public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
 {
     return base.Run(
         obj,
         new [] {"'" + ImpressionEngine.DateTimeFormat + "'" },
         bag,
         markup
     );
 }
Example #12
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " expects one parameter.");

            if (obj == null)
                return null;

            return Join(obj, parameters[0]);
        }
Example #13
0
        public virtual object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept parameters.");

            if (obj != null)
            {
                obj = Regex.Replace(obj.ToString(), @"<(.|\r|\n)*?>", string.Empty);
            }
            return obj;
        }
Example #14
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Formatter " + Keyword + " cannot be used with parameters.", markup);

            // make sure the obj is not null
            if (obj != null)
                obj = HttpUtility.UrlEncode(obj.ToString());

            return obj;
        }
Example #15
0
        virtual public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept parameters.");
            }

            if (obj != null)
            {
                obj = obj.ToString().Replace("\n", "").Replace("\r", "");
            }
            return(obj);
        }
Example #16
0
        virtual public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept parameters.");
            }

            if (obj != null)
            {
                string text = obj.ToString();

                // firstly encode any special characters for html
                string newtext = HttpUtility.HtmlEncode(text);

                // be friendly with newlines from different platforms
                newtext = newtext.Replace("\r\n", "\n");
                newtext = newtext.Replace("\r", "\n");

                // split double \n into paragraphs
                string[] paragraphs = newtext.Split(
                    new[] { "\n\n" },
                    StringSplitOptions.RemoveEmptyEntries
                    );

                // clean up whitespace on each paragraph
                for (int i = 0, len = paragraphs.Length; i < len; i++)
                {
                    paragraphs[i] = paragraphs[i].Trim();
                }

                // if there is actually some content
                if (paragraphs.Length > 0)
                {
                    // wrap paragraphs in html p tags
                    newtext = "<p>" + string.Join(
                        "</p><p>",
                        paragraphs
                        ) + "</p>";

                    // replace existing single \n within paragraphs with link breaks
                    newtext = newtext.Replace("\n", "<br />");
                }
                else
                {
                    newtext = null;
                }

                return(newtext);
            }
            return(obj);
        }
Example #17
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);

            bool hasValue = (obj is string && !string.IsNullOrEmpty((string)obj)) || (obj != null);

            if (!hasValue)
            {
                return true;
            }

            return obj;
        }
Example #18
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Formatter " + Keyword + " cannot be used with parameters.", markup);
            }

            // make sure the obj is not null
            if (obj != null)
            {
                obj = HttpUtility.UrlEncode(obj.ToString());
            }

            return(obj);
        }
Example #19
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
            {
                throw new ImpressionParseException("default expects 1 parameter", markup);
            }

            bool hasValue = (obj is string && !string.IsNullOrEmpty((string)obj)) || (obj != null);

            return !hasValue
                ? (IsLiteral(parameters[0])
                    ? GetLiteral(parameters[0])
                    : bag[parameters[0]])
                : obj;
        }
Example #20
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            var list = obj as ModelListWithPages;

            if (list == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            if (list.CurrentPage.First)
            {
                sb.Append("<span class=\"page first disabled\">First</span>");
                sb.Append("<span class=\"page prev disabled\">Prev</span>");
            }
            else
            {
                sb.AppendFormat("<a href=\"{0}\" class=\"page first\">First</a>", list.FirstPage.Url);
                sb.AppendFormat("<a href=\"{0}\" class=\"page prev\">Prev</a>", list.PrevPage.Url);
            }

            foreach (var page in list.Pages)
            {
                if (page.Current)
                {
                    sb.AppendFormat("<span class=\"page current\">{0}</span>", page.Number);
                }
                else
                {
                    sb.AppendFormat("<a href=\"{0}\" class=\"page\">{1}</a>", page.Url, page.Number);
                }
            }

            if (list.CurrentPage.Last)
            {
                sb.Append("<span class=\"page next disabled\">Next</span>");
                sb.Append("<span class=\"page last disabled\">Last</span>");
            }
            else
            {
                sb.AppendFormat("<a href=\"{0}\" class=\"page next\">Next</a>", list.NextPage.Url);
                sb.AppendFormat("<a href=\"{0}\" class=\"page last\">Last</a>", list.LastPage.Url);
            }

            return(sb.ToString());
        }
Example #21
0
        public object RunFilters(object obj, string[] filterTexts, IPropertyBag bag, IMarkupBase markup)
        {
            foreach (string filterText in filterTexts)
            {
                string[] parameters = null;
                string keyword = ParseParameterizedFilter(filterText, out parameters);

                IFilter filter = formatterCache.Get(keyword);
                //if (filter == null)
                //    throw new ImpressionInterpretException("Unsupported filter detected, " + filterText, markup);

                if (filter != null)
                    obj = filter.Run(obj, parameters, bag, markup);

            }
            return obj;
        }
Example #22
0
        public virtual object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept parameters.");

            if (obj != null) {

                string text = obj.ToString();

                // firstly encode any special characters for html
                string newtext = HttpUtility.HtmlEncode(text);

                // be friendly with newlines from different platforms
                newtext = newtext.Replace("\r\n", "\n");
                newtext = newtext.Replace("\r", "\n");

                // split double \n into paragraphs
                string[] paragraphs = newtext.Split(
                    new[] { "\n\n" },
                    StringSplitOptions.RemoveEmptyEntries
                );

                // clean up whitespace on each paragraph
                for (int i = 0, len = paragraphs.Length; i < len; i++)
                    paragraphs[i] = paragraphs[i].Trim();

                // if there is actually some content
                if (paragraphs.Length > 0) {
                    // wrap paragraphs in html p tags
                    newtext = "<p>" + string.Join(
                        "</p><p>",
                        paragraphs
                    ) + "</p>";

                    // replace existing single \n within paragraphs with link breaks
                    newtext = newtext.Replace("\n", "<br />");
                }
                else {
                    newtext = null;
                }

                return newtext;
            }
            return obj;
        }
Example #23
0
        public object RunFilters(object obj, string[] filterTexts, IPropertyBag bag, IMarkupBase markup)
        {
            foreach (string filterText in filterTexts)
            {
                string[] parameters = null;
                string   keyword    = ParseParameterizedFilter(filterText, out parameters);

                IFilter filter = formatterCache.Get(keyword);
                //if (filter == null)
                //    throw new ImpressionInterpretException("Unsupported filter detected, " + filterText, markup);

                if (filter != null)
                {
                    obj = filter.Run(obj, parameters, bag, markup);
                }
            }
            return(obj);
        }
Example #24
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");

            if (obj == null)
            {
                obj = 0.0;
            }

            double val = 0;
            string valString = obj.ToString();
            if (Double.TryParse(valString, out val))
            {
                int pointIndex = valString.IndexOf('.');
                obj = pointIndex >= 0 ? valString.Substring(0, pointIndex) : valString;
            }

            return obj;
        }
Example #25
0
        virtual public object Run(object obj, string[] paramaters, IPropertyBag bag, IMarkupBase markup)
        {
            //TODO read the number of characters from the first parameter

            string s = (obj != null) ? obj.ToString() : null;

            if (!string.IsNullOrEmpty(s))
            {
                string[] words = s.Split(new[] { " " }, StringSplitOptions.None);

                bool truncated = false;
                if (words.Length > 200)
                {
                    truncated = true;
                    words     = new List <string>(words).GetRange(0, 200).ToArray();
                }
                obj = string.Join(" ", words) + (truncated ? "..." : "");
            }
            return(obj);
        }
Example #26
0
        virtual public object Run(object obj, string[] paramaters, IPropertyBag bag, IMarkupBase markup)
        {
            //TODO read the number of characters from the first parameter

            string s = (obj != null) ? obj.ToString() : null;

            if (!string.IsNullOrEmpty(s))
            {
                string[] words = s.Split(new[] { " " }, StringSplitOptions.None);

                bool     truncated   = false;
                string[] subsetWords = new string[200];
                if (words.Length > 200)
                {
                    truncated = true;
                    words.CopyTo(subsetWords, 0);
                }
                s = string.Join(" ", words) + (truncated ? "..." : "");
            }
            return(s);
        }
Example #27
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);

            if (obj == null)
                return false;

            bool isEmpty = true;
            if (obj is string && !string.IsNullOrEmpty((string)obj)) {
                isEmpty = false;
            } else {
                if (obj is IEnumerable) {
                    var en = (obj as IEnumerable).GetEnumerator();
                    isEmpty = !en.MoveNext();
                } else {
                    isEmpty = false;
                }
            }

            return !isEmpty;
        }
Example #28
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");
            }

            if (obj == null)
            {
                obj = 0.0;
            }

            double val = 0;

            if (Double.TryParse(obj.ToString(), out val))
            {
                string moneyFormat = ImpressionEngine.MoneyFormat;
                obj = val.ToString(moneyFormat);
            }

            return(obj);
        }
Example #29
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");
            }

            if (obj == null)
            {
                obj = 0.0;
            }

            double val       = 0;
            string valString = obj.ToString();

            if (Double.TryParse(valString, out val))
            {
                int pointIndex = valString.IndexOf('.');
                if (pointIndex >= 0)
                {
                    string subs = valString.Substring(pointIndex + 1, valString.Length - (pointIndex + 1));
                    if (subs.Length > 2)
                    {
                        obj = subs.Substring(0, 2);
                    }
                    else
                    {
                        obj = subs.PadRight(2, '0');
                    }
                }
                else
                {
                    obj = "00";
                }
            }

            return(obj);
        }
Example #30
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 2)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 2 parameters", markup);
            }

            bool isTrue = AsBoolean(obj);

            int index = isTrue ? 0 : 1;

            if (IsLiteral(parameters[index]))
            {
                obj = GetLiteral(parameters[index]);
            }
            else
            {
                // lookup property on the bag
                obj = bag[parameters[index]];
            }

            return obj;
        }
Example #31
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");
            }

            if (obj == null)
            {
                obj = 0.0;
            }

            double val       = 0;
            string valString = obj.ToString();

            if (Double.TryParse(valString, out val))
            {
                int pointIndex = valString.IndexOf('.');
                obj = pointIndex >= 0 ? valString.Substring(0, pointIndex) : valString;
            }

            return(obj);
        }
Example #32
0
        override public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            string dateFormat = null;

            if (parameters != null && parameters.Length > 1)
            {
                throw new ImpressionInterpretException("Formatter " + Keyword + " does not accept more than one parameter.");
            }

            if (parameters == null || parameters.Length == 0)
            {
                dateFormat = ImpressionEngine.DateFormat;
            }
            else
            {
                dateFormat = IsLiteral(parameters[0])
                                        ? GetLiteral(parameters[0])
                                        : bag[parameters[0]].ToString();
            }

            if (obj != null)
            {
                if (obj is DateTime)
                {
                    obj = ((DateTime)obj).ToString(dateFormat);
                }
                else
                {
                    DateTime val;
                    if (DateTime.TryParse(obj.ToString(), out val))
                    {
                        obj = val.ToString(dateFormat);
                    }
                }
            }
            return(obj);
        }
 public ImpressionParseException(string message, IMarkupBase markupBase)
     : base(message, markupBase)
 {
 }
Example #34
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 2)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 2 parameters", markup);
            }

            bool isTrue = AsBoolean(obj);

            int index = isTrue ? 0 : 1;

            if (IsLiteral(parameters[index]))
            {
                obj = GetLiteral(parameters[index]);
            }
            else
            {
                // lookup property on the bag
                obj = bag[parameters[index]];
            }

            return(obj);
        }
 public ImpressionParseException(string message, IMarkupBase markupBase) : base(message, markupBase)
 {
 }
Example #36
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || (parameters.Length < 2 || parameters.Length > 3))
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 2 or 3 parameters.", markup);
            }

            // text field to bind to
            // selected value

            // text field to bind to
            // value field to bind to
            // selected value

            if (obj == null)
            {
                return(null);
            }

            if (obj.GetType().GetInterface("IEnumerable") != null)
            {
                IReflector reflector = new Reflector();

                bool   textOnly      = parameters.Length == 2;
                string textField     = parameters[0];
                string selectedField = textOnly ? parameters[1] : parameters[2];

                StringBuilder optionBuilder = new StringBuilder();
                IEnumerator   en            = ((IEnumerable)obj).GetEnumerator();

                // &#34; for quotes
                // &#39; for apostrophes

                // lookup the selected value
                object selectedObject = bag == null ? null : reflector.Eval(bag, selectedField);
                string selectedValue  = selectedObject != null?selectedObject.ToString() : null;

                if (textOnly)
                {
                    while (en.MoveNext())
                    {
                        object current    = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null?textObject.ToString() : null;

                        string selected = (textString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option{1}>{0}</option>", textString, selected);
                    }
                }
                else
                {
                    string valueField = parameters[1];

                    while (en.MoveNext())
                    {
                        object current    = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null?textObject.ToString() : null;

                        object valueObject = reflector.Eval(current, valueField);
                        string valueString = valueObject != null?valueObject.ToString() : null;

                        string selected = (valueString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option value=\"{0}\"{2}>{1}</option>", valueString, textString, selected);
                    }
                }
                return(optionBuilder.ToString());
            }

            return(null);
        }
Example #37
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            if (obj == null)
            {
                return(null);
            }

            if (obj is string)
            {
                return(obj);
            }

            if (obj is IEnumerable)
            {
                return(Random((IEnumerable)obj));
            }

            return(Random(obj));
        }
Example #38
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 1 parameter.");

            var enumerable = obj as IEnumerable;
            if (enumerable == null)
                return null;

            int pageNumber = 1;
            object pageNumberObject = bag["Page.Number"];
            if (pageNumberObject != null) {
                Int32.TryParse(pageNumberObject.ToString(), out pageNumber);
                if (pageNumber < 1)
                    pageNumber = 1;
            }

            int pageSize = 12;
            string pageSizeString = parameters[0];
            object pageSizeObject = bag["Page.Size"];
            if (pageSizeObject != null) {
                pageSizeString = pageSizeObject.ToString();
            }
            Int32.TryParse(pageSizeString, out pageSize);
            if (pageSize < 1)
                pageSize = 12;

            int i = 0, start = (pageNumber - 1)*pageSize, end = (pageNumber*pageSize)-1;
            var list = new ModelListWithPages(pageSize);

            // add the "paged" items
            foreach(var item in enumerable) {
                if (i >= start && i <= end)
                        list.Add(item);

                i++;
            }

            // add the pages
            var totalPages = (int)Math.Ceiling(i / (double)pageSize);
            var totalPages0 = totalPages - 1;
            var pageNumber0 = pageNumber - 1;
            for (i = 0; i < totalPages; i++) {
                list.Pages.Add( new PageModel {
                    Current = (i == pageNumber0),
                    First = (i == 0),
                    Last = (i == (totalPages0)),
                    Number = (i+1),
                    Url = "?page=" + (i+1)
                } );
            }

            list.FirstPage = list.Pages[0];
            list.PrevPage = pageNumber != 1 ? list.Pages[pageNumber0-1]: null;
            list.CurrentPage = list.Pages[pageNumber0];
            list.NextPage = pageNumber != totalPages ? list.Pages[pageNumber]: null;
            list.LastPage = list.Pages[totalPages0];

            return list;
        }
Example #39
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            bool hasValue = (obj is string && !string.IsNullOrEmpty((string)obj)) || (obj != null);

            if (!hasValue)
            {
                return(true);
            }

            return(obj);
        }
Example #40
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            if (obj == null)
            {
                return(false);
            }

            bool isEmpty = true;

            if (obj is string && !string.IsNullOrEmpty((string)obj))
            {
                isEmpty = false;
            }
            else
            {
                if (obj is IEnumerable)
                {
                    var en = (obj as IEnumerable).GetEnumerator();
                    isEmpty = !en.MoveNext();
                }
                else
                {
                    isEmpty = false;
                }
            }

            return(!isEmpty);
        }
Example #41
0
        public virtual object Run(object obj, string[] paramaters, IPropertyBag bag, IMarkupBase markup)
        {
            //TODO read the number of characters from the first parameter

            string s = (obj != null) ? obj.ToString() : null;
            if (!string.IsNullOrEmpty(s)) {
                string[] words = s.Split(new[] { " " }, StringSplitOptions.None);

                bool truncated = false;
                if (words.Length > 200) {
                    truncated = true;
                    words = new List<string>(words).GetRange(0, 200).ToArray();
                }
                obj = string.Join(" ", words) + (truncated ? "..." : "");
            }
            return obj;
        }
Example #42
0
 public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
 {
     return(base.Run(
                obj,
                new [] { "'" + ImpressionEngine.DateTimeFormat + "'" },
                bag,
                markup
                ));
 }
Example #43
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");

            if (obj == null) {
                obj = 0.0;
            }

            double val = 0;
            if (Double.TryParse(obj.ToString(), out val)) {

                string moneyFormat = ImpressionEngine.MoneyFormat;

                string symbol = bag != null ? bag["Money.Symbol"] as string : null;
                string currency = bag != null ? bag["Money.Currency"] as string: null;
                obj = (symbol ?? "") + val.ToString(moneyFormat) + (!string.IsNullOrEmpty(currency) ? " " + currency : "");
            }

            return obj;
        }
Example #44
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 1)
                throw new ImpressionInterpretException("Filter " + Keyword + " does not accept parameters.");

            if (obj == null) {
                obj = 0.0;
            }

            double val = 0;
            if (Double.TryParse(obj.ToString(), out val)) {
                string moneyFormat = ImpressionEngine.MoneyFormat;
                obj = val.ToString(moneyFormat);
            }

            return obj;
        }
Example #45
0
        public virtual object Run(object obj, string[] paramaters, IPropertyBag bag, IMarkupBase markup)
        {
            //TODO read the number of characters from the first parameter

            string s = (obj != null) ? obj.ToString() : null;
            if (!string.IsNullOrEmpty(s)) {
                string[] words = s.Split(new[] { " " }, StringSplitOptions.None);

                bool truncated = false;
                string[] subsetWords = new string[200];
                if (words.Length > 200) {
                    truncated = true;
                    words.CopyTo(subsetWords, 0);
                }
                s = string.Join(" ", words) + (truncated ? "..." : "");
            }
            return s;
        }
Example #46
0
 public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
 {
     return(base.Run(
                obj,
                parameters != null && parameters.Length == 0
                                 ? parameters
                                 : new[] { ImpressionEngine.LongDateTimeFormat },
                bag,
                markup
                ));
 }
Example #47
0
 public abstract object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup);
Example #48
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
            {
                throw new ImpressionParseException("default expects 1 parameter", markup);
            }

            bool hasValue = (obj is string && !string.IsNullOrEmpty((string)obj)) || (obj != null);

            return(!hasValue
                                ? (IsLiteral(parameters[0])
                                        ? GetLiteral(parameters[0])
                                        : bag[parameters[0]])
                                : obj);
        }
Example #49
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            return(AsBoolean(obj) ? "checked=\"checked\"" : "");
        }
Example #50
0
 public abstract object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup);
 public ImpressionInterpretException(string message, IMarkupBase markupBase)
     : base(message, markupBase)
 {
 }
Example #52
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            var list = obj as ModelListWithPages;

            if (list == null)
                return null;

            StringBuilder sb = new StringBuilder();

            if (list.CurrentPage.First) {
                sb.Append("<span class=\"page first disabled\">First</span>");
                sb.Append("<span class=\"page prev disabled\">Prev</span>");
            } else {
                sb.AppendFormat("<a href=\"{0}\" class=\"page first\">First</a>", list.FirstPage.Url);
                sb.AppendFormat("<a href=\"{0}\" class=\"page prev\">Prev</a>", list.PrevPage.Url);
            }

            foreach (var page in list.Pages) {
                if (page.Current) {
                    sb.AppendFormat("<span class=\"page current\">{0}</span>", page.Number);
                }
                else {
                    sb.AppendFormat("<a href=\"{0}\" class=\"page\">{1}</a>", page.Url, page.Number);
                }
            }

            if (list.CurrentPage.Last) {
                sb.Append("<span class=\"page next disabled\">Next</span>");
                sb.Append("<span class=\"page last disabled\">Last</span>");
            } else {
                sb.AppendFormat("<a href=\"{0}\" class=\"page next\">Next</a>", list.NextPage.Url);
                sb.AppendFormat("<a href=\"{0}\" class=\"page last\">Last</a>", list.LastPage.Url);
            }

            return sb.ToString();
        }
Example #53
0
 public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
 {
     return base.Run(
         obj,
         parameters != null && parameters.Length == 0
             ? parameters
             : new[] { ImpressionEngine.LongDateFormat },
         bag,
         markup
     );
 }
Example #54
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters != null && parameters.Length > 0)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " cannot be used with parameters.", markup);
            }

            if (obj is string)
            {
                return(Shuffle(obj as string));
            }

            //if (obj is IEnumerable && obj.GetType().IsGenericType)
            //{

            //}
            //    return Shuffle(obj);

            if (obj is IEnumerable)
            {
                return(Shuffle(obj as IEnumerable));
            }

            if (obj is IEnumerable)
            {
                return(Shuffle(obj as IEnumerable));
            }

            return(Shuffle(obj));
        }
Example #55
0
        public object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 1 parameter.");
            }

            var enumerable = obj as IEnumerable;

            if (enumerable == null)
            {
                return(null);
            }

            int    pageNumber       = 1;
            object pageNumberObject = bag["Page.Number"];

            if (pageNumberObject != null)
            {
                Int32.TryParse(pageNumberObject.ToString(), out pageNumber);
                if (pageNumber < 1)
                {
                    pageNumber = 1;
                }
            }

            int    pageSize       = 12;
            string pageSizeString = parameters[0];
            object pageSizeObject = bag["Page.Size"];

            if (pageSizeObject != null)
            {
                pageSizeString = pageSizeObject.ToString();
            }
            Int32.TryParse(pageSizeString, out pageSize);
            if (pageSize < 1)
            {
                pageSize = 12;
            }

            int i = 0, start = (pageNumber - 1) * pageSize, end = (pageNumber * pageSize) - 1;
            var list = new ModelListWithPages(pageSize);

            // add the "paged" items
            foreach (var item in enumerable)
            {
                if (i >= start && i <= end)
                {
                    list.Add(item);
                }

                i++;
            }

            // add the pages
            var totalPages  = (int)Math.Ceiling(i / (double)pageSize);
            var totalPages0 = totalPages - 1;
            var pageNumber0 = pageNumber - 1;

            for (i = 0; i < totalPages; i++)
            {
                list.Pages.Add(new PageModel {
                    Current = (i == pageNumber0),
                    First   = (i == 0),
                    Last    = (i == (totalPages0)),
                    Number  = (i + 1),
                    Url     = "?page=" + (i + 1)
                });
            }

            list.FirstPage   = list.Pages[0];
            list.PrevPage    = pageNumber != 1 ? list.Pages[pageNumber0 - 1]: null;
            list.CurrentPage = list.Pages[pageNumber0];
            list.NextPage    = pageNumber != totalPages ? list.Pages[pageNumber]: null;
            list.LastPage    = list.Pages[totalPages0];

            return(list);
        }
Example #56
0
        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || parameters.Length != 1)
            {
                throw new ImpressionInterpretException("Filter " + Keyword + " expects one parameter.");
            }

            if (obj == null)
            {
                return(null);
            }

            return(Join(obj, parameters[0]));
        }
 public ImpressionInterpretException(string message, IMarkupBase markupBase) : base(message, markupBase)
 {
 }