Beispiel #1
0
        }         // func GetStringArray

        private async Task OpenCursorAsync(LuaTable table)
        {
            // not optional
            var selectExpression = table.GetOptionalValue("name", (string)null) ?? throw new ArgumentNullException("name");

            // parse selector
            var selectorExpression = PpsDataFilterExpression.Parse(table.GetMemberValue("filter"));

            // parse optional columns
            var columns = PpsDataColumnExpression.Parse(table.GetMemberValue("columns")).ToArray();

            // parse optional order
            var orderExpressions = PpsDataOrderExpression.Parse(table.GetMemberValue("order")).ToArray();

            // try to get a list
            int cursorId;

            lock (cursors)
                cursorId = ++lastCursorId;

            var cursor = new OpenCursor(cursorId, await provider.GetListAsync(selectExpression, columns, selectorExpression, orderExpressions));

            lock (cursors)
                cursors.Add(cursorId, cursor);

            // return the cursor id
            await PushPacketAsync(new LuaTable()
            {
                ["id"] = cursorId
            });
        }         // proc OpenCursorAsync
Beispiel #2
0
        }         // ctor

        private StringBuilder ToString(StringBuilder sb)
        {
            sb.Append("v=");
            sb.Append(ViewId);

            if (Filter != null && Filter != PpsDataFilterExpression.True)
            {
                sb.Append("&f=").Append(Uri.EscapeDataString(Filter.ToString()));
            }
            if (Columns != null && Columns.Length > 0)
            {
                sb.Append("&r=").Append(PpsDataColumnExpression.ToString(Columns));
            }
            if (Order != null && Order.Length > 0)
            {
                sb.Append("&o=").Append(Uri.EscapeDataString(PpsDataOrderExpression.ToString(Order)));
            }
            if (Start != -1)
            {
                sb.Append("&s=").Append(Start);
            }
            if (Count != -1)
            {
                sb.Append("&c=").Append(Count);
            }
            if (!String.IsNullOrEmpty(AttributeSelector))
            {
                sb.Append("&a=").Append(AttributeSelector);
            }

            return(sb);
        }         // func ToString
Beispiel #3
0
        /// <summary>Parse string representation from ToString.</summary>
        /// <param name="data"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public static bool TryParse(string data, out PpsDataQuery list)
        {
            var arguments = HttpUtility.ParseQueryString(data, Encoding.UTF8);
            var viewId    = arguments["v"];

            if (String.IsNullOrEmpty(viewId))
            {
                list = null;
                return(false);
            }

            list = new PpsDataQuery(viewId);

            var f = arguments["f"];

            if (!String.IsNullOrEmpty(f))
            {
                list.Filter = PpsDataFilterExpression.Parse(f);
            }

            var l = arguments["l"];

            if (!String.IsNullOrEmpty(l))
            {
                list.Columns = PpsDataColumnExpression.Parse(l).ToArray();
            }

            var o = arguments["o"];

            if (!String.IsNullOrEmpty(o))
            {
                list.Order = PpsDataOrderExpression.Parse(o).ToArray();
            }

            var s = arguments["s"];

            if (!String.IsNullOrEmpty(s))
            {
                list.Start = Int32.Parse(s);
            }
            var c = arguments["c"];

            if (!String.IsNullOrEmpty(c))
            {
                list.Count = Int32.Parse(c);
            }

            var a = arguments["a"];

            if (!String.IsNullOrEmpty(a))
            {
                list.AttributeSelector = a;
            }

            return(true);
        }         // func TryParse
Beispiel #4
0
            }             // func CreateSelectorAsync

            /// <summary>Create a selector from a select information.</summary>
            /// <param name="select"></param>
            /// <param name="columns"></param>
            /// <param name="filter"></param>
            /// <param name="order"></param>
            /// <param name="throwException"></param>
            /// <returns></returns>
            public async Task <PpsDataSelector> CreateSelectorAsync(string select, PpsDataColumnExpression[] columns, PpsDataFilterExpression filter = null, PpsDataOrderExpression[] order = null, bool throwException = true)
            {
                if (String.IsNullOrEmpty(select))
                {
                    throw new ArgumentNullException(nameof(select));
                }

                // create selector
                var selectorInfo = new PpsViewJoinExpression(this, select, throwException);

                if (!selectorInfo.IsValid && !throwException)
                {
                    return(null);
                }

                // create selector
                var selector = await selectorInfo.CreateSelectorAsync();

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

                // column restrictions
                if (!PpsDataColumnExpression.IsEmpty(columns))
                {
                    selector = selector.ApplyColumns(columns);
                }

                // apply filter rules
                if (!PpsDataFilterExpression.IsEmpty(filter))
                {
                    selector = selector.ApplyFilter(filter, selectorInfo.LookupFilter);
                }

                // apply order
                if (!PpsDataOrderExpression.IsEmpty(order))
                {
                    selector = selector.ApplyOrder(order, selectorInfo.LookupOrder);
                }

                return(selector);
            }             // func CreateSelector